]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/Schedulers.pl
wingate -> Wingate
[infobot.git] / src / IRC / Schedulers.pl
index e52f4eb7ff93f583bc4a405ac5812fd5f089a1c1..9fbe0c8cc5c64c03780ff9bfc3171b9b2c5794e7 100644 (file)
@@ -56,29 +56,32 @@ sub setupSchedulers {
     # ONCE OFF.
 
     # REPETITIVE.
-    # 1 for run straight away, 2 for on next-run.
-    &uptimeLoop(1);
+    # 2 for on next-run.
     &randomQuote(2);
     &randomFactoid(2);
-    &logLoop(1);
-    &chanlimitCheck(1);
-    &netsplitCheck(1); # mandatory
-    &floodLoop(1);     # mandatory
     &seenFlush(2);
     &leakCheck(2);     # mandatory
-    &ignoreCheck(1);   # mandatory
     &seenFlushOld(2);
-    &ircCheck(1);      # mandatory
-    &miscCheck(1);     # mandatory
     &miscCheck2(2);    # mandatory
-    &shmFlush(1);      # mandatory
     &slashdotLoop(2);
     &plugLoop(2);
     &kernelLoop(2);
     &wingateWriteFile(2);
     &factoidCheck(2);  # takes a couple of seconds on a 486. defer it
 # TODO: convert to new format... or nuke altogether.
-    &newsFlush(1);
+    &newsFlush(2);
+
+    # 1 for run straight away
+    &uptimeLoop(1);
+    &logLoop(1);
+    &chanlimitCheck(1);
+    &netsplitCheck(1); # mandatory
+    &floodLoop(1);     # mandatory
+    &ignoreCheck(1);   # mandatory
+    &miscCheck(1);     # mandatory
+    &shmFlush(1);      # mandatory
+    sleep 1;
+    &ircCheck(1);      # mandatory
 
     # TODO: squeeze this into a one-liner.
 #    my $count = map { exists $sched{$_}{TIME} } keys %sched;
@@ -109,7 +112,7 @@ sub ScheduleThis {
        return;
     }
 
-    #&DEBUG("Scheduling \&$codename() " . \&$codename . " for " . &Time2String($waittime),3);
+    &DEBUG("Scheduling \&$codename() " . \&$codename . " for " . &Time2String($waittime),3);
 
     my $retval = $conn->schedule($waittime, \&$codename, @args);
     $sched{$codename}{LABEL}   = $retval;
@@ -128,15 +131,15 @@ sub randomQuote {
        return if ($_[0] eq "2");       # defer.
     }
 
-    my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.randtext");
-    if (!defined $line) {
-       &ERROR("random Quote: weird error?");
-       return;
-    }
-
     foreach ( &ChanConfList("randomQuote") ) {
        next unless (&validChan($_));
 
+       my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.randtext");
+       if (!defined $line) {
+           &ERROR("random Quote: weird error?");
+           return;
+       }
+
        &status("sending random Quote to $_.");
        &action($_, "Ponders: ".$line);
     }
@@ -154,22 +157,22 @@ sub randomFactoid {
        return if ($_[0] eq "2");       # defer.
     }
 
-    while (1) {
-       ($key,$val) = &randKey("factoids","factoid_key,factoid_value");
-###    $val =~ tr/^[A-Z]/[a-z]/;       # blah is Good => blah is good.
-       last if (defined $val and $val !~ /^</);
-
-       $error++;
-       if ($error == 5) {
-           &ERROR("rF: tried 5 times but failed.");
-           return;
-       }
-    }
-
     foreach ( &ChanConfList("randomFactoid") ) {
        next unless (&validChan($_));
 
        &status("sending random Factoid to $_.");
+       while (1) {
+           ($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:/));
+
+           $error++;
+           if ($error == 5) {
+               &ERROR("rF: tried 5 times but failed.");
+               return;
+           }
+       }
        &action($_, "Thinks: \037$key\037 is $val");
        ### FIXME: Use &getReply() on above to format factoid properly?
        $good++;
@@ -367,6 +370,7 @@ sub newsFlush {
 
 sub chanlimitCheck {
     my $interval = &getChanConfDefault("chanlimitcheckInterval", 10);
+    my $mynick=$conn->nick();
 
     if (@_) {
        &ScheduleThis($interval, "chanlimitCheck");
@@ -408,7 +412,7 @@ sub chanlimitCheck {
            next;
        }
 
-       if (!exists $channels{$chan}{'o'}{$ident}) {
+       if (!exists $channels{$chan}{'o'}{$mynick}) {
            &status("chanlimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
            $cache{warn}{chanlimit}{$chan} = 1;
            &chanServCheck($chan);
@@ -675,6 +679,7 @@ sub ircCheck {
     $cache{statusSafe} = 1;
     foreach (sort keys %conns) {
        $conn=$conns{$_};
+       my $mynick=$conn->nick();
        &DEBUG("ircCheck for $_");
        my @join = &getJoinChans(1);
        if (scalar @join) {
@@ -694,7 +699,7 @@ sub ircCheck {
            } else {
                &status('ircCheck: possible lost in space; checking.'.
                    scalar(gmtime) );
-               &msg($ident, "TEST");
+               &msg($mynick, "TEST");
                $cache{connect} = time();
            }
        }
@@ -838,11 +843,11 @@ sub getNickInUse {
 
 sub uptimeLoop {
     return if (!defined &uptimeWriteFile);
-#    return unless &IsChanConf("uptime");
+#    return unless &IsChanConf('Uptime');
 
     if (@_) {
-       &ScheduleThis(60, "uptimeLoop");
-       return if ($_[0] eq "2");       # defer.
+       &ScheduleThis(60, 'uptimeLoop');
+       return if ($_[0] eq '2');       # defer.
     }
 
     &uptimeWriteFile();
@@ -851,14 +856,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);
 
@@ -874,14 +879,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);
 
@@ -919,14 +924,14 @@ sub kernelLoop {
 }
 
 sub wingateCheck {
-    return unless &IsChanConf("wingate");
+    return unless &IsChanConf('Wingate');
 
     ### 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');
 
-       my $reason      = &getChanConf("wingateKick");
+       my $reason      = &getChanConf('wingateKick');
 
        next unless ($reason);
        &kick($who, "", $reason)
@@ -940,21 +945,21 @@ sub wingateCheck {
        &DEBUG("Already scanned $host. good.");
     }
 
-    my $interval = &getChanConfDefault("wingateInterval", 60); # seconds.
-    return if (defined $forked{'wingate'});
+    my $interval = &getChanConfDefault('wingateInterval', 60); # 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.
     }
 
@@ -962,7 +967,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>) {
@@ -976,7 +981,7 @@ sub wingateWriteFile {
        @wingateNow = sort keys %hash;
     }
 
-    &DEBUG("wingateWF: writing...");
+    &DEBUG('wingateWF: writing...');
     open(OUT, ">$file");
     foreach (@wingateNow) {
        print OUT "$_\n";