From 0e5b2508b1789c8cd4448280aea8e0021b25290c Mon Sep 17 00:00:00 2001 From: dms Date: Mon, 23 Apr 2001 12:14:04 +0000 Subject: [PATCH] allow join to join irrelevent of being on chan 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 | 19 +++++++++++--- src/IRC/IrcHooks.pl | 17 +++++++----- src/IRC/Schedulers.pl | 17 ++++++++---- src/Process.pl | 4 +-- src/UserExtra.pl | 9 +++---- src/logger.pl | 60 ++++++++++++++++++++++++++----------------- 6 files changed, 79 insertions(+), 47 deletions(-) diff --git a/src/IRC/Irc.pl b/src/IRC/Irc.pl index 615b62f..0c25bb8 100644 --- a/src/IRC/Irc.pl +++ b/src/IRC/Irc.pl @@ -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; } diff --git a/src/IRC/IrcHooks.pl b/src/IRC/IrcHooks.pl index 7c6ea78..0d5ea9f 100644 --- a/src/IRC/IrcHooks.pl +++ b/src/IRC/IrcHooks.pl @@ -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'}); } } diff --git a/src/IRC/Schedulers.pl b/src/IRC/Schedulers.pl index 484147d..8830f2f 100644 --- a/src/IRC/Schedulers.pl +++ b/src/IRC/Schedulers.pl @@ -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~"); } diff --git a/src/Process.pl b/src/Process.pl index dedad4e..54ab15b 100644 --- a/src/Process.pl +++ b/src/Process.pl @@ -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. diff --git a/src/UserExtra.pl b/src/UserExtra.pl index c09291e..f405a11 100644 --- a/src/UserExtra.pl +++ b/src/UserExtra.pl @@ -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"; diff --git a/src/logger.pl b/src/logger.pl index 25a4deb..ad4efa5 100644 --- a/src/logger.pl +++ b/src/logger.pl @@ -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//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); -- 2.39.2