X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=blootbot%2Fsrc%2FCommandStubs.pl;h=0bb6eb90978403658ab95597ec614c10a4c1044f;hb=febf9430a18b923212121cea07dbb568232bb955;hp=47dc9d3325d5b25cdcb2deac32f14699e259065f;hpb=e79c0245555b975c385c51f1290060aba2ec05d4;p=infobot.git diff --git a/blootbot/src/CommandStubs.pl b/blootbot/src/CommandStubs.pl index 47dc9d3..0bb6eb9 100644 --- a/blootbot/src/CommandStubs.pl +++ b/blootbot/src/CommandStubs.pl @@ -3,23 +3,23 @@ # WARN: this file does not reload on HUP. # -# use strict; # TODO +# TODO: +# use strict; use vars qw($who $msgType $conn $chan $message $ident $talkchannel - $bot_version $babel_lang_regex $bot_data_dir); + $bot_version $bot_data_dir); use vars qw(@vernick @vernicktodo); use vars qw(%channels %cache %mask %userstats %myModules %cmdstats %hooks_extra %lang %ver); # FIX THE FOLLOWING: use vars qw($total $x $type $i $good); -$babel_lang_regex = "fr|sp|es|po|pt|it|ge|de|gr|en|zh|ja|jp|ko|kr|ru"; +$w3search_regex = "google"; ### COMMAND HOOK IMPLEMENTATION. # addCmdHook("SECTION", 'TEXT_HOOK', -# (CODEREF => 'Blah', +# (CODEREF => 'Blah', # Forker => 1, -# CheckModule => 1, # ??? # Module => 'blah.pl' # preload module. # Identifier => 'config_label', # change to Config? # Help => 'help_label', @@ -43,7 +43,8 @@ sub addCmdHook { # RUN IF ADDRESSED. sub parseCmdHook { my ($hashname, $line) = @_; - $line =~ /^(\S+)( (.*))?$/; + $line =~ s/^\s+|\s+$//g; # again. + $line =~ /^(\S+)(\s+(.*))?$/; my $cmd = $1; # command name is whitespaceless. my $flatarg = $3; my @args = split(/\s+/, $flatarg || ''); @@ -72,7 +73,7 @@ sub parseCmdHook { next; } - &status("hooks($hashname): $cmd matched '$ident'"); + &status("hooks($hashname): $cmd matched '$ident' '$flatarg'"); my %hash = %{ ${"hooks_$hashname"}{$ident} }; if (!scalar keys %hash) { @@ -161,80 +162,83 @@ sub parseCmdHook { ### START ADDING HOOKS. ### &addCmdHook("extra", 'd?bugs', ('CODEREF' => 'DBugs::Parse', - 'Forker' => 1, 'Identifier' => 'debianExtra', + 'Forker' => 1, 'Identifier' => 'DebianExtra', 'Cmdstats' => 'Debian Bugs') ); &addCmdHook("extra", 'dauthor', ('CODEREF' => 'Debian::searchAuthor', - 'Forker' => 1, 'Identifier' => 'debian', + 'Forker' => 1, 'Identifier' => 'Debian', 'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) ); &addCmdHook("extra", '(d|search)desc', ('CODEREF' => 'Debian::searchDescFE', - 'Forker' => 1, 'Identifier' => 'debian', + 'Forker' => 1, 'Identifier' => 'Debian', 'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) ); &addCmdHook("extra", 'dnew', ('CODEREF' => 'DebianNew', - 'Identifier' => 'debian' ) ); + 'Identifier' => 'Debian' ) ); &addCmdHook("extra", 'dincoming', ('CODEREF' => 'Debian::generateIncoming', - 'Forker' => 1, 'Identifier' => 'debian' ) ); + 'Forker' => 1, 'Identifier' => 'Debian' ) ); &addCmdHook("extra", 'dstats', ('CODEREF' => 'Debian::infoStats', - 'Forker' => 1, 'Identifier' => 'debian', + 'Forker' => 1, 'Identifier' => 'Debian', 'Cmdstats' => 'Debian Statistics' ) ); &addCmdHook("extra", 'd?contents', ('CODEREF' => 'Debian::searchContents', - 'Forker' => 1, 'Identifier' => 'debian', + 'Forker' => 1, 'Identifier' => 'Debian', 'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) ); &addCmdHook("extra", 'd?find', ('CODEREF' => 'Debian::DebianFind', - 'Forker' => 1, 'Identifier' => 'debian', + 'Forker' => 1, 'Identifier' => 'Debian', 'Cmdstats' => 'Debian Search', 'Help' => "find" ) ); &addCmdHook("extra", 'insult', ('CODEREF' => 'Insult::Insult', 'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) ); &addCmdHook("extra", 'kernel', ('CODEREF' => 'Kernel::Kernel', - 'Forker' => 1, 'Identifier' => 'kernel', + 'Forker' => 1, 'Identifier' => 'Kernel', 'Cmdstats' => 'Kernel', 'NoArgs' => 1) ); &addCmdHook("extra", 'listauth', ('CODEREF' => 'CmdListAuth', - 'Identifier' => 'search', Module => 'factoids', + 'Identifier' => 'search', Module => 'Factoids', 'Help' => 'listauth') ); &addCmdHook("extra", 'quote', ('CODEREF' => 'Quote::Quote', - 'Forker' => 1, 'Identifier' => 'quote', + 'Forker' => 1, 'Identifier' => 'Quote', 'Help' => 'quote', 'Cmdstats' => 'Quote') ); -&addCmdHook("extra", 'countdown', ('CODEREF' => 'Countdown', +&addCmdHook("extra", 'countdown', ('CODEREF' => 'countdown', 'Module' => 'countdown', 'Identifier' => 'countdown', - 'Cmdstats' => 'Countdown') ); + 'Cmdstats' => 'countdown') ); &addCmdHook("extra", 'lart', ('CODEREF' => 'lart', 'Identifier' => 'lart', 'Help' => 'lart') ); &addCmdHook("extra", 'convert', ('CODEREF' => 'convert', 'Forker' => 1, 'Identifier' => 'units', 'Help' => 'convert') ); &addCmdHook("extra", '(cookie|random)', ('CODEREF' => 'cookie', - 'Forker' => 1, 'Identifier' => 'factoids') ); + 'Forker' => 1, 'Identifier' => 'Factoids') ); &addCmdHook("extra", 'u(ser)?info', ('CODEREF' => 'userinfo', 'Identifier' => 'userinfo', 'Help' => 'userinfo', 'Module' => 'userinfo') ); -&addCmdHook("extra", 'rootWarn', ('CODEREF' => 'CmdrootWarn', - 'Identifier' => 'rootWarn', 'Module' => 'rootwarn') ); +&addCmdHook("extra", 'RootWarn', ('CODEREF' => 'CmdrootWarn', + 'Identifier' => 'RootWarn', 'Module' => 'RootWarn') ); &addCmdHook("extra", 'seen', ('CODEREF' => 'seen', 'Identifier' => 'seen') ); -&addCmdHook("extra", 'dict', ('CODEREF' => 'Dict::Dict', - 'Identifier' => 'dict', 'Help' => 'dict', +&addCmdHook("extra", 'Dict', ('CODEREF' => 'Dict::Dict', + 'Identifier' => 'Dict', 'Help' => 'dict', 'Forker' => 1, 'Cmdstats' => 'Dict') ); &addCmdHook("extra", 'slashdot', ('CODEREF' => 'Slashdot::Slashdot', 'Identifier' => 'slashdot', 'Forker' => 1, 'Cmdstats' => 'Slashdot') ); -&addCmdHook("extra", 'plug', ('CODEREF' => 'Plug::Plug', - 'Identifier' => 'plug', 'Forker' => 1, +&addCmdHook("extra", 'Plug', ('CODEREF' => 'Plug::Plug', + 'Identifier' => 'Plug', 'Forker' => 1, 'Cmdstats' => 'Plug') ); &addCmdHook("extra", 'uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime', 'Cmdstats' => 'Uptime') ); &addCmdHook("extra", 'nullski', ('CODEREF' => 'nullski', ) ); -&addCmdHook("extra", '(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat', - 'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat', - 'Forker' => 1, 'Help' => 'freshmeat') ); &addCmdHook("extra", 'verstats', ('CODEREF' => 'do_verstats' ) ); &addCmdHook("extra", 'weather', ('CODEREF' => 'Weather::Weather', 'Identifier' => 'weather', 'Help' => 'weather', 'Cmdstats' => 'weather', 'Forker' => 1) ); +&addCmdHook("extra", 'metar', ('CODEREF' => 'Weather::Metar', + 'Identifier' => 'weather', 'Help' => 'weather', + 'Cmdstats' => 'weather', 'Forker' => 1) ); &addCmdHook("extra", 'bzflist', ('CODEREF' => 'BZFlag::list', - 'Identifier' => 'bzflag', 'Cmdstats' => 'BZFlag', + 'Identifier' => 'BZFlag', 'Cmdstats' => 'BZFlag', + 'Forker' => 1) ); +&addCmdHook("extra", 'bzflist17', ('CODEREF' => 'BZFlag::list17', + 'Identifier' => 'BZFlag', 'Cmdstats' => 'BZFlag', 'Forker' => 1) ); &addCmdHook("extra", 'bzfquery', ('CODEREF' => 'BZFlag::query', - 'Identifier' => 'bzflag', 'Cmdstats' => 'BZFlag', - 'Forker' => 1, 'Help' => 'bzflag') ); + 'Identifier' => 'BZFlag', 'Cmdstats' => 'BZFlag', + 'Forker' => 1) ); &addCmdHook("extra", 'zfi', ('CODEREF' => 'zfi::query', 'Identifier' => 'zfi', 'Cmdstats' => 'zfi', 'Forker' => 1) ); @@ -245,11 +249,25 @@ sub parseCmdHook { 'Identifier' => 'zsi', 'Cmdstats' => 'zsi', 'Forker' => 1) ); &addCmdHook("extra", '(ex)?change', ('CODEREF' => 'Exchange::query', - 'Identifier' => 'exchange', 'Cmdstats' => 'exchange', + 'Identifier' => 'Exchange', 'Cmdstats' => 'Exchange', 'Forker' => 1) ); -&addCmdHook("extra", 'botmail', ('CODEREF' => 'botmail::parse', +&addCmdHook("extra", '(botmail|message)', ('CODEREF' => 'botmail::parse', 'Identifier' => 'botmail', 'Cmdstats' => 'botmail') ); - +&addCmdHook("extra", 'HTTPDtype', ('CODEREF' => 'HTTPDtype::HTTPDtype', + 'Identifier' => 'HTTPDtype', 'Cmdstats' => 'HTTPDtype', + 'Forker' => 1) ); +&addCmdHook("extra", 'Rss', ('CODEREF' => 'Rss::Rss', + 'Identifier' => 'Rss', 'Cmdstats' => 'Rss', + 'Forker' => 1, 'Help' => 'rss') ); +&addCmdHook("extra", 'wiki(pedia)?', ('CODEREF' => 'wikipedia::wikipedia', + 'Identifier' => 'wikipedia', 'Cmdstats' => 'wikipedia', + 'Forker' => 1, 'Help' => 'wikipedia') ); +&addCmdHook("extra", 'page', ('CODEREF' => 'pager::page', + 'Identifier' => 'pager', 'Cmdstats' => 'pager', + 'Forker' => 1, 'Help' => 'page') ); +&addCmdHook("extra", 'babel(fish)?|x|xlate|translate', ('CODEREF' => 'babelfish::babelfish', + 'Identifier' => 'babelfish', 'Cmdstats' => 'babelfish', + 'Forker' => 1, 'Help' => 'babelfish') ); ### ### END OF ADDING HOOKS. ### @@ -261,26 +279,7 @@ sub Modules { return; } - # babel bot: Jonathan Feinberg++ - if ($message =~ m{ - ^\s* - (?:babel(?:fish)?|x|xlate|translate) - \s+ - ($babel_lang_regex)\w* # from language? - \s+ - ($babel_lang_regex)\w* # to language? - \s* - (.+) # The phrase to be translated - }xoi) { - return unless (&hasParam("babelfish")); - - &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } ); - - $cmdstats{'BabelFish'}++; - return; - } - - my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?'; + my $debiancmd = 'conflicts?|depends?|desc|file|(?:d)?info|provides?'; $debiancmd .= '|recommends?|suggests?|maint|maintainer'; if ($message =~ /^($debiancmd)(\s+(.*))?$/i) { @@ -297,7 +296,7 @@ sub Modules { } # google searching. Simon++ - if ($message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)["']?\s*\?*$/i) { + if ($message =~ /^(?:search\s+)?($w3search_regex)\s+(?:for\s+)?['"]?(.*?)["']?\s*\?*$/i) { return unless (&hasParam("wwwsearch")); &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } ); @@ -310,105 +309,8 @@ sub Modules { my $itc; $itc = &getChanConf("ircTextCounters"); $itc = &findChanConf("ircTextCounters") unless ($itc); - if ($itc) { - $itc =~ s/([^\w\s])/\\$1/g; - my $z = join '|', split ' ', $itc; - - if ($msgType eq "privmsg" and $message =~ / ($mask{chan})$/) { - &DEBUG("ircTC: privmsg detected; chan = $1"); - $chan = $1; - } - - if ($message =~ /^_stats(\s+(\S+))$/i) { - &textstats_main($2); - return; - } - - if ($message =~ /^($z)stats(\s+(\S+))?$/i) { - my $type = $1; - my $arg = $3; - - # even more uglier with channel/time arguments. - my $c = $chan; -# my $c = $chan || "PRIVATE"; - my $where = "type=".&sqlQuote($type); - $where .= " AND channel=".&sqlQuote($c) if (defined $c); - &DEBUG("not using chan arg") if (!defined $c); - my $sum = (&sqlRawReturn("SELECT SUM(counter) FROM stats" - ." WHERE ".$where ))[0]; - - if (!defined $arg or $arg =~ /^\s*$/) { - # this is way fucking ugly. - - my %hash = &sqlSelectColHash("stats", "nick,counter", - { }, - $where." ORDER BY counter DESC LIMIT 3", 1 - ); - my $i; - my @top; - - # unfortunately we have to sort it again! - # todo: make dbGetCol return hash and array? too much effort. - my $tp = 0; - foreach $i (sort { $b <=> $a } keys %hash) { - foreach (keys %{ $hash{$i} }) { - my $p = sprintf("%.01f", 100*$i/$sum); - $tp += $p; - push(@top, "\002$_\002 -- $i ($p%)"); - } - } - my $topstr = ""; - &DEBUG("*stats: tp => $tp"); - if (scalar @top) { - $topstr = ". Top ".scalar(@top).": ".join(', ', @top); - } - - if (defined $sum) { - &pSReply("total count of \037$type\037 on \002$c\002: $sum$topstr"); - } else { - &pSReply("zero counter for \037$type\037."); - } - } else { - my $x = (&sqlRawReturn("SELECT SUM(counter) FROM stats". - " WHERE $where AND nick=".&sqlQuote($arg) ))[0]; - - if (!defined $x) { # !defined. - &pSReply("$arg has not said $type yet."); - return; - } - - # defined. - my @array = &sqlSelect("stats", "nick", undef, - $where." ORDER BY counter", 1 - ); - my $good = 0; - my $i = 0; - for($i=0; $i 0) { my $i; $i = $userstats{lc $seen[0]}{'Count'}; $reply .= ". Has said a total of \002$i\002 messages" if (defined $i); @@ -752,6 +642,7 @@ sub lart { my ($target) = &fixString($_[0]); my $extra = 0; my $chan = $talkchannel; + my ($for); if ($msgType eq 'private') { if ($target =~ /^($mask{chan})\s+(.*)$/) { @@ -764,6 +655,10 @@ sub lart { return; } } + if ($target =~ /^(.*)(\s+for\s+.*)$/) { + $target = $1; + $for = $2; + } my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.lart"); if (defined $line) { @@ -772,6 +667,7 @@ sub lart { } else { $line =~ s/WHO/$target/g; } + $line .= $for if ($for); $line .= ", courtesy of $who" if ($extra); &action($chan, $line); @@ -917,6 +813,111 @@ sub verstats_flush { $conn->schedule(3, \&verstats_flush() ); } +sub do_text_counters { + my ($itc) = @_; + $itc =~ s/([^\w\s])/\\$1/g; + my $z = join '|', split ' ', $itc; + + if ($msgType eq "privmsg" and $message =~ / ($mask{chan})$/) { + &DEBUG("ircTC: privmsg detected; chan = $1"); + $chan = $1; + } + + if ($message =~ /^_stats(\s+(\S+))$/i) { + &textstats_main($2); + return 1; + } + + my ($type,$arg); + if ($message =~ /^($z)stats(\s+(\S+))?$/i) { + $type = $1; + $arg = $3; + } else { + return 0; + } + + # even more uglier with channel/time arguments. + my $c = $chan; +# my $c = $chan || "PRIVATE"; + my $where = "type=".&sqlQuote($type); + if (defined $c) { + &DEBUG("c => $c"); + $where .= " AND channel=".&sqlQuote($c) if (defined $c); + } else { + &DEBUG("not using chan arg"); + } + + my $sum = (&sqlRawReturn("SELECT SUM(counter) FROM stats" + ." WHERE ".$where ))[0]; + + if (!defined $arg or $arg =~ /^\s*$/) { + # this is way fucking ugly. + + # TODO: convert $where to hash + my %hash = &sqlSelectColHash("stats", "nick,counter", + { }, + $where." ORDER BY counter DESC LIMIT 3", 1 + ); + my $i; + my @top; + + # unfortunately we have to sort it again! + my $tp = 0; + foreach $i (sort { $b <=> $a } keys %hash) { + foreach (keys %{ $hash{$i} }) { + my $p = sprintf("%.01f", 100*$i/$sum); + $tp += $p; + push(@top, "\002$_\002 -- $i ($p%)"); + } + } + my $topstr = ""; + if (scalar @top) { + $topstr = ". Top ".scalar(@top).": ".join(', ', @top); + } + + if (defined $sum) { + &pSReply("total count of \037$type\037 on \002$c\002: $sum$topstr"); + } else { + &pSReply("zero counter for \037$type\037."); + } + } else { + # TODO: convert $where to hash and use a sqlSelect + my $x = (&sqlRawReturn("SELECT SUM(counter) FROM stats". + " WHERE $where AND nick=".&sqlQuote($arg) ))[0]; + + if (!defined $x) { # !defined. + &pSReply("$arg has not said $type yet."); + return 1; + } + + # defined. + # TODO: convert $where to hash + my @array = &sqlSelect("stats", "nick", undef, + $where." ORDER BY counter", 1 + ); + my $good = 0; + my $i = 0; + for ($i=0; $i $a } keys %hash) { foreach (keys %{ $hash{$i} }) { @@ -952,7 +952,6 @@ sub textstats_main { } my $topstr = ""; - &DEBUG("*stats: tp => $tp"); if (scalar @top) { $topstr = ". Top ".scalar(@top).": ".join(', ', @top); } @@ -962,54 +961,62 @@ sub textstats_main { } else { &pSReply("zero counter for \037$type\037."); } - } else { - my %hash = &sqlSelectColHash("stats", "type,counter", - $where_href, " AND nick=".&sqlQuote($arg) - ); - # this is totally fucked... needs to be fixed... and cleaned up. - my $total; - my $good; - my $ii; - my $x; - foreach (keys %hash) { - &DEBUG("_stats: hash{$_} => $hash{$_}"); - # ranking. - my @array = &sqlSelect("stats", "nick", undef, - $where." ORDER BY counter", 1); - $good = 0; - $ii = 0; - for(my $i=0; $i $i, good => $good, total => $total"); - $x .= " ".$total."blah blah"; + # TODO: add nick to where_href + my %hash = &sqlSelectColHash("stats", "type,counter", + $where_href, " AND nick=".&sqlQuote($arg) + ); + # this is totally fucked... needs to be fixed... and cleaned up. + my $total; + my $good; + my $ii; + my $x; + + foreach (keys %hash) { + &DEBUG("_stats: hash{$_} => $hash{$_}"); + # ranking. + # TODO: convert $where to hash + my @array = &sqlSelect("stats", "nick", undef, + $where." ORDER BY counter", 1); + $good = 0; + $ii = 0; + for(my $i=0; $i $i, good => $good, total => $total"); + $x .= " ".$total."blah blah"; + } - if (!defined $x) { # !defined. - &pSReply("$arg has not said $type yet."); - return; - } +# return; - my $xtra = ""; - if ($total and $good) { - my $pct = sprintf("%.01f", 100*(1+$total-$ii)/$total); - $xtra = ", ranked $ii\002/\002$total (percentile: \002$pct\002 %)"; - } + if (!defined $x) { # !defined. + &pSReply("$arg has not said $type yet."); + return; + } - my $pct1 = sprintf("%.01f", 100*$x/$sum); - &pSReply("\002$arg\002 has said \037$type\037 \002$x\002 times (\002$pct1\002 %)$xtra"); + my $xtra = ""; + if ($total and $good) { + my $pct = sprintf("%.01f", 100*(1+$total-$ii)/$total); + $xtra = ", ranked $ii\002/\002$total (percentile: \002$pct\002 %)"; } + + my $pct1 = sprintf("%.01f", 100*$x/$sum); + &pSReply("\002$arg\002 has said \037$type\037 \002$x\002 times (\002$pct1\002 %)$xtra"); } -sub nullski { my ($arg) = @_; return unless (defined $arg); - foreach (`$arg`) { &msg($who,$_); } } +sub nullski { + my ($arg) = @_; + return unless (defined $arg); + # big security hole + #foreach (`$arg`) { &msg($who,$_); } +} 1;