X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FCommandStubs.pl;h=cc0a3fb926a759a0eaaeceff275cf1f303beeb62;hb=5b661567bd6bdb15cc1e48e102bda3a26d03bd65;hp=9c68e2cf5d8005ba08bcdacf26c9e6184e24e010;hpb=5ba82e7b401520f6f311a2c87ad0554648b5356c;p=infobot.git diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index 9c68e2c..cc0a3fb 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -3,9 +3,18 @@ # WARN: this file does not reload on HUP. # -#use strict; +# use strict; # TODO + +use vars qw($who $msgType $conn $chan $message $ident $talkchannel + $bot_version $babel_lang_regex $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', @@ -120,7 +129,7 @@ sub parseCmdHook { # check if CODEREF exists. if (!defined &{ $hash{'CODEREF'} }) { - &WARN("coderef $hash{'CODEREF'} don't exist."); + &WARN("coderef $hash{'CODEREF'} does not exist."); if (defined $who) { &msg($who, "coderef does not exist for $ident."); } @@ -208,16 +217,16 @@ sub parseCmdHook { &addCmdHook("extra", 'slashdot', ('CODEREF' => 'Slashdot::Slashdot', 'Identifier' => 'slashdot', 'Forker' => 1, 'Cmdstats' => 'Slashdot') ); +&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') ); + 'Cmdstats' => 'weather', 'Forker' => 1) ); &addCmdHook("extra", 'bzflist', ('CODEREF' => 'BZFlag::list', 'Identifier' => 'bzflag', 'Cmdstats' => 'BZFlag', 'Forker' => 1) ); @@ -227,9 +236,17 @@ sub parseCmdHook { &addCmdHook("extra", 'zfi', ('CODEREF' => 'zfi::query', 'Identifier' => 'zfi', 'Cmdstats' => 'zfi', 'Forker' => 1) ); +&addCmdHook("extra", '(zippy|yow)', ('CODEREF' => 'zippy::get', + 'Identifier' => 'zippy', 'Cmdstats' => 'zippy', + 'Forker' => 1) ); &addCmdHook("extra", 'zsi', ('CODEREF' => 'zsi::query', 'Identifier' => 'zsi', 'Cmdstats' => 'zsi', 'Forker' => 1) ); +&addCmdHook("extra", '(ex)?change', ('CODEREF' => 'Exchange::query', + 'Identifier' => 'exchange', 'Cmdstats' => 'exchange', + 'Forker' => 1) ); +&addCmdHook("extra", '(botmail|message)', ('CODEREF' => 'botmail::parse', + 'Identifier' => 'botmail', 'Cmdstats' => 'botmail') ); ### ### END OF ADDING HOOKS. @@ -278,7 +295,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); } ); @@ -312,22 +329,24 @@ sub Modules { # even more uglier with channel/time arguments. my $c = $chan; # my $c = $chan || "PRIVATE"; - my $where = "type=".&dbQuote($type); - $where .= " AND channel=".&dbQuote($c) if (defined $c); + my $where = "type=".&sqlQuote($type); + $where .= " AND channel=".&sqlQuote($c) if (defined $c); &DEBUG("not using chan arg") if (!defined $c); - my $sum = (&dbRawReturn("SELECT SUM(counter) FROM stats" + my $sum = (&sqlRawReturn("SELECT SUM(counter) FROM stats" ." WHERE ".$where ))[0]; if (!defined $arg or $arg =~ /^\s*$/) { # this is way fucking ugly. - my %hash = &dbGetCol("stats", "nick,counter", - $where." ORDER BY counter DESC LIMIT 3", 1); + # 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! - # todo: make dbGetCol return hash and array? too much effort. my $tp = 0; foreach $i (sort { $b <=> $a } keys %hash) { foreach (keys %{ $hash{$i} }) { @@ -348,8 +367,9 @@ sub Modules { &pSReply("zero counter for \037$type\037."); } } else { - my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats". - " WHERE $where AND nick=".&dbQuote($arg) ))[0]; + # 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."); @@ -357,8 +377,10 @@ sub Modules { } # defined. - my @array = &dbGet("stats", "nick", - $where." ORDER BY counter", 1); + # 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 $person } ); } if (scalar @seen < 2) { @@ -692,8 +695,8 @@ sub cookie { ### TODO: convert this to a Forker function! if ($arg) { my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg); - $key = &getRandom(@list); - $val = &getFactInfo("factoids", $key, "factoid_value"); + $key = &getRandom(@list); + $value = &getFactInfo($key, "factoid_value"); } else { ($key,$value) = &randKey("factoids","factoid_key,factoid_value"); } @@ -822,7 +825,7 @@ sub do_verstats { return; } - &msg($who, "Sending CTCP VERSION to #$chan..."); + &msg($who, "Sending CTCP VERSION to $chan; results in 60s."); $conn->ctcp("VERSION", $chan); $cache{verstats}{chan} = $chan; $cache{verstats}{who} = $who; @@ -876,6 +879,8 @@ sub do_verstats { } } + # hack. this is one major downside to scheduling. + $chan = $c; &pSReply( &formListReply(0, "IRC Client versions for $c ", @list) ); # clean up not-needed data structures. @@ -905,22 +910,24 @@ sub textstats_main { # even more uglier with channel/time arguments. my $c = $chan; # my $c = $chan || "PRIVATE"; - my $where = "channel=".&dbQuote($c) if (defined $c); &DEBUG("not using chan arg") if (!defined $c); - my $sum = (&dbRawReturn("SELECT SUM(counter) FROM stats" - ." WHERE ".$where ))[0]; + + # example of converting from RawReturn to sqlSelect. + my $where_href = (defined $c) ? { channel => $c } : ""; + my $sum = &sqlSelect("stats", "SUM(counter)", $where_href); if (!defined $arg or $arg =~ /^\s*$/) { # this is way fucking ugly. &DEBUG("_stats: !arg"); - my %hash = &dbGetCol("stats", "nick,counter", - $where." ORDER BY counter DESC LIMIT 3", 1); + my %hash = &sqlSelectColHash("stats", "nick,counter", + $where_href, + " 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} }) { @@ -942,25 +949,34 @@ sub textstats_main { &pSReply("zero counter for \037$type\037."); } } else { - my %hash = &dbGetCol("stats", "type,counter", - "$where AND nick=".&dbQuote($arg) ); + # 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. - my @array = &dbGet("stats", "nick", + # 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 $i, good => $good, total => $total"); + $x .= " ".$total."blah blah"; } return; @@ -972,8 +988,8 @@ sub textstats_main { my $xtra = ""; if ($total and $good) { - my $pct = sprintf("%.01f", 100*(1+$total-$i)/$total); - $xtra = ", ranked $i\002/\002$total (percentile: \002$pct\002 %)"; + 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);