+}
+
+sub factoidCheck {
+ if (@_) {
+ &ScheduleThis(1440, "factoidCheck");
+ return if ($_[0] eq "2"); # defer.
+ } else {
+ delete $sched{"factoidCheck"}{RUNNING};
+ }
+
+ my @list = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
+ my $stale = &getChanConfDefault("factoidDeleteDelay", 30) *60*60*24;
+ my $time = time();
+
+ foreach (@list) {
+ my $age = &getFactInfo($_, "modified_time");
+ if (!defined $age or $age !~ /^\d+$/) {
+ &WARN("age == NULL or not numeric.");
+ next;
+ }
+
+ next unless ($time - $age > $stale);
+
+ my $fix = $_;
+ $fix =~ s/ #DEL#$//g;
+ &DEBUG("safedel: Removing $fix ($_) for good.");
+
+ &delFactoid($_);
+ }
+
+}
+
+sub dccStatus {
+ return unless (scalar keys %{ $dcc{CHAT} });
+
+ if (@_) {
+ &ScheduleThis(10, "dccStatus");
+ return if ($_[0] eq "2"); # defer.
+ } else {
+ delete $sched{"dccStatus"}{RUNNING};
+ }
+
+ my $time = strftime("%H:%M", localtime(time()) );
+
+ my $c;
+ foreach (keys %channels) {
+ my $c = $_;
+ my $users = keys %{ $channels{$c}{''} };
+ my $chops = keys %{ $channels{$c}{o} };
+ my $bans = keys %{ $channels{$c}{b} };
+
+ my $txt = "[$time] $c: $users members ($chops chops), $bans bans";
+ foreach (keys %{ $dcc{'CHAT'} }) {
+ next unless (exists $channels{$c}{''}{lc $_});
+ $conn->privmsg($dcc{'CHAT'}{$_}, $txt);
+ }
+ }
+}
+
+sub scheduleList {
+ ###
+ # custom:
+ # a - time == now.
+ # b - weird time.
+ ###
+
+ &DEBUG("sched:");
+ foreach (keys %{ $irc->{_queue} }) {
+ my $q = $_;
+
+ my $sched;
+ foreach (keys %sched) {
+ next unless ($q eq $sched{$_});
+ $sched = $_;
+ last;
+ }
+
+ my $time = $irc->{_queue}->{$q}->[0] - time();
+
+ if (defined $sched) {
+ &DEBUG(" $sched($q): ".&Time2String($time) );
+ } else {
+ &DEBUG(" NULL($q): ".&Time2String($time) );
+ }
+ }
+
+ &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;
+
+ if ( -e "$file~" ) {
+ $backup++ if ( -s $file > -s "$file~");
+ $backup++ if ((stat $file)[9] - (stat "$file~")[9] > $time);
+ } else {
+ $backup++;
+ }
+ return unless ($backup);
+
+ ### TODO: do internal copying.
+ &status("Backup: $file to $file~");
+ CORE::system("/bin/cp $file $file~");
+ CORE::system("/bin/touch $file~"); # needed!