]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/Schedulers.pl
Apply patch from stew and #370040
[infobot.git] / src / IRC / Schedulers.pl
index 9c155c40d7b2a275f0558e436c5bbbffd0565c2d..1327833e457e29ef50dcf9bb45815c2c4d432837 100644 (file)
@@ -29,7 +29,7 @@ sub setupSchedulersII {
 
 sub queueTask {
     my($codename, $chanconfdef, $intervaldef, $defer) = @_;
-    my $t = &getChanConfDefault($chanconfdef, $intervaldef);
+    my $t = &getChanConfDefault($chanconfdef, $intervaldef, $chan);
     my $waittime = &getRandomInt($t);
 
     if (!defined $waittime) {
@@ -125,7 +125,7 @@ sub ScheduleThis {
 ####
 
 sub randomQuote {
-    my $interval = &getChanConfDefault("randomQuoteInterval", 60);
+    my $interval = &getChanConfDefault("randomQuoteInterval", 60, $chan);
     if (@_) {
        &ScheduleThis($interval, "randomQuote");
        return if ($_[0] eq "2");       # defer.
@@ -151,7 +151,7 @@ sub randomFactoid {
     my ($key,$val);
     my $error = 0;
 
-    my $interval = &getChanConfDefault("randomFactoidInterval", 60);
+    my $interval = &getChanConfDefault("randomFactoidInterval", 60, $chan);
     if (@_) {
        &ScheduleThis($interval, "randomFactoid");
        return if ($_[0] eq "2");       # defer.
@@ -165,7 +165,7 @@ sub randomFactoid {
            ($key,$val) = &randKey("factoids","factoid_key,factoid_value");
            &DEBUG("rF: $key, $val");
 ###        $val =~ tr/^[A-Z]/[a-z]/;   # blah is Good => blah is good.
-           last if ((defined $val) and ($val !~ /^</) and ($key !~ /\#DEL\#/) and ($key !~ /^CMD:/));
+           last if ((defined $val) and ($val !~ /^</) and ($key !~ /\#DEL\#/) and ($key !~ /^cmd:/));
 
            $error++;
            if ($error == 5) {
@@ -254,18 +254,20 @@ sub seenFlushOld {
        return if ($_[0] eq "2");       # defer.
     }
 
+    # NO SEEN FLUSHING!!!
+    return;
     # is this global-only?
     return unless (&IsChanConf("seen") > 0);
     return unless (&IsChanConf("seenFlushInterval") > 0);
 
     # global setting. does not make sense for per-channel.
-    my $max_time = &getChanConfDefault("seenMaxDays", 30) *60*60*24;
+    my $max_time = &getChanConfDefault("seenMaxDays", 30, $chan) *60*60*24;
     my $delete   = 0;
 
-    if ($param{'DBType'} =~ /^(pgsql|mysql|sqlite)/i) {
+    if ($param{'DBType'} =~ /^(pgsql|mysql|sqlite(2)?)$/i) {
        my $query;
 
-       if ($param{'DBType'} =~ /^mysql|sqlite$/i) {
+       if ($param{'DBType'} =~ /^(mysql|sqlite(2)?)$/i) {
            $query = "SELECT nick,time FROM seen GROUP BY nick HAVING ".
                        "UNIX_TIMESTAMP() - time > $max_time";
        } else {        # pgsql.
@@ -296,7 +298,7 @@ sub newsFlush {
        return if ($_[0] eq "2");       # defer.
     }
 
-    if (!&ChanConfList("news")) {
+    if (!&ChanConfList('News')) {
        &DEBUG("newsFlush: news disabled? (chan => $chan)");
        return;
     }
@@ -369,7 +371,7 @@ sub newsFlush {
 }
 
 sub chanlimitCheck {
-    my $interval = &getChanConfDefault("chanlimitcheckInterval", 10);
+    my $interval = &getChanConfDefault("chanlimitcheckInterval", 10, $chan);
     my $mynick=$conn->nick();
 
     if (@_) {
@@ -523,7 +525,7 @@ sub floodLoop {
     }
 
     my $time           = time();
-    my $interval       = &getChanConfDefault("floodCycle",60);
+    my $interval       = &getChanConfDefault("floodCycle",60, $chan);
 
     foreach $who (keys %flood) {
        foreach (keys %{ $flood{$who} }) {
@@ -543,26 +545,29 @@ sub floodLoop {
 
 sub seenFlush {
     if (@_) {
-       my $interval = &getChanConfDefault("seenFlushInterval", 60);
+       my $interval = &getChanConfDefault("seenFlushInterval", 60, $chan);
        &ScheduleThis($interval, "seenFlush");
        return if ($_[0] eq "2");
     }
 
     my %stats;
     my $nick;
-    my $flushed        = 0;
+    my $flushed = 0;
     $stats{'count_old'} = &countKeys("seen") || 0;
     $stats{'new'}      = 0;
     $stats{'old'}      = 0;
 
-    if ($param{'DBType'} =~ /^(mysql|pgsql|sqlite)$/i) {
+    if ($param{'DBType'} =~ /^(mysql|pgsql|sqlite(2)?)$/i) {
        foreach $nick (keys %seencache) {
+           my $lastcount = &sqlSelect('seen','messagecount',{nick=>lc $seencache{$nick}{'nick'}}) || 0;
            my $retval = &sqlReplace("seen", {
                        nick    => lc $seencache{$nick}{'nick'},
                        time    => $seencache{$nick}{'time'},
                        host    => $seencache{$nick}{'host'},
                        channel => $seencache{$nick}{'chan'},
                        message => $seencache{$nick}{'msg'},
+                       messagecount => $lastcount+$seencache{$nick}{'msgcount'},
+                                               
            } );
 
            delete $seencache{$nick};
@@ -687,7 +692,11 @@ sub ircCheck {
            &joinNextChan();
        }
 
-       # TODO: fix on_disconnect()
+    my @join = &getJoinChans(1);
+    if (scalar @join) {
+       &FIXME('ircCheck: found channels to join! ' . join(',',@join));
+       &joinNextChan();
+    }
 
        if (time() - $msgtime > 3600) {
            # TODO: shouldn't we use cache{connect} somewhere?
@@ -703,14 +712,24 @@ sub ircCheck {
                $cache{connect} = time();
            }
        }
+    }
 
-       if (grep /^\s*$/, keys %channels) {
-           &WARN('ircCheck: we have a NULL chan in hash channels? removing!');
-           if (!exists $channels{''}) {
-               &DEBUG('ircCheck: this should never happen!');
-           }
-
-           delete $channels{''};
+       if (grep /^\s*$/, keys %channels) {
+           &WARN('ircCheck: we have a NULL chan in hash channels? removing!');
+           if (!exists $channels{''}) {
+               &DEBUG('ircCheck: this should never happen!');
+           }
+      }
+    if ($ident !~ /^\Q$param{ircNick}\E$/) {
+       # this does not work unfortunately.
+       &WARN("ircCheck: ident($ident) != param{ircNick}($param{ircNick}).");
+
+       # this check is misleading... perhaps we should do a notify.
+       if (! &IsNickInAnyChan( $param{ircNick} ) ) {
+           &DEBUG("$param{ircNick} not in use... changing!");
+           &nick( $param{ircNick} );
+       } else {
+           &WARN("$param{ircNick} is still in use...");
        }
     }
 
@@ -843,11 +862,11 @@ sub getNickInUse {
 
 sub uptimeLoop {
     return if (!defined &uptimeWriteFile);
-#    return unless &IsChanConf("uptime");
+#    return unless &IsParam('Uptime');
 
     if (@_) {
-       &ScheduleThis(60, "uptimeLoop");
-       return if ($_[0] eq "2");       # defer.
+       &ScheduleThis(60, 'uptimeLoop');
+       return if ($_[0] eq '2');       # defer.
     }
 
     &uptimeWriteFile();
@@ -856,14 +875,14 @@ sub uptimeLoop {
 sub slashdotLoop {
 
     if (@_) {
-       &ScheduleThis(60, "slashdotLoop");
+       &ScheduleThis(60, 'slashdotLoop');
        return if ($_[0] eq "2");
     }
 
-    my @chans = &ChanConfList("slashdotAnnounce");
+    my @chans = &ChanConfList('slashdotAnnounce');
     return unless (scalar @chans);
 
-    &Forker("slashdot", sub {
+    &Forker('slashdot', sub {
        my $line = &Slashdot::slashdotAnnounce();
        return unless (defined $line);
 
@@ -879,14 +898,14 @@ sub slashdotLoop {
 sub plugLoop {
 
     if (@_) {
-       &ScheduleThis(60, "plugLoop");
+       &ScheduleThis(60, 'plugLoop');
        return if ($_[0] eq "2");
     }
 
-    my @chans = &ChanConfList("plugAnnounce");
+    my @chans = &ChanConfList('plugAnnounce');
     return unless (scalar @chans);
 
-    &Forker("plug", sub {
+    &Forker('Plug', sub {
        my $line = &Plug::plugAnnounce();
        return unless (defined $line);
 
@@ -908,7 +927,7 @@ sub kernelLoop {
     my @chans = &ChanConfList("kernelAnnounce");
     return unless (scalar @chans);
 
-    &Forker("kernel", sub {
+    &Forker("Kernel", sub {
        my @data = &Kernel::kernelAnnounce();
 
        foreach (@chans) {
@@ -924,14 +943,14 @@ sub kernelLoop {
 }
 
 sub wingateCheck {
-    return unless &IsChanConf("wingate");
+    return unless &IsChanConf('Wingate') > 0;
 
     ### FILE CACHE OF OFFENDING WINGATES.
     foreach (grep /^$host$/, @wingateBad) {
        &status("Wingate: RUNNING ON $host BY $who");
-       &ban("*!*\@$host", "") if &IsChanConf("wingateBan");
+       &ban("*!*\@$host", "") if &IsChanConf('wingateBan') > 0;
 
-       my $reason      = &getChanConf("wingateKick");
+       my $reason      = &getChanConf('wingateKick');
 
        next unless ($reason);
        &kick($who, "", $reason)
@@ -945,21 +964,21 @@ sub wingateCheck {
        &DEBUG("Already scanned $host. good.");
     }
 
-    my $interval = &getChanConfDefault("wingateInterval", 60); # seconds.
-    return if (defined $forked{'wingate'});
+    my $interval = &getChanConfDefault('wingateInterval', 60, $chan); # seconds.
+    return if (defined $forked{'Wingate'});
     return if (time() - $wingaterun <= $interval);
     return unless (scalar(keys %wingateToDo));
 
     $wingaterun = time();
 
-    &Forker("wingate", sub { &Wingate::Wingates(keys %wingateToDo); } );
+    &Forker('Wingate', sub { &Wingate::Wingates(keys %wingateToDo); } );
     undef @wingateNow;
 }
 
 ### TODO: ??
 sub wingateWriteFile {
     if (@_) {
-       &ScheduleThis(60, "wingateWriteFile");
+       &ScheduleThis(60, 'wingateWriteFile');
        return if ($_[0] eq "2");       # defer.
     }
 
@@ -967,7 +986,7 @@ sub wingateWriteFile {
 
     my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
     if ($bot_pid != $$) {
-       &DEBUG("wingateWriteFile: Reorganising!");
+       &DEBUG('wingateWriteFile: Reorganising!');
 
        open(IN, $file);
        while (<IN>) {
@@ -981,7 +1000,7 @@ sub wingateWriteFile {
        @wingateNow = sort keys %hash;
     }
 
-    &DEBUG("wingateWF: writing...");
+    &DEBUG('wingateWF: writing...');
     open(OUT, ">$file");
     foreach (@wingateNow) {
        print OUT "$_\n";
@@ -996,7 +1015,7 @@ sub factoidCheck {
     }
 
     my @list   = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
-    my $stale  = &getChanConfDefault("factoidDeleteDelay", 14) *60*60*24;
+    my $stale  = &getChanConfDefault("factoidDeleteDelay", 14, $chan) *60*60*24;
     if ($stale < 1) {
        # disable it since it's "illegal".
        return;