]> git.donarmstrong.com Git - infobot.git/commitdiff
Many changes, basically added and integrated News, and bug fixes.
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 31 Mar 2001 14:19:14 +0000 (14:19 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 31 Mar 2001 14:19:14 +0000 (14:19 +0000)
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 <reply> :)" -- FIXED.

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

12 files changed:
src/CommandStubs.pl
src/DynaConfig.pl
src/Factoids/Statement.pl
src/Factoids/Update.pl
src/IRC/Irc.pl
src/IRC/IrcHooks.pl
src/IRC/Schedulers.pl
src/Modules/UserDCC.pl
src/Process.pl
src/UserExtra.pl
src/core.pl
src/modules.pl

index d4e22442be8c8edce78113b7c910865115010d37..4a052a8eec787076539f12e0012cb03b41cbf556 100644 (file)
@@ -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') );
index 29a44ec1846fe620b5a565c6b5b520af068ba2ff..2a78ebf249848e976c6579a2dacfd15f3d0e9185 100644 (file)
@@ -307,8 +307,8 @@ sub writeChanFile {
            }
        }
 
-       &DEBUG("chans => ".scalar(keys %chanconf)." - 1");
        foreach (keys %opts) {
+           next unless ($opts{$_} > 1);
            &DEBUG("  opts{$_} => $opts{$_}");
        }
 
index 903a4f857d717380efdb031e136940012e54f808..6c05f93a075d27a2a8025b032600fd2d1b9904d5 100644 (file)
@@ -99,9 +99,8 @@ sub doStatement {
            }
        }
 
-       if (&update($lhs, $mhs, $rhs)) {
-           return;     # success.
-       }
+       # success.
+       return if (&update($lhs, $mhs, $rhs));
     }
 
     return "CONTINUE";
index df9a38854a8c5675f3756e99c9957de381ad219c..827e9cd25d91b6858fd0d5e5cfe52751eac2b80c 100644 (file)
@@ -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
index 53d100408c2f4949c90c12d8de5a494f175c6aa8..3fab9912474cdc8784810b3bf862b1642a0d758e 100644 (file)
@@ -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}) {
index c4f1ef08d55d1a55210daa8ef6b4985f67de9387..87d3f6857967ff88098b3d4a7172ed48e98c167f 100644 (file)
@@ -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);
 }
 
index b4d8e5d265e669586a2225e1bb8d6c08f4d48e13..2abf5eaa6815b30f5bb019da243e9e4150402ff5 100644 (file)
@@ -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");
index 72d08d141c73903bb65a1fdc46ddb1ee32b25bfb..04cd8c13777394044c3fb4e33ca080ccc9585c58 100644 (file)
@@ -709,7 +709,7 @@ sub userDCC {
        }
 
        if (!defined $user) {
-           &pSReply("user $user does not exist.");
+           &pSReply("user does not exist.");
            return;
        }
 
index 5e59a021d4c70f4bd39f2d9a86ca090c5ef05d2d..c24f51ca6fa3a51f2da590832968d0708a35f22f 100644 (file)
@@ -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.';
     }
index e0c234a4cadc3580cb1e05503e77bc18af88b8ef..56c3ccfcc4902c6407195934dd8efd0de36c44b9 100644 (file)
@@ -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.
index 4d5363ec47b543cd65cf8ac34194f01f01c2a83a..02db5aac7f17420778a8221dfcbc8c13f480fa3a 100644 (file)
@@ -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}/#;
 
index fa93df42615dd28399939e60e244f6ccc12f8eb6..7050f233dfed49be48b460f2fdb9cf3f9ace8174 100644 (file)
@@ -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?