X-Git-Url: https://git.donarmstrong.com/?p=infobot.git;a=blobdiff_plain;f=src%2FCommandStubs.pl;h=65dc132edcfd77e5913c1ae9eb8e81318aac09e2;hp=2fe133493ae509735d0f81c1f32dd704ceabb2a8;hb=HEAD;hpb=40f6dad8bfd5a8a707a69cb31ba62cc6d26139c1 diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index 2fe1334..65dc132 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -49,7 +49,7 @@ sub parseCmdHook { &shmFlush(); - if ( !defined %cmdhooks ) { + if ( !%cmdhooks ) { &WARN('%cmdhooks does not exist.'); return 0; } @@ -182,17 +182,16 @@ sub Modules { return; } - # google searching. Simon++ - my $w3search_regex = 'google'; + # google searching -- thanks Brett Cave if ( $message =~ - /^(?:search\s+)?($w3search_regex)\s+(?:for\s+)?['"]?(.*?)["']?\s*\?*$/i + /^(\s+)?google\s+['"]?(.*?)["']?\s*\?*$/i ) { - return unless ( &IsChanConfOrWarn('W3Search') ); + return unless ( &IsChanConfOrWarn('Google') ); - &Forker( 'W3Search', sub { &W3Search::W3Search( $1, $2 ); } ); + &Forker( 'Google', sub { &Google::GoogleSearch( $2 ); } ); - $cmdstats{'W3Search'}++; + $cmdstats{'Google'}++; return; } @@ -315,7 +314,7 @@ sub uptime { my $count = 1; &msg( $who, "- Uptime for $ident -" ); &msg( $who, - "Now: " . &Time2String( &uptimeNow() ) . " running $bot_version" ); + 'Now: ' . &Time2String( &uptimeNow() ) . " running $bot_version" ); foreach ( &uptimeGetInfo() ) { /^(\d+)\.\d+ (.*)/; @@ -591,8 +590,14 @@ sub do_verstats { return; } - &msg( $who, "Sending CTCP VERSION to $chan; results in 60s." ); - $conn->ctcp( 'VERSION', $chan ); + &msg( $who, "Sending CTCP VERSION to $chan; results in 60s." ); + &msg( $chan, "WARNING: $who has forced me to CTCP VERSION the channel!" ); + + # Workaround for bug in Net::Irc, provided by quin@freenode. Details at: + # http://rt.cpan.org/Public/Bug/Display.html?id=11421 + # $conn->ctcp( 'VERSION', $chan ); + $conn->sl("PRIVMSG $chan :\001VERSION\001"); + $cache{verstats}{chan} = $chan; $cache{verstats}{who} = $who; $cache{verstats}{msgType} = $msgType; @@ -618,7 +623,6 @@ sub do_verstats { my $vtotal = 0; my $c = lc $cache{verstats}{chan}; my $total = keys %{ $channels{$c}{''} }; - $chan = $c; $who = $cache{verstats}{who}; $msgType = $cache{verstats}{msgType}; delete $cache{verstats}; # sufficient? @@ -629,13 +633,13 @@ sub do_verstats { my %sorted; my $unknown = $total - $vtotal; - my $perc = sprintf( "%.1f", $unknown * 100 / $total ); + my $perc = sprintf( '%.1f', $unknown * 100 / $total ); $perc =~ s/.0$//; $sorted{$perc}{'unknown/cloak'} = "$unknown ($perc%)" if ($unknown); foreach ( keys %ver ) { my $count = scalar keys %{ $ver{$_} }; - $perc = sprintf( "%.01f", $count * 100 / $total ); + $perc = sprintf( '%.01f', $count * 100 / $total ); $perc =~ s/.0$//; # lame compression. $sorted{$perc}{$_} = "$count ($perc%)"; @@ -651,8 +655,7 @@ sub do_verstats { } # hack. this is one major downside to scheduling. - $chan = $c; - &performStrictReply( + &msg($c, &formListReply( 0, "IRC Client versions for $c ", @list ) ); # clean up not-needed data structures. @@ -669,12 +672,14 @@ sub verstats_flush { last unless ( scalar @vernicktodo ); my $n = shift(@vernicktodo); - $conn->ctcp( 'VERSION', $n ); + #$conn->ctcp( 'VERSION', $n ); + # See do_verstats $conn->sl for explantaion + $conn->sl("PRIVMSG $n :\001VERSION\001"); } return unless ( scalar @vernicktodo ); - $conn->schedule( 3, \&verstats_flush() ); + $conn->schedule( 3, \&verstats_flush ); } sub do_text_counters { @@ -718,7 +723,7 @@ sub do_text_counters { my $tp = 0; foreach $i ( sort { $b <=> $a } keys %hash ) { foreach ( keys %{ $hash{$i} } ) { - my $p = sprintf( "%.01f", 100 * $i / $sum ); + my $p = sprintf( '%.01f', 100 * $i / $sum ); $tp += $p; push( @top, "\002$_\002 -- $i ($p%)" ); } @@ -762,12 +767,12 @@ sub do_text_counters { my $xtra; if ( $total and $rank ) { - my $pct = sprintf( "%.01f", 100 * ($rank) / $total ); + my $pct = sprintf( '%.01f', 100 * ($rank) / $total ); $xtra = ", ranked $rank\002/\002$total (percentile: \002$pct\002 %)"; } - my $pct1 = sprintf( "%.01f", 100 * $x / $sum ); + my $pct1 = sprintf( '%.01f', 100 * $x / $sum ); &performStrictReply( "\002$arg\002 has said \037$type\037 \002$x\002 times (\002$pct1\002 %)$xtra" ); @@ -776,24 +781,17 @@ sub do_text_counters { return 1; } -sub nullski { - my ($arg) = @_; - return unless ( defined $arg ); - - # big security hole - #foreach (`$arg`) { &msg($who,$_); } -} - %cmdhooks=(); ### ### START ADDING HOOKS. ### -&addCmdHook('(babel(fish)?|x|xlate|translate)', ('CODEREF' => 'babelfish::babelfish', 'Identifier' => 'babelfish', 'Cmdstats' => 'babelfish', 'Forker' => 1, 'Help' => 'babelfish', 'Module' => 'babelfish') ); +&addCmdHook('(x|xlate|translate)', ('CODEREF' => 'translate::translate', 'Identifier' => 'translate', 'Cmdstats' => 'translate', 'Forker' => 1, 'Help' => 'translate', 'Module' => 'translate') ); &addCmdHook('(botmail|message)', ('CODEREF' => 'botmail::parse', 'Identifier' => 'botmail', 'Cmdstats' => 'botmail') ); &addCmdHook('bzflist17', ('CODEREF' => 'BZFlag::list17', 'Identifier' => 'BZFlag', 'Cmdstats' => 'BZFlag', 'Forker' => 1, 'Module' => 'BZFlag') ); &addCmdHook('bzflist', ('CODEREF' => 'BZFlag::list', 'Identifier' => 'BZFlag', 'Cmdstats' => 'BZFlag', 'Forker' => 1, 'Module' => 'BZFlag') ); &addCmdHook('bzfquery', ('CODEREF' => 'BZFlag::query', 'Identifier' => 'BZFlag', 'Cmdstats' => 'BZFlag', 'Forker' => 1, 'Module' => 'BZFlag') ); &addCmdHook('chan(stats|info)', ('CODEREF' => 'chaninfo', ) ); +&addCmdHook('conn(stats|info)', ('CODEREF' => 'conninfo', ) ); &addCmdHook('cmd(stats|info)', ('CODEREF' => 'cmdstats', ) ); &addCmdHook('convert', ('CODEREF' => 'convert', 'Forker' => 1, 'Identifier' => 'Units', 'Help' => 'convert') ); &addCmdHook('(cookie|random)', ('CODEREF' => 'cookie', 'Forker' => 1, 'Identifier' => 'Factoids') ); @@ -827,7 +825,6 @@ sub nullski { &addCmdHook('metar', ('CODEREF' => 'Weather::Metar', 'Identifier' => 'Weather', 'Help' => 'weather', 'Cmdstats' => 'Weather', 'Forker' => 1) ); &addCmdHook('News', ('CODEREF' => 'News::Parse', Module => 'News', 'Cmdstats' => 'News', 'Identifier' => 'News' ) ); &addCmdHook('(?:nick|lame)ometer(?: for)?', ('CODEREF' => 'nickometer::query', 'Identifier' => 'nickometer', 'Cmdstats' => 'nickometer', 'Forker' => 1) ); -&addCmdHook('nullski', ('CODEREF' => 'nullski', ) ); &addCmdHook('OnJoin', ('CODEREF' => 'Cmdonjoin', 'Identifier' => 'OnJoin', 'Module' => 'OnJoin') ); &addCmdHook('page', ('CODEREF' => 'pager::page', 'Identifier' => 'pager', 'Cmdstats' => 'pager', 'Forker' => 1, 'Help' => 'page') ); &addCmdHook('piglatin', ('CODEREF' => 'piglatin::piglatin', 'Identifier' => 'piglatin', 'Cmdstats' => 'piglatin', 'Forker' => 1) ); @@ -843,9 +840,10 @@ sub nullski { &addCmdHook('slashdot', ('CODEREF' => 'Slashdot::Slashdot', 'Identifier' => 'slashdot', 'Forker' => 1, 'Cmdstats' => 'slashdot') ); &addCmdHook('tell|explain', ('CODEREF' => 'tell', Help => 'tell', Identifier => 'allowTelling', Cmdstats => 'Tell') ); &addCmdHook('uc', ('CODEREF' => 'case::upper', 'Identifier' => 'case', 'Cmdstats' => 'case', 'Forker' => 1, 'Module' => 'case') ); +&addCmdHook('upsidedown', ('CODEREF' => 'upsidedown::upsidedown', 'Identifier' => 'upsidedown', 'Cmdstats' => 'upsidedown', 'Forker' => 1, 'Module' => 'upsidedown') ); &addCmdHook('Uptime', ('CODEREF' => 'uptime', 'Identifier' => 'Uptime', 'Cmdstats' => 'Uptime') ); &addCmdHook('u(ser)?info', ('CODEREF' => 'userinfo', 'Identifier' => 'UserInfo', 'Help' => 'userinfo', 'Module' => 'UserInfo') ); -&addCmdHook('verstats', ('CODEREF' => 'do_verstats' ) ); +&addCmdHook('verstats', ('CODEREF' => 'do_verstats', 'Identifier' => 'verstats', 'Help' => 'verstats', 'Cmdstats' => 'verstats') ); &addCmdHook('Weather', ('CODEREF' => 'Weather::Weather', 'Identifier' => 'Weather', 'Help' => 'weather', 'Cmdstats' => 'Weather', 'Forker' => 1, 'Module' => 'Weather') ); &addCmdHook('wiki(pedia)?', ('CODEREF' => 'wikipedia::wikipedia', 'Identifier' => 'wikipedia', 'Cmdstats' => 'wikipedia', 'Forker' => 1, 'Help' => 'wikipedia', 'Module' => 'wikipedia') ); &addCmdHook('wtf', ('CODEREF' => 'wtf::query', 'Identifier' => 'wtf', 'Cmdstats' => 'wtf', 'Forker' => 1, 'Help' => 'wtf', 'Module' => 'wtf') );