#
# User Command Extension Stubs
+# WARN: this file does not reload on HUP.
#
-if (&IsParam("useStrict")) { use strict; }
+# use strict; # TODO
-$babel::lang_regex = ""; # lame fix.
+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);
-### PROPOSED COMMAND HOOK IMPLEMENTATION.
-# addCmdHook('TEXT_HOOK',
+$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',
# Forker => 1,
# CheckModule => 1, # ???
###
sub addCmdHook {
- my ($ident, %hash) = @_;
+ my ($hashname, $ident, %hash) = @_;
+
+ if (exists ${"hooks_$hashname"}{$ident}) {
+### &WARN("aCH: cmd hooks \%$hashname{$ident} already exists.");
+ return;
+ }
&VERB("aCH: added $ident",2); # use $hash{'Identifier'}?
- $cmdhooks{$ident} = \%hash;
+ ### hrm... prevent warnings?
+ ${"hooks_$hashname"}{$ident} = \%hash;
}
# RUN IF ADDRESSED.
sub parseCmdHook {
- my @args = split(' ', $message);
- my $cmd = shift(@args);
+ my ($hashname, $line) = @_;
+ $line =~ /^(\S+)( (.*))?$/;
+ my $cmd = $1; # command name is whitespaceless.
+ my $flatarg = $3;
+ my @args = split(/\s+/, $flatarg || '');
+ my $done = 0;
&shmFlush();
- foreach (keys %cmdhooks) {
+ if (!defined %{"hooks_$hashname"}) {
+ &WARN("cmd hooks \%$hashname does not exist.");
+ return 0;
+ }
+
+ if (!defined $cmd) {
+ &WARN("cstubs: cmd == NULL.");
+ return 0;
+ }
+
+ foreach (keys %{"hooks_$hashname"}) {
+ # rename to something else! like $id or $label?
my $ident = $_;
next unless ($cmd =~ /^$ident$/i);
- &DEBUG("pCH: $cmd matched $ident");
- my %hash = %{ $cmdhooks{$ident} };
+ if ($done) {
+ &WARN("pCH: Multiple hook match: $ident");
+ next;
+ }
+
+ &status("hooks($hashname): $cmd matched '$ident'");
+ my %hash = %{ ${"hooks_$hashname"}{$ident} };
+
+ if (!scalar keys %hash) {
+ &WARN("CmdHook: hash is NULL?");
+ return 1;
+ }
+
+ if ($hash{NoArgs} and $flatarg) {
+ &DEBUG("cmd $ident does not take args ('$flatarg'); skipping.");
+ next;
+ }
+
+ if (!exists $hash{CODEREF}) {
+ &ERROR("CODEREF undefined for $cmd or $ident.");
+ return 1;
+ }
### DEBUG.
foreach (keys %hash) {
- &DEBUG(" $cmd->$_ => '$hash{$_}'.");
+ &VERB(" $cmd->$_ => '$hash{$_}'.",2);
}
### HELP.
### IDENTIFIER.
if (exists $hash{'Identifier'}) {
- return $noreply unless (&hasParam($hash{'Identifier'}));
+ return 1 unless (&hasParam($hash{'Identifier'}));
+ }
+
+ ### USER FLAGS.
+ if (exists $hash{'UserFlag'}) {
+ return 1 unless (&hasFlag($hash{'UserFlag'}));
}
### FORKER,IDENTIFIER,CODEREF.
if (exists $hash{'Forker'}) {
- &Forker($hash{'Identifier'}, sub { \&{$hash{'CODEREF'}}(@args) } );
+ $hash{'Identifier'} .= "-" if ($hash{'Forker'} eq "NULL");
+
+ if (exists $hash{'ArrayArgs'}) {
+ &Forker($hash{'Identifier'}, sub { \&{ $hash{'CODEREF'} }(@args) } );
+ } else {
+ &Forker($hash{'Identifier'}, sub { \&{ $hash{'CODEREF'} }($flatarg) } );
+ }
+
} else {
if (exists $hash{'Module'}) {
&loadMyModule($myModules{ $hash{'Module'} });
}
- ### TODO: check if CODEREF exists.
+ # check if CODEREF exists.
+ if (!defined &{ $hash{'CODEREF'} }) {
+ &WARN("coderef $hash{'CODEREF'} does not exist.");
+ if (defined $who) {
+ &msg($who, "coderef does not exist for $ident.");
+ }
+
+ return 1;
+ }
-### ANY PROBLEMS WITH THIS? if so, add option to do either.
-### &{$hash{'CODEREF'}}(@args);
- &{$hash{'CODEREF'}}(join ' ', @args);
+ if (exists $hash{'ArrayArgs'}) {
+ &{ $hash{'CODEREF'} }(@args);
+ } else {
+ &{ $hash{'CODEREF'} }($flatarg);
+ }
}
### CMDSTATS.
if (exists $hash{'Cmdstats'}) {
- $cmdstats{$hash{'Cmdstats'}}++;
+ $cmdstats{ $hash{'Cmdstats'} }++;
}
- &DEBUG("pCH: ended.");
+ &VERB("hooks: End of command.",2);
- return 1;
+ $done = 1;
}
+ return 1 if ($done);
return 0;
}
-&addCmdHook('d?bugs', ('CODEREF' => 'debianBugs',
+###
+### START ADDING HOOKS.
+###
+&addCmdHook("extra", 'd?bugs', ('CODEREF' => 'DBugs::Parse',
'Forker' => 1, 'Identifier' => 'debianExtra',
'Cmdstats' => 'Debian Bugs') );
-&addCmdHook('dauthor', ('CODEREF' => 'Debian::searchAuthor',
+&addCmdHook("extra", 'dauthor', ('CODEREF' => 'Debian::searchAuthor',
'Forker' => 1, 'Identifier' => 'debian',
'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) );
-&addCmdHook('(d|search)desc', ('CODEREF' => 'Debian::searchDesc',
+&addCmdHook("extra", '(d|search)desc', ('CODEREF' => 'Debian::searchDescFE',
'Forker' => 1, 'Identifier' => 'debian',
'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) );
-&addCmdHook('dincoming', ('CODEREF' => 'Debian::generateIncoming',
+&addCmdHook("extra", 'dnew', ('CODEREF' => 'DebianNew',
+ 'Identifier' => 'debian' ) );
+&addCmdHook("extra", 'dincoming', ('CODEREF' => 'Debian::generateIncoming',
'Forker' => 1, 'Identifier' => 'debian' ) );
-&addCmdHook('dstats', ('CODEREF' => 'Debian::infoStats',
+&addCmdHook("extra", 'dstats', ('CODEREF' => 'Debian::infoStats',
'Forker' => 1, 'Identifier' => 'debian',
'Cmdstats' => 'Debian Statistics' ) );
-&addCmdHook('d?contents', ('CODEREF' => 'Debian::searchContents',
+&addCmdHook("extra", 'd?contents', ('CODEREF' => 'Debian::searchContents',
'Forker' => 1, 'Identifier' => 'debian',
'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) );
-&addCmdHook('d?find', ('CODEREF' => 'Debian::DebianFind',
+&addCmdHook("extra", 'd?find', ('CODEREF' => 'Debian::DebianFind',
'Forker' => 1, 'Identifier' => 'debian',
'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
-&addCmdHook('insult', ('CODEREF' => 'Insult::Insult',
+&addCmdHook("extra", 'insult', ('CODEREF' => 'Insult::Insult',
'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
-&addCmdHook('kernel', ('CODEREF' => 'Kernel::Kernel',
+&addCmdHook("extra", 'kernel', ('CODEREF' => 'Kernel::Kernel',
'Forker' => 1, 'Identifier' => 'kernel',
- 'Cmdstats' => 'Kernel') );
-&addCmdHook('listauth', ('CODEREF' => 'CmdListAuth',
+ 'Cmdstats' => 'Kernel', 'NoArgs' => 1) );
+&addCmdHook("extra", 'listauth', ('CODEREF' => 'CmdListAuth',
'Identifier' => 'search', Module => 'factoids',
'Help' => 'listauth') );
-&addCmdHook('quote', ('CODEREF' => 'Quote::Quote',
+&addCmdHook("extra", 'quote', ('CODEREF' => 'Quote::Quote',
'Forker' => 1, 'Identifier' => 'quote',
'Help' => 'quote', 'Cmdstats' => 'Quote') );
-&addCmdHook('countdown', ('CODEREF' => 'Countdown',
+&addCmdHook("extra", 'countdown', ('CODEREF' => 'Countdown',
'Module' => 'countdown', 'Identifier' => 'countdown',
'Cmdstats' => 'Countdown') );
-&addCmdHook('lart', ('CODEREF' => 'lart',
+&addCmdHook("extra", 'lart', ('CODEREF' => 'lart',
'Identifier' => 'lart', 'Help' => 'lart') );
-&addCmdHook('convert', ('CODEREF' => 'convert',
+&addCmdHook("extra", 'convert', ('CODEREF' => 'convert',
'Forker' => 1, 'Identifier' => 'units',
'Help' => 'convert') );
-&addCmdHook('(cookie|random)', ('CODEREF' => 'cookie',
+&addCmdHook("extra", '(cookie|random)', ('CODEREF' => 'cookie',
'Forker' => 1, 'Identifier' => 'factoids') );
-&addCmdHook('u(ser)?info', ('CODEREF' => 'userinfo',
+&addCmdHook("extra", 'u(ser)?info', ('CODEREF' => 'userinfo',
'Identifier' => 'userinfo', 'Help' => 'userinfo',
'Module' => 'userinfo') );
-&addCmdHook('rootWarn', ('CODEREF' => 'CmdrootWarn',
+&addCmdHook("extra", 'rootWarn', ('CODEREF' => 'CmdrootWarn',
'Identifier' => 'rootWarn', 'Module' => 'rootwarn') );
-&addCmdHook('seen', ('CODEREF' => 'seen', 'Identifier' => 'seen') );
-&addCmdHook('dict', ('CODEREF' => 'Dict::Dict',
+&addCmdHook("extra", 'seen', ('CODEREF' => 'seen', 'Identifier' =>
+ 'seen') );
+&addCmdHook("extra", 'dict', ('CODEREF' => 'Dict::Dict',
'Identifier' => 'dict', 'Help' => 'dict',
'Forker' => 1, 'Cmdstats' => 'Dict') );
-&addCmdHook('slashdot', ('CODEREF' => 'Slashdot::Slashdot',
+&addCmdHook("extra", 'slashdot', ('CODEREF' => 'Slashdot::Slashdot',
'Identifier' => 'slashdot', 'Forker' => 1,
'Cmdstats' => 'Slashdot') );
-&addCmdHook('uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
+&addCmdHook("extra", 'plug', ('CODEREF' => 'Plug::Plug',
+ 'Identifier' => 'plug', 'Forker' => 1,
+ 'Cmdstats' => 'Plug') );
+&addCmdHook("extra", 'uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
'Cmdstats' => 'Uptime') );
-&addCmdHook('nullski', ('CODEREF' => 'nullski', ) );
-&addCmdHook('crash', ('CODEREF' => 'crash' ) );
-sub nullski { my ($arg) = @_; foreach (`$arg`) { &msg($who,$_); } }
-&addCmdHook('(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
- 'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
- 'Forker' => 1, 'Help' => 'freshmeat') );
-
-
-
-
-&status("CMD: loaded ".scalar(keys %cmdhooks)." command hooks.");
+&addCmdHook("extra", 'nullski', ('CODEREF' => 'nullski', ) );
+&addCmdHook("extra", 'verstats', ('CODEREF' => 'do_verstats' ) );
+&addCmdHook("extra", 'weather', ('CODEREF' => 'Weather::Weather',
+ 'Identifier' => 'weather', 'Help' => 'weather',
+ 'Cmdstats' => 'weather', 'Forker' => 1) );
+&addCmdHook("extra", 'bzflist', ('CODEREF' => 'BZFlag::list',
+ 'Identifier' => 'bzflag', 'Cmdstats' => 'BZFlag',
+ 'Forker' => 1) );
+&addCmdHook("extra", 'bzfquery', ('CODEREF' => 'BZFlag::query',
+ 'Identifier' => 'bzflag', 'Cmdstats' => 'BZFlag',
+ 'Forker' => 1, 'Help' => 'bzflag') );
+&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.
+###
+&status("CMD: loaded ".scalar(keys %hooks_extra)." EXTRA command hooks.");
sub Modules {
if (!defined $message) {
}
# babel bot: Jonathan Feinberg++
- if (&IsParam("babelfish") and $message =~ m{
+ if ($message =~ m{
^\s*
(?:babel(?:fish)?|x|xlate|translate)
\s+
- (to|from) # direction of translation (through)
+ ($babel_lang_regex)\w* # from language?
\s+
- ($babel::lang_regex)\w* # which language?
+ ($babel_lang_regex)\w* # to language?
\s*
(.+) # The phrase to be translated
- }xoi) {
+ }xoi) {
+ return unless (&hasParam("babelfish"));
&Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
$cmdstats{'BabelFish'}++;
- return $noreply;
+ return;
}
- if (&IsParam("debian")) {
- my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
- $debiancmd .= '|recommends?|suggests?|maint|maintainer';
- if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
- my $package = lc $3;
+ my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
+ $debiancmd .= '|recommends?|suggests?|maint|maintainer';
- if (defined $package) {
- &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
- } else {
- &help($1);
- }
+ if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
+ return unless (&hasParam("debian"));
+ my $package = lc $3;
- return $noreply;
+ if (defined $package) {
+ &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
+ } else {
+ &help($1);
}
+
+ return;
}
# google searching. Simon++
- if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
- return $noreply unless (&hasParam("wwwsearch"));
+ if ($message =~ /^(?:search\s+)?($w3search_regex)\s+for\s+['"]?(.*?)["']?\s*\?*$/i) {
+ return unless (&hasParam("wwwsearch"));
- &DEBUG("wwwsearch: 1 => $1");
- &DEBUG("wwwsearch: 2 => $2");
- &DEBUG("wwwsearch: 3 => $3");
-
- &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2,$3); } );
+ &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
$cmdstats{'WWWSearch'}++;
- return $noreply;
+ return;
+ }
+
+ # text counters. (eg: hehstats)
+ 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.
+
+ # 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 = "";
+ &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 {
+ # 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;
+ }
+
+ # 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<scalar @array; $i++) {
+ next unless ($array[0] =~ /^\Q$who\E$/);
+ $good++;
+ last;
+ }
+ $i++;
+
+ my $total = scalar(@array);
+ 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 $pct1 = sprintf("%.01f", 100*$x/$sum);
+ &pSReply("\002$arg\002 has said \037$type\037 \002$x\002 times (\002$pct1\002 %)$xtra");
+ }
+
+ return;
+ }
+
+ if ($@) {
+ &DEBUG("regex failed: $@");
+ return;
+ }
}
# list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
- if ($message =~ /^list(\S+)( (.*))?$/i) {
- return $noreply unless (&hasParam("search"));
+ if ($message =~ /^list(\S+)(\s+(.*))?$/i) {
+ return unless (&hasParam("search"));
- my $thiscmd = lc($1);
- my $args = $3;
+ my $thiscmd = lc $1;
+ my $args = $3 || "";
- $thiscmd =~ s/^vals$/values/;
- return $noreply if ($thiscmd ne "keys" && $thiscmd ne "values");
+ $thiscmd =~ s/^vals$/values/;
+ return if ($thiscmd ne "keys" && $thiscmd ne "values");
# Usage:
- if (!defined $args) {
+ if (!defined $args or $args =~ /^\s*$/) {
&help("list". $thiscmd);
- return $noreply;
+ return;
}
- if (length $args == 1) {
- &msg($who,"search string is too short.");
- return $noreply;
+ # suggested by asuffield and \broken.
+ if ($args =~ /^["']/ and $args =~ /["']$/) {
+ &DEBUG("list*: removed quotes.");
+ $args =~ s/^["']|["']$//g;
+ }
+
+ if (length $args < 2 && &IsFlag("o") ne "o") {
+ &msg($who, "search string is too short.");
+ return;
}
&Forker("search", sub { &Search::Search($thiscmd, $args); } );
$cmdstats{'Factoid Search'}++;
- return $noreply;
+ return;
}
# Nickometer. Adam Spiers++
if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
- return $noreply unless (&hasParam("nickometer"));
+ return unless (&hasParam("nickometer"));
my $term = (lc $1 eq 'me') ? $who : $1;
- $term =~ s/\?+\s*//;
&loadMyModule($myModules{'nickometer'});
+
+ if ($term =~ /^$mask{chan}$/) {
+ &status("Doing nickometer for chan $term.");
+
+ if (!&validChan($term)) {
+ &msg($who, "error: channel is invalid.");
+ return;
+ }
+
+ # step 1.
+ my %nickometer;
+ foreach (keys %{ $channels{lc $term}{''} }) {
+ my $str = $_;
+ if (!defined $str) {
+ &WARN("nickometer: nick in chan $term undefined?");
+ next;
+ }
+
+ my $value = &nickometer($str);
+ $nickometer{$value}{$str} = 1;
+ }
+
+ # step 2.
+ ### TODO: compact with map?
+ my @list;
+ foreach (sort {$b <=> $a} keys %nickometer) {
+ my $str = join(", ", sort keys %{ $nickometer{$_} });
+ push(@list, "$str ($_%)");
+ }
+
+ &pSReply( &formListReply(0, "Nickometer list for $term ", @list) );
+ &DEBUG("test.");
+
+ return;
+ }
+
my $percentage = &nickometer($term);
if ($percentage =~ /NaN/) {
$percentage = "off the scale";
} else {
$percentage = sprintf("%0.4f", $percentage);
- $percentage =~ s/\.?0+$//;
+ $percentage =~ s/(\.\d+)0+$/$1/;
$percentage .= '%';
}
&msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
}
- return $noreply;
+ return;
}
# Topic management. xk++
- # may want to add a flag(??) for topic in the near future. -xk
+ # may want to add a userflags for topic. -xk
if ($message =~ /^topic(\s+(.*))?$/i) {
- return $noreply unless (&hasParam("topic"));
+ return unless (&hasParam("topic"));
my $chan = $talkchannel;
- my @args = split(/ /, $2);
+ my @args = split / /, $2 || "";
if (!scalar @args) {
&msg($who,"Try 'help topic'");
- return $noreply;
+ return;
}
$chan = lc(shift @args) if ($msgType eq 'private');
if ($msgType eq 'public' && $thiscmd =~ /^#/) {
&msg($who, "error: channel argument is not required.");
&msg($who, "\002Usage\002: topic <CMD>");
- return $noreply;
+ return;
}
# topic over private:
if ($msgType eq 'private' && $chan !~ /^#/) {
&msg($who, "error: channel argument is required.");
&msg($who, "\002Usage\002: topic #channel <CMD>");
- return $noreply;
+ return;
}
if (&validChan($chan) == 0) {
&msg($who,"error: invalid channel \002$chan\002");
- return $noreply;
+ return;
}
# for semi-outsiders.
if (!&IsNickInChan($who,$chan)) {
&msg($who, "Failed. You ($who) are not in $chan, hey?");
- return $noreply;
+ return;
}
# now lets do it.
&loadMyModule($myModules{'topic'});
&Topic($chan, $thiscmd, join(' ', @args));
$cmdstats{'Topic'}++;
- return $noreply;
+ return;
}
# wingate.
if ($message =~ /^wingate$/i) {
- return $noreply unless (&hasParam("wingate"));
+ return unless (&hasParam("wingate"));
my $reply = "Wingate statistics: scanned \002"
.scalar(keys %wingate)."\002 hosts";
$reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
}
- &performStrictReply("$reply.");
+ &pSReply("$reply.");
- return $noreply;
+ return;
}
# do nothing and let the other routines have a go
- return '';
-}
-
-# Freshmeat. xk++
-sub freshmeat {
- my ($query) = @_;
-
- if (!defined $query) {
- &help("freshmeat");
- &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
- return $noreply;
- }
-
- &Freshmeat::Freshmeat($query);
+ return "CONTINUE";
}
# Uptime. xk++
# seen.
sub seen {
- my($person) = @_;
+ my($person) = lc shift;
+ $person =~ s/\?*$//;
- if (!defined $person) {
+ if (!defined $person or $person =~ /^$/) {
&help("seen");
my $i = &countKeys("seen");
&msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
"seen ". &fixPlural("entry",$i) ." that I know of.");
- return $noreply;
+ return;
}
my @seen;
- $person =~ s/\?*$//;
&seenFlush(); # very evil hack. oh well, better safe than sorry.
- ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
+ # TODO: convert to &sqlSelectRowHash();
my $select = "nick,time,channel,host,message";
if ($person eq "random") {
@seen = &randKey("seen", $select);
} else {
- @seen = &dbGet("seen", "nick", $person, $select);
+ @seen = &sqlSelect("seen", $select, { nick => $person } );
}
if (scalar @seen < 2) {
&DEBUG("seen: _ => '$_'.");
}
&performReply("i haven't seen '$person'");
- return $noreply;
+ return;
}
# valid seen.
my $reply;
### TODO: multi channel support. may require &IsNick() to return
### all channels or something.
- my @chans = &GetNickInChans($seen[0]);
+ my @chans = &getNickInChans($seen[0]);
if (scalar @chans) {
$reply = "$seen[0] is currently on";
"saying\002:\002 '$seen[4]'.";
}
- &performStrictReply($reply);
- return $noreply;
+ &pSReply($reply);
+ return;
}
# User Information Services. requested by Flugh.
$arg = $2;
if (!defined $arg) {
&help("userinfo set");
- return $noreply;
+ return;
}
&UserInfoSet(split /\s+/, $arg, 2);
$arg = $2;
if (!defined $arg) {
&help("userinfo unset");
- return $noreply;
+ return;
}
&UserInfoSet($arg, "");
# lets find that secret cookie.
my $target = ($msgType ne 'public') ? $who : $talkchannel;
- my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
+ my $cookiemsg = &getRandom(keys %{ $lang{'cookie'} });
my ($key,$value);
### WILL CHEW TONS OF MEM.
### 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");
}
if (!$to or !$from) {
&msg($who, "Invalid format!");
&help("convert");
- return $noreply;
+ return;
}
&Units::convertUnits($from, $to);
- return $noreply;
+ return;
}
sub lart {
} else {
&msg($who, "error: invalid format or missing arguments.");
&help("lart");
- return $noreply;
+ return;
}
}
- my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
+ my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.lart");
if (defined $line) {
if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
$line =~ s/WHO/$who/g;
}
}
+sub DebianNew {
+ my $idx = "debian/Packages-sid.idx";
+ my $error = 0;
+ my %pkg;
+ my @new;
+
+ $error++ unless ( -e $idx);
+ $error++ unless ( -e "$idx-old");
+
+ if ($error) {
+ $error = "no sid/sid-old index file found.";
+ &ERROR("Debian: $error");
+ &msg($who, $error);
+ return;
+ }
+
+ open(IDX1, $idx);
+ open(IDX2, "$idx-old");
+
+ while (<IDX2>) {
+ chop;
+ next if (/^\*/);
+
+ $pkg{$_} = 1;
+ }
+ close IDX2;
+
+ open(IDX1,$idx);
+ while (<IDX1>) {
+ chop;
+ next if (/^\*/);
+ next if (exists $pkg{$_});
+
+ push(@new, $_);
+ }
+ close IDX1;
+
+ &::pSReply( &::formListReply(0, "New debian packages:", @new) );
+}
+
+sub do_verstats {
+ my ($chan) = @_;
+
+ if (!defined $chan) {
+ &help("verstats");
+ return;
+ }
+
+ if (!&validChan($chan)) {
+ &msg($who, "chan $chan is invalid.");
+ return;
+ }
+
+ if (scalar @vernick > scalar(keys %{ $channels{lc $chan}{''} })/4) {
+ &msg($who, "verstats already in progress for someone else.");
+ return;
+ }
+
+ &msg($who, "Sending CTCP VERSION to $chan; results in 60s.");
+ $conn->ctcp("VERSION", $chan);
+ $cache{verstats}{chan} = $chan;
+ $cache{verstats}{who} = $who;
+ $cache{verstats}{msgType} = $msgType;
+
+ $conn->schedule(30, sub {
+ my $c = lc $cache{verstats}{chan};
+ @vernicktodo = ();
+
+ foreach (keys %{ $channels{$c}{''} } ) {
+ next if (grep /^\Q$_\E$/i, @vernick);
+ push(@vernicktodo, $_);
+ }
+
+ &verstats_flush();
+ } );
+
+ $conn->schedule(60, sub {
+ 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?
+
+ foreach (keys %ver) {
+ $vtotal += scalar keys %{ $ver{$_} };
+ }
+
+ my %sorted;
+ my $unknown = $total - $vtotal;
+ 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 =~ s/.0$//; # lame compression.
+
+ $sorted{$perc}{$_} = "$count ($perc%)";
+ }
+
+ ### can be compressed to a map?
+ my @list;
+ foreach ( sort { $b <=> $a } keys %sorted ) {
+ my $perc = $_;
+ foreach (sort keys %{ $sorted{$perc} }) {
+ push(@list, "$_ - $sorted{$perc}{$_}");
+ }
+ }
+
+ # 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.
+ undef %ver;
+ undef @vernick;
+ } );
+
+ return;
+}
+
+sub verstats_flush {
+ for (1..5) {
+ last unless (scalar @vernicktodo);
+
+ my $n = shift(@vernicktodo);
+ $conn->ctcp("VERSION", $n);
+ }
+
+ return unless (scalar @vernicktodo);
+
+ $conn->schedule(3, \&verstats_flush() );
+}
+
+sub textstats_main {
+ my($arg) = @_;
+
+ # even more uglier with channel/time arguments.
+ my $c = $chan;
+# my $c = $chan || "PRIVATE";
+ &DEBUG("not using chan arg") if (!defined $c);
+
+ # 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 = &sqlSelectColHash("stats", "nick,counter",
+ $where_href,
+ " 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 = "";
+ &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 {
+ # 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<scalar @array; $i++) {
+ next unless ($array[0] =~ /^\Q$who\E$/);
+ $good++;
+ last;
+ }
+ $ii++;
+
+ $total = scalar(@array);
+ &DEBUG(" i => $i, good => $good, total => $total");
+ $x .= " ".$total."blah blah";
+ }
+
+ return;
+
+ if (!defined $x) { # !defined.
+ &pSReply("$arg has not said $type yet.");
+ 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 %)";
+ }
+
+ 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,$_); } }
+
1;