]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/Schedulers.pl
debug for seenflush
[infobot.git] / src / IRC / Schedulers.pl
index d92d9a53f594526c5438970f8c73277974c19dbc..6a5a3486ece717a943e6954af3ad8e513a31b991 100644 (file)
@@ -41,7 +41,7 @@ sub ScheduleThis {
 }
 
 sub randomQuote {
-    my $line = &getRandomLineFromFile($infobot_misc_dir. "/infobot.randtext");
+    my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.randtext");
     if (!defined $line) {
        &ERROR("random Quote: weird error?");
        return;
@@ -106,6 +106,7 @@ sub randomFactoid {
 }
 
 sub logCycle {
+    # check if current size is too large.
     if ( -s $file{log} > $param{'maxLogSize'}) {
        my $date = sprintf("%04d%02d%02d", (localtime)[5,4,3]);
        $file{log} = $param{'logfile'} ."-". $date;
@@ -129,6 +130,45 @@ sub logCycle {
        &status("cycling log file.");
     }
 
+    # check if all the logs exceed size.
+    my $logdir = "$bot_base_dir/log/";
+    if (opendir(LOGS, $logdir)) {
+       my $tsize = 0;
+       my (%age, %size);
+
+       while (defined($_ = readdir LOGS)) {
+           my $logfile = "$logdir/$_";
+
+           next unless ( -f $logfile);
+           my $size = -s $logfile;
+           my $age = (stat $logfile)[9]; ### or 8 ?
+
+           $age{$age}          = $logfile;
+           $size{$logfile}     = $size;
+
+           $tsize              += $size;
+       }
+       closedir LOGS;
+
+       my $delete = 0;
+       while ($tsize > $param{'maxLogSize'}) {
+           &status("LOG: current size > max ($tsize > $param{'maxLogSize'})");
+           my $oldest = (sort {$a <=> $b} keys %age)[0];
+           &status("LOG: unlinking $age{$oldest}.");
+           ### NOT YET.
+           # unlink $age{$oldest};
+           $tsize -= $oldest;
+           $delete++;
+       }
+
+       ### TODO: add how many b,kb,mb removed?
+       if ($delete) {
+           &status("LOG: removed $delete logs.");
+       }
+    } else {
+       &WARN("could not open dir $logdir");
+    }
+
     &ScheduleThis(60, "logCycle") if (@_);
 }
 
@@ -209,6 +249,20 @@ sub netsplitCheck {
        }
     }
 
+    # %netsplit hash checker.
+    foreach (keys %netsplit) {
+       if (&IsNickInAnyChan($_)) {
+           &DEBUG("netsplitC: $_ is in some chan; removing from netsplit list.");
+           delete $netsplit{$_};
+       }
+       next unless (time() - $netsplit{$_} > 60*60*2); # 2 hours.
+
+       if (!&IsNickInAnyChan($_)) {
+           &DEBUG("netsplitC: $_ didn't come back from netsplit in 2 hours; removing from netsplit list.");
+           delete $netsplit{$_};
+       }
+    }
+
     &ScheduleThis(30, "netsplitCheck") if (@_);
 }
 
@@ -288,6 +342,7 @@ sub seenFlush {
     }
 
     &VERB("Flushed $flushed seen entries.",2);
+    &DEBUG("seen: ".scalar(keys %seenflush)." remaining.");
 
     my $interval = $param{'seenFlushInterval'} || 60;
     &ScheduleThis($interval, "seenFlush") if (@_);
@@ -344,8 +399,15 @@ sub ircCheck {
        &FIXME("ircCheck: current channels * 2 <= config channels. FIXME.");
     }
 
+    my @ipcs;
+    if ( -x "/usr/bin/ipcs") {
+       @ipcs = `/usr/bin/ipcs`;
+    } else {
+       &WARN("ircCheck: no 'ipcs' binary.");
+    }
+
     # shmid stale remove.
-    foreach (`ipcs`) {
+    foreach (@ipcs) {
        chop;
 
        # key, shmid, owner, perms, bytes, nattch
@@ -355,7 +417,7 @@ sub ircCheck {
        next unless ($shmid != $shm and $size == 2000);
 
        &status("SHM: nuking shmid $shmid");
-       system("ipcrm shm $shmid >/dev/null");
+       system("/usr/bin/ipcrm shm $shmid >/dev/null");
     }
 
     if (!$conn->connected and time - $msgtime > 3600) {
@@ -368,6 +430,11 @@ sub ircCheck {
        &WARN("ircCheck: ident($ident) != param{ircNick}($param{IrcNick}).");
     }
 
+    if (scalar @joinchan) {
+       &WARN("We have some channels to join, doing so.");
+       &joinNextChan();
+    }
+
     &ScheduleThis(240, "ircCheck") if (@_);
 }
 
@@ -402,6 +469,18 @@ sub shmFlush {
     &ScheduleThis(5, "shmFlush") if (@_);
 }
 
+sub getNickInUse {
+    if ($ident eq $param{'ircNick'}) {
+       &status("okay, got my nick back.");
+       return;
+    }
+
+    &status("Trying to get my nick back.");
+    &nick($param{'ircNick'});
+
+    &ScheduleThis(5, "getNickInUse") if (@_);
+}
+
 sub uptimeCycle {
     &uptimeWriteFile();
 
@@ -462,8 +541,8 @@ sub wingateCheck {
 sub wingateWriteFile {
     return unless (scalar @wingateCache);
 
-    my $file = "$infobot_base_dir/$param{'ircUser'}.wingate";
-    if ($infobot_pid != $$) {
+    my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
+    if ($bot_pid != $$) {
        &DEBUG("wingateWriteFile: Reorganising!");
 
        open(IN, $file);