2 # ProcessExtra.pl: Extensions to Process.pl
4 # Version: v0.5 (20010124)
10 use POSIX qw(strftime);
14 &VERB("Starting schedulers...",2);
19 # 1 for run straight away, 2 for on next-run.
26 &netsplitCheck(1); # mandatory
27 &floodLoop(1); # mandatory
29 &leakCheck(2); # mandatory
30 &ignoreCheck(1); # mandatory
32 &ircCheck(1); # mandatory
33 &miscCheck(1); # mandatory
34 &miscCheck2(2); # mandatory
35 &shmFlush(1); # mandatory
41 &factoidCheck(2); # takes a couple of seconds on a 486. defer it
44 # todo: squeeze this into a one-liner.
45 # my $count = map { exists $sched{$_}{TIME} } keys %sched;
47 foreach (keys %sched) {
48 my $time = $sched{$_}{TIME};
49 next unless (defined $time and $time > time());
54 &status("Schedulers: $count will be running.");
59 my ($interval, $codename, @args) = @_;
60 my $waittime = &getRandomInt($interval);
62 if (!defined $waittime) {
63 &WARN("interval == waittime == UNDEF for $codename.");
67 my $time = $sched{$codename}{TIME};
68 if (defined $time and $time > time()) {
69 &WARN("Sched for $codename already exists.");
73 # &VERB("Scheduling \&$codename() for ".&Time2String($waittime),3);
75 my $retval = $conn->schedule($waittime, \&$codename, @args);
76 $sched{$codename}{LABEL} = $retval;
77 $sched{$codename}{TIME} = time()+$waittime;
78 $sched{$codename}{LOOP} = 1;
82 #### LET THE FUN BEGIN.
86 my $interval = &getChanConfDefault("randomQuoteInterval", 60);
88 &ScheduleThis($interval, "randomQuote");
89 return if ($_[0] eq "2"); # defer.
92 my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.randtext");
94 &ERROR("random Quote: weird error?");
98 foreach ( &ChanConfList("randomQuote") ) {
99 next unless (&validChan($_));
101 &status("sending random Quote to $_.");
102 &action($_, "Ponders: ".$line);
104 ### TODO: if there were no channels, don't reschedule until channel
105 ### configuration is modified.
112 my $interval = &getChanConfDefault("randomFactoidInterval", 60);
114 &ScheduleThis($interval, "randomFactoid");
115 return if ($_[0] eq "2"); # defer.
119 ($key,$val) = &randKey("factoids","factoid_key,factoid_value");
120 ### $val =~ tr/^[A-Z]/[a-z]/; # blah is Good => blah is good.
121 last if (defined $val and $val !~ /^</);
125 &ERROR("rF: tried 5 times but failed.");
130 foreach ( &ChanConfList("randomFactoid") ) {
131 next unless (&validChan($_));
133 &status("sending random Factoid to $_.");
134 &action($_, "Thinks: \037$key\037 is $val");
135 ### FIXME: Use &getReply() on above to format factoid properly?
140 sub randomFreshmeat {
141 my $interval = &getChanConfDefault("randomFreshmeatInterval", 60);
144 &ScheduleThis($interval, "randomFreshmeat");
145 return if ($_[0] eq "2"); # defer.
148 my @chans = &ChanConfList("randomFreshmeat");
149 return unless (scalar @chans);
151 &Forker("freshmeat", sub {
152 my $retval = &Freshmeat::randPackage();
155 next unless (&validChan($_));
157 &status("sending random Freshmeat to $_.");
165 &ScheduleThis(60, "logLoop");
166 return if ($_[0] eq "2"); # defer.
169 return unless (defined fileno LOG);
170 return unless (&IsParam("logfile"));
171 return unless (&IsParam("maxLogSize"));
173 ### check if current size is too large.
174 if ( -s $file{log} > $param{'maxLogSize'}) {
175 my $date = sprintf("%04d%02d%02d", (gmtime)[5,4,3]);
176 $file{log} = $param{'logfile'} ."-". $date;
177 &status("cycling log file.");
179 if ( -e $file{log}) {
183 $newlog = $file{log}."-".$i;
184 last if (! -e $newlog);
187 $file{log} = $newlog;
191 CORE::system("/bin/mv '$param{'logfile'}' '$file{log}'");
192 &compress($file{log});
194 &status("cycling log file.");
197 ### check if all the logs exceed size.
198 if (!opendir(LOGS, $bot_log_dir)) {
199 &WARN("logLoop: could not open dir '$bot_log_dir'");
205 while (defined($_ = readdir LOGS)) {
206 my $logfile = "$bot_log_dir/$_";
208 next unless ( -f $logfile);
210 my $size = -s $logfile;
211 my $age = (stat $logfile)[9];
212 $age{$age} = $logfile;
213 $size{$logfile} = $size;
219 while ($tsize > $param{'maxLogSize'}) {
220 &status("LOG: current size > max ($tsize > $param{'maxLogSize'})");
221 my $oldest = (sort {$a <=> $b} keys %age)[0];
222 &status("LOG: unlinking $age{$oldest}.");
223 unlink $age{$oldest};
228 ### TODO: add how many b,kb,mb removed?
229 &status("LOG: removed $delete logs.") if ($delete);
234 &ScheduleThis(1440, "seenFlushOld");
235 return if ($_[0] eq "2"); # defer.
238 # is this global-only?
239 return unless (&IsChanConf("seen") > 0);
240 return unless (&IsChanConf("seenFlushInterval") > 0);
242 # global setting. does not make sense for per-channel.
243 my $max_time = &getChanConfDefault("seenMaxDays", 30) *60*60*24;
246 if ($param{'DBType'} =~ /^pgsql|mysql|sqlite/i) {
249 if ($param{'DBType'} =~ /^mysql|sqlite$/i) {
250 $query = "SELECT nick,time FROM seen GROUP BY nick HAVING ".
251 "UNIX_TIMESTAMP() - time > $max_time";
253 $query = "SELECT nick,time FROM seen WHERE ".
254 "extract(epoch from timestamp 'now') - time > $max_time";
257 my $sth = $dbh->prepare($query);
259 while (my @row = $sth->fetchrow_array) {
260 my ($nick,$time) = @row;
262 &dbDel("seen",{"nick"=>$nick});
267 } elsif ($param{'DBType'} =~ /^dbm/i) {
270 foreach (keys %seen) {
271 my $delta_time = $time - &dbGet("seen", "time", "nick", $_);
272 next unless ($delta_time > $max_time);
274 &DEBUG("seenFlushOld: ".&Time2String($delta_time) );
279 &FIXME("seenFlushOld: for PG/NO-DB.");
281 &VERB("SEEN deleted $delete seen entries.",2);
287 &ScheduleThis(60, "newsFlush");
288 return if ($_[0] eq "2"); # defer.
291 if (!&ChanConfList("news")) {
292 &DEBUG("newsFlush: news disabled? (chan => $chan)");
299 foreach $chan (keys %::news) {
301 my $total = scalar(keys %{ $::news{$chan} });
304 delete $::news{$chan};
308 foreach $item (keys %{ $::news{$chan} }) {
309 my $t = $::news{$chan}{$item}{Expire};
311 my $tadd = $::news{$chan}{$item}{Time};
312 $oldest = $tadd if ($oldest > $tadd);
314 next if ($t == 0 or $t == -1);
316 &status("newsFlush: Fixed Expire time for $chan/$item, should not happen anyway.");
317 $::news{$chan}{$item}{Expire} = time() + $t*60*60*24;
321 my $delta = $t - time();
323 next unless (time() > $t);
325 # todo: show how old it was.
326 delete $::news{$chan}{$item};
327 &status("NEWS: (newsflush) deleted '$item'");
332 &status("NEWS (newsflush) {$chan}: deleted [$i/$total] news entries.") if ($i);
333 $none{$chan} = 1 if ($total == $i);
336 # todo: flush users aswell.
338 foreach $chan (keys %::newsuser) {
339 next if (exists $none{$chan});
341 foreach (keys %{ $::newsuser{$chan} }) {
342 my $t = $::newsuser{$chan}{$_};
343 if (!defined $t or ($t > 2 and $t < 1000)) {
344 &DEBUG("something wrong with newsuser{$chan}{$_} => $t");
348 next unless ($oldest > $t);
350 delete $::newsuser{$chan}{$_};
354 my $i = scalar(keys %{ $::newsuser{$chan} });
355 delete $::newsuser{$chan} unless ($i);
358 if ($delete or $duser) {
360 &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
365 my $interval = &getChanConfDefault("chanlimitcheckInterval", 10);
368 &ScheduleThis($interval, "chanlimitCheck");
369 return if ($_[0] eq "2");
372 my $str = join(' ', &ChanConfList("chanlimitcheck") );
374 foreach $chan ( &ChanConfList("chanlimitcheck") ) {
375 next unless (&validChan($chan));
377 if ($chan eq "_default") {
378 &WARN("chanlimit: we're doing $chan!! HELP ME!");
382 my $limitplus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
383 my $newlimit = scalar(keys %{ $channels{$chan}{''} }) + $limitplus;
384 my $limit = $channels{$chan}{'l'};
386 if (scalar keys %netsplitservers) {
387 if (defined $limit) {
388 &status("chanlimit: netsplit; removing it for $chan.");
389 $conn->mode($chan, "-l");
390 $cache{chanlimitChange}{$chan} = time();
391 &status("chanlimit: netsplit; removed.");
397 if (defined $limit and scalar keys %{ $channels{$chan}{''} } > $limit) {
398 &FIXME("LIMIT: set too low!!! FIXME");
399 ### run NAMES again and flush it.
402 if (defined $limit and $limit == $newlimit) {
403 $cache{chanlimitChange}{$chan} = time();
407 if (!exists $channels{$chan}{'o'}{$ident}) {
408 &status("chanlimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
409 $cache{warn}{chanlimit}{$chan} = 1;
410 &chanServCheck($chan);
413 delete $cache{warn}{chanlimit}{$chan};
415 if (!defined $limit) {
416 &status("chanlimit: setting for first time or from netsplit, for $chan");
419 if (exists $cache{chanlimitChange}{$chan}) {
420 my $delta = time() - $cache{chanlimitChange}{$chan};
421 if ($delta < $interval*60) {
422 &DEBUG("chanlimit: not going to change chanlimit! ($delta<$interval*60)");
427 $conn->mode($chan, "+l", $newlimit);
428 $cache{chanlimitChange}{$chan} = time();
436 &ScheduleThis(15, "netsplitCheck");
437 return if ($_[0] eq "2");
440 $cache{'netsplitCache'}++;
441 # &DEBUG("running netsplitCheck... $cache{netsplitCache}");
443 if (!scalar %netsplit and scalar %netsplitservers) {
444 &DEBUG("nsC: !hash netsplit but hash netsplitservers <- removing!");
445 undef %netsplitservers;
449 # well... this shouldn't happen since %netsplit code does it anyway.
450 foreach $s1 (keys %netsplitservers) {
452 foreach $s2 (keys %{ $netsplitservers{$s1} }) {
453 my $delta = time() - $netsplitservers{$s1}{$s2};
455 if ($delta > 60*30) {
456 &status("netsplit between $s1 and $s2 appears to be stale.");
457 delete $netsplitservers{$s1}{$s2};
462 my $i = scalar(keys %{ $netsplitservers{$s1} });
463 delete $netsplitservers{$s1} unless ($i);
466 # %netsplit hash checker.
467 my $count = scalar keys %netsplit;
469 foreach (keys %netsplit) {
470 if (&IsNickInAnyChan($_)) { # why would this happen?
471 # &DEBUG("nsC: $_ is in some chan; removing from netsplit list.");
472 delete $netsplit{$_};
477 next unless (time() - $netsplit{$_} > 60*15);
480 delete $netsplit{$_};
484 foreach (keys %channels) {
485 my $i = $cache{maxpeeps}{$chan} || 0;
486 my $j = scalar(keys %{ $channels{$chan} });
487 next unless ($i > 10 and 0.25*$i > $j);
489 &DEBUG("netsplit: 0.25*max($i) > current($j); possible netsplit?");
493 my $j = scalar(keys %netsplit);
494 &status("nsC: removed from netsplit list: (before: $count; after: $j)");
497 if (!scalar %netsplit and scalar %netsplitservers) {
498 &DEBUG("nsC: ok hash netsplit is NULL; purging hash netsplitservers");
499 undef %netsplitservers;
502 if ($count and !scalar keys %netsplit) {
503 &DEBUG("nsC: netsplit is hopefully gone. reinstating chanlimit check.");
513 &ScheduleThis(60, "floodLoop"); # minutes.
514 return if ($_[0] eq "2");
518 my $interval = &getChanConfDefault("floodCycle",60);
520 foreach $who (keys %flood) {
521 foreach (keys %{ $flood{$who} }) {
522 if (!exists $flood{$who}{$_}) {
523 &WARN("flood{$who}{$_} undefined?");
527 if ($time - $flood{$who}{$_} > $interval) {
528 delete $flood{$who}{$_};
533 &VERB("floodLoop: deleted $delete items.",2);
538 my $interval = &getChanConfDefault("seenFlushInterval", 60);
539 &ScheduleThis($interval, "seenFlush");
540 return if ($_[0] eq "2");
546 $stats{'count_old'} = &countKeys("seen") || 0;
550 if ($param{'DBType'} =~ /^(mysql|pgsql|sqlite|dbm)$/i) {
551 foreach $nick (keys %seencache) {
552 my $retval = &dbReplace("seen", "nick", (
553 "nick" => lc $seencache{$nick}{'nick'},
554 "time" => $seencache{$nick}{'time'},
555 "host" => $seencache{$nick}{'host'},
556 "channel" => $seencache{$nick}{'chan'},
557 "message" => $seencache{$nick}{'msg'},
559 delete $seencache{$nick};
563 &DEBUG("seenFlush: NO VALID FACTOID SUPPORT?");
566 &status("Seen: Flushed $flushed entries.") if ($flushed);
567 &VERB(sprintf(" new seen: %03.01f%% (%d/%d)",
568 $stats{'new'}*100/($stats{'count_old'} || 1),
569 $stats{'new'}, ( $stats{'count_old'} || 1) ), 2) if ($stats{'new'});
570 &VERB(sprintf(" now seen: %3.1f%% (%d/%d)",
571 $stats{'old'}*100 / ( &countKeys("seen") || 1),
572 $stats{'old'}, &countKeys("seen") ), 2) if ($stats{'old'});
574 &WARN("scalar keys seenflush != 0!") if (scalar keys %seenflush);
582 &ScheduleThis(240, "leakCheck");
583 return if ($_[0] eq "2");
586 # flood. this is dealt with in floodLoop()
587 foreach $blah1 (keys %flood) {
588 foreach $blah2 (keys %{ $flood{$blah1} }) {
589 $count += scalar(keys %{ $flood{$blah1}{$blah2} });
592 &VERB("leak: hash flood has $count total keys.",2);
596 foreach $blah1 (keys %floodjoin) {
597 foreach $blah2 (keys %{ $floodjoin{$blah1} }) {
598 $count += scalar(keys %{ $floodjoin{$blah1}{$blah2} });
601 &VERB("leak: hash floodjoin has $count total keys.",2);
604 $count = scalar(keys %floodwarn);
605 &VERB("leak: hash floodwarn has $count total keys.",2);
608 foreach $chan (grep /[A-Z]/, keys %channels) {
609 &DEBUG("leak: chan => '$chan'.");
611 foreach $i (keys %{ $channels{$chan} }) {
612 foreach (keys %{ $channels{$chan}{$i} }) {
613 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
619 $count = scalar(keys %chanstats);
620 &VERB("leak: hash chanstats has $count total keys.",2);
624 foreach (keys %nuh) {
625 next if (&IsNickInAnyChan($_));
626 next if (exists $dcc{CHAT}{$_});
632 &status("leak: $delete nuh{} items deleted; now have ".
633 scalar(keys %nuh) ) if ($delete);
638 &ScheduleThis(60, "ignoreCheck");
639 return if ($_[0] eq "2"); # defer.
645 foreach (keys %ignore) {
648 foreach (keys %{ $ignore{$chan} }) {
649 my @array = @{ $ignore{$chan}{$_} };
651 next unless ($array[0] and $time > $array[0]);
653 delete $ignore{$chan}{$_};
654 &status("ignore: $_/$chan has expired.");
659 $cache{ignoreCheckTime} = time();
661 &VERB("ignore: $count items deleted.",2);
666 &ScheduleThis(15, "ircCheck");
667 return if ($_[0] eq "2"); # defer.
670 $cache{statusSafe} = 1;
672 my @x = &getJoinChans();
673 my $iconf = scalar( @x );
674 my $inow = scalar( keys %channels );
675 if ($iconf > 2 and $inow * 2 <= $iconf) {
676 &FIXME("ircCheck: current channels * 2 <= config channels. FIXME.");
677 &FIXME("ircCheck: iconf = $iconf");
678 &FIXME("ircCheck: inow = $inow");
683 if (!$conn->connected or time() - $msgtime > 3600) {
684 # todo: shouldn't we use cache{connect} somewhere?
685 if (exists $cache{connect}) {
686 &WARN("ircCheck: no msg for 3600 and disco'd! reconnecting!");
687 $msgtime = time(); # just in case.
689 delete $cache{connect};
691 &status("IRCTEST: possible lost in space; checking. ".
693 &msg($ident, "TEST");
694 $cache{connect} = time();
698 if ($ident !~ /^\Q$param{ircNick}\E$/) {
699 # this does not work unfortunately.
700 &WARN("ircCheck: ident($ident) != param{ircNick}($param{ircNick}).");
702 # this check is misleading... perhaps we should do a notify.
703 if (! &IsNickInAnyChan( $param{ircNick} ) ) {
704 &DEBUG("$param{ircNick} not in use... changing!");
705 &nick( $param{ircNick} );
707 &WARN("$param{ircNick} is still in use...");
711 if (grep /^\s*$/, keys %channels) {
712 &WARN("ircCheck: we have a NULL chan in hash channels? removing!");
713 if (!exists $channels{''}) {
714 &DEBUG("ircCheck: this should never happen!");
717 delete $channels{''};
720 $cache{statusSafe} = 0;
723 if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
725 $wtime_userfile = time();
728 if ($utime_chanfile > $wtime_chanfile and time() - $wtime_chanfile > 3600) {
730 $wtime_chanfile = time();
736 &ScheduleThis(120, "miscCheck");
737 return if ($_[0] eq "2"); # defer.
742 if ( -x "/usr/bin/ipcs") {
743 @ipcs = `/usr/bin/ipcs`;
745 &WARN("ircCheck: no 'ipcs' binary.");
749 # shmid stale remove.
753 # key, shmid, owner, perms, bytes, nattch
754 next unless (/^(0x\d+) (\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+/);
756 my ($shmid, $size) = ($2,$5);
757 next unless ($shmid != $shm and $size == 2000);
758 my $z = &shmRead($shmid);
759 if ($z =~ /^(\d+): /) {
761 next if (time() - $time < 60*60);
764 # &DEBUG("shm: $shmid is not ours or old blootbot => ($z)");
768 &status("SHM: nuking shmid $shmid");
769 CORE::system("/usr/bin/ipcrm shm $shmid >/dev/null");
772 # make backup of important files.
773 &mkBackup( $bot_state_dir."/blootbot.chan", 60*60*24*3);
774 &mkBackup( $bot_state_dir."/blootbot.users", 60*60*24*3);
775 &mkBackup( $bot_base_dir."/blootbot-news.txt", 60*60*24*1);
777 # flush cache{lobotomy}
778 foreach (keys %{ $cache{lobotomy} }) {
779 next unless (time() - $cache{lobotomy}{$_} > 60*60);
780 delete $cache{lobotomy}{$_};
783 ### check modules if they've been modified. might be evil.
789 &ScheduleThis(240, "miscCheck2");
790 return if ($_[0] eq "2"); # defer.
794 opendir(DEBIAN, "$bot_state_dir/debian");
795 foreach ( grep /gz$/, readdir(DEBIAN) ) {
796 my $exit = CORE::system("gzip -t $bot_state_dir/debian/$_");
799 &status("debian: unlinking file => $_");
800 unlink "$bot_state_dir/debian/$_";
804 # compress logs that should have been compressed.
805 # todo: use strftime?
806 my ($day,$month,$year) = (gmtime(time()))[3,4,5];
807 my $date = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
809 if (!opendir(DIR,"$bot_log_dir")) {
810 &ERROR("misccheck2: log dir $bot_log_dir does not exist.");
815 while (my $f = readdir(DIR)) {
816 next unless ( -f "$bot_log_dir/$f");
817 next if ($f =~ /gz|bz2/);
818 next unless ($f =~ /(\d{8})/);
819 next if ($date eq $1);
821 &compress("$bot_log_dir/$f");
826 ### this is semi-scheduled
828 if ($ident eq $param{'ircNick'}) {
829 &status("okay, got my nick back.");
834 &ScheduleThis(30, "getNickInUse");
835 return if ($_[0] eq "2"); # defer.
838 &nick( $param{'ircNick'} );
842 return unless &IsChanConf("uptime");
845 &ScheduleThis(60, "uptimeLoop");
846 return if ($_[0] eq "2"); # defer.
855 &ScheduleThis(60, "slashdotLoop");
856 return if ($_[0] eq "2");
859 my @chans = &ChanConfList("slashdotAnnounce");
860 return unless (scalar @chans);
862 &Forker("slashdot", sub {
863 my $line = &Slashdot::slashdotAnnounce();
864 return unless (defined $line);
867 next unless (&::validChan($_));
869 &::status("sending slashdot update to $_.");
870 ¬ice($_, "Slashdot: $line");
878 &ScheduleThis(60, "plugLoop");
879 return if ($_[0] eq "2");
882 my @chans = &ChanConfList("plugAnnounce");
883 return unless (scalar @chans);
885 &Forker("plug", sub {
886 my $line = &Plug::plugAnnounce();
887 return unless (defined $line);
890 next unless (&::validChan($_));
892 &::status("sending plug update to $_.");
893 ¬ice($_, "Plug: $line");
900 &ScheduleThis(60, "freshmeatLoop");
901 return if ($_[0] eq "2");
904 my @chans = &ChanConfList("freshmeatAnnounce");
905 return unless (scalar @chans);
907 &Forker("freshmeat", sub {
908 my $data = &Freshmeat::freshmeatAnnounce();
911 next unless (&::validChan($_));
913 &::status("sending freshmeat update to $_.");
921 &ScheduleThis(240, "kernelLoop");
922 return if ($_[0] eq "2");
925 my @chans = &ChanConfList("kernelAnnounce");
926 return unless (scalar @chans);
928 &Forker("kernel", sub {
929 my @data = &Kernel::kernelAnnounce();
932 next unless (&::validChan($_));
934 &::status("sending kernel update to $_.");
937 ¬ice($c, "Kernel: $_");
944 return unless &IsChanConf("wingate");
946 ### FILE CACHE OF OFFENDING WINGATES.
947 foreach (grep /^$host$/, @wingateBad) {
948 &status("Wingate: RUNNING ON $host BY $who");
949 &ban("*!*\@$host", "") if &IsChanConf("wingateBan");
951 my $reason = &getChanConf("wingateKick");
953 next unless ($reason);
954 &kick($who, "", $reason)
957 ### RUN CACHE OF TRIED WINGATES.
958 if (grep /^$host$/, @wingateCache) {
959 push(@wingateNow, $host); # per run.
960 push(@wingateCache, $host); # cache per run.
962 &DEBUG("Already scanned $host. good.");
965 my $interval = &getChanConfDefault("wingateInterval", 60); # seconds.
966 return if (defined $forked{'wingate'});
967 return if (time() - $wingaterun <= $interval);
968 return unless (scalar(keys %wingateToDo));
970 $wingaterun = time();
972 &Forker("wingate", sub { &Wingate::Wingates(keys %wingateToDo); } );
977 sub wingateWriteFile {
979 &ScheduleThis(60, "wingateWriteFile");
980 return if ($_[0] eq "2"); # defer.
983 return unless (scalar @wingateCache);
985 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
986 if ($bot_pid != $$) {
987 &DEBUG("wingateWriteFile: Reorganising!");
992 push(@wingateNow, $_);
997 my %hash = map { $_ => 1 } @wingateNow;
998 @wingateNow = sort keys %hash;
1001 &DEBUG("wingateWF: writing...");
1002 open(OUT, ">$file");
1003 foreach (@wingateNow) {
1011 &ScheduleThis(720, "factoidCheck");
1012 return if ($_[0] eq "2"); # defer.
1015 my @list = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
1016 my $stale = &getChanConfDefault("factoidDeleteDelay", 14) *60*60*24;
1018 # disable it since it's "illegal".
1025 my $age = &getFactInfo($_, "modified_time");
1027 if (!defined $age or $age !~ /^\d+$/) {
1028 if (scalar @list > 50) {
1029 if (!$cache{warnDel}) {
1030 &WARN("list is over 50 (".scalar(@list)."... giving it a miss.");
1031 $cache{warnDel} = 1;
1036 &WARN("del factoid: old cruft (no time): $_");
1041 next unless ($time - $age > $stale);
1044 $fix =~ s/ #DEL#$//g;
1045 my $agestr = &Time2String($time - $age);
1046 &status("safedel: Removing '$_' for good. [$agestr old]");
1053 return unless (scalar keys %{ $dcc{CHAT} });
1056 &ScheduleThis(10, "dccStatus");
1057 return if ($_[0] eq "2"); # defer.
1060 my $time = strftime("%H:%M", gmtime(time()) );
1063 foreach (keys %channels) {
1065 my $users = keys %{ $channels{$c}{''} };
1066 my $chops = keys %{ $channels{$c}{o} };
1067 my $bans = keys %{ $channels{$c}{b} };
1069 my $txt = "[$time] $c: $users members ($chops chops), $bans bans";
1070 foreach (keys %{ $dcc{'CHAT'} }) {
1071 next unless (exists $channels{$c}{''}{lc $_});
1072 $conn->privmsg($dcc{'CHAT'}{$_}, $txt);
1085 foreach (keys %{ $irc->{_queue} }) {
1089 foreach (keys %sched) {
1090 next unless ($q eq $sched{$_});
1095 my $time = $irc->{_queue}->{$q}->[0] - time();
1097 if (defined $sched) {
1098 &DEBUG(" $sched($q): ".&Time2String($time) );
1100 &DEBUG(" NULL($q): ".&Time2String($time) );
1104 &DEBUG("end of sList.");
1108 my($file, $time) = @_;
1112 &VERB("mkB: file '$file' does not exist.",2);
1117 if ( -e "$file~" ) {
1118 $backup++ if ((stat $file)[9] - (stat "$file~")[9] > $time);
1119 my $delta = time() - (stat "$file~")[9];
1120 $age = &Time2String($delta);
1125 return unless ($backup);
1127 ### TODO: do internal copying.
1128 &status("Backup: $file ($age)");
1129 CORE::system("/bin/cp $file $file~");