From c06de18db33a91048332365ee5f771f8d0439a14 Mon Sep 17 00:00:00 2001 From: dms Date: Sat, 31 Mar 2001 14:19:14 +0000 Subject: [PATCH] Many changes, basically added and integrated News, and bug fixes. Some more notes: CommandStubs.pl - fixed "kernel blah" Modules/UserDCC.pl - dont print $user when undefined. modules.pl - added News.pl Modules/News.pl - new feature. Process.pl - "blootbot: ok is :)" -- FIXED. git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@422 c11ca15a-4712-0410-83d8-924469b57eb5 --- src/CommandStubs.pl | 13 +++++--- src/DynaConfig.pl | 2 +- src/Factoids/Statement.pl | 5 ++-- src/Factoids/Update.pl | 4 +-- src/IRC/Irc.pl | 2 +- src/IRC/IrcHooks.pl | 45 ++++++++++++++++++++++++++-- src/IRC/Schedulers.pl | 63 +++++++++++++++++++++++++++++++++++++-- src/Modules/UserDCC.pl | 2 +- src/Process.pl | 7 ++--- src/UserExtra.pl | 32 +++++++++++++++----- src/core.pl | 2 ++ src/modules.pl | 9 ++++-- 12 files changed, 155 insertions(+), 31 deletions(-) diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index d4e2244..4a052a8 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -57,7 +57,7 @@ sub parseCmdHook { next; } - &DEBUG("pCH(hooks_$hashname): $cmd matched $ident"); + &status("hooks($hashname): $cmd matched '$ident'"); my %hash = %{ ${"hooks_$hashname"}{$ident} }; if (!scalar keys %hash) { @@ -65,6 +65,11 @@ sub parseCmdHook { return 1; } + if ($hash{NoArgs} and $flatarg) { + &DEBUG("cmd $ident does not take args; skipping."); + next; + } + if (!exists $hash{CODEREF}) { &ERROR("CODEREF undefined for $cmd or $ident."); return 1; @@ -72,7 +77,7 @@ sub parseCmdHook { ### DEBUG. foreach (keys %hash) { - &DEBUG(" $cmd->$_ => '$hash{$_}'."); + &VERB(" $cmd->$_ => '$hash{$_}'.",2); } ### HELP. @@ -120,7 +125,7 @@ sub parseCmdHook { $cmdstats{ $hash{'Cmdstats'} }++; } - &DEBUG("pCH: ended."); + &VERB("hooks: End of command.",2); $done = 1; } @@ -158,7 +163,7 @@ sub parseCmdHook { 'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) ); &addCmdHook("extra", 'kernel', ('CODEREF' => 'Kernel::Kernel', 'Forker' => 1, 'Identifier' => 'kernel', - 'Cmdstats' => 'Kernel') ); + 'Cmdstats' => 'Kernel', 'NoArgs' => 1) ); &addCmdHook("extra", 'listauth', ('CODEREF' => 'CmdListAuth', 'Identifier' => 'search', Module => 'factoids', 'Help' => 'listauth') ); diff --git a/src/DynaConfig.pl b/src/DynaConfig.pl index 29a44ec..2a78ebf 100644 --- a/src/DynaConfig.pl +++ b/src/DynaConfig.pl @@ -307,8 +307,8 @@ sub writeChanFile { } } - &DEBUG("chans => ".scalar(keys %chanconf)." - 1"); foreach (keys %opts) { + next unless ($opts{$_} > 1); &DEBUG(" opts{$_} => $opts{$_}"); } diff --git a/src/Factoids/Statement.pl b/src/Factoids/Statement.pl index 903a4f8..6c05f93 100644 --- a/src/Factoids/Statement.pl +++ b/src/Factoids/Statement.pl @@ -99,9 +99,8 @@ sub doStatement { } } - if (&update($lhs, $mhs, $rhs)) { - return; # success. - } + # success. + return if (&update($lhs, $mhs, $rhs)); } return "CONTINUE"; diff --git a/src/Factoids/Update.pl b/src/Factoids/Update.pl index df9a388..827e9cd 100644 --- a/src/Factoids/Update.pl +++ b/src/Factoids/Update.pl @@ -49,8 +49,8 @@ sub update { } # also checking. - my $also = ($rhs =~ s/^(-?)also //i); - &DEBUG("1=>$1"); + my $also = ($rhs =~ s/^(\-)?also //i); + &DEBUG("1=>$1"); # this does not work! my $also_or = ($also and $rhs =~ s/\s+(or|\|\|)\s+//); # freshmeat diff --git a/src/IRC/Irc.pl b/src/IRC/Irc.pl index 53d1004..3fab991 100644 --- a/src/IRC/Irc.pl +++ b/src/IRC/Irc.pl @@ -685,7 +685,7 @@ sub joinfloodCheck { return unless (&IsChanConf("joinfloodCheck")); if (exists $netsplit{lc $who}) { # netsplit join. - &DEBUG("jfC: $who was in netsnipe; not checking."); + &DEBUG("jfC: $who was in netsplit; not checking."); } if (exists $floodjoin{$chan}{$who}{Time}) { diff --git a/src/IRC/IrcHooks.pl b/src/IRC/IrcHooks.pl index c4f1ef0..87d3f68 100644 --- a/src/IRC/IrcHooks.pl +++ b/src/IRC/IrcHooks.pl @@ -65,10 +65,12 @@ sub on_chat { ### TODO: prevent users without CRYPT chatting. if (!defined $crypto) { - &DEBUG("chat: no pass required."); -### $success++; + &DEBUG("todo: dcc close chat"); + &msg($who, "nope, no guest logins allowed..."); + return; + } - } elsif (&ckpasswd($msg, $crypto)) { + if (&ckpasswd($msg, $crypto)) { # stolen from eggdrop. $self->privmsg($sock, "Connected to $ident"); $self->privmsg($sock, "Commands start with '.' (like '.quit' or '.help')"); @@ -475,6 +477,35 @@ sub on_join { $user =~ /^r(oo|ew|00)t$/i && $channels{$chan}{'o'}{$ident}); + ### NEWS: + if (&IsChanConf("news") && &IsChanConf("newsKeepRead")) { + my @new; + foreach (keys %{ $::news{$chan} }) { + my $t = $::newsuser{$chan}{$who}; + next if (!defined $t); + next if ($t > $::news{$chan}{$_}{Time}); + + push(@new, $_); + } + + if (scalar @new) { + &msg($who, "+==== New news for $chan (".scalar(@new)."):"); + # todo: show how many sec/min/etc ago? + my $timestr = &Time2String( $::newsuser{$chan}{$who} ); + &msg($who, "|= Last time read $timestr ago"); + + foreach (@new) { + my $i = &News::getNewsItem($_); + my $age = time() - $::news{$chan}{$_}{Time}; + &msg($who, sprintf("\002[\002%2d\002]\002 %s (%s)", + $i, $_, &Time2String($age) ) ); + } + + # lame hack to prevent dupes if we just ignore it. + $::newsuser{$chan}{$who} = time(); + } + } + ### chanlimit check. &chanLimitVerify($chan); @@ -552,6 +583,14 @@ sub on_msg { $nuh = $nick."!".$uh; $msgtime = time(); + if ($nick eq $ident) { # hopefully ourselves. + if ($msg eq "TEST") { + &status("Local: Yes, we're alive."); + delete $cache{connect}; + return; + } + } + &hookMsg('private', undef, $nick, $msg); } diff --git a/src/IRC/Schedulers.pl b/src/IRC/Schedulers.pl index b4d8e5d..2abf5ea 100644 --- a/src/IRC/Schedulers.pl +++ b/src/IRC/Schedulers.pl @@ -16,6 +16,7 @@ sub setupSchedulers { # ONCE OFF. # REPETITIVE. + # 1 for run straight away, 2 for on next-run. &uptimeLoop(1); &randomQuote(2); &randomFactoid(2); @@ -29,13 +30,14 @@ sub setupSchedulers { &ignoreCheck(1); # mandatory &seenFlushOld(2); &ircCheck(1); # mandatory - &miscCheck(2); # mandatory + &miscCheck(1); # mandatory &shmFlush(1); # mandatory &slashdotLoop(2); &freshmeatLoop(2); &kernelLoop(2); &wingateWriteFile(2); &factoidCheck(2); + &newsFlush(1); # my $count = map { exists $sched{$_}{TIME} } keys %sched; my $count = 0; @@ -281,6 +283,62 @@ sub seenFlushOld { } +sub newsFlush { + if (@_) { + &ScheduleThis(1440, "newsFlush"); + return if ($_[0] eq "2"); # defer. + } else { + delete $sched{"newsFlush"}{RUNNING}; + } + + return unless (&IsChanConf("news") > 0); + + my $delete = 0; + my $oldest = time(); + foreach $chan (keys %::news) { + foreach $item (keys %{ $::news{$chan} }) { + my $t = $::news{$chan}{$item}{Expire}; + + next if ($t == 0 or $t == -1); + if ($t < 1000) { + &status("newsFlush: Fixed Expire time for $chan/$item, should not happen anyway."); + $::news{$chan}{$item}{Expire} = time() + $t*60*60*24; + next; + } + + $oldest = $t if ($t < $oldest); + + next unless (time() > $t); + # todo: show how old it was. + &DEBUG("delete $chan/'$item'."); + delete $::news{$chan}{$item}; + $delete++; + } + } + + # todo: flush users aswell. + my $duser = 0; + foreach $chan (keys %::newsuser) { + foreach (keys %{ $::newsuser{$chan} }) { + my $t = $::newsuser{$chan}{$_}; + if (!defined $t or $t < 1000) { + &DEBUG("something wrong with newsuser{$chan}{$_} => $t"); + next; + } + + next unless ($oldest > $t); + + delete $::newsuser{$chan}{$_}; + $duser++; + } + } + + &News::writeNews(); + +# &VERB("NEWS deleted $delete seen entries.",2); + &status("NEWS deleted $delete news entries; $duser user cache."); +} + sub chanlimitCheck { my $interval = &getChanConfDefault("chanlimitcheckInterval", 10); @@ -562,6 +620,7 @@ sub ircCheck { } if (!$conn->connected or time - $msgtime > 3600) { + # todo: shouldn't we use cache{connect} somewhere? if (exists $cache{connect}) { &WARN("ircCheck: no msg for 3600 and disco'd! reconnecting!"); $msgtime = time(); # just in case. @@ -645,7 +704,7 @@ sub miscCheck { } else { &DEBUG("shm: $shmid is not ours or old blootbot => ($z)"); - next; +# next; } &status("SHM: nuking shmid $shmid"); diff --git a/src/Modules/UserDCC.pl b/src/Modules/UserDCC.pl index 72d08d1..04cd8c1 100644 --- a/src/Modules/UserDCC.pl +++ b/src/Modules/UserDCC.pl @@ -709,7 +709,7 @@ sub userDCC { } if (!defined $user) { - &pSReply("user $user does not exist."); + &pSReply("user does not exist."); return; } diff --git a/src/Process.pl b/src/Process.pl index 5e59a02..c24f51c 100644 --- a/src/Process.pl +++ b/src/Process.pl @@ -377,7 +377,6 @@ sub FactoidStuff { } } - # factoid forget. if ($message =~ s/^forget\s+//i) { return 'forget: no addr' unless ($addressed); @@ -585,9 +584,9 @@ sub FactoidStuff { return; } - # Fix up $message for question. - for ($message) { + my $question = $message; + for ($question) { # fix the string. s/^hey([, ]+)where/where/i; s/whois/who is/ig; @@ -619,7 +618,7 @@ sub FactoidStuff { $correction_plausible = 0; } - my $result = &doQuestion($message); + my $result = &doQuestion($question); if (!defined $result or $result eq $noreply) { return 'result from doQ undef.'; } diff --git a/src/UserExtra.pl b/src/UserExtra.pl index e0c234a..56c3ccf 100644 --- a/src/UserExtra.pl +++ b/src/UserExtra.pl @@ -31,7 +31,7 @@ use vars qw(%channels %chanstats %cmdstats); Forker => "NULL", ) ); &addCmdHook("main", 'tell|explain', ('CODEREF' => 'tell', Help => 'tell', Identifier => 'allowTelling', ) ); - +&addCmdHook("main", 'news', ('CODEREF' => 'News::Parse', ) ); &status("CMD: loaded ".scalar(keys %hooks_main)." MAIN command hooks."); @@ -75,6 +75,10 @@ sub chaninfo { push(@nicks, $_); } } + &DEBUG("nicks => '".scalar(@nicks)."'..."); + if (scalar @nicks != $uucount) { + &DEBUG("nicks != uucount..."); + } my $chans = scalar(keys %channels); &pSReply( @@ -616,17 +620,31 @@ sub userCommands { } # ircstats. - if ($message =~ /^ircstats$/i) { + if ($message =~ /^ircstats?$/i) { + $ircstats{'TotalTime'} ||= 0; + $ircstats{'OffTime'} ||= 0; + my $count = $ircstats{'ConnectCount'}; my $format_time = &Time2String(time() - $ircstats{'ConnectTime'}); - my $total_time = time() - $ircstats{'ConnectTime'} + $ircstats{'TotalTime'}; + my $total_time = time() - $ircstats{'ConnectTime'} + + $ircstats{'TotalTime'}; my $reply; - &DEBUG("ircstats: total_time => $total_time."); - &DEBUG("ircstats: offtime => $ircstats{'OffTime'}"); + my $connectivity = 100 * ($total_time - $ircstats{'OffTime'}) / + $total_time; + my $p = sprintf("%.02f", $connectivity); + $p =~ s/(\.\d*)0+$/$1/; + if ($p =~ s/\.0$//) { + &DEBUG("p sar not working properly :("); + } else { + $p =~ s/\.$// + } + + &DEBUG("connectivity => $p %"); - foreach (keys %ircstats) { - &DEBUG("ircstats: $_ => '$ircstats{$_}'."); + if ($total_time != (time() - $ircstats{'ConnectTime'}) ) { + my $tt_format = &Time2String($total_time); + &DEBUG("tt_format => $tt_format"); } ### RECONNECT COUNT. diff --git a/src/core.pl b/src/core.pl index 4d5363e..02db5aa 100644 --- a/src/core.pl +++ b/src/core.pl @@ -85,6 +85,7 @@ sub doExit { &writeUserFile(); &writeChanFile(); &uptimeWriteFile() if (&ChanConfList("uptime")); + &News::writeNews() if (&ChanConfList("news")); &closeDB(); &closeSHM($shm); &dumpallvars() if (&IsParam("dumpvarsAtExit")); @@ -300,6 +301,7 @@ sub setup { &openDB($param{'DBName'}, $param{'SQLUser'}, $param{'SQLPass'}); &status("Setup: ". &countKeys("factoids") ." factoids."); + &News::readNews() if (&ChanConfList("news")); $param{tempDir} =~ s#\~/#$ENV{HOME}/#; diff --git a/src/modules.pl b/src/modules.pl index fa93df4..7050f23 100644 --- a/src/modules.pl +++ b/src/modules.pl @@ -31,6 +31,7 @@ if ($@) { "kernel" => "Kernel.pl", "ircdcc" => "UserDCC.pl", "perlMath" => "Math.pl", + "news" => "News.pl", "quote" => "Quote.pl", "rootwarn" => "RootWarn.pl", "search" => "Search.pl", @@ -46,8 +47,9 @@ if ($@) { "nickometer" => "nickometer.pl", "babelfish" => "babel.pl", ); +### THIS IS NOT LOADED ON RELOAD :( BEGIN { - @myModulesLoadNow = ('topic', 'uptime',); + @myModulesLoadNow = ('topic', 'uptime', 'news'); @myModulesReloadNot = ('IRC/Irc.pl','IRC/Schedulers.pl'); } @@ -187,7 +189,8 @@ sub loadMyModulesNow { next; } - if (!&IsParam($_) and !&IsChanConf($_)) { + if (!&IsParam($_) and !&IsChanConf($_) and !&getChanConfList($_)) { + &DEBUG("_ => $_"); if (exists $myModules{$_}) { &status("myModule: $myModules{$_} (1) not loaded."); } else { @@ -201,7 +204,7 @@ sub loadMyModulesNow { $loaded++; } - &status("Module: Loaded/Total [$loaded/$total]"); + &status("Module: Runtime: Loaded/Total [$loaded/$total]"); } ### rename to moduleReloadAll? -- 2.39.5