&seenFlushOld(2);
&ircCheck(1); # mandatory
&miscCheck(1); # mandatory
+ &miscCheck2(1); # mandatory
&shmFlush(1); # mandatory
&slashdotLoop(2);
&freshmeatLoop(2);
if ($param{'DBType'} =~ /^mysql|pg|postgres/i) {
foreach $nick (keys %seencache) {
if (0) {
- my $retval = &dbReplace("seen", $nick, (
+ #BROKEN#
+ my $retval = &dbReplace("seen", "nick", $nick, (
"nick" => $seencache{$nick}{'nick'},
"time" => $seencache{$nick}{'time'},
"host" => $seencache{$nick}{'host'},
# flood.
foreach $blah1 (keys %flood) {
- foreach $blah2 (keys %{$flood{$blah1}}) {
- $count += scalar(keys %{$flood{$blah1}{$blah2}});
+ foreach $blah2 (keys %{ $flood{$blah1} }) {
+ $count += scalar(keys %{ $flood{$blah1}{$blah2} });
}
}
- &VERB("\%flood has $count total keys.",2);
+ &DEBUG("leak: hash flood has $count total keys.",2);
+
+ # floodjoin.
+ $count = 0;
+ foreach $blah1 (keys %floodjoin) {
+ foreach $blah2 (keys %{ $floodjoin{$blah1} }) {
+ $count += scalar(keys %{ $floodjoin{$blah1}{$blah2} });
+ }
+ }
+ &DEBUG("leak: hash flood has $count total keys.",2);
+
+ # floodwarn.
+ $count = scalar(keys %floodwarn);
+ &DEBUG("leak: hash floodwarn has $count total keys.",2);
my $chan;
foreach $chan (grep /[A-Z]/, keys %channels) {
&DEBUG("leak: chan => '$chan'.");
my ($i,$j);
- foreach $i (keys %{$channels{$chan}}) {
- foreach (keys %{$channels{$chan}{$i}}) {
+ foreach $i (keys %{ $channels{$chan} }) {
+ foreach (keys %{ $channels{$chan}{$i} }) {
&DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
}
}
$delete++;
}
- &status("leakC: $delete nuh{} items deleted; now have ".
+ &status("leak: $delete nuh{} items deleted; now have ".
scalar(keys %nuh) ) if ($delete);
}
CORE::system("/usr/bin/ipcrm shm $shmid >/dev/null");
}
- # debian check.
- opendir(DEBIAN, "$bot_base_dir/debian");
- foreach ( grep /gz$/, readdir(DEBIAN) ) {
- my $exit = CORE::system("gzip -t $bot_base_dir/debian/$_");
- next unless ($exit);
-
- &status("debian: unlinking file => $_");
- unlink "$bot_base_dir/debian/$_";
- }
- closedir DEBIAN;
-
# make backup of important files.
&mkBackup( $bot_misc_dir."/blootbot.chan", 60*60*24*1);
&mkBackup( $bot_misc_dir."/blootbot.users", 60*60*24*1);
&reloadAllModules();
}
+sub miscCheck2 {
+ if (@_) {
+ &ScheduleThis(240, "miscCheck2");
+ return if ($_[0] eq "2"); # defer.
+ } else {
+ delete $sched{"miscCheck2"}{RUNNING};
+ }
+
+ &DEBUG("miscCheck2: Doing debian checking...");
+
+ # debian check.
+ opendir(DEBIAN, "$bot_base_dir/debian");
+ foreach ( grep /gz$/, readdir(DEBIAN) ) {
+ my $exit = CORE::system("gzip -t $bot_base_dir/debian/$_");
+ next unless ($exit);
+
+ &status("debian: unlinking file => $_");
+ unlink "$bot_base_dir/debian/$_";
+ }
+ closedir DEBIAN;
+
+ # compress logs that should have been compressed.
+ # todo: use strftime?
+ my ($day,$month,$year) = (localtime(time()))[3,4,5];
+ my $date = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
+
+ opendir(DIR,"$bot_base_dir/log");
+ while (my $f = readdir(DIR)) {
+ next unless ( -f "$bot_base_dir/log/$f");
+ next if ($f =~ /gz|bz2/);
+ next unless ($f =~ /(\d{8})/);
+ next if ($date eq $1);
+
+ &compress("$bot_base_dir/log/$f");
+ }
+ closedir DIR;
+}
+
sub shmFlush {
return if ($$ != $::bot_pid); # fork protection.
my($file, $time) = @_;
my $backup = 0;
+ if (! -f $file) {
+ &WARN("mkB: file $file don't exist.");
+ return;
+ }
+
if ( -e "$file~" ) {
- $backup++ if ( -s $file > -s "$file~");
$backup++ if ((stat $file)[9] - (stat "$file~")[9] > $time);
} else {
$backup++;
### TODO: do internal copying.
&status("Backup: $file to $file~");
CORE::system("/bin/cp $file $file~");
- CORE::system("/bin/touch $file~"); # needed!
}
1;
#
# News.pl: Advanced news management
# Author: dms
-# Version: v0.2 (20010326)
+# Version: v0.3 (20014012)
# Created: 20010326
# Notes: Testing done by greycat, kudos!
#
### structure:
-# news{ channel }{ string } { items }
+# news{ channel }{ string } { item }
# newsuser{ channel }{ user } = time()
-### where items is:
+### where item is:
# Time - when it was added (used for sorting)
# Author - Who by.
# Expire - Time to expire.
$chan = undef;
if (!keys %::news) {
- if (!exists $cache{newsFirst}) {
+ if (!exists $::cache{newsFirst}) {
&::DEBUG("looks like we enabled news option just then; loading up news file just in case.");
- $cache{newsFirst} = 1;
+ $::cache{newsFirst} = 1;
}
&readNews();
}
- if ($::msgType eq "private") {
- } else {
+ if ($::msgType ne "private") {
$chan = $::chan;
}
my @chans = &::GetNickInChans($::who);
if (scalar @chans > 1) {
- &::msg($::who, "error: I dunno which channel you are referring to since you're on more than one.");
+ &::msg($::who, "error: I dunno which channel you are referring to since you're on more than one. Try 'news #chan ...' instead");
return;
}
&::DEBUG("!defined item, never happen!");
next;
}
+
$::news{$chan}{$item}{$1} = $2;
next;
}
return;
}
-# my $item = (exists $::news{$chan}{$str}) ? $str : &getNewsItem($str);
my $item = &getNewsItem($str);
if (!defined $item or !scalar keys %{ $::news{$chan}{$item} }) {
&::msg($::who, "No news item called '$str'");
return;
}
- # todo: show item number.
- # todo: show ago-time aswell?
- # todo: show request stats aswell.
- my $t = localtime($::news{$chan}{$item}{Time});
- my $a = $::news{$chan}{$item}{Author};
- &::msg($::who, "+- News \002$chan\002 ##, item '\037$item\037':");
+ my $t = localtime( $::news{$chan}{$item}{Time} );
+ my $a = $::news{$chan}{$item}{Author};
+ my $text = $::news{$chan}{$item}{Text};
+ my $num = &newsS2N($item);
+ my $rwho = $::news{$chan}{$item}{Request_By} || $::who;
+ my $rcount = $::news{$chan}{$item}{Request_Count} || 0;
+
+ if (length $text < $::param{maxKeySize}) {
+ &::DEBUG("NEWS: Possible news->factoid redirection.");
+ my $f = &::getFactoid($text);
+
+ if (defined $f) {
+ &::DEBUG("NEWS: ok, $text is factoid redirection.");
+ $f =~ s/^<REPLY>\s*//i; # anything else?
+ $text = $f;
+ }
+ }
+
+ &::msg($::who, "+- News \002$chan\002 #$num: \037$item\037");
&::msg($::who, "| Added by $a at $t");
- &::msg($::who, $::news{$chan}{$item}{Text});
+ &::msg($::who, "| Requested $rcount times, last by $rwho");
+ &::msg($::who, $text);
$::news{$chan}{$item}{'Request_By'} = $::who;
$::news{$chan}{$item}{'Request_Time'} = time();
return;
}
+ # todo: clean this up.
my $old = $::news{$chan}{$news}{$what};
if (defined $old) {
&::DEBUG("old => $old.");
return;
}
+ if (!$flag) {
+ my $unread = scalar @new;
+ my $total = scalar keys %{ $::news{$chan} };
+ &::msg($::who, "There are unread news in $chan ($unread unread, $total, total). /msg $::ident news latest");
+ return;
+ }
+
if (scalar @new) {
&::msg($::who, "+==== New news for \002$chan\002 (".
scalar(@new)." new items):");
foreach (@new) {
my $i = &newsS2N($_);
- &::DEBUG("i = $i, _ => $_");
my $age = time() - $::news{$chan}{$_}{Time};
&::msg($::who, sprintf("\002[\002%2d\002]\002 %s",
$i, $_) );
} else {
# partial string to full string resolution
+ # in some cases, string->number resolution.
my @items;
my $no;
push(@items, $time{$_}) if ($time{$_} =~ /\Q$what\E/i);
}
- # since we have so much built into this function, there is so
- # many guesses we can make.
- # todo: split this command in the future into:
- # full_string->number and number->string
- # partial_string->full_string
- &::DEBUG("no => $no, items => @items.");
if (defined $no and !@items) {
- &::DEBUG("string->number resolution.");
+ &::DEBUG("string->number resolution: $what->$no.");
return $no;
}
return;
}
- &::DEBUG("gNI: string->number(??): $what->$items[0]");
+ &::DEBUG("gNI: part_string->full_string: $what->$items[0]");
if (@items) {
&::DEBUG("gNI: Guessed '$items[0]'.");
return $items[0];
&writeUserFile();
&writeChanFile();
+ &News::writeNews() if (&ChanConfList("news"));
return;
}
Help => 'tell', Identifier => 'allowTelling',
Cmdstats => 'Tell') );
&addCmdHook("main", 'news', ('CODEREF' => 'News::Parse',
- Module => 'news', Identifier => 'news') );
+ Module => 'news', ) );
+# Module => 'news', Identifier => 'news') );
&status("CMD: loaded ".scalar(keys %hooks_main)." MAIN command hooks.");
}
#####
-# Usage: &dbReplace($table, $primkey, %hash);
+# Usage: &dbReplace($table, $primkey, $primval, %hash);
sub dbReplace {
- my ($table, $primkey, %hash) = @_;
+ my ($table, $primkey, $primval, %hash) = @_;
my (@keys, @vals);
foreach (keys %hash) {
}
&dbRaw("Replace($table)", "REPLACE INTO $table (".join(',',@keys).
- ") VALUES (".join(',',@vals).")"
+ ") VALUES (".join(',',@vals).") WHERE $primkey=".
+ &dbQuote($primval)
);
return 1;
&SQLDebug($query);
if (!$sth->execute) {
&ERROR("Raw($prefix): => '$query'");
- &ERROR("Raw($prefix): $DBI::errstr");
+# &ERROR("Raw($prefix): $DBI::errstr");
$sth->finish;
return 0;
}