]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/Schedulers.pl
- now support verstats for those who don't reply to "CTCP VERSION
[infobot.git] / src / IRC / Schedulers.pl
index 1a2d48c64cca4019a8f82b25d933ee9b6be245b5..c325ab32e22afa416fa8c60ccc43a7dc8ff66678 100644 (file)
@@ -29,7 +29,6 @@ sub setupSchedulers {
     &leakCheck(2);     # mandatory
     &ignoreCheck(1);   # mandatory
     &seenFlushOld(2);
-#    &ircCheck(2);     # mandatory
     &ircCheck(1);      # mandatory
     &miscCheck(1);     # mandatory
     &miscCheck2(2);    # mandatory
@@ -89,7 +88,7 @@ sub randomQuote {
        return if ($_[0] eq "2");       # defer.
     }
 
-    my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.randtext");
+    my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.randtext");
     if (!defined $line) {
        &ERROR("random Quote: weird error?");
        return;
@@ -195,13 +194,12 @@ sub logLoop {
     }
 
     ### check if all the logs exceed size.
-    my $logdir = "$bot_base_dir/log/";
-    if (opendir(LOGS, $logdir)) {
+    if (opendir(LOGS, $bot_log_dir)) {
        my $tsize = 0;
        my (%age, %size);
 
        while (defined($_ = readdir LOGS)) {
-           my $logfile         = "$logdir/$_";
+           my $logfile         = "$bot_log_dir/$_";
 
            next unless ( -f $logfile);
            my $size            = -s $logfile;
@@ -227,7 +225,7 @@ sub logLoop {
        ### TODO: add how many b,kb,mb removed?
        &status("LOG: removed $delete logs.") if ($delete);
     } else {
-       &WARN("could not open dir $logdir");
+       &WARN("could not open dir $bot_log_dir");
     }
 
 }
@@ -441,7 +439,7 @@ sub netsplitCheck {
     }
 
     $cache{'netsplitCache'}++;
-    &DEBUG("running netsplitCheck... $cache{netsplitCache}");
+#    &DEBUG("running netsplitCheck... $cache{netsplitCache}");
 
     if (!scalar %netsplit and scalar %netsplitservers) {
        &DEBUG("nsC: !hash netsplit but hash netsplitservers <- removing!");
@@ -494,7 +492,7 @@ sub netsplitCheck {
 
     if ($delete) {
        my $j = scalar(keys %netsplit);
-       &DEBUG("nsC: removed from netsplit list: (before: $count; after: $j)");
+       &status("nsC: removed from netsplit list: (before: $count; after: $j)");
     }
 
     if (!scalar %netsplit and scalar %netsplitservers) {
@@ -553,7 +551,7 @@ sub seenFlush {
     if ($param{'DBType'} =~ /^(mysql|pgsql)$/i) {
        foreach $nick (keys %seencache) {
            my $retval = &dbReplace("seen", "nick", (
-                       "nick" => $seencache{$nick}{'nick'},
+                       "nick" => lc $seencache{$nick}{'nick'},
                        "time" => $seencache{$nick}{'time'},
                        "host" => $seencache{$nick}{'host'},
                        "channel" => $seencache{$nick}{'chan'},
@@ -643,7 +641,7 @@ sub leakCheck {
            $count += scalar(keys %{ $flood{$blah1}{$blah2} });
        }
     }
-    &DEBUG("leak: hash flood has $count total keys.",2);
+    &VERB("leak: hash flood has $count total keys.",2);
 
     # floodjoin.
     $count = 0;
@@ -652,11 +650,11 @@ sub leakCheck {
            $count += scalar(keys %{ $floodjoin{$blah1}{$blah2} });
        }
     }
-    &DEBUG("leak: hash floodjoin has $count total keys.",2);
+    &VERB("leak: hash floodjoin has $count total keys.",2);
 
     # floodwarn.
     $count = scalar(keys %floodwarn);
-    &DEBUG("leak: hash floodwarn has $count total keys.",2);
+    &VERB("leak: hash floodwarn has $count total keys.",2);
 
     my $chan;
     foreach $chan (grep /[A-Z]/, keys %channels) {
@@ -671,7 +669,7 @@ sub leakCheck {
 
     # chanstats
     $count = scalar(keys %chanstats);
-    &DEBUG("leak: hash chanstats has $count total keys.",2);
+    &VERB("leak: hash chanstats has $count total keys.",2);
 
     # nuh.
     my $delete = 0;
@@ -709,6 +707,9 @@ sub ignoreCheck {
            $count++;
        }
     }
+
+    $cache{ignoreCheckTime} = time();
+
     &VERB("ignore: $count items deleted.",2);
 }
 
@@ -718,6 +719,8 @@ sub ircCheck {
        return if ($_[0] eq "2");       # defer.
     }
 
+    $cache{statusSafe} = 1;
+
     my @x      = &getJoinChans();
     my $iconf  = scalar( @x );
     my $inow   = scalar( keys %channels );
@@ -757,15 +760,15 @@ sub ircCheck {
 
     if (grep /^\s*$/, keys %channels) {
        &WARN("ircCheck: we have a NULL chan in hash channels? removing!");
-       if (exists $channels{''}) {
-           &DEBUG("ircCheck: ok it existed!");
-       } else {
-           &DEBUG("ircCheck: this hsould never happen!");
+       if (!exists $channels{''}) {
+           &DEBUG("ircCheck: this should never happen!");
        }
 
        delete $channels{''};
     }
 
+    $cache{statusSafe} = 0;
+
     ### USER FILE.
     if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
        &writeUserFile();
@@ -780,10 +783,21 @@ sub ircCheck {
 
 sub miscCheck {
     if (@_) {
-       &ScheduleThis(240, "miscCheck");
+       &ScheduleThis(120, "miscCheck");
        return if ($_[0] eq "2");       # defer.
     }
 
+    # debian check.
+    opendir(DEBIAN, "$bot_state_dir/debian");
+    foreach ( grep /gz$/, readdir(DEBIAN) ) {
+       my $exit = CORE::system("gzip -t $bot_state_dir/debian/$_");
+       next unless ($exit);
+
+       &status("debian: unlinking file => $_");
+       unlink "$bot_state_dir/debian/$_";
+    }
+    closedir DEBIAN;
+
     # SHM check.
     my @ipcs;
     if ( -x "/usr/bin/ipcs") {
@@ -817,8 +831,8 @@ sub miscCheck {
     }
 
     # make backup of important files.
-    &mkBackup( $bot_misc_dir."/blootbot.chan", 60*60*24*3);
-    &mkBackup( $bot_misc_dir."/blootbot.users", 60*60*24*3);
+    &mkBackup( $bot_state_dir."/blootbot.chan", 60*60*24*3);
+    &mkBackup( $bot_state_dir."/blootbot.users", 60*60*24*3);
     &mkBackup( $bot_base_dir."/blootbot-news.txt", 60*60*24*1);
 
     # flush cache{lobotomy}
@@ -837,30 +851,24 @@ sub miscCheck2 {
        return if ($_[0] eq "2");       # defer.
     }
 
-    # debian check.
-    opendir(DEBIAN, "$bot_base_dir/debian");
-    foreach ( grep /gz$/, readdir(DEBIAN) ) {
-       my $exit = CORE::system("gzip -t $bot_base_dir/debian/$_");
-       next unless ($exit);
-
-       &status("debian: unlinking file => $_");
-       unlink "$bot_base_dir/debian/$_";
-    }
-    closedir DEBIAN;
-
     # compress logs that should have been compressed.
     # todo: use strftime?
     my ($day,$month,$year) = (localtime(time()))[3,4,5];
     my $date = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
 
-    opendir(DIR,"$bot_base_dir/log");
+    if (!opendir(DIR,"$bot_log_dir")) {
+       &ERROR("misccheck2: log dir $bot_log_dir does not exist.");
+       closedir DIR;
+       return -1;
+    }
+
     while (my $f = readdir(DIR)) {
-       next unless ( -f "$bot_base_dir/log/$f");
+       next unless ( -f "$bot_log_dir/$f");
        next if ($f =~ /gz|bz2/);
        next unless ($f =~ /(\d{8})/);
        next if ($date eq $1);
 
-       &compress("$bot_base_dir/log/$f");
+       &compress("$bot_log_dir/$f");
     }
     closedir DIR;
 }