]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/Schedulers.pl
ws
[infobot.git] / src / IRC / Schedulers.pl
index b5bca95c393aa3f6b1d785fb56ad57fdcefcc48b..bf254ba6c6d46f85b2d92a68a8678df98bde668b 100644 (file)
@@ -5,10 +5,50 @@
 #         Created: 20000117
 #
 
-if (&IsParam("useStrict")) { use strict; }
+# use strict;  # TODO
 
 use POSIX qw(strftime);
-use vars qw(%sched);
+use vars qw(%sched %schedule);
+
+# format: function name = (
+#      str     chanconfdefault,
+#      int     internaldefault,
+#      bool    deferred,
+#      int     next run,               (optional)
+# )
+
+#%schedule = {
+#      uptimeLoop => ("", 60, 1),
+#};
+
+sub setupSchedulersII {
+    foreach (keys %schedule) {
+       &queueTask($_, @{ $schedule{$_} });
+    }
+}
+
+sub queueTask {
+    my($codename, $chanconfdef, $intervaldef, $defer) = @_;
+    my $t = &getChanConfDefault($chanconfdef, $intervaldef);
+    my $waittime = &getRandomInt($t);
+
+    if (!defined $waittime) {
+       &WARN("interval == waittime == UNDEF for $codename.");
+       return;
+    }
+
+    my $time = $schedule{$codename}[3];
+    if (defined $time and $time > time()) {
+       &WARN("Sched for $codename already exists.");
+       return;
+    }
+
+#    &VERB("Scheduling \&$codename() for ".&Time2String($waittime),3);
+
+    my $retval = $conn->schedule($waittime, sub {
+               \&$codename;
+    }, @args );
+}
 
 sub setupSchedulers {
     &VERB("Starting schedulers...",2);
@@ -20,7 +60,6 @@ sub setupSchedulers {
     &uptimeLoop(1);
     &randomQuote(2);
     &randomFactoid(2);
-    &randomFreshmeat(2);
     &logLoop(1);
     &chanlimitCheck(1);
     &netsplitCheck(1); # mandatory
@@ -29,22 +68,22 @@ sub setupSchedulers {
     &leakCheck(2);     # mandatory
     &ignoreCheck(1);   # mandatory
     &seenFlushOld(2);
-#    &ircCheck(2);     # mandatory
     &ircCheck(1);      # mandatory
     &miscCheck(1);     # mandatory
     &miscCheck2(2);    # mandatory
     &shmFlush(1);      # mandatory
     &slashdotLoop(2);
-    &freshmeatLoop(2);
+    &plugLoop(2);
     &kernelLoop(2);
     &wingateWriteFile(2);
-    &factoidCheck(1);
+    &factoidCheck(2);  # takes a couple of seconds on a 486. defer it
+# todo: convert to new format... or nuke altogether.
     &newsFlush(1);
 
+    # todo: squeeze this into a one-liner.
 #    my $count = map { exists $sched{$_}{TIME} } keys %sched;
     my $count  = 0;
     foreach (keys %sched) {
-#      next unless (exists $sched{$_}{TIME});
        my $time = $sched{$_}{TIME};
        next unless (defined $time and $time > time());
 
@@ -89,7 +128,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;
@@ -137,29 +176,6 @@ sub randomFactoid {
     }
 }
 
-sub randomFreshmeat {
-    my $interval = &getChanConfDefault("randomFresheatInterval", 60);
-
-    if (@_) {
-       &ScheduleThis($interval, "randomFreshmeat");
-       return if ($_[0] eq "2");       # defer.
-    }
-
-    my @chans = &ChanConfList("randomFreshmeat");
-    return unless (scalar @chans);
-
-    &Forker("freshmeat", sub {
-       my $retval = &Freshmeat::randPackage();
-
-       foreach (@chans) {
-           next unless (&validChan($_));
-
-           &status("sending random Freshmeat to $_.");
-           &say($_, $line);
-       }
-    } );
-}
-
 sub logLoop {
     if (@_) {
        &ScheduleThis(60, "logLoop");
@@ -172,7 +188,7 @@ sub logLoop {
 
     ### check if current size is too large.
     if ( -s $file{log} > $param{'maxLogSize'}) {
-       my $date = sprintf("%04d%02d%02d", (localtime)[5,4,3]);
+       my $date = sprintf("%04d%02d%02d", (gmtime)[5,4,3]);
        $file{log} = $param{'logfile'} ."-". $date;
        &status("cycling log file.");
 
@@ -195,41 +211,38 @@ sub logLoop {
     }
 
     ### 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/$_";
+    if (!opendir(LOGS, $bot_log_dir)) {
+       &WARN("logLoop: could not open dir '$bot_log_dir'");
+       return;
+    }
 
-           next unless ( -f $logfile);
-           my $size            = -s $logfile;
-           my $age             = (stat $logfile)[9];
+    my $tsize          = 0;
+    my (%age, %size);
+    while (defined($_ = readdir LOGS)) {
+       my $logfile     = "$bot_log_dir/$_";
 
-           $age{$age}          = $logfile;
-           $size{$logfile}     = $size;
+       next unless ( -f $logfile);
 
-           $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}.");
-           unlink $age{$oldest};
-           $tsize      -= $oldest;
-           $delete++;
-       }
+       my $size        = -s $logfile;
+       my $age         = (stat $logfile)[9];
+       $age{$age}      = $logfile;
+       $size{$logfile} = $size;
+       $tsize          += $size;
+    }
+    closedir LOGS;
 
-       ### TODO: add how many b,kb,mb removed?
-       &status("LOG: removed $delete logs.") if ($delete);
-    } else {
-       &WARN("could not open dir $logdir");
+    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}.");
+       unlink $age{$oldest};
+       $tsize          -= $oldest;
+       $delete++;
     }
 
+    ### TODO: add how many b,kb,mb removed?
+    &status("LOG: removed $delete logs.") if ($delete);
 }
 
 sub seenFlushOld {
@@ -246,31 +259,29 @@ sub seenFlushOld {
     my $max_time = &getChanConfDefault("seenMaxDays", 30) *60*60*24;
     my $delete   = 0;
 
-    if ($param{'DBType'} =~ /^pg|postgres|mysql/i) {
-       my $query = "SELECT nick,time FROM seen GROUP BY nick HAVING UNIX_TIMESTAMP() - time > $max_time";
-       my $sth = $dbh->prepare($query);
-       $sth->execute;
-
-       while (my @row = $sth->fetchrow_array) {
-           my ($nick,$time) = @row;
+    if ($param{'DBType'} =~ /^(pgsql|mysql|sqlite)/i) {
+       my $query;
 
-           &dbDel("seen","nick",$nick);
-           $delete++;
+       if ($param{'DBType'} =~ /^mysql|sqlite$/i) {
+           $query = "SELECT nick,time FROM seen GROUP BY nick HAVING ".
+                       "UNIX_TIMESTAMP() - time > $max_time";
+       } else {        # pgsql.
+           $query = "SELECT nick,time FROM seen WHERE ".
+               "extract(epoch from timestamp 'now') - time > $max_time";
        }
-       $sth->finish;
-    } elsif ($param{'DBType'} =~ /^dbm/i) {
-       my $time = time();
 
-       foreach (keys %seen) {
-           my $delta_time = $time - &dbGet("seen", "time", "nick", $_);
-           next unless ($delta_time > $max_time);
+       my $sth = $dbh->prepare($query);
+       if ($sth->execute) {
+           while (my @row = $sth->fetchrow_array) {
+               my ($nick,$time) = @row;
 
-           &DEBUG("seenFlushOld: ".&Time2String($delta_time) );
-           delete $seen{$_};
-           $delete++;
+               &sqlDelete("seen", { nick => $nick } );
+               $delete++;
+           }
+           $sth->finish;
        }
     } else {
-       &FIXME("seenFlushOld: for PG/NO-DB.");
+       &FIXME("seenFlushOld: for bad DBType:" . $param{'DBType'} . ".");
     }
     &VERB("SEEN deleted $delete seen entries.",2);
 
@@ -350,7 +361,6 @@ sub newsFlush {
     }
 
     if ($delete or $duser) {
-       &News::writeNews();
        &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
     }
 }
@@ -364,7 +374,6 @@ sub chanlimitCheck {
     }
 
     my $str = join(' ', &ChanConfList("chanlimitcheck") );
-    &DEBUG("chanlimitCheck: str => $str");
 
     foreach $chan ( &ChanConfList("chanlimitcheck") ) {
        next unless (&validChan($chan));
@@ -381,15 +390,16 @@ sub chanlimitCheck {
        if (scalar keys %netsplitservers) {
            if (defined $limit) {
                &status("chanlimit: netsplit; removing it for $chan.");
-               &rawout("MODE $chan -l");
+               $conn->mode($chan, "-l");
                $cache{chanlimitChange}{$chan} = time();
+               &status("chanlimit: netsplit; removed.");
            }
 
            next;
        }
 
        if (defined $limit and scalar keys %{ $channels{$chan}{''} } > $limit) {
-           &FIXME("LIMIT: set too low!!! FIXME");
+           &FIXME("LIMIT: set too low!!!");
            ### run NAMES again and flush it.
        }
 
@@ -399,7 +409,7 @@ sub chanlimitCheck {
        }
 
        if (!exists $channels{$chan}{'o'}{$ident}) {
-           &status("ChanLimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
+           &status("chanlimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
            $cache{warn}{chanlimit}{$chan} = 1;
            &chanServCheck($chan);
            next;
@@ -407,18 +417,18 @@ sub chanlimitCheck {
        delete $cache{warn}{chanlimit}{$chan};
 
        if (!defined $limit) {
-           &status("chanLimit: setting for first time or from netsplit, for $chan");
+           &status("chanlimit: $chan: setting for first time or from netsplit.");
        }
 
        if (exists $cache{chanlimitChange}{$chan}) {
            my $delta = time() - $cache{chanlimitChange}{$chan};
            if ($delta < $interval*60) {
-               &DEBUG("chanLimit: not going to change chanlimit! ($delta<$interval*60)");
+               &DEBUG("chanlimit: not going to change chanlimit! ($delta<$interval*60)");
                return;
            }
        }
 
-       &rawout("MODE $chan +l $newlimit");
+       $conn->mode($chan, "+l", $newlimit);
        $cache{chanlimitChange}{$chan} = time();
     }
 }
@@ -432,7 +442,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!");
@@ -485,7 +495,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) {
@@ -541,65 +551,15 @@ sub seenFlush {
     $stats{'new'}      = 0;
     $stats{'old'}      = 0;
 
-    if ($param{'DBType'} =~ /^mysql|pg|postgres/i) {
+    if ($param{'DBType'} =~ /^(mysql|pgsql|sqlite)$/i) {
        foreach $nick (keys %seencache) {
-           my $retval = &dbReplace("seen", (
-                       "nick" => $seencache{$nick}{'nick'},
-                       "time" => $seencache{$nick}{'time'},
-                       "host" => $seencache{$nick}{'host'},
-                       "channel" => $seencache{$nick}{'chan'},
-                       "message" => $seencache{$nick}{'msg'},
-           ) );
-           delete $seencache{$nick};
-           $flushed++;
-
-           next;
-
-           ###
-           ### old code.
-           ###
-
-           my $exists = &dbGet("seen", "nick", "nick=".&dbQuote($nick) );
-
-           if (defined $exists and $exists) {
-               &dbUpdate("seen", "nick", $nick, (
-                       "time" => $seencache{$nick}{'time'},
-                       "host" => $seencache{$nick}{'host'},
-                       "channel" => $seencache{$nick}{'chan'},
-                       "message" => $seencache{$nick}{'msg'},
-               ) );
-               $stats{'old'}++;
-           } else {
-               my $retval = &dbInsert("seen", $nick, (
-                       "nick" => $seencache{$nick}{'nick'},
-                       "time" => $seencache{$nick}{'time'},
-                       "host" => $seencache{$nick}{'host'},
-                       "channel" => $seencache{$nick}{'chan'},
-                       "message" => $seencache{$nick}{'msg'},
-               ) );
-               $stats{'new'}++;
-
-               ### TODO: put bad nick into a list and don't do it again!
-               &FIXME("Should never happen! (nick => $nick)") if !$retval;
-           }
-
-           delete $seencache{$nick};
-           $flushed++;
-       }
-
-    } elsif ($param{'DBType'} =~ /^dbm/i) {
-
-       foreach $nick (keys %seencache) {
-           my $retval = &dbInsert("seen", $nick, (
-               "nick" => $seencache{$nick}{'nick'},
-               "time" => $seencache{$nick}{'time'},
-               "host" => $seencache{$nick}{'host'},
-               "channel" => $seencache{$nick}{'chan'},
-               "message" => $seencache{$nick}{'msg'},
-           ) );
-
-           ### TODO: put bad nick into a list and don't do it again!
-           &FIXME("Should never happen! (nick => $nick)") if !$retval;
+           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'},
+           } );
 
            delete $seencache{$nick};
            $flushed++;
@@ -634,7 +594,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;
@@ -643,11 +603,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) {
@@ -662,7 +622,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;
@@ -700,6 +660,9 @@ sub ignoreCheck {
            $count++;
        }
     }
+
+    $cache{ignoreCheckTime} = time();
+
     &VERB("ignore: $count items deleted.",2);
 }
 
@@ -709,16 +672,20 @@ sub ircCheck {
        return if ($_[0] eq "2");       # defer.
     }
 
+    $cache{statusSafe} = 1;
+
     my @x      = &getJoinChans();
     my $iconf  = scalar( @x );
     my $inow   = scalar( keys %channels );
     if ($iconf > 2 and $inow * 2 <= $iconf) {
-       &FIXME("ircCheck: current channels * 2 <= config channels. FIXME.");
-       @joinchan       = @x;
+       &FIXME("ircCheck: current channels ($inow) * 2 <= config channels ($iconf).");
+#      @joinchan       = @x;
        &joinNextChan();
     }
 
-    if (!$conn->connected or time() - $msgtime > 3600) {
+    # todo: fix on_disconnect()
+
+    if (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!");
@@ -727,7 +694,7 @@ sub ircCheck {
            delete $cache{connect};
        } else {
            &status("IRCTEST: possible lost in space; checking. ".
-               scalar(localtime) );
+               scalar(gmtime) );
            &msg($ident, "TEST");
            $cache{connect} = time();
        }
@@ -735,7 +702,7 @@ sub ircCheck {
 
     if ($ident !~ /^\Q$param{ircNick}\E$/) {
        # this does not work unfortunately.
-       &WARN("ircCheck: ident($ident) != param{ircNick}($param{IrcNick}).");
+       &WARN("ircCheck: ident($ident) != param{ircNick}($param{ircNick}).");
 
        # this check is misleading... perhaps we should do a notify.
        if (! &IsNickInAnyChan( $param{ircNick} ) ) {
@@ -748,15 +715,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();
@@ -771,7 +738,7 @@ sub ircCheck {
 
 sub miscCheck {
     if (@_) {
-       &ScheduleThis(240, "miscCheck");
+       &ScheduleThis(120, "miscCheck");
        return if ($_[0] eq "2");       # defer.
     }
 
@@ -794,13 +761,18 @@ sub miscCheck {
        my ($shmid, $size) = ($2,$5);
        next unless ($shmid != $shm and $size == 2000);
        my $z   = &shmRead($shmid);
-       if ($z =~ /^(\d+): /) {
-           my $time    = $1;
+       if ($z =~ /^(\S+):(\d+):(\d+): /) {
+           my $n       = $1;
+           my $pid     = $2;
+           my $time    = $3;
            next if (time() - $time < 60*60);
-
+           # FIXME remove not-pid shm if parent process dead
+           next if ($pid == $bot_pid);
+           # don't touch other bots, if they're running.
+           next unless ($param{ircNick} =~ /^\Q$n\E$/);
        } else {
-#          &DEBUG("shm: $shmid is not ours or old blootbot => ($z)");
-#          next;
+           &DEBUG("shm: $shmid is not ours or old blootbot => ($z)");
+           next;
        }
 
        &status("SHM: nuking shmid $shmid");
@@ -808,8 +780,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}
@@ -829,76 +801,38 @@ sub miscCheck2 {
     }
 
     # debian check.
-    opendir(DEBIAN, "$bot_base_dir/debian");
+    opendir(DEBIAN, "$bot_state_dir/debian");
     foreach ( grep /gz$/, readdir(DEBIAN) ) {
-       my $exit = CORE::system("gzip -t $bot_base_dir/debian/$_");
+       my $exit = CORE::system("gzip -t $bot_state_dir/debian/$_");
        next unless ($exit);
 
        &status("debian: unlinking file => $_");
-       unlink "$bot_base_dir/debian/$_";
+       unlink "$bot_state_dir/debian/$_";
     }
     closedir DEBIAN;
 
     # compress logs that should have been compressed.
     # todo: use strftime?
-    my ($day,$month,$year) = (localtime(time()))[3,4,5];
+    my ($day,$month,$year) = (gmtime(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;
 }
 
-sub shmFlush {
-    return if ($$ != $::bot_pid); # fork protection.
-
-    if (@_) {
-       &ScheduleThis(5, "shmFlush");
-       return if ($_[0] eq "2");
-    }
-
-    my $time;
-    my $shmmsg = &shmRead($shm);
-    $shmmsg =~ s/\0//g;         # remove padded \0's.
-    if ($shmmsg =~ s/^(\d+): //) {
-       $time   = $1;
-    }
-
-    foreach (split '\|\|', $shmmsg) {
-       next if (/^$/);
-       &VERB("shm: Processing '$_'.",2);
-
-       if (/^DCC SEND (\S+) (\S+)$/) {
-           my ($nick,$file) = ($1,$2);
-           if (exists $dcc{'SEND'}{$who}) {
-               &msg($nick, "DCC already active.");
-           } else {
-               &DEBUG("shm: dcc sending $2 to $1.");
-               $conn->new_send($1,$2);
-               $dcc{'SEND'}{$who} = time();
-           }
-       } elsif (/^SET FORKPID (\S+) (\S+)/) {
-           $forked{$1}{PID} = $2;
-       } elsif (/^DELETE FORK (\S+)$/) {
-           delete $forked{$1};
-       } elsif (/^EVAL (.*)$/) {
-           &DEBUG("evaling '$1'.");
-           eval $1;
-       } else {
-           &DEBUG("shm: unknown msg. ($_)");
-       }
-    }
-
-    &shmWrite($shm,"") if ($shmmsg ne "");
-}
-
 ### this is semi-scheduled
 sub getNickInUse {
     if ($ident eq $param{'ircNick'}) {
@@ -915,7 +849,8 @@ sub getNickInUse {
 }
 
 sub uptimeLoop {
-    return unless &IsChanConf("uptime");
+    return if (!defined &uptimeWriteFile);
+#    return unless &IsChanConf("uptime");
 
     if (@_) {
        &ScheduleThis(60, "uptimeLoop");
@@ -948,23 +883,25 @@ sub slashdotLoop {
     } );
 }
 
-sub freshmeatLoop {
+sub plugLoop {
+
     if (@_) {
-       &ScheduleThis(60, "freshmeatLoop");
+       &ScheduleThis(60, "plugLoop");
        return if ($_[0] eq "2");
     }
 
-    my @chans = &ChanConfList("freshmeatAnnounce");
+    my @chans = &ChanConfList("plugAnnounce");
     return unless (scalar @chans);
 
-    &Forker("freshmeat", sub {
-       my $data = &Freshmeat::freshmeatAnnounce();
+    &Forker("plug", sub {
+       my $line = &Plug::plugAnnounce();
+       return unless (defined $line);
 
        foreach (@chans) {
            next unless (&::validChan($_));
 
-           &::status("sending freshmeat update to $_.");
-           &msg($_, $data);
+           &::status("sending plug update to $_.");
+           &notice($_, "Plug: $line");
        }
     } );
 }
@@ -1075,7 +1012,7 @@ sub factoidCheck {
     my $time   = time();
 
     foreach (@list) {
-       my $age = &getFactInfo($_, "modified_time");    
+       my $age = &getFactInfo($_, "modified_time");
 
        if (!defined $age or $age !~ /^\d+$/) {
            if (scalar @list > 50) {
@@ -1110,7 +1047,7 @@ sub dccStatus {
        return if ($_[0] eq "2");       # defer.
     }
 
-    my $time = strftime("%H:%M", localtime(time()) );
+    my $time = strftime("%H:%M", gmtime(time()) );
 
     my $c;
     foreach (keys %channels) {
@@ -1157,30 +1094,6 @@ sub scheduleList {
     &DEBUG("end of sList.");
 }
 
-sub getChanConfDefault {
-    my($what, $default, $chan) = @_;
-
-    if (exists $param{$what}) {
-       if (!exists $cache{config}{$what}) {
-           &status("conf: backward-compat: found param{$what} ($param{$what}) instead.");
-           $cache{config}{$what} = 1;
-       }
-
-       return $param{$what};
-    }
-
-    my $val = &getChanConf($what, $chan);
-    if (defined $val) {
-       return $val;
-    }
-
-    $param{$what}      = $default;
-    &status("conf: auto-setting param{$what} = $default");
-    $cache{config}{$what} = 1;
-
-    return $default;
-}
-
 sub mkBackup {
     my($file, $time)   = @_;
     my $backup         = 0;