]> git.donarmstrong.com Git - infobot.git/commitdiff
- remove several debug messages; convert some to VERB()
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 4 May 2001 14:38:36 +0000 (14:38 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 4 May 2001 14:38:36 +0000 (14:38 +0000)
- forgot to increment {pub|not|msg}sleep counters
- nick() and on_nick now works properly!
- on_nick_taken - no endless loops
- removed 10lines of debug code from hookMsg()
- chanlimitcheck: unset limit if in netsplit.

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

src/IRC/Irc.pl
src/IRC/IrcHelpers.pl
src/IRC/IrcHooks.pl
src/IRC/Schedulers.pl
src/Misc.pl
src/Modules/Debian.pl
src/Modules/News.pl
src/UserExtra.pl

index 4e93b2ca1d06fea72053551dd4db052fdd0a087e..c650cbdc668ef00b2a6556e628d87b4d84fd656c 100644 (file)
@@ -197,9 +197,11 @@ sub say {
 
            if ( ($pubcount % $i) == 0 and $pubcount) {
                sleep 1;
+               $pubsleep++;
            } elsif ($pubsize > $j) {
                sleep 1;
                $pubsize -= $j;
+               $pubsleep++;
            }
 
        } else {
@@ -238,9 +240,11 @@ sub msg {
            my $j = &getChanConfDefault("sendPrivateLimitBytes", 1000);
            if ( ($msgcount % $i) == 0 and $msgcount) {
                sleep 1;
+               $msgsleep++;
            } elsif ($msgsize > $j) {
                sleep 1;
                $msgsize -= $j;
+               $msgsleep++;
            }
 
        } else {
@@ -294,9 +298,11 @@ sub notice {
 
        if ( ($notcount % $i) == 0 and $notcount) {
            sleep 1;
+           $notsleep++;
        } elsif ($notsize > $j) {
            sleep 1;
            $notsize -= $j;
+           $notsleep++;
        }
 
     } else {
@@ -555,11 +561,35 @@ sub quit {
 sub nick {
     my ($nick) = @_;
 
+    if (!defined $nick) {
+       &ERROR("nick: nick == NULL.");
+       return;
+    }
+
+    if (defined $ident and $nick eq $ident) {
+       &WARN("nick: nick == ident == '$ident'.");
+    }
+
+    my $bad     = 0;
+    $bad++ if (exists $nuh{ $param{'ircNick'} });
+    $bad++ if (&IsNickInAnyChan($param{'ircNick'}));
+
+    if ($bad) {
+       &WARN("Nick: not going to try and get my nick back. [".
+               scalar(localtime). "]");
+       return;
+    }
+
     if ($nick =~ /^$mask{nick}$/) {
-       &DEBUG("nick: Changing nick to $nick (from $ident)");
        rawout("NICK ".$nick);
-       # unfortunately, on_nick doesn't catch ourself.
-       $ident  = $nick;
+
+       if (defined $ident) {
+           &status("nick: Changing nick to $nick (from $ident)");
+       } else {
+           &DEBUG("first time nick change.");
+           $ident      = $nick;
+       }
+
        return 1;
     }
     &DEBUG("nick: failed... why oh why (nick => $nick)");
@@ -579,8 +609,6 @@ sub invite {
 
 # Usage: &joinNextChan();
 sub joinNextChan {
-    &DEBUG("joinNextChan called.");
-
     if (scalar @joinchan) {
        $chan = shift @joinchan;
        &joinchan($chan);
@@ -589,20 +617,24 @@ sub joinNextChan {
            &status("joinNextChan: $i chans to join.");
        }
 
-    } else {
-       if (exists $cache{joinTime}) {
-           my $delta   = time() - $cache{joinTime};
-           my $timestr = &Time2String($delta);
-           my $rate    = sprintf("%.1f", $delta / &getJoinChans() );
-           delete $cache{joinTime};
+       return;
 
-           &DEBUG("time taken to join all chans: $timestr; rate: $rate sec/join");
-       }
-       # chanserv check: global channels, in case we missed one.
+    }
 
-       foreach ( &ChanConfList("chanServ_ops") ) {
-           &chanServCheck($_);
-       }
+    # !scalar @joinchan:
+
+    if (exists $cache{joinTime}) {
+       my $delta       = time() - $cache{joinTime};
+       my $timestr = &Time2String($delta);
+       my $rate        = sprintf("%.1f", $delta / &getJoinChans() );
+       delete $cache{joinTime};
+
+       &DEBUG("time taken to join all chans: $timestr; rate: $rate sec/join");
+    }
+    # chanserv check: global channels, in case we missed one.
+
+    foreach ( &ChanConfList("chanServ_ops") ) {
+       &chanServCheck($_);
     }
 }
 
index c050904db15002baba5ea85329289fdac5358ff7..021350be63286c6aa0ac89fbb1b9f57df3fbcfc2 100644 (file)
@@ -261,7 +261,10 @@ sub chanLimitVerify {
     my($chan)  = @_;
     my $l      = $channels{$chan}{'l'};
 
-    if (scalar keys %netsplitservers) {
+    &DEBUG("cLV: netsplitservers: ".scalar(keys %netsplitservers) );
+    &DEBUG("cLV: netsplit: ".scalar(keys %netsplit) );
+
+    if (scalar keys %netsplit) {
        &WARN("clV: netsplit active (1); skipping.");
        return;
     }
@@ -289,7 +292,7 @@ sub chanLimitVerify {
 
        ### todo: unify code with chanlimitcheck()
        if ($delta > 5) {
-           &status("clc: big change in limit; changing.");
+           &status("clc: big change in limit; going for it.");
            &rawout("MODE $chan +l ".($count+$plus) );
            $cache{chanlimitChange}{$chan} = time();
        }
@@ -312,7 +315,7 @@ sub chanServCheck {
        return 0;
     }
 
-    &DEBUG("chanServCheck($chan) called.");
+    &VERB("chanServCheck($chan) called.",2);
 
     if ( &IsParam("nickServ_pass") and !$nickserv) {
        &DEBUG("chanServ_ops($chan): nickserv enabled but not alive? (ircCheck)");
index b1010b9565712a9cf9ea3831ac3c0becec7716dc..9b7c45918f13b79b8248ddd1a51fdff3b7ba763d 100644 (file)
@@ -130,9 +130,8 @@ sub on_chat {
 sub on_endofmotd {
     my ($self) = @_;
 
-    # what's the following for?
-    $ident                     = $param{'ircNick'};
     # update IRCStats.
+    $ident     ||= $param{'ircNick'};  # hack.
     $ircstats{'ConnectTime'}   = time();
     $ircstats{'ConnectCount'}++;
     $ircstats{'OffTime'}       += time() - $ircstats{'DisconnectTime'}
@@ -627,35 +626,34 @@ sub on_nick {
     }
     # todo: do %flood* aswell.
 
-    &DeleteUserInfo($nick,keys %channels);
+    &DeleteUserInfo($nick, keys %channels);
     $nuh{lc $newnick} = $nuh{lc $nick};
     delete $nuh{lc $nick};
 
-    # successful self-nick change.
-    &DEBUG("on_nick... nick => $nick, ident => $ident");
-    if ($ident eq "$nick-" or "$ident-" eq $nick) {
-       &DEBUG("on_nick: well... we need this bug fixed.");
-       &DEBUG("ident => $ident");
-       &DEBUG("nick => $nick");
-       $ident = $newnick;
-    }
-
     if ($nick eq $ident) {
        &status(">>> I materialized into $b_green$newnick$ob from $nick");
-       $ident = $newnick;
+       $ident  = $newnick;
     } else {
        &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
+
+       if ($nick =~ /^\Q$param{'ircNick'}\E$/i) {
+           &getNickInUse();
+       }
     }
 }
 
 sub on_nick_taken {
-    my ($self) = @_;
-    my $nick = $self->nick;
-    my $newnick = substr($nick,0,7)."-";
+    my ($self) = @_;
+    my $nick   = $self->nick;
+    my $newnick = $nick."-";
 
-    &status("nick taken; changing to temporary nick ($nick -> $newnick).");
-    &nick($newnick);
-    &getNickInUse(1);
+    &status("nick taken ($nick); preparing nick change.");
+
+    $self->whois($nick);
+    $conn->schedule(5, sub {
+       &status("nick taken; changing to temporary nick ($nick -> $newnick).");
+       &nick($newnick);
+    } );
 }
 
 sub on_notice {
@@ -766,26 +764,14 @@ sub on_public {
     # todo: move this out of hookMsg to here?
     ($user,$host) = split(/\@/, $uh);
 
+    # rare case should this happen - catch it just in case.
     if ($bot_pid != $$) {
        &ERROR("run-away fork; exiting.");
        &delForked($forker);
     }
 
-    ### DEBUGGING.
-    if ($statcount < 200) {
-       foreach $chan (grep /[A-Z]/, keys %channels) {
-           &DEBUG("leak: chan => '$chan'.");
-           my ($i,$j);
-           foreach $i (keys %{ $channels{$chan} }) {  
-               foreach (keys %{ $channels{$chan}{$i} }) {
-                   &DEBUG("leak:   \$channels{$chan}{$i}{$_} ...");
-               }
-           }
-       }
-    }
-
-    $msgtime = time();
-    $lastWho{$chan} = $nick;
+    $msgtime           = time();
+    $lastWho{$chan}    = $nick;
     ### TODO: use $nick or lc $nick?
     if (&IsChanConf("seenStats")) {
        $userstats{lc $nick}{'Count'}++;
@@ -841,6 +827,7 @@ sub on_quit {
     if ($reason =~ /^($mask{host})\s($mask{host})$/) { # netsplit.
        $reason = "NETSPLIT: $1 <=> $2";
 
+       # chanlimit code.
        if (&ChanConfList("chanlimitcheck") and !scalar keys %netsplit) {
            &DEBUG("on_quit: netsplit detected; disabling chan limit.");
            &rawout("MODE $chan -l");
index 5ec5802dff07fe2f3f8d1f05f611b2c621c4d445..f2c35667e4ecfdb52d1b3a231af5dff817bf384f 100644 (file)
@@ -298,17 +298,15 @@ sub newsFlush {
     my $delete = 0;
     my $oldest = time();
     foreach $chan (keys %::news) {
-       &DEBUG("sched: chan => $chan");
+       my $i           = 0;
+       my $total       = scalar(keys %{ $::news{$chan} });
 
        foreach $item (keys %{ $::news{$chan} }) {
            my $t = $::news{$chan}{$item}{Expire};
-           &DEBUG("sched; item => $item");
 
            my $tadd    = $::news{$chan}{$item}{Time};
            $oldest     = $tadd if ($oldest > $tadd);
 
-           &DEBUG("sched: t => $t");
-
            next if ($t == 0 or $t == -1);
            if ($t < 1000) {
                &status("newsFlush: Fixed Expire time for $chan/$item, should not happen anyway.");
@@ -317,20 +315,17 @@ sub newsFlush {
            }
 
            my $delta = $t - time();
-           &DEBUG("news: delta: $delta");
 
            next unless (time() > $t);
 
            # todo: show how old it was.
            delete $::news{$chan}{$item};
-           &VERB("NEWS: deleted '$item'", 2);
+           &status("NEWS: deleted '$item'");
            $delete++;
+           $i++;
        }
-    }
 
-    if ($delete) {
-       &DEBUG("sched: Writing news....");
-       &News::writeNews();
+       &status("NEWS {$chan}: deleted [$i/$total] news entries.");
     }
 
     # todo: flush users aswell.
@@ -350,10 +345,12 @@ sub newsFlush {
        }
     }
 
-#    &VERB("NEWS deleted $delete seen entries.",2);
-    &status("NEWS deleted: $delete news entries; $duser user cache.");
+    if ($delete or $duser) {
+       &DEBUG("newsF: Writing news.");
+       &News::writeNews();
+    }
 
-    &News::writeNews();
+    &status("NEWS deleted: $delete news entries; $duser user cache.");
 }
 
 sub chanlimitCheck {
@@ -366,11 +363,6 @@ sub chanlimitCheck {
        delete $sched{"chanlimitCheck"}{RUNNING};
     }
 
-    if (scalar keys %netsplitservers) {
-       &WARN("clC: netsplit active (2); skipping. (netsplit => $netsplit)");
-       return;
-    }
-
     foreach $chan ( &ChanConfList("chanlimitcheck") ) {
        next unless (&validChan($chan));
 
@@ -378,6 +370,16 @@ sub chanlimitCheck {
        my $newlimit    = scalar(keys %{ $channels{$chan}{''} }) + $limitplus;
        my $limit       = $channels{$chan}{'l'};
 
+       if (scalar keys %netsplitservers) {
+           if (defined $limit) {
+               &DEBUG("chanlimit: removing it for $chan.");
+               &rawout("MODE $chan -l");
+               $cache{chanlimitChange}{$chan} = time();
+           }
+
+           next;
+       }
+
        if (defined $limit and scalar keys %{ $channels{$chan}{''} } > $limit) {
            &FIXME("LIMIT: set too low!!! FIXME");
            ### run NAMES again and flush it.
@@ -447,8 +449,11 @@ sub netsplitCheck {
        delete $netsplit{$_};
     }
 
+    &DEBUG("nsC: netsplitservers: ".scalar(keys %netsplitservers) );
+    &DEBUG("nsC: netsplit: ".scalar(keys %netsplit) );
+
     if ($count and !scalar keys %netsplit) {
-       &DEBUG("ok, netsplit is hopefully gone. reinstating chanlimit check.");
+       &DEBUG("nsC: netsplit is hopefully gone. reinstating chanlimit check.");
        &chanlimitCheck();
     }
 }
@@ -879,7 +884,6 @@ sub shmFlush {
 
 ### this is semi-scheduled
 sub getNickInUse {
-    &DEBUG("gNIU: ident => $ident, ircNick => $param{'ircNick'}");
     if ($ident eq $param{'ircNick'}) {
        &status("okay, got my nick back.");
        return;
@@ -892,7 +896,6 @@ sub getNickInUse {
        delete $sched{"getNickInUse"}{RUNNING};
     }
 
-    &status("Trying to get my nick back.");
     &nick( $param{'ircNick'} );
 }
 
@@ -1049,7 +1052,6 @@ sub wingateWriteFile {
        print OUT "$_\n";
     }
     close OUT;
-
 }
 
 sub factoidCheck {
@@ -1174,11 +1176,11 @@ sub getChanConfDefault {
 }
 
 sub mkBackup {
-    my($file, $time) = @_;
-    my $backup = 0;
+    my($file, $time)   = @_;
+    my $backup         = 0;
 
     if (! -f $file) {
-       &WARN("mkB: file $file don't exist.");
+       &WARN("mkB: file '$file' does not exist.");
        return;
     }
 
@@ -1189,7 +1191,10 @@ sub mkBackup {
     }
     return unless ($backup);
 
-    my $age = &Time2String(time() - (stat $file)[9]);
+    my $delta = time() - (stat $file)[9];
+    &DEBUG("mkb: delta => $delta");
+
+    my $age = &Time2String($delta);
 
     ### TODO: do internal copying.
     &status("Backup: $file ($age)");
index 52cbc7bd72aeb1a3e874fbc367103aec71275df5..c5069f892dbe3baba3c7a88b56262ad60e8c9ab8 100644 (file)
@@ -456,8 +456,6 @@ sub isStale {
        &DEBUG("stale: $age2. (". &Time2String($age2) .")");
     }
     $age *= 60*60*24 if ($age >= 0 and $age < 30);
-    &DEBUG("age = $age");
-    &DEBUG("... = ".(stat $file)[9] );
 
     return 1 if (time() - (stat($file))[9] > $age);
     return 0;
index 4aa912fe9f66fa379e0605186831eeb6c4a7a404..75af9609584f44e73eb116724d992ee49ff7c6e4 100644 (file)
@@ -935,7 +935,7 @@ sub validPackage {
     }
     close IN;
 
-    &::DEBUG("vP: scanned $count items in index.");
+    &::VERB("vP: scanned $count items in index.",2);
 
     return @files;
 }
@@ -1015,15 +1015,16 @@ sub getDistro {
     }
 
     if (exists $dists{$dist}) {
-       &::DEBUG("gD: returning dists{$dist} ($dists{$dist})");
+       &::VERB("gD: returning dists{$dist} ($dists{$dist})",2);
        return $dists{$dist};
+
     } else {
        if (!grep /^\Q$dist\E$/i, %dists) {
            &::msg($::who, "invalid dist '$dist'.");
            return;
        }
 
-       &::DEBUG("gD: returning $dist (no change or conversion)");
+       &::VERB("gD: returning $dist (no change or conversion)",2);
        return $dist;
     }
 }
index 842e6df79ab3bd470128ff254c1148a00efd36c7..79324f6ac8414ee2e3d0aa2ce6bb9fe28b8a1231 100644 (file)
@@ -187,7 +187,7 @@ sub readNews {
 }
 
 sub writeNews {
-    if (!scalar keys %::news) {
+    if (!scalar keys %::news and !scalar keys %::newsuser) {
        &::DEBUG("wN: nothing to write.");
        return;
     }
@@ -534,7 +534,6 @@ sub set {
 
     &::DEBUG("item => '$item'.");
     my $news = &getNewsItem($item);
-    &::DEBUG("news => '$news'");
 
     if (!defined $news) {
        &::notice($::who, "Could not find item '$item' substring or # in news list.");
@@ -690,7 +689,13 @@ sub latest {
 
        # don't list new items if they don't have Text.
        if (!exists $::news{$chan}{$_}{Text}) {
-           &::WARN("news: news{$chan}{$_}{Text} undef.");
+           if (time() - $::news{$chan}{$_}{Time} > 60*60*24*3) {
+               &::DEBUG("deleting news{$chan}{$_} because it was too old and had no text info.");
+               delete $::news{$chan}{$_};
+           } else {
+               &::WARN("news: news{$chan}{$_}{Text} undef.");
+           }
+
            next;
        }
 
@@ -851,9 +856,8 @@ sub getNewsItem {
            return;
        }
 
-       &::DEBUG("gNI: part_string->full_string: $what->$items[0]");
        if (@items) {
-           &::DEBUG("gNI: Guessed '$items[0]'.");
+           &::DEBUG("gNI: part_string->full_string: $what->$items[0]");
            return $items[0];
        } else {
            &::DEBUG("gNI: No match.");
index 8f6aff3fb6712a1acf178303e47c5aea4b935166..92bb19537093209d74ca076a65a90b50e52d80c2 100644 (file)
@@ -157,7 +157,7 @@ sub chaninfo {
 
     my($count) = (sort { $b <=> $a } keys %new)[0];
     if ($count) {
-       $reply .= ".  \002$new{$count}\002 has said the most with a total of \002$count\002 messages";
+       $reply .= ".  \002$count\002 has said the most with a total of \002$new{$count}\002 messages";
     }
     &pSReply("$reply.");
 }