2 # ProcessExtra.pl: Extensions to Process.pl
4 # Version: v0.5 (20010124)
10 use POSIX qw(strftime);
11 use vars qw(%sched %schedule);
13 # format: function name = (
14 # str chanconfdefault,
15 # int internaldefault,
17 # int next run, (optional)
21 # uptimeLoop => ("", 60, 1),
24 sub setupSchedulersII {
25 foreach (keys %schedule) {
26 &queueTask($_, @{ $schedule{$_} });
31 my($codename, $chanconfdef, $intervaldef, $defer) = @_;
32 my $t = &getChanConfDefault($chanconfdef, $intervaldef, $chan);
33 my $waittime = &getRandomInt($t);
35 if (!defined $waittime) {
36 &WARN("interval == waittime == UNDEF for $codename.");
40 my $time = $schedule{$codename}[3];
41 if (defined $time and $time > time()) {
42 &WARN("Sched for $codename already exists in " . &Time2String(time() - $time) . ".");
46 #&VERB("Scheduling \&$codename() for " . &Time2String($waittime),3);
48 my $retval = $conn->schedule($waittime, sub {
54 &VERB("Starting schedulers...",2);
63 &leakCheck(2); # mandatory
65 &miscCheck2(2); # mandatory
70 &factoidCheck(2); # takes a couple of seconds on a 486. defer it
71 # TODO: convert to new format... or nuke altogether.
74 # 1 for run straight away
78 &netsplitCheck(1); # mandatory
79 &floodLoop(1); # mandatory
80 &ignoreCheck(1); # mandatory
81 &miscCheck(1); # mandatory
82 &shmFlush(1); # mandatory
84 &ircCheck(1); # mandatory
86 # TODO: squeeze this into a one-liner.
87 # my $count = map { exists $sched{$_}{TIME} } keys %sched;
89 foreach (keys %sched) {
90 my $time = $sched{$_}{TIME};
91 next unless (defined $time and $time > time());
96 &status("Schedulers: $count will be running.");
101 my ($interval, $codename, @args) = @_;
102 my $waittime = &getRandomInt($interval);
104 if (!defined $waittime) {
105 &WARN("interval == waittime == UNDEF for $codename.");
109 my $time = $sched{$codename}{TIME};
110 if (defined $time and $time > time()) {
111 &WARN("Sched for $codename already exists in " . &Time2String(time() - $time) . ".");
115 &DEBUG("Scheduling \&$codename() " . \&$codename . " for " . &Time2String($waittime),3);
117 my $retval = $conn->schedule($waittime, \&$codename, @args);
118 $sched{$codename}{LABEL} = $retval;
119 $sched{$codename}{TIME} = time()+$waittime;
120 $sched{$codename}{LOOP} = 1;
124 #### LET THE FUN BEGIN.
128 my $interval = &getChanConfDefault("randomQuoteInterval", 60, $chan);
130 &ScheduleThis($interval, "randomQuote");
131 return if ($_[0] eq "2"); # defer.
134 foreach ( &ChanConfList("randomQuote") ) {
135 next unless (&validChan($_));
137 my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.randtext");
138 if (!defined $line) {
139 &ERROR("random Quote: weird error?");
143 &status("sending random Quote to $_.");
144 &action($_, "Ponders: ".$line);
146 ### TODO: if there were no channels, don't reschedule until channel
147 ### configuration is modified.
154 my $interval = &getChanConfDefault("randomFactoidInterval", 60, $chan);
156 &ScheduleThis($interval, "randomFactoid");
157 return if ($_[0] eq "2"); # defer.
160 foreach ( &ChanConfList("randomFactoid") ) {
161 next unless (&validChan($_));
163 &status("sending random Factoid to $_.");
165 ($key,$val) = &randKey("factoids","factoid_key,factoid_value");
166 &DEBUG("rF: $key, $val");
167 ### $val =~ tr/^[A-Z]/[a-z]/; # blah is Good => blah is good.
168 last if ((defined $val) and ($val !~ /^</) and ($key !~ /\#DEL\#/) and ($key !~ /^cmd:/));
172 &ERROR("rF: tried 5 times but failed.");
176 &action($_, "Thinks: \037$key\037 is $val");
177 ### FIXME: Use &getReply() on above to format factoid properly?
184 &ScheduleThis(60, "logLoop");
185 return if ($_[0] eq "2"); # defer.
188 return unless (defined fileno LOG);
189 return unless (&IsParam("logfile"));
190 return unless (&IsParam("maxLogSize"));
192 ### check if current size is too large.
193 if ( -s $file{log} > $param{'maxLogSize'}) {
194 my $date = sprintf("%04d%02d%02d", (gmtime)[5,4,3]);
195 $file{log} = $param{'logfile'} ."-". $date;
196 &status("cycling log file.");
198 if ( -e $file{log}) {
202 $newlog = $file{log}."-".$i;
203 last if (! -e $newlog);
206 $file{log} = $newlog;
210 CORE::system("/bin/mv '$param{'logfile'}' '$file{log}'");
211 &compress($file{log});
213 &status("cycling log file.");
216 ### check if all the logs exceed size.
217 if (!opendir(LOGS, $bot_log_dir)) {
218 &WARN("logLoop: could not open dir '$bot_log_dir'");
224 while (defined($_ = readdir LOGS)) {
225 my $logfile = "$bot_log_dir/$_";
227 next unless ( -f $logfile);
229 my $size = -s $logfile;
230 my $age = (stat $logfile)[9];
231 $age{$age} = $logfile;
232 $size{$logfile} = $size;
238 while ($tsize > $param{'maxLogSize'}) {
239 &status("LOG: current size > max ($tsize > $param{'maxLogSize'})");
240 my $oldest = (sort {$a <=> $b} keys %age)[0];
241 &status("LOG: unlinking $age{$oldest}.");
242 unlink $age{$oldest};
247 ### TODO: add how many b,kb,mb removed?
248 &status("LOG: removed $delete logs.") if ($delete);
253 &ScheduleThis(1440, "seenFlushOld");
254 return if ($_[0] eq "2"); # defer.
257 # is this global-only?
258 return unless (&IsChanConf("seen") > 0);
259 return unless (&IsChanConf("seenFlushInterval") > 0);
261 # global setting. does not make sense for per-channel.
262 my $max_time = &getChanConfDefault("seenMaxDays", 30, $chan) *60*60*24;
265 if ($param{'DBType'} =~ /^(pgsql|mysql|sqlite(2)?)$/i) {
268 if ($param{'DBType'} =~ /^(mysql|sqlite(2)?)$/i) {
269 $query = "SELECT nick,time FROM seen GROUP BY nick HAVING ".
270 "UNIX_TIMESTAMP() - time > $max_time";
272 $query = "SELECT nick,time FROM seen WHERE ".
273 "extract(epoch from timestamp 'now') - time > $max_time";
276 my $sth = $dbh->prepare($query);
278 while (my @row = $sth->fetchrow_array) {
279 my ($nick,$time) = @row;
281 &sqlDelete("seen", { nick => $nick } );
287 &FIXME("seenFlushOld: for bad DBType:" . $param{'DBType'} . ".");
289 &VERB("SEEN deleted $delete seen entries.",2);
295 &ScheduleThis(60, "newsFlush");
296 return if ($_[0] eq "2"); # defer.
299 if (!&ChanConfList('News')) {
300 &DEBUG("newsFlush: news disabled? (chan => $chan)");
307 foreach $chan (keys %::news) {
309 my $total = scalar(keys %{ $::news{$chan} });
312 delete $::news{$chan};
316 foreach $item (keys %{ $::news{$chan} }) {
317 my $t = $::news{$chan}{$item}{Expire};
319 my $tadd = $::news{$chan}{$item}{Time};
320 $oldest = $tadd if ($oldest > $tadd);
322 next if ($t == 0 or $t == -1);
324 &status("newsFlush: Fixed Expire time for $chan/$item, should not happen anyway.");
325 $::news{$chan}{$item}{Expire} = time() + $t*60*60*24;
329 my $delta = $t - time();
331 next unless (time() > $t);
333 # TODO: show how old it was.
334 delete $::news{$chan}{$item};
335 &status("NEWS: (newsflush) deleted '$item'");
340 &status("NEWS (newsflush) {$chan}: deleted [$i/$total] news entries.") if ($i);
341 $none{$chan} = 1 if ($total == $i);
344 # TODO: flush users aswell.
346 foreach $chan (keys %::newsuser) {
347 next if (exists $none{$chan});
349 foreach (keys %{ $::newsuser{$chan} }) {
350 my $t = $::newsuser{$chan}{$_};
351 if (!defined $t or ($t > 2 and $t < 1000)) {
352 &DEBUG("something wrong with newsuser{$chan}{$_} => $t");
356 next unless ($oldest > $t);
358 delete $::newsuser{$chan}{$_};
362 my $i = scalar(keys %{ $::newsuser{$chan} });
363 delete $::newsuser{$chan} unless ($i);
366 if ($delete or $duser) {
367 &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
372 my $interval = &getChanConfDefault("chanlimitcheckInterval", 10, $chan);
373 my $mynick=$conn->nick();
376 &ScheduleThis($interval, "chanlimitCheck");
377 return if ($_[0] eq "2");
380 my $str = join(' ', &ChanConfList("chanlimitcheck") );
382 foreach $chan ( &ChanConfList("chanlimitcheck") ) {
383 next unless (&validChan($chan));
385 if ($chan eq "_default") {
386 &WARN("chanlimit: we're doing $chan!! HELP ME!");
390 my $limitplus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
391 my $newlimit = scalar(keys %{ $channels{$chan}{''} }) + $limitplus;
392 my $limit = $channels{$chan}{'l'};
394 if (scalar keys %netsplitservers) {
395 if (defined $limit) {
396 &status("chanlimit: netsplit; removing it for $chan.");
397 $conn->mode($chan, "-l");
398 $cache{chanlimitChange}{$chan} = time();
399 &status("chanlimit: netsplit; removed.");
405 if (defined $limit and scalar keys %{ $channels{$chan}{''} } > $limit) {
406 &FIXME("LIMIT: set too low!!!");
407 ### run NAMES again and flush it.
410 if (defined $limit and $limit == $newlimit) {
411 $cache{chanlimitChange}{$chan} = time();
415 if (!exists $channels{$chan}{'o'}{$mynick}) {
416 &status("chanlimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
417 $cache{warn}{chanlimit}{$chan} = 1;
418 &chanServCheck($chan);
421 delete $cache{warn}{chanlimit}{$chan};
423 if (!defined $limit) {
424 &status("chanlimit: $chan: setting for first time or from netsplit.");
427 if (exists $cache{chanlimitChange}{$chan}) {
428 my $delta = time() - $cache{chanlimitChange}{$chan};
429 if ($delta < $interval*60) {
430 &DEBUG("chanlimit: not going to change chanlimit! ($delta<$interval*60)");
435 $conn->mode($chan, "+l", $newlimit);
436 $cache{chanlimitChange}{$chan} = time();
444 &ScheduleThis(15, "netsplitCheck");
445 return if ($_[0] eq "2");
448 $cache{'netsplitCache'}++;
449 # &DEBUG("running netsplitCheck... $cache{netsplitCache}");
451 if (!scalar %netsplit and scalar %netsplitservers) {
452 &DEBUG("nsC: !hash netsplit but hash netsplitservers <- removing!");
453 undef %netsplitservers;
457 # well... this shouldn't happen since %netsplit code does it anyway.
458 foreach $s1 (keys %netsplitservers) {
460 foreach $s2 (keys %{ $netsplitservers{$s1} }) {
461 my $delta = time() - $netsplitservers{$s1}{$s2};
463 if ($delta > 60*30) {
464 &status("netsplit between $s1 and $s2 appears to be stale.");
465 delete $netsplitservers{$s1}{$s2};
470 my $i = scalar(keys %{ $netsplitservers{$s1} });
471 delete $netsplitservers{$s1} unless ($i);
474 # %netsplit hash checker.
475 my $count = scalar keys %netsplit;
477 foreach (keys %netsplit) {
478 if (&IsNickInAnyChan($_)) { # why would this happen?
479 # &DEBUG("nsC: $_ is in some chan; removing from netsplit list.");
480 delete $netsplit{$_};
485 next unless (time() - $netsplit{$_} > 60*15);
488 delete $netsplit{$_};
492 foreach (keys %channels) {
493 my $i = $cache{maxpeeps}{$chan} || 0;
494 my $j = scalar(keys %{ $channels{$chan} });
495 next unless ($i > 10 and 0.25*$i > $j);
497 &DEBUG("netsplit: 0.25*max($i) > current($j); possible netsplit?");
501 my $j = scalar(keys %netsplit);
502 &status("nsC: removed from netsplit list: (before: $count; after: $j)");
505 if (!scalar %netsplit and scalar %netsplitservers) {
506 &DEBUG("nsC: ok hash netsplit is NULL; purging hash netsplitservers");
507 undef %netsplitservers;
510 if ($count and !scalar keys %netsplit) {
511 &DEBUG("nsC: netsplit is hopefully gone. reinstating chanlimit check.");
521 &ScheduleThis(60, "floodLoop"); # minutes.
522 return if ($_[0] eq "2");
526 my $interval = &getChanConfDefault("floodCycle",60, $chan);
528 foreach $who (keys %flood) {
529 foreach (keys %{ $flood{$who} }) {
530 if (!exists $flood{$who}{$_}) {
531 &WARN("flood{$who}{$_} undefined?");
535 if ($time - $flood{$who}{$_} > $interval) {
536 delete $flood{$who}{$_};
541 &VERB("floodLoop: deleted $delete items.",2);
546 my $interval = &getChanConfDefault("seenFlushInterval", 60, $chan);
547 &ScheduleThis($interval, "seenFlush");
548 return if ($_[0] eq "2");
554 $stats{'count_old'} = &countKeys("seen") || 0;
558 if ($param{'DBType'} =~ /^(mysql|pgsql|sqlite(2)?)$/i) {
559 foreach $nick (keys %seencache) {
560 my $retval = &sqlSet("seen", {'nick' => lc $seencache{$nick}{'nick'}}, {
561 time => $seencache{$nick}{'time'},
562 host => $seencache{$nick}{'host'},
563 channel => $seencache{$nick}{'chan'},
564 message => $seencache{$nick}{'msg'},
567 delete $seencache{$nick};
571 &DEBUG("seenFlush: NO VALID FACTOID SUPPORT?");
574 &status("Seen: Flushed $flushed entries.") if ($flushed);
575 &VERB(sprintf(" new seen: %03.01f%% (%d/%d)",
576 $stats{'new'}*100/($stats{'count_old'} || 1),
577 $stats{'new'}, ( $stats{'count_old'} || 1) ), 2) if ($stats{'new'});
578 &VERB(sprintf(" now seen: %3.1f%% (%d/%d)",
579 $stats{'old'}*100 / ( &countKeys("seen") || 1),
580 $stats{'old'}, &countKeys("seen") ), 2) if ($stats{'old'});
582 &WARN("scalar keys seenflush != 0!") if (scalar keys %seenflush);
590 &ScheduleThis(240, "leakCheck");
591 return if ($_[0] eq "2");
594 # flood. this is dealt with in floodLoop()
595 foreach $blah1 (keys %flood) {
596 foreach $blah2 (keys %{ $flood{$blah1} }) {
597 $count += scalar(keys %{ $flood{$blah1}{$blah2} });
600 &VERB("leak: hash flood has $count total keys.",2);
604 foreach $blah1 (keys %floodjoin) {
605 foreach $blah2 (keys %{ $floodjoin{$blah1} }) {
606 $count += scalar(keys %{ $floodjoin{$blah1}{$blah2} });
609 &VERB("leak: hash floodjoin has $count total keys.",2);
612 $count = scalar(keys %floodwarn);
613 &VERB("leak: hash floodwarn has $count total keys.",2);
616 foreach $chan (grep /[A-Z]/, keys %channels) {
617 &DEBUG("leak: chan => '$chan'.");
619 foreach $i (keys %{ $channels{$chan} }) {
620 foreach (keys %{ $channels{$chan}{$i} }) {
621 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
627 $count = scalar(keys %chanstats);
628 &VERB("leak: hash chanstats has $count total keys.",2);
632 foreach (keys %nuh) {
633 next if (&IsNickInAnyChan($_));
634 next if (exists $dcc{CHAT}{$_});
640 &status("leak: $delete nuh{} items deleted; now have ".
641 scalar(keys %nuh) ) if ($delete);
646 &ScheduleThis(60, "ignoreCheck");
647 return if ($_[0] eq "2"); # defer.
653 foreach (keys %ignore) {
656 foreach (keys %{ $ignore{$chan} }) {
657 my @array = @{ $ignore{$chan}{$_} };
659 next unless ($array[0] and $time > $array[0]);
661 delete $ignore{$chan}{$_};
662 &status("ignore: $_/$chan has expired.");
667 $cache{ignoreCheckTime} = time();
669 &VERB("ignore: $count items deleted.",2);
674 &ScheduleThis(15, "ircCheck");
675 return if ($_[0] eq "2"); # defer.
678 $cache{statusSafe} = 1;
679 foreach (sort keys %conns) {
681 my $mynick=$conn->nick();
682 &DEBUG("ircCheck for $_");
683 my @join = &getJoinChans(1);
685 &FIXME('ircCheck: found channels to join! ' . join(',',@join));
689 # TODO: fix on_disconnect()
691 if (time() - $msgtime > 3600) {
692 # TODO: shouldn't we use cache{connect} somewhere?
693 if (exists $cache{connect}) {
694 &WARN("ircCheck: no msg for 3600 and disco'd! reconnecting!");
695 $msgtime = time(); # just in case.
697 delete $cache{connect};
699 &status('ircCheck: possible lost in space; checking.'.
701 &msg($mynick, "TEST");
702 $cache{connect} = time();
706 if (grep /^\s*$/, keys %channels) {
707 &WARN('ircCheck: we have a NULL chan in hash channels? removing!');
708 if (!exists $channels{''}) {
709 &DEBUG('ircCheck: this should never happen!');
712 delete $channels{''};
716 $cache{statusSafe} = 0;
719 if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
721 $wtime_userfile = time();
724 if ($utime_chanfile > $wtime_chanfile and time() - $wtime_chanfile > 3600) {
726 $wtime_chanfile = time();
732 &ScheduleThis(120, "miscCheck");
733 return if ($_[0] eq "2"); # defer.
738 if ( -x "/usr/bin/ipcs") {
739 @ipcs = `/usr/bin/ipcs`;
741 &WARN("ircCheck: no 'ipcs' binary.");
745 # make backup of important files.
746 &mkBackup( $bot_state_dir."/blootbot.chan", 60*60*24*3);
747 &mkBackup( $bot_state_dir."/blootbot.users", 60*60*24*3);
748 &mkBackup( $bot_base_dir."/blootbot-news.txt", 60*60*24*1);
750 # flush cache{lobotomy}
751 foreach (keys %{ $cache{lobotomy} }) {
752 next unless (time() - $cache{lobotomy}{$_} > 60*60);
753 delete $cache{lobotomy}{$_};
756 ### check modules if they've been modified. might be evil.
759 # shmid stale remove.
763 # key, shmid, owner, perms, bytes, nattch
764 next unless (/^(0x\d+) (\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+/);
766 my ($shmid, $size) = ($2,$5);
767 next unless ($shmid != $shm and $size == 2000);
768 my $z = &shmRead($shmid);
769 if ($z =~ /^(\S+):(\d+):(\d+): /) {
773 next if (time() - $time < 60*60);
774 # FIXME remove not-pid shm if parent process dead
775 next if ($pid == $bot_pid);
776 # don't touch other bots, if they're running.
777 next unless ($param{ircUser} =~ /^\Q$n\E$/);
779 &DEBUG("shm: $shmid is not ours or old blootbot => ($z)");
783 &status("SHM: nuking shmid $shmid");
784 CORE::system("/usr/bin/ipcrm shm $shmid >/dev/null");
790 &ScheduleThis(240, "miscCheck2");
791 return if ($_[0] eq "2"); # defer.
795 opendir(DEBIAN, "$bot_state_dir/debian");
796 foreach ( grep /gz$/, readdir(DEBIAN) ) {
797 my $exit = CORE::system("gzip -t $bot_state_dir/debian/$_");
800 &status("debian: unlinking file => $_");
801 unlink "$bot_state_dir/debian/$_";
805 # compress logs that should have been compressed.
806 # TODO: use strftime?
807 my ($day,$month,$year) = (gmtime(time()))[3,4,5];
808 my $date = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
810 if (!opendir(DIR,"$bot_log_dir")) {
811 &ERROR("misccheck2: log dir $bot_log_dir does not exist.");
816 while (my $f = readdir(DIR)) {
817 next unless ( -f "$bot_log_dir/$f");
818 next if ($f =~ /gz|bz2/);
819 next unless ($f =~ /(\d{8})/);
820 next if ($date eq $1);
822 &compress("$bot_log_dir/$f");
827 ### this is semi-scheduled
829 # FIXME: broken for multiple connects
830 # if ($ident eq $param{'ircNick'}) {
831 # &status("okay, got my nick back.");
836 # &ScheduleThis(30, "getNickInUse");
837 # return if ($_[0] eq "2"); # defer.
840 # &nick( $param{'ircNick'} );
844 return if (!defined &uptimeWriteFile);
845 # return unless &IsParam('Uptime');
848 &ScheduleThis(60, 'uptimeLoop');
849 return if ($_[0] eq '2'); # defer.
858 &ScheduleThis(60, 'slashdotLoop');
859 return if ($_[0] eq "2");
862 my @chans = &ChanConfList('slashdotAnnounce');
863 return unless (scalar @chans);
865 &Forker('slashdot', sub {
866 my $line = &Slashdot::slashdotAnnounce();
867 return unless (defined $line);
870 next unless (&::validChan($_));
872 &::status("sending slashdot update to $_.");
873 ¬ice($_, "Slashdot: $line");
881 &ScheduleThis(60, 'plugLoop');
882 return if ($_[0] eq "2");
885 my @chans = &ChanConfList('plugAnnounce');
886 return unless (scalar @chans);
888 &Forker('Plug', sub {
889 my $line = &Plug::plugAnnounce();
890 return unless (defined $line);
893 next unless (&::validChan($_));
895 &::status("sending plug update to $_.");
896 ¬ice($_, "Plug: $line");
903 &ScheduleThis(240, "kernelLoop");
904 return if ($_[0] eq "2");
907 my @chans = &ChanConfList("kernelAnnounce");
908 return unless (scalar @chans);
910 &Forker("Kernel", sub {
911 my @data = &Kernel::kernelAnnounce();
914 next unless (&::validChan($_));
916 &::status("sending kernel update to $_.");
919 ¬ice($c, "Kernel: $_");
926 return unless &IsChanConf('Wingate') > 0;
928 ### FILE CACHE OF OFFENDING WINGATES.
929 foreach (grep /^$host$/, @wingateBad) {
930 &status("Wingate: RUNNING ON $host BY $who");
931 &ban("*!*\@$host", "") if &IsChanConf('wingateBan') > 0;
933 my $reason = &getChanConf('wingateKick');
935 next unless ($reason);
936 &kick($who, "", $reason)
939 ### RUN CACHE OF TRIED WINGATES.
940 if (grep /^$host$/, @wingateCache) {
941 push(@wingateNow, $host); # per run.
942 push(@wingateCache, $host); # cache per run.
944 &DEBUG("Already scanned $host. good.");
947 my $interval = &getChanConfDefault('wingateInterval', 60, $chan); # seconds.
948 return if (defined $forked{'Wingate'});
949 return if (time() - $wingaterun <= $interval);
950 return unless (scalar(keys %wingateToDo));
952 $wingaterun = time();
954 &Forker('Wingate', sub { &Wingate::Wingates(keys %wingateToDo); } );
959 sub wingateWriteFile {
961 &ScheduleThis(60, 'wingateWriteFile');
962 return if ($_[0] eq "2"); # defer.
965 return unless (scalar @wingateCache);
967 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
968 if ($bot_pid != $$) {
969 &DEBUG('wingateWriteFile: Reorganising!');
974 push(@wingateNow, $_);
979 my %hash = map { $_ => 1 } @wingateNow;
980 @wingateNow = sort keys %hash;
983 &DEBUG('wingateWF: writing...');
985 foreach (@wingateNow) {
993 &ScheduleThis(720, "factoidCheck");
994 return if ($_[0] eq "2"); # defer.
997 my @list = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
998 my $stale = &getChanConfDefault("factoidDeleteDelay", 14, $chan) *60*60*24;
1000 # disable it since it's "illegal".
1007 my $age = &getFactInfo($_, "modified_time");
1009 if (!defined $age or $age !~ /^\d+$/) {
1010 if (scalar @list > 50) {
1011 if (!$cache{warnDel}) {
1012 &WARN("list is over 50 (".scalar(@list)."... giving it a miss.");
1013 $cache{warnDel} = 1;
1018 &WARN("del factoid: old cruft (no time): $_");
1023 next unless ($time - $age > $stale);
1026 $fix =~ s/ #DEL#$//g;
1027 my $agestr = &Time2String($time - $age);
1028 &status("safedel: Removing '$_' for good. [$agestr old]");
1035 return unless (scalar keys %{ $dcc{CHAT} });
1038 &ScheduleThis(10, "dccStatus");
1039 return if ($_[0] eq "2"); # defer.
1042 my $time = strftime("%H:%M", gmtime(time()) );
1045 foreach (keys %channels) {
1047 my $users = keys %{ $channels{$c}{''} };
1048 my $chops = keys %{ $channels{$c}{o} };
1049 my $bans = keys %{ $channels{$c}{b} };
1051 my $txt = "[$time] $c: $users members ($chops chops), $bans bans";
1052 foreach (keys %{ $dcc{'CHAT'} }) {
1053 next unless (exists $channels{$c}{''}{lc $_});
1054 $conn->privmsg($dcc{'CHAT'}{$_}, $txt);
1066 my $reply = "sched:";
1067 foreach (keys %{ $irc->{_queue}}) {
1069 my $coderef = $irc->{_queue}->{$q}->[1];
1071 foreach (keys %sched) {
1073 next unless defined(\&$schedname);
1074 next unless ($coderef eq \&$schedname);
1075 $sched = $schedname;
1079 my $time = $irc->{_queue}->{$q}->[0] - time();
1081 if (defined $sched) {
1082 $reply = "$reply, $sched($q):" . &Time2String($time);
1084 $reply = "$reply, NULL($q):" . &Time2String($time);
1092 my($file, $time) = @_;
1096 &VERB("mkB: file '$file' does not exist.",2);
1101 if ( -e "$file~" ) {
1102 $backup++ if ((stat $file)[9] - (stat "$file~")[9] > $time);
1103 my $delta = time() - (stat "$file~")[9];
1104 $age = &Time2String($delta);
1109 return unless ($backup);
1111 ### TODO: do internal copying.
1112 &status("Backup: $file ($age)");
1113 CORE::system("/bin/cp $file $file~");