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),
25 &VERB( 'Starting schedulers...', 2 );
34 &leakCheck(2); # mandatory
36 &miscCheck2(2); # mandatory
41 &factoidCheck(2); # takes a couple of seconds on a 486. defer it
43 # TODO: convert to new format... or nuke altogether.
47 # 1 for run straight away
51 &netsplitCheck(1); # mandatory
52 &floodLoop(1); # mandatory
53 &ignoreCheck(1); # mandatory
54 &miscCheck(1); # mandatory
55 &shmFlush(1); # mandatory
57 &ircCheck(1); # mandatory
59 # TODO: squeeze this into a one-liner.
60 # my $count = map { exists $sched{$_}{TIME} } keys %sched;
62 foreach ( keys %sched ) {
63 my $time = $sched{$_}{TIME};
64 next unless ( defined $time and $time > time() );
69 &status("Schedulers: $count will be running.");
74 my ( $interval, $codename, @args ) = @_;
76 # Set to supllied value plus a random 0-60 seconds to avoid simultaneous runs
78 &getRandomInt( "$interval-" . ( $interval + &getRandomInt(60) ) );
80 if ( !defined $waittime ) {
81 &WARN("interval == waittime == UNDEF for $codename.");
85 my $time = $sched{$codename}{TIME};
86 if ( defined $time and $time > time() ) {
87 &WARN( "Sched for $codename already exists in "
88 . &Time2String( time() - $time )
94 "Scheduling \&$codename() "
95 . \&$codename . ' for '
96 . &Time2String($waittime),
100 my $retval = $conn->schedule( $waittime, \&$codename, @args );
101 $sched{$codename}{LABEL} = $retval;
102 $sched{$codename}{TIME} = time() + $waittime;
103 $sched{$codename}{LOOP} = 1;
107 #### LET THE FUN BEGIN.
111 my $interval = $param{'rssFeedTime'} || 30;
113 &ScheduleThis( $interval * 60, 'rssFeeds' ); # minutes
114 return if ( $_[0] eq '2' ); # defer.
119 my $line = &RSSFeeds::RSS();
120 return unless ( defined $line );
127 my $interval = &getChanConfDefault( 'randomQuoteInterval', 60, $chan );
129 &ScheduleThis( $interval * 60, 'randomQuote' ); # every hour
130 return if ( $_[0] eq '2' ); # defer.
133 foreach ( &ChanConfList('randomQuote') ) {
134 next unless ( &validChan($_) );
137 &getRandomLineFromFile( $bot_data_dir . '/infobot.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 * 60, 'randomFactoid' ); # minutes
157 return if ( $_[0] eq '2' ); # defer.
160 foreach ( &ChanConfList('randomFactoid') ) {
161 next unless ( &validChan($_) );
163 &status("sending random Factoid to $_.");
166 &randKey( 'factoids', 'factoid_key,factoid_value' );
167 &DEBUG("rF: $key, $val");
168 ### $val =~ tr/^[A-Z]/[a-z]/; # blah is Good => blah is good.
170 if ( ( defined $val )
172 and ( $key !~ /\#DEL\#/ )
173 and ( $key !~ /^cmd:/ ) );
177 &ERROR('rF: tried 5 times but failed.');
181 &action( $_, "Thinks: \037$key\037 is $val" );
182 ### FIXME: Use &getReply() on above to format factoid properly?
189 &ScheduleThis( 3600, 'logLoop' ); # 1 hour
190 return if ( $_[0] eq '2' ); # defer.
193 return unless ( defined fileno LOG );
194 return unless ( &IsParam('logfile') );
195 return unless ( &IsParam('maxLogSize') );
197 ### check if current size is too large.
198 if ( -s $file{log} > $param{'maxLogSize'} ) {
199 my $date = sprintf( '%04d%02d%02d', (gmtime)[ 5, 4, 3 ] );
200 $file{log} = $param{'logfile'} . '-' . $date;
201 &status('cycling log file.');
203 if ( -e $file{log} ) {
207 $newlog = $file{log} . '-' . $i;
208 last if ( !-e $newlog );
211 $file{log} = $newlog;
215 CORE::system("/bin/mv '$param{'logfile'}' '$file{log}'");
216 &compress( $file{log} );
218 &status('cycling log file.');
221 ### check if all the logs exceed size.
222 if ( !opendir( LOGS, $bot_log_dir ) ) {
223 &WARN("logLoop: could not open dir '$bot_log_dir'");
229 while ( defined( $_ = readdir LOGS ) ) {
230 my $logfile = "$bot_log_dir/$_";
232 next unless ( -f $logfile );
234 my $size = -s $logfile;
235 my $age = ( stat $logfile )[9];
236 $age{$age} = $logfile;
237 $size{$logfile} = $size;
243 while ( $tsize > $param{'maxLogSize'} ) {
244 &status("LOG: current size > max ($tsize > $param{'maxLogSize'})");
245 my $oldest = ( sort { $a <=> $b } keys %age )[0];
246 &status("LOG: unlinking $age{$oldest}.");
247 unlink $age{$oldest};
252 ### TODO: add how many b,kb,mb removed?
253 &status("LOG: removed $delete logs.") if ($delete);
258 &ScheduleThis( 86400, 'seenFlushOld' ); # 1 day
259 return if ( $_[0] eq '2' ); # defer.
262 # is this global-only?
263 return unless ( &IsChanConf('seen') > 0 );
264 return unless ( &IsChanConf('seenFlushInterval') > 0 );
266 # global setting. does not make sense for per-channel.
268 &getChanConfDefault( 'seenMaxDays', 30, $chan ) * 60 * 60 * 24;
271 if ( $param{'DBType'} =~ /^(pgsql|mysql|sqlite(2)?)$/i ) {
274 if ( $param{'DBType'} =~ /^mysql$/i ) {
276 'SELECT nick,time FROM seen GROUP BY nick HAVING '
277 . "UNIX_TIMESTAMP() - time > $max_time";
279 elsif ( $param{'DBType'} =~ /^sqlite(2)?$/i ) {
281 'SELECT nick,time FROM seen GROUP BY nick HAVING '
282 . "strftime('%s','now','localtime') - time > $max_time";
286 'SELECT nick,time FROM seen WHERE '
287 . "extract(epoch from timestamp 'now') - time > $max_time";
290 my $sth = $dbh->prepare($query);
291 if ( $sth->execute ) {
292 while ( my @row = $sth->fetchrow_array ) {
293 my ( $nick, $time ) = @row;
295 &sqlDelete( 'seen', { nick => $nick } );
302 &FIXME( 'seenFlushOld: for bad DBType:' . $param{'DBType'} . '.' );
304 &VERB( "SEEN deleted $delete seen entries.", 2 );
310 &ScheduleThis( 3600, 'newsFlush' ); # 1 hour
311 return if ( $_[0] eq '2' ); # defer.
314 if ( !&ChanConfList('News') ) {
315 &DEBUG("newsFlush: news disabled? (chan => $chan)");
322 foreach $chan ( keys %::news ) {
324 my $total = scalar( keys %{ $::news{$chan} } );
327 delete $::news{$chan};
331 foreach $item ( keys %{ $::news{$chan} } ) {
332 my $t = $::news{$chan}{$item}{Expire};
334 my $tadd = $::news{$chan}{$item}{Time};
335 $oldest = $tadd if ( $oldest > $tadd );
337 next if ( $t == 0 or $t == -1 );
340 "newsFlush: Fixed Expire time for $chan/$item, should not happen anyway."
342 $::news{$chan}{$item}{Expire} = time() + $t * 60 * 60 * 24;
346 my $delta = $t - time();
348 next unless ( time() > $t );
350 # TODO: show how old it was.
351 delete $::news{$chan}{$item};
352 &status("NEWS: (newsflush) deleted '$item'");
357 &status("NEWS (newsflush) {$chan}: deleted [$i/$total] news entries.")
359 $none{$chan} = 1 if ( $total == $i );
362 # TODO: flush users aswell.
364 foreach $chan ( keys %::newsuser ) {
365 next if ( exists $none{$chan} );
367 foreach ( keys %{ $::newsuser{$chan} } ) {
368 my $t = $::newsuser{$chan}{$_};
369 if ( !defined $t or ( $t > 2 and $t < 1000 ) ) {
370 &DEBUG("something wrong with newsuser{$chan}{$_} => $t");
374 next unless ( $oldest > $t );
376 delete $::newsuser{$chan}{$_};
380 my $i = scalar( keys %{ $::newsuser{$chan} } );
381 delete $::newsuser{$chan} unless ($i);
384 if ( $delete or $duser ) {
385 &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
390 my $interval = &getChanConfDefault( 'chanlimitcheckInterval', 10, $chan );
391 my $mynick = $conn->nick();
394 &ScheduleThis( $interval * 60, 'chanlimitCheck' ); # default 10 minutes
395 return if ( $_[0] eq '2' );
398 my $str = join( ' ', &ChanConfList('chanlimitcheck') );
400 foreach $chan ( &ChanConfList('chanlimitcheck') ) {
401 next unless ( &validChan($chan) );
403 if ( $chan eq '_default' ) {
404 &WARN("chanlimit: we're doing $chan!! HELP ME!");
408 my $limitplus = &getChanConfDefault( 'chanlimitcheckPlus', 5, $chan );
409 my $newlimit = scalar( keys %{ $channels{$chan}{''} } ) + $limitplus;
410 my $limit = $channels{$chan}{'l'};
412 if ( scalar keys %netsplitservers ) {
413 if ( defined $limit ) {
414 &status("chanlimit: netsplit; removing it for $chan.");
415 $conn->mode( $chan, '-l' );
416 $cache{chanlimitChange}{$chan} = time();
417 &status('chanlimit: netsplit; removed.');
423 if ( defined $limit and scalar keys %{ $channels{$chan}{''} } > $limit )
425 &FIXME('LIMIT: set too low!!!');
426 ### run NAMES again and flush it.
429 if ( defined $limit and $limit == $newlimit ) {
430 $cache{chanlimitChange}{$chan} = time();
434 if ( !exists $channels{$chan}{'o'}{$mynick} ) {
435 &status("chanlimit: dont have ops on $chan.")
436 unless ( exists $cache{warn}{chanlimit}{$chan} );
437 $cache{warn}{chanlimit}{$chan} = 1;
438 &chanServCheck($chan);
441 delete $cache{warn}{chanlimit}{$chan};
443 if ( !defined $limit ) {
445 "chanlimit: $chan: setting for first time or from netsplit.");
448 if ( exists $cache{chanlimitChange}{$chan} ) {
449 my $delta = time() - $cache{chanlimitChange}{$chan};
450 if ( $delta < $interval * 60 ) {
452 "chanlimit: not going to change chanlimit! ($delta<$interval*60)"
458 $conn->mode( $chan, '+l', $newlimit );
459 $cache{chanlimitChange}{$chan} = time();
467 &ScheduleThis( 300, 'netsplitCheck' ); # every 5 minutes
468 return if ( $_[0] eq '2' );
471 $cache{'netsplitCache'}++;
473 # &DEBUG("running netsplitCheck... $cache{netsplitCache}");
475 if ( !scalar %netsplit and scalar %netsplitservers ) {
476 &DEBUG('nsC: !hash netsplit but hash netsplitservers <- removing!');
477 undef %netsplitservers;
481 # well... this shouldn't happen since %netsplit code does it anyway.
482 foreach $s1 ( keys %netsplitservers ) {
484 foreach $s2 ( keys %{ $netsplitservers{$s1} } ) {
485 my $delta = time() - $netsplitservers{$s1}{$s2};
487 if ( $delta > 60 * 30 ) {
488 &status("netsplit between $s1 and $s2 appears to be stale.");
489 delete $netsplitservers{$s1}{$s2};
494 my $i = scalar( keys %{ $netsplitservers{$s1} } );
495 delete $netsplitservers{$s1} unless ($i);
498 # %netsplit hash checker.
499 my $count = scalar keys %netsplit;
501 foreach ( keys %netsplit ) {
502 if ( &IsNickInAnyChan($_) ) { # why would this happen?
504 # &DEBUG("nsC: $_ is in some chan; removing from netsplit list.");
505 delete $netsplit{$_};
510 next unless ( time() - $netsplit{$_} > 60 * 15 );
513 delete $netsplit{$_};
517 # FIXED: $ch should be used rather than $chan since it creates NULL channels in the hash
518 foreach my $ch ( keys %channels ) {
519 my $i = $cache{maxpeeps}{$ch} || 0;
520 my $j = scalar( keys %{ $channels{$ch} } );
521 next unless ( $i > 10 and 0.25 * $i > $j );
523 &DEBUG("netsplit: 0.25*max($i) > current($j); possible netsplit?");
527 my $j = scalar( keys %netsplit );
528 &status("nsC: removed from netsplit list: (before: $count; after: $j)");
531 if ( !scalar %netsplit and scalar %netsplitservers ) {
532 &DEBUG('nsC: ok hash netsplit is NULL; purging hash netsplitservers');
533 undef %netsplitservers;
536 if ( $count and !scalar keys %netsplit ) {
537 &DEBUG('nsC: netsplit is hopefully gone. reinstating chanlimit check.');
547 &ScheduleThis( 60, 'floodLoop' ); # 1 minute
548 return if ( $_[0] eq '2' );
552 my $interval = &getChanConfDefault( 'floodCycle', 60, $chan );
554 foreach $who ( keys %flood ) {
555 foreach ( keys %{ $flood{$who} } ) {
556 if ( !exists $flood{$who}{$_} ) {
557 &WARN("flood{$who}{$_} undefined?");
561 if ( $time - $flood{$who}{$_} > $interval ) {
562 delete $flood{$who}{$_};
567 &VERB( "floodLoop: deleted $delete items.", 2 );
572 my $interval = &getChanConfDefault( 'seenFlushInterval', 60, $chan );
573 &ScheduleThis( $interval * 60, 'seenFlush' ); # minutes
574 return if ( $_[0] eq '2' );
580 $stats{'count_old'} = &countKeys('seen') || 0;
584 if ( $param{'DBType'} =~ /^(mysql|pgsql|sqlite(2)?)$/i ) {
585 foreach $nick ( keys %seencache ) {
586 my $retval = &sqlSet(
588 { 'nick' => lc $seencache{$nick}{'nick'} },
590 time => $seencache{$nick}{'time'},
591 host => $seencache{$nick}{'host'},
592 channel => $seencache{$nick}{'chan'},
593 message => $seencache{$nick}{'msg'},
597 delete $seencache{$nick};
602 &DEBUG('seenFlush: NO VALID FACTOID SUPPORT?');
605 &status("Seen: Flushed $flushed entries.") if ($flushed);
608 ' new seen: %03.01f%% (%d/%d)',
609 $stats{'new'} * 100 / ( $stats{'count_old'} || 1 ),
611 ( $stats{'count_old'} || 1 )
614 ) if ( $stats{'new'} );
617 ' now seen: %3.1f%% (%d/%d)',
618 $stats{'old'} * 100 / ( &countKeys('seen') || 1 ), $stats{'old'},
622 ) if ( $stats{'old'} );
624 &WARN('scalar keys seenflush != 0!') if ( scalar keys %seenflush );
628 my ( $blah1, $blah2 );
632 &ScheduleThis( 14400, 'leakCheck' ); # every 4 hours
633 return if ( $_[0] eq '2' );
636 # flood. this is dealt with in floodLoop()
637 foreach $blah1 ( keys %flood ) {
638 foreach $blah2 ( keys %{ $flood{$blah1} } ) {
639 $count += scalar( keys %{ $flood{$blah1}{$blah2} } );
642 &VERB( "leak: hash flood has $count total keys.", 2 );
646 foreach $blah1 ( keys %floodjoin ) {
647 foreach $blah2 ( keys %{ $floodjoin{$blah1} } ) {
648 $count += scalar( keys %{ $floodjoin{$blah1}{$blah2} } );
651 &VERB( "leak: hash floodjoin has $count total keys.", 2 );
654 $count = scalar( keys %floodwarn );
655 &VERB( "leak: hash floodwarn has $count total keys.", 2 );
658 foreach $chan ( grep /[A-Z]/, keys %channels ) {
659 &DEBUG("leak: chan => '$chan'.");
661 foreach $i ( keys %{ $channels{$chan} } ) {
662 foreach ( keys %{ $channels{$chan}{$i} } ) {
663 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
669 $count = scalar( keys %chanstats );
670 &VERB( "leak: hash chanstats has $count total keys.", 2 );
674 foreach ( keys %nuh ) {
675 next if ( &IsNickInAnyChan($_) );
676 next if ( exists $dcc{CHAT}{$_} );
683 "leak: $delete nuh{} items deleted; now have " . scalar( keys %nuh ) )
689 &ScheduleThis( 60, 'ignoreCheck' ); # once every minute
690 return if ( $_[0] eq '2' ); # defer.
696 foreach ( keys %ignore ) {
699 foreach ( keys %{ $ignore{$chan} } ) {
700 my @array = @{ $ignore{$chan}{$_} };
702 next unless ( $array[0] and $time > $array[0] );
704 delete $ignore{$chan}{$_};
705 &status("ignore: $_/$chan has expired.");
710 $cache{ignoreCheckTime} = time();
712 &VERB( "ignore: $count items deleted.", 2 );
718 &ScheduleThis( 300, 'ircCheck' ); # every 5 minutes
719 return $retval if ( $_[0] eq '2' ); # defer.
722 $cache{statusSafe} = 1;
723 # save current connection
724 my $saveconn = $conn;
725 foreach ( sort keys %conns ) {
727 next if (!defined $conn);
728 my $nick = $conn->nick();
729 &DEBUG("ircCheck for $_");
730 # Display with min of 900sec delay between redisplay
731 # FIXME: should only use 900sec when we are on the LAST %conns
732 my @join = &getJoinChans(900);
733 if ( scalar @join ) {
734 &FIXME( 'ircCheck: found ' . scalar @join . ' channels to join! ' . join( ',', @join ) );
735 $retval += scalar @join;
739 # TODO: fix on_disconnect()
741 if ( time() - $msgtime > 3600 ) {
743 # TODO: shouldn't we use cache{connect} somewhere?
744 if ( exists $cache{connect} ) {
745 &WARN("ircCheck: no msg for 3600 and disco'd! reconnecting!");
746 $msgtime = time(); # just in case.
748 delete $cache{connect};
751 &status( 'ircCheck: possible lost in space; checking.'
753 &msg( $mynick, 'TEST' );
754 $cache{connect} = time();
758 # restore connection we were called from
761 if ( grep /^\s*$/, keys %channels ) {
762 &WARN('ircCheck: we have a NULL chan in hash channels? removing!');
763 if ( !exists $channels{''} ) {
764 &DEBUG('ircCheck: this should never happen!');
767 if ( $ident !~ /^\Q$param{ircNick}\E$/ ) {
769 # this does not work unfortunately.
770 &WARN("ircCheck: ident($ident) != param{ircNick}($param{ircNick}).");
772 # this check is misleading... perhaps we should do a notify.
773 if ( !&IsNickInAnyChan( $param{ircNick} ) ) {
774 &DEBUG("$param{ircNick} not in use... changing!");
775 &nick( $param{ircNick} );
778 &WARN("$param{ircNick} is still in use...");
782 $cache{statusSafe} = 0;
785 if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
787 $wtime_userfile = time();
790 if ($utime_chanfile > $wtime_chanfile and time() - $wtime_chanfile > 3600) {
792 $wtime_chanfile = time();
799 &ScheduleThis( 7200, 'miscCheck' ); # every 2 hours
800 return if ( $_[0] eq '2' ); # defer.
805 if ( -x '/usr/bin/ipcs' ) {
806 @ipcs = `/usr/bin/ipcs`;
809 &WARN("ircCheck: no 'ipcs' binary.");
813 # make backup of important files.
814 &mkBackup( $bot_state_dir . '/infobot.chan', 60 * 60 * 24 * 3 );
815 &mkBackup( $bot_state_dir . '/infobot.users', 60 * 60 * 24 * 3 );
816 &mkBackup( $bot_base_dir . '/infobot-news.txt', 60 * 60 * 24 * 1 );
818 # flush cache{lobotomy}
819 foreach ( keys %{ $cache{lobotomy} } ) {
820 next unless ( time() - $cache{lobotomy}{$_} > 60 * 60 );
821 delete $cache{lobotomy}{$_};
824 ### check modules if they've been modified. might be evil.
827 # shmid stale remove.
831 # key, shmid, owner, perms, bytes, nattch
832 next unless (/^(0x\d+) (\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+/);
834 my ( $shmid, $size ) = ( $2, $5 );
835 next unless ( $shmid != $shm and $size == 2000 );
836 my $z = &shmRead($shmid);
837 if ( $z =~ /^(\S+):(\d+):(\d+): / ) {
841 next if ( time() - $time < 60 * 60 );
843 # FIXME remove not-pid shm if parent process dead
844 next if ( $pid == $bot_pid );
846 # don't touch other bots, if they're running.
847 next unless ( $param{ircUser} =~ /^\Q$n\E$/ );
850 &DEBUG("shm: $shmid is not ours or old infobot => ($z)");
854 &status("SHM: nuking shmid $shmid");
855 CORE::system("/usr/bin/ipcrm shm $shmid >/dev/null");
861 &ScheduleThis( 14400, 'miscCheck2' ); # every 4 hours
862 return if ( $_[0] eq '2' ); # defer.
866 opendir( DEBIAN, "$bot_state_dir/debian" );
867 foreach ( grep /gz$/, readdir(DEBIAN) ) {
868 my $exit = CORE::system("gzip -t $bot_state_dir/debian/$_");
871 &status("debian: unlinking file => $_");
872 unlink "$bot_state_dir/debian/$_";
876 # compress logs that should have been compressed.
877 # TODO: use strftime?
878 my ( $day, $month, $year ) = ( gmtime( time() ) )[ 3, 4, 5 ];
879 my $date = sprintf( '%04d%02d%02d', $year + 1900, $month + 1, $day );
881 if ( !opendir( DIR, "$bot_log_dir" ) ) {
882 &ERROR("misccheck2: log dir $bot_log_dir does not exist.");
887 while ( my $f = readdir(DIR) ) {
888 next unless ( -f "$bot_log_dir/$f" );
889 next if ( $f =~ /gz|bz2/ );
890 next unless ( $f =~ /(\d{8})/ );
891 next if ( $date eq $1 );
893 &compress("$bot_log_dir/$f");
898 ### this is semi-scheduled
901 # FIXME: broken for multiple connects
902 # if ($ident eq $param{'ircNick'}) {
903 # &status('okay, got my nick back.');
908 # &ScheduleThis(30, 'getNickInUse');
909 # return if ($_[0] eq '2'); # defer.
912 # &nick( $param{'ircNick'} );
916 return if ( !defined &uptimeWriteFile );
918 # return unless &IsParam('Uptime');
921 &ScheduleThis( 3600, 'uptimeLoop' ); # once per hour
922 return if ( $_[0] eq '2' ); # defer.
931 &ScheduleThis( 3600, 'slashdotLoop' ); # once per hour
932 return if ( $_[0] eq '2' );
935 my @chans = &ChanConfList('slashdotAnnounce');
936 return unless ( scalar @chans );
941 my $line = &Slashdot::slashdotAnnounce();
942 return unless ( defined $line );
945 next unless ( &::validChan($_) );
947 &::status("sending slashdot update to $_.");
948 ¬ice( $_, "Slashdot: $line" );
957 &ScheduleThis( 3600, 'plugLoop' ); # once per hour
958 return if ( $_[0] eq '2' );
961 my @chans = &ChanConfList('plugAnnounce');
962 return unless ( scalar @chans );
967 my $line = &Plug::plugAnnounce();
968 return unless ( defined $line );
971 next unless ( &::validChan($_) );
973 &::status("sending plug update to $_.");
974 ¬ice( $_, "Plug: $line" );
982 &ScheduleThis( 14400, 'kernelLoop' ); # once every 4 hours
983 return if ( $_[0] eq '2' );
986 my @chans = &ChanConfList('kernelAnnounce');
987 return unless ( scalar @chans );
992 my @data = &Kernel::kernelAnnounce();
995 next unless ( &::validChan($_) );
997 &::status("sending kernel update to $_.");
1000 ¬ice( $c, "Kernel: $_" );
1008 return unless &IsChanConf('Wingate') > 0;
1010 ### FILE CACHE OF OFFENDING WINGATES.
1011 foreach ( grep /^$host$/, @wingateBad ) {
1012 &status("Wingate: RUNNING ON $host BY $who");
1013 &ban( "*!*\@$host", '' ) if &IsChanConf('wingateBan') > 0;
1015 my $reason = &getChanConf('wingateKick');
1017 next unless ($reason);
1018 &kick( $who, '', $reason );
1021 ### RUN CACHE OF TRIED WINGATES.
1022 if ( grep /^$host$/, @wingateCache ) {
1023 push( @wingateNow, $host ); # per run.
1024 push( @wingateCache, $host ); # cache per run.
1027 &DEBUG("Already scanned $host. good.");
1031 &getChanConfDefault( 'wingateInterval', 60, $chan ); # seconds.
1032 return if ( defined $forked{'Wingate'} );
1033 return if ( time() - $wingaterun <= $interval );
1034 return unless ( scalar( keys %wingateToDo ) );
1036 $wingaterun = time();
1038 &Forker( 'Wingate', sub { &Wingate::Wingates( keys %wingateToDo ); } );
1043 sub wingateWriteFile {
1045 &ScheduleThis( 3600, 'wingateWriteFile' ); # once per hour
1046 return if ( $_[0] eq '2' ); # defer.
1049 return unless ( scalar @wingateCache );
1051 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
1052 if ( $bot_pid != $$ ) {
1053 &DEBUG('wingateWriteFile: Reorganising!');
1058 push( @wingateNow, $_ );
1063 my %hash = map { $_ => 1 } @wingateNow;
1064 @wingateNow = sort keys %hash;
1067 &DEBUG('wingateWF: writing...');
1068 open( OUT, ">$file" );
1069 foreach (@wingateNow) {
1077 &ScheduleThis( 43200, 'factoidCheck' ); # ever 12 hours
1078 return if ( $_[0] eq '2' ); # defer.
1082 &searchTable( 'factoids', 'factoid_key', 'factoid_key', ' #DEL#' );
1084 &getChanConfDefault( 'factoidDeleteDelay', 14, $chan ) * 60 * 60 * 24;
1087 # disable it since it's 'illegal'.
1094 my $age = &getFactInfo( $_, 'modified_time' );
1096 if ( !defined $age or $age !~ /^\d+$/ ) {
1097 if ( scalar @list > 50 ) {
1098 if ( !$cache{warnDel} ) {
1099 &WARN( 'list is over 50 ('
1101 . '... giving it a miss.' );
1102 $cache{warnDel} = 1;
1107 &WARN("del factoid: old cruft (no time): $_");
1112 next unless ( $time - $age > $stale );
1115 $fix =~ s/ #DEL#$//g;
1116 my $agestr = &Time2String( $time - $age );
1117 &status("safedel: Removing '$_' for good. [$agestr old]");
1124 return unless ( scalar keys %{ $dcc{CHAT} } );
1127 &ScheduleThis( 600, 'dccStatus' ); # every 10 minutes
1128 return if ( $_[0] eq '2' ); # defer.
1131 my $time = strftime( '%H:%M', gmtime( time() ) );
1134 foreach ( keys %channels ) {
1136 my $users = keys %{ $channels{$c}{''} };
1137 my $chops = keys %{ $channels{$c}{o} };
1138 my $bans = keys %{ $channels{$c}{b} };
1140 my $txt = "[$time] $c: $users members ($chops chops), $bans bans";
1141 foreach ( keys %{ $dcc{'CHAT'} } ) {
1142 next unless ( exists $channels{$c}{''}{ lc $_ } );
1143 $conn->privmsg( $dcc{'CHAT'}{$_}, $txt );
1155 my $reply = 'sched:';
1156 foreach ( keys %{ $irc->{_queue} } ) {
1158 my $coderef = $irc->{_queue}->{$q}->[1];
1160 foreach ( keys %sched ) {
1162 next unless defined( \&$schedname );
1163 next unless ( $coderef eq \&$schedname );
1164 $sched = $schedname;
1168 my $time = $irc->{_queue}->{$q}->[0] - time();
1170 if ( defined $sched ) {
1171 $reply = "$reply, $sched($q):" . &Time2String($time);
1174 $reply = "$reply, NULL($q):" . &Time2String($time);
1182 my ( $file, $time ) = @_;
1186 &VERB( "mkB: file '$file' does not exist.", 2 );
1191 if ( -e "$file~" ) {
1192 $backup++ if ( ( stat $file )[9] - ( stat "$file~" )[9] > $time );
1193 my $delta = time() - ( stat "$file~" )[9];
1194 $age = &Time2String($delta);
1200 return unless ($backup);
1202 ### TODO: do internal copying.
1203 &status("Backup: $file ($age)");
1204 CORE::system("/bin/cp $file $file~");
1209 # vim:ts=4:sw=4:expandtab:tw=80