From: dms Date: Thu, 12 Apr 2001 13:12:42 +0000 (+0000) Subject: news: added news->factoid redirection X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6613e021e045081554e304c8e5235d366e207ed6;p=infobot.git news: added news->factoid redirection ton load of minor changes or bug fixes that cannot really be summarized git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@437 c11ca15a-4712-0410-83d8-924469b57eb5 --- diff --git a/src/IRC/Schedulers.pl b/src/IRC/Schedulers.pl index 2df8512..b9d4623 100644 --- a/src/IRC/Schedulers.pl +++ b/src/IRC/Schedulers.pl @@ -31,6 +31,7 @@ sub setupSchedulers { &seenFlushOld(2); &ircCheck(1); # mandatory &miscCheck(1); # mandatory + &miscCheck2(1); # mandatory &shmFlush(1); # mandatory &slashdotLoop(2); &freshmeatLoop(2); @@ -468,7 +469,8 @@ sub seenFlush { 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'}, @@ -556,18 +558,31 @@ sub leakCheck { # 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}{$_} ..."); } } @@ -582,7 +597,7 @@ sub leakCheck { $delete++; } - &status("leakC: $delete nuh{} items deleted; now have ". + &status("leak: $delete nuh{} items deleted; now have ". scalar(keys %nuh) ) if ($delete); } @@ -730,17 +745,6 @@ sub miscCheck { 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); @@ -756,6 +760,44 @@ sub miscCheck { &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. @@ -1090,8 +1132,12 @@ sub mkBackup { 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++; @@ -1101,7 +1147,6 @@ sub mkBackup { ### TODO: do internal copying. &status("Backup: $file to $file~"); CORE::system("/bin/cp $file $file~"); - CORE::system("/bin/touch $file~"); # needed! } 1; diff --git a/src/Modules/News.pl b/src/Modules/News.pl index b9cd1be..ab274d3 100644 --- a/src/Modules/News.pl +++ b/src/Modules/News.pl @@ -1,14 +1,14 @@ # # 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. @@ -22,16 +22,15 @@ sub Parse { $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; } @@ -44,7 +43,7 @@ sub Parse { 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; } @@ -119,6 +118,7 @@ sub readNews { &::DEBUG("!defined item, never happen!"); next; } + $::news{$chan}{$item}{$1} = $2; next; } @@ -353,7 +353,6 @@ sub read { 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'"); @@ -365,14 +364,28 @@ sub read { 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/^\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(); @@ -577,6 +590,7 @@ sub set { return; } + # todo: clean this up. my $old = $::news{$chan}{$news}{$what}; if (defined $old) { &::DEBUG("old => $old."); @@ -610,6 +624,13 @@ sub latest { 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):"); @@ -619,7 +640,6 @@ sub latest { foreach (@new) { my $i = &newsS2N($_); - &::DEBUG("i = $i, _ => $_"); my $age = time() - $::news{$chan}{$_}{Time}; &::msg($::who, sprintf("\002[\002%2d\002]\002 %s", $i, $_) ); @@ -703,6 +723,7 @@ sub getNewsItem { } else { # partial string to full string resolution + # in some cases, string->number resolution. my @items; my $no; @@ -717,14 +738,8 @@ sub getNewsItem { 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; } @@ -734,7 +749,7 @@ sub getNewsItem { 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]; diff --git a/src/Modules/UserDCC.pl b/src/Modules/UserDCC.pl index 04cd8c1..06fe68c 100644 --- a/src/Modules/UserDCC.pl +++ b/src/Modules/UserDCC.pl @@ -1084,6 +1084,7 @@ sub userDCC { &writeUserFile(); &writeChanFile(); + &News::writeNews() if (&ChanConfList("news")); return; } diff --git a/src/UserExtra.pl b/src/UserExtra.pl index be48b36..1a62202 100644 --- a/src/UserExtra.pl +++ b/src/UserExtra.pl @@ -33,7 +33,8 @@ use vars qw(%channels %chanstats %cmdstats); 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."); diff --git a/src/db_mysql.pl b/src/db_mysql.pl index a88051c..754bcda 100644 --- a/src/db_mysql.pl +++ b/src/db_mysql.pl @@ -186,9 +186,9 @@ sub dbInsert { } ##### -# 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) { @@ -198,7 +198,8 @@ sub dbReplace { } &dbRaw("Replace($table)", "REPLACE INTO $table (".join(',',@keys). - ") VALUES (".join(',',@vals).")" + ") VALUES (".join(',',@vals).") WHERE $primkey=". + &dbQuote($primval) ); return 1; @@ -242,7 +243,7 @@ sub dbRaw { &SQLDebug($query); if (!$sth->execute) { &ERROR("Raw($prefix): => '$query'"); - &ERROR("Raw($prefix): $DBI::errstr"); +# &ERROR("Raw($prefix): $DBI::errstr"); $sth->finish; return 0; }