]> git.donarmstrong.com Git - infobot.git/commitdiff
- now support verstats for those who don't reply to "CTCP VERSION
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 29 Dec 2001 12:26:55 +0000 (12:26 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 29 Dec 2001 12:26:55 +0000 (12:26 +0000)
  #channel" but "CTCP VERSION $nick".
  there's a max of 5*30/3 nicks unless we change verstats_flush.
- status() now supports a hack'ish hook to debug %channels (that is,
  ircCheck())
- if ignoreCheck hasn't been run in more than 60 seconds and we have a
  possible ignore match, run it.  unfortunately, the first message will
  be ignored if the removed entry matches the person asking the bot.

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@536 c11ca15a-4712-0410-83d8-924469b57eb5

src/CommandStubs.pl
src/IRC/IrcHelpers.pl
src/IRC/IrcHooks.pl
src/IRC/Schedulers.pl
src/core.pl
src/logger.pl
src/modules.pl

index e3586e01cddd7700ce3d892d8747e71f2af4374a..520e326b743cd2da836b0b1c9c181a83ddc637e2 100644 (file)
@@ -803,6 +803,17 @@ sub do_verstats {
     $cache{verstats}{who}      = $who;
     $cache{verstats}{msgType}  = $msgType;
 
+    $conn->schedule(30, sub {
+       my $c           = lc $cache{verstats}{chan};
+       @vernicktodo    = ();
+       foreach (keys %{ $channels{$c}{''} } ) {
+           next if (grep /^\Q$_\E$/i, @vernick);
+           push(@vernicktodo, $_);
+       }
+
+       &verstats_flush();
+    } );
+
     $conn->schedule(60, sub {
        my $vtotal      = 0;
        my $c           = lc $cache{verstats}{chan};
@@ -820,7 +831,7 @@ sub do_verstats {
        my $unknown     = $total - $vtotal;
        my $perc        = sprintf("%.1f", $unknown * 100 / $total);
        $perc           =~ s/.0$//;
-       $sorted{$perc}{"unknown/cloak"} = "$unknown ($perc%)";
+       $sorted{$perc}{"unknown/cloak"} = "$unknown ($perc%)" if ($unknown);
 
        foreach (keys %ver) {
            my $count   = scalar keys %{ $ver{$_} };
@@ -849,6 +860,19 @@ sub do_verstats {
     return;
 }
 
+sub verstats_flush {
+    for (1..5) {
+       last unless (scalar @vernicktodo);
+
+       my $n = shift(@vernicktodo);
+       $conn->ctcp("VERSION", $n);
+    }
+
+    return unless (scalar @vernicktodo);
+
+    $conn->schedule(3, \&verstats_flush() );
+}
+
 sub textstats_main {
     my($arg) = @_;
 
index 40a3e18976dfc7c65c26dc84d0927c1197f1482c..0bc344d982fe048e7ccc5e127f5c9197d944b1f2 100644 (file)
@@ -239,7 +239,14 @@ sub hookMsg {
     foreach (@ignore) {
        s/\*/\\S*/g;
 
-       next unless (eval { $nuh =~ /^$_$/i });
+       next unless (eval { $nuh =~ /^$_$/i } );
+
+       # better to ignore an extra message than to allow one to get
+       # through, although it would be better to go through ignore
+       # checking again.
+       if (time() - $cache{ignoreCheckTime} > 60) {
+           &ignoreCheck();
+       }
 
        &status("IGNORE <$who> $message");
        return;
index a4ffd21a55e6b0edbc9a65041b520a43e26cd083..985fbacf2c4a6cd9ceec4a3e6c073887a47d2c4c 100644 (file)
@@ -189,6 +189,9 @@ sub on_endofmotd {
        @joinchan = &getJoinChans(1);
     }
 
+    # ok, we're free to do whatever we want now. go for it!
+    $running = 1;
+
     # unfortunately, Net::IRC does not implement this :(
     # invalid command... what is it?
 #    &rawout("NOTIFY $ident");
@@ -893,7 +896,7 @@ sub on_quit {
 ###    $chan   = $reason;      # no.
 
     my $count  = 0;
-    foreach (keys %channels) {
+    foreach (grep !/^_default$/, keys %channels) {
        # fixes inconsistent chanstats bug #1.
        if (!&IsNickInChan($nick,$_)) {
            $count++;
index 3f284cdf9a23450cd974ca90fc83910db9defc65..c325ab32e22afa416fa8c60ccc43a7dc8ff66678 100644 (file)
@@ -29,7 +29,6 @@ sub setupSchedulers {
     &leakCheck(2);     # mandatory
     &ignoreCheck(1);   # mandatory
     &seenFlushOld(2);
-#    &ircCheck(2);     # mandatory
     &ircCheck(1);      # mandatory
     &miscCheck(1);     # mandatory
     &miscCheck2(2);    # mandatory
@@ -708,6 +707,9 @@ sub ignoreCheck {
            $count++;
        }
     }
+
+    $cache{ignoreCheckTime} = time();
+
     &VERB("ignore: $count items deleted.",2);
 }
 
@@ -717,6 +719,8 @@ sub ircCheck {
        return if ($_[0] eq "2");       # defer.
     }
 
+    $cache{statusSafe} = 1;
+
     my @x      = &getJoinChans();
     my $iconf  = scalar( @x );
     my $inow   = scalar( keys %channels );
@@ -756,15 +760,15 @@ sub ircCheck {
 
     if (grep /^\s*$/, keys %channels) {
        &WARN("ircCheck: we have a NULL chan in hash channels? removing!");
-       if (exists $channels{''}) {
-           &DEBUG("ircCheck: ok it existed!");
-       } else {
-           &DEBUG("ircCheck: this hsould never happen!");
+       if (!exists $channels{''}) {
+           &DEBUG("ircCheck: this should never happen!");
        }
 
        delete $channels{''};
     }
 
+    $cache{statusSafe} = 0;
+
     ### USER FILE.
     if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
        &writeUserFile();
index a51064bfbc4ad855e8aeef02941536386b044081..28c24bdf5951a1758038f661b70b78d79752c3cf 100644 (file)
@@ -22,6 +22,7 @@ use vars qw(
        $pubsize $pubcount $pubtime
        $msgsize $msgcount $msgtime
        $notsize $notcount $nottime
+       $running
 );
 
 # dynamic hash.
@@ -56,6 +57,7 @@ $ucount_userfile = 0;
 $utime_chanfile        = 0;
 $wtime_chanfile        = 0;
 $ucount_chanfile = 0;
+$running       = 0;
 ### more variables...
 $msgtime       = time();
 $msgsize       = 0;
index f550962a6041a6b428fdc0543856d2d865ce55a3..474188c6d88aca2b6cee7aba9c263cec48418f0c 100644 (file)
@@ -9,9 +9,9 @@
 use strict;
 
 use vars qw($statcount $bot_pid $forkedtime $statcountfix $addressed);
-use vars qw($logDate $logold $logcount $logtime $logrepeat);
+use vars qw($logDate $logold $logcount $logtime $logrepeat $running);
 use vars qw(@backlog);
-use vars qw(%param %file);
+use vars qw(%param %file %cache);
 
 require 5.001;
 
@@ -189,6 +189,12 @@ sub status {
     my($input) = @_;
     my $status;
 
+    # a way to hook onto status without looping.
+    # todo: find why $channels{undef} is created.
+    if (0 and $running and !$cache{statusSafe}) {
+       &ircCheck();
+    }
+
     if ($input eq $logold) {
        # allow perl flooding
        $logrepeat++ unless ($input =~ /PERL: Use of uninitialized/);
@@ -197,6 +203,8 @@ sub status {
        if ($logrepeat >= 3) {
            $logrepeat = 0;
            &status("LOG: repeat throttle.");
+           # we block it to ensure sequence of logging is intact.
+           # could go with $conn->schedule but that's evil :)
            sleep 1;
        }
     } else {
@@ -217,7 +225,7 @@ sub status {
 
     # Something is using this w/ NULL.
     if (!defined $input or $input =~ /^\s*$/) {
-       $input = "Blank status call? HELP HELP HELP";
+       $input = "ERROR: Blank status call? HELP HELP HELP";
     }
 
     for ($input) {
@@ -287,7 +295,8 @@ sub status {
            printf $_green."[%6d]".$ob." ", $statcount;
        }
 
-       # three uberstabs to Derek Moeller.
+       # three uberstabs to Derek Moeller. I don't remember why but he
+       # deserved it :)
        my $printable = $input;
 
        if ($printable =~ s/^(<\/\S+>) //) {
@@ -346,14 +355,14 @@ sub status {
        my $newlogDate = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
        if (defined $logDate and $newlogDate != $logDate) {
            &closeLog();
-           &compress($file{log});
+           &compress( $file{log} );
            &openLog();
        }
     } else {
        $date   = $time;
     }
 
-    print LOG sprintf("%s %s\n", $date, $input);
+    printf LOG "%s %s\n", $date, $input;
 }
 
 sub openSQLDebug {
index 43d623e0d0cfd0b7c50df47369b98d58f7fab22c..c567c2e585ffe74dcbe47e9c8df7ef7ca64f2114 100644 (file)
@@ -247,7 +247,7 @@ sub reloadModule {
        return if ($age == $moduleAge{$file});
 
        if ($age < $moduleAge{$file}) {
-           &WARN("rM: we're not gonna downgrade the file. use 'touch'.");
+           &WARN("rM: we're not gonna downgrade '$file'; use touch.");
            return;
        }