]> git.donarmstrong.com Git - infobot.git/commitdiff
allow join to join irrelevent of being on chan
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Mon, 23 Apr 2001 12:14:04 +0000 (12:14 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Mon, 23 Apr 2001 12:14:04 +0000 (12:14 +0000)
chanstats: count stats if exist - make perl happy
misc cleanup of status()
add time taken to join all channels, useless stats.
disable notify code
leakCheck: show stats on hash chanstats
mkBackup: show age of file.

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

src/IRC/Irc.pl
src/IRC/IrcHooks.pl
src/IRC/Schedulers.pl
src/Process.pl
src/UserExtra.pl
src/logger.pl

index 615b62f49c5f3c80b524c1eabfef7adeb4d258b3..0c25bb8951e59004562391c1e896d8978984cc33 100644 (file)
@@ -580,6 +580,14 @@ sub joinNextChan {
        }
 
     } else {
+       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") ) {
@@ -683,10 +691,12 @@ sub clearIRCVars {
     undef %channels;
     undef %floodjoin;
 
-    @joinchan  = &getJoinChans();
+    @joinchan          = &getJoinChans(1);
+    $cache{joinTime}   = time();
 }
 
 sub getJoinChans {
+    my($show)  = @_;
     my @chans;
     my @skip;
 
@@ -710,12 +720,15 @@ sub getJoinChans {
        push(@chans, $_);
     }
 
+    my $str;
     if (scalar @skip) {
-       &status("gJC: channels not auto-joining: @skip");
+       $str = "gJC: channels not auto-joining: @skip";
     } else {
-       &status("gJC: auto-joining all chans.");
+       $str = "gJC: auto-joining all chans.";
     }
 
+    &status($str) if ($show);
+
     return @chans;
 }
 
index 7c6ea7881fed46d868392b46fea8007cc2816336..0d5ea9f5dc72f72b1b6e39716e0859c8d86ccc30 100644 (file)
@@ -179,12 +179,13 @@ sub on_endofmotd {
     &status("End of motd. Now lets join some channels...");
     if (!scalar @joinchan) {
        &WARN("joinchan array is empty!!!");
-       @joinchan = &getJoinChans();
+       @joinchan = &getJoinChans(1);
     }
 
     # unfortunately, Net::IRC does not implement this :(
-    &rawout("NOTIFY $ident");
-    &DEBUG("adding self to NOTIFY list.");
+    # invalid command... what is it?
+#    &rawout("NOTIFY $ident");
+#    &DEBUG("adding self to NOTIFY list.");
 
     &joinNextChan();
 }
@@ -787,8 +788,9 @@ sub on_public {
 
 sub on_quit {
     my ($self, $event) = @_;
-    my $nick = $event->nick();
-    my $reason = ($event->args)[0];
+    my $nick   = $event->nick();
+    my $reason = ($event->args)[0];
+
     # hack for ICC.
     $msgType   = "public";
     $who       = $nick;
@@ -816,9 +818,10 @@ sub on_quit {
        &DEBUG("on_quit: nuh{lc $nick} does not exist! FIXME");
     }
     delete $userstats{lc $nick} if (&IsChanConf("seenStats"));
+    delete $chanstats{lc $nick};
 
     # should fix chanstats inconsistencies bug #2.
-    if ($reason=~/^($mask{host})\s($mask{host})$/) {   # netsplit.
+    if ($reason =~ /^($mask{host})\s($mask{host})$/) { # netsplit.
        $reason = "NETSPLIT: $1 <=> $2";
 
        if (&ChanConfList("chanlimitcheck") and !scalar keys %netsplit) {
@@ -839,7 +842,7 @@ sub on_quit {
     }
 
     if ($nick !~ /^\Q$ident\E$/ and $nick =~ /^\Q$param{'ircNick'}\E$/i) {
-       &status("own nickname became free; changing.");
+       &status("nickchange: own nickname became free; changing.");
        &nick($param{'ircNick'});
     }
 }
index 484147d58d535a82ed29e5f7b1e6d4a05ff8c94d..8830f2f753473a74adef8d4e6d4571ff4cb365a5 100644 (file)
@@ -566,7 +566,7 @@ sub leakCheck {
        delete $sched{"leakCheck"}{RUNNING};
     }
 
-    # flood.
+    # flood. this is dealt with in floodLoop()
     foreach $blah1 (keys %flood) {
        foreach $blah2 (keys %{ $flood{$blah1} }) {
            $count += scalar(keys %{ $flood{$blah1}{$blah2} });
@@ -581,7 +581,7 @@ sub leakCheck {
            $count += scalar(keys %{ $floodjoin{$blah1}{$blah2} });
        }
     }
-    &DEBUG("leak: hash flood has $count total keys.",2);
+    &DEBUG("leak: hash floodjoin has $count total keys.",2);
 
     # floodwarn.
     $count = scalar(keys %floodwarn);
@@ -598,6 +598,11 @@ sub leakCheck {
        }
     }
 
+    # chanstats
+    $count = scalar(keys %chanstats);
+    &DEBUG("leak: hash chanstats has $count total keys.",2);
+
+    # nuh.
     my $delete = 0;
     foreach (keys %nuh) {
        next if (&IsNickInAnyChan($_));
@@ -647,8 +652,8 @@ sub ircCheck {
     }
 
     my @x      = &getJoinChans();
-    my $iconf = scalar( @x );
-    my $inow  = scalar( keys %channels );
+    my $iconf  = scalar( @x );
+    my $inow   = scalar( keys %channels );
     if ($iconf > 2 and $inow * 2 <= $iconf) {
        &FIXME("ircCheck: current channels * 2 <= config channels. FIXME.");
        @joinchan       = @x;
@@ -1160,8 +1165,10 @@ sub mkBackup {
     }
     return unless ($backup);
 
+    my $age = &Time2String(time() - (stat $file)[9]);
+
     ### TODO: do internal copying.
-    &status("Backup: $file to $file~");
+    &status("Backup: $file ($age)");
     CORE::system("/bin/cp $file $file~");
 }
 
index dedad4eac304878685fb65ba13fe173d5dfd3d6c..54ab15b906ad8511b0b953f6ad4e4cc6b0e18a40 100644 (file)
@@ -63,8 +63,8 @@ sub process {
            }
 
            if (&validChan($thischan)) {
-               &msg($who,"I'm already on $thischan...");
-               return;
+               &msg($who,"warn: I'm already on $thischan, joining  anyway...");
+#              return;
            }
        }
        $cache{join}{$thischan} = $who; # used for on_join self.
index c09291ef9a31184d5ac200fe6e25d55abf5c4866..f405a11d50b41d95504c87e7f1a4f43188c98950 100644 (file)
@@ -147,15 +147,12 @@ sub chaninfo {
     $reply .= ".  At the moment, ". &IJoin(@array);
 
     # Step 3:
-    ### TODO: what's wrong with the following?
+    my %new;
     foreach (keys %userstats) {
-       next if (exists $userstats{$_}{'Count'});
-       delete $userstats{$_};
-       $delete++;
+       next unless (exists $userstats{$_}{'Count'});
+       $new{$_} = $userstats{$_}{'Count'};
     }
-    &DEBUG("chanstats: delete: $delete... nowtotal => ".scalar(keys %userstats) );
 
-    my %new = map { $userstats{$_}{'Count'} => $_ } keys %userstats;
     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";
index 25a4debb7defb10ecfac484e08f681bd10a1282b..ad4efa53a4dd9979548eb96272c387a1af20eb8c 100644 (file)
@@ -93,7 +93,7 @@ sub openLog {
     }
 
     if (&IsParam("logType") and $param{'logType'} =~ /DAILY/i) {
-       my ($day,$month,$year) = (localtime(time()))[3,4,5];
+       my ($day,$month,$year) = (localtime time())[3,4,5];
        $logDate = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
        $file{log} .= "-".$logDate;
     }
@@ -123,12 +123,11 @@ sub compress {
     my $okay = 0;
 
     if (! -f $file) {
-       # ironically this does not get logged :)
        &WARN("compress: file ($file) does not exist.");
        return 0;
     }
 
-    if (-f "$file.gz" or -f "$file.bz2") {
+    if ( -f "$file.gz" or -f "$file.bz2" ) {
        &WARN("compress: file.(gz|bz2) already exists.");
        return 0;
     }
@@ -169,7 +168,7 @@ sub WARN {
 }
 
 sub FIXME {
-    &status("${b_cyan}!FIXME!$ob $_[0] (SHOULD NOT HAPPEN?)");
+    &status("${b_cyan}!FIXME!$ob $_[0]");
 }
 
 sub TODO {
@@ -191,20 +190,25 @@ sub status {
     my $status;
 
     if ($input eq $logold) {
+       # allow perl flooding
        $logrepeat++ unless (/!WARN! PERL: Use of uninitialized/);
 
+       # todo: prevent massive repetitive throttling.
        if ($logrepeat >= 3) {
            $logrepeat = 0;
            &status("LOG: repeat throttle.");
            sleep 1;
        }
+    } else {
+       $logold = $input;
     }
-    $logold = $input;
 
     # if it's not a scalar, attempt to warn and fix.
-    if (ref($input) ne "") {
-       &status("status: 'input' is not scalar (".ref($input).").");
-       if (ref($input) eq "ARRAY") {
+    my $ref = ref $input;
+    if (defined $ref and $ref ne "") {
+       &status("status: 'input' is not scalar ($ref).");
+
+       if ($ref eq "ARRAY") {
            foreach (@$input) {
                &WARN("status: '$_'.");
            }
@@ -213,12 +217,16 @@ sub status {
 
     # Something is using this w/ NULL.
     if (!defined $input or $input =~ /^\s*$/) {
-       $input = "Blank status call?";
+       $input = "Blank status call? HELP HELP HELP";
     }
-    $input =~ s/\n+$//;
-    $input =~ s/\002|037//g;   # bold,video,underline => remove.
 
-    # pump up the stats (or loglinenum).
+    for ($input) {
+       s/\n+$//;
+       s/\n/<NL>/g;
+       s/\002|037//g;  # bold,video,underline => remove.
+    }
+
+    # pump up the stats.
     $statcount++;
 
     # fix style of output if process is child.
@@ -229,19 +237,21 @@ sub status {
 
     ### LOG THROTTLING.
     ### TODO: move this _after_ printing?
-    my $time = time();
-    my $reset = 0;
-    if ($logtime != $time) {
-       $reset++;
-    } elsif ($logtime == $time) {
-       if ($logcount < 25) {           # too high?
+    my $time   = time();
+    my $reset  = 0;
+
+    if ($logtime == $time) {
+       if ($logcount < 25) {                   # too high?
            $logcount++;
        } else {
            sleep 1;
            &status("LOG: Throttling.");        # recursive?
            $reset++;
        }
+    } else {   # $logtime != $time.
+       $reset++;
     }
+
     if ($reset) {
        $logtime        = $time;
        $logcount       = 0;
@@ -252,7 +262,7 @@ sub status {
        $status = "!$statcount! ".$input;
        if ($statcount > 1000) {
            print LOG "ERROR: FORKED PROCESS RAN AWAY; KILLING.\n";
-           print LOG "VERB: ".(&Time2String(time() - $forkedtime))."\n";
+           print LOG "VERB: ".(&Time2String($time - $forkedtime))."\n";
            exit 0;
        }
     } else {
@@ -316,15 +326,17 @@ sub status {
     return unless (defined fileno LOG);
 
     # remove control characters from logging.
-    $input =~ s/\e\[[0-9;]+m//g;
-    $input =~ s/[\cA-\c_]//g;
+    for ($input) {
+       s/\e\[[0-9;]+m//g;      # escape codes.
+       s/[\cA-\c_]//g;         # control chars.
+    }
     $input = "FORK($$) ".$input if ($statcountfix);
 
     my $date;
     if (&IsParam("logType") and $param{'logType'} =~ /DAILY/i) {
-       $date = sprintf("%02d:%02d.%02d", (localtime(time()))[2,1,0]);
+       $date = sprintf("%02d:%02d.%02d", (localtime $time)[2,1,0]);
 
-       my ($day,$month,$year) = (localtime(time()))[3,4,5];
+       my ($day,$month,$year) = (localtime $time)[3,4,5];
        my $newlogDate = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
        if (defined $logDate and $newlogDate != $logDate) {
            &closeLog();
@@ -332,7 +344,7 @@ sub status {
            &openLog();
        }
     } else {
-       $date = time();
+       $date   = $time;
     }
 
     print LOG sprintf("%s %s\n", $date, $input);