From: dms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Date: Sat, 29 Dec 2001 12:26:55 +0000 (+0000)
Subject: - now support verstats for those who don't reply to "CTCP VERSION
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=92e6b69ce18671857f425fa505c9bb78465bb751;p=infobot.git

- now support verstats for those who don't reply to "CTCP VERSION
  #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@536 c11ca15a-4712-0410-83d8-924469b57eb5
---

diff --git a/blootbot/src/CommandStubs.pl b/blootbot/src/CommandStubs.pl
index e3586e0..520e326 100644
--- a/blootbot/src/CommandStubs.pl
+++ b/blootbot/src/CommandStubs.pl
@@ -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) = @_;
 
diff --git a/blootbot/src/IRC/IrcHelpers.pl b/blootbot/src/IRC/IrcHelpers.pl
index 40a3e18..0bc344d 100644
--- a/blootbot/src/IRC/IrcHelpers.pl
+++ b/blootbot/src/IRC/IrcHelpers.pl
@@ -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;
diff --git a/blootbot/src/IRC/IrcHooks.pl b/blootbot/src/IRC/IrcHooks.pl
index a4ffd21..985fbac 100644
--- a/blootbot/src/IRC/IrcHooks.pl
+++ b/blootbot/src/IRC/IrcHooks.pl
@@ -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++;
diff --git a/blootbot/src/IRC/Schedulers.pl b/blootbot/src/IRC/Schedulers.pl
index 3f284cd..c325ab3 100644
--- a/blootbot/src/IRC/Schedulers.pl
+++ b/blootbot/src/IRC/Schedulers.pl
@@ -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();
diff --git a/blootbot/src/core.pl b/blootbot/src/core.pl
index a51064b..28c24bd 100644
--- a/blootbot/src/core.pl
+++ b/blootbot/src/core.pl
@@ -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;
diff --git a/blootbot/src/logger.pl b/blootbot/src/logger.pl
index f550962..474188c 100644
--- a/blootbot/src/logger.pl
+++ b/blootbot/src/logger.pl
@@ -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 {
diff --git a/blootbot/src/modules.pl b/blootbot/src/modules.pl
index 43d623e..c567c2e 100644
--- a/blootbot/src/modules.pl
+++ b/blootbot/src/modules.pl
@@ -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;
 	}