2 # User Command Extension Stubs
3 # WARN: this file does not reload on HUP.
8 $babel_lang_regex = "fr|sp|es|po|pt|it|ge|de|gr|en|zh|ja|jp|ko|kr|ru";
10 ### COMMAND HOOK IMPLEMENTATION.
11 # addCmdHook("SECTION", 'TEXT_HOOK',
14 # CheckModule => 1, # ???
15 # Module => 'blah.pl' # preload module.
16 # Identifier => 'config_label', # change to Config?
17 # Help => 'help_label',
18 # Cmdstats => 'text_label',)
23 my ($hashname, $ident, %hash) = @_;
25 if (exists ${"hooks_$hashname"}{$ident}) {
26 ### &WARN("aCH: cmd hooks \%$hashname{$ident} already exists.");
30 &VERB("aCH: added $ident",2); # use $hash{'Identifier'}?
31 ### hrm... prevent warnings?
32 ${"hooks_$hashname"}{$ident} = \%hash;
37 my ($hashname, $line) = @_;
38 $line =~ /^(\S+)( (.*))?$/;
39 my $cmd = $1; # command name is whitespaceless.
41 my @args = split(/\s+/, $flatarg || '');
46 if (!defined %{"hooks_$hashname"}) {
47 &WARN("cmd hooks \%$hashname does not exist.");
52 &WARN("cstubs: cmd == NULL.");
56 foreach (keys %{"hooks_$hashname"}) {
57 # rename to something else! like $id or $label?
60 next unless ($cmd =~ /^$ident$/i);
63 &WARN("pCH: Multiple hook match: $ident");
67 &status("hooks($hashname): $cmd matched '$ident'");
68 my %hash = %{ ${"hooks_$hashname"}{$ident} };
70 if (!scalar keys %hash) {
71 &WARN("CmdHook: hash is NULL?");
75 if ($hash{NoArgs} and $flatarg) {
76 &DEBUG("cmd $ident does not take args ('$flatarg'); skipping.");
80 if (!exists $hash{CODEREF}) {
81 &ERROR("CODEREF undefined for $cmd or $ident.");
86 foreach (keys %hash) {
87 &VERB(" $cmd->$_ => '$hash{$_}'.",2);
91 if (exists $hash{'Help'} and !scalar(@args)) {
92 &help( $hash{'Help'} );
97 if (exists $hash{'Identifier'}) {
98 return 1 unless (&hasParam($hash{'Identifier'}));
102 if (exists $hash{'UserFlag'}) {
103 return 1 unless (&hasFlag($hash{'UserFlag'}));
106 ### FORKER,IDENTIFIER,CODEREF.
107 if (exists $hash{'Forker'}) {
108 $hash{'Identifier'} .= "-" if ($hash{'Forker'} eq "NULL");
110 if (exists $hash{'ArrayArgs'}) {
111 &Forker($hash{'Identifier'}, sub { \&{ $hash{'CODEREF'} }(@args) } );
113 &Forker($hash{'Identifier'}, sub { \&{ $hash{'CODEREF'} }($flatarg) } );
117 if (exists $hash{'Module'}) {
118 &loadMyModule($myModules{ $hash{'Module'} });
121 # check if CODEREF exists.
122 if (!defined &{ $hash{'CODEREF'} }) {
123 &WARN("coderef $hash{'CODEREF'} does not exist.");
125 &msg($who, "coderef does not exist for $ident.");
131 if (exists $hash{'ArrayArgs'}) {
132 &{ $hash{'CODEREF'} }(@args);
134 &{ $hash{'CODEREF'} }($flatarg);
139 if (exists $hash{'Cmdstats'}) {
140 $cmdstats{ $hash{'Cmdstats'} }++;
143 &VERB("hooks: End of command.",2);
153 ### START ADDING HOOKS.
155 &addCmdHook("extra", 'd?bugs', ('CODEREF' => 'DBugs::Parse',
156 'Forker' => 1, 'Identifier' => 'debianExtra',
157 'Cmdstats' => 'Debian Bugs') );
158 &addCmdHook("extra", 'dauthor', ('CODEREF' => 'Debian::searchAuthor',
159 'Forker' => 1, 'Identifier' => 'debian',
160 'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) );
161 &addCmdHook("extra", '(d|search)desc', ('CODEREF' => 'Debian::searchDescFE',
162 'Forker' => 1, 'Identifier' => 'debian',
163 'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) );
164 &addCmdHook("extra", 'dnew', ('CODEREF' => 'DebianNew',
165 'Identifier' => 'debian' ) );
166 &addCmdHook("extra", 'dincoming', ('CODEREF' => 'Debian::generateIncoming',
167 'Forker' => 1, 'Identifier' => 'debian' ) );
168 &addCmdHook("extra", 'dstats', ('CODEREF' => 'Debian::infoStats',
169 'Forker' => 1, 'Identifier' => 'debian',
170 'Cmdstats' => 'Debian Statistics' ) );
171 &addCmdHook("extra", 'd?contents', ('CODEREF' => 'Debian::searchContents',
172 'Forker' => 1, 'Identifier' => 'debian',
173 'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) );
174 &addCmdHook("extra", 'd?find', ('CODEREF' => 'Debian::DebianFind',
175 'Forker' => 1, 'Identifier' => 'debian',
176 'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
177 &addCmdHook("extra", 'insult', ('CODEREF' => 'Insult::Insult',
178 'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
179 &addCmdHook("extra", 'kernel', ('CODEREF' => 'Kernel::Kernel',
180 'Forker' => 1, 'Identifier' => 'kernel',
181 'Cmdstats' => 'Kernel', 'NoArgs' => 1) );
182 &addCmdHook("extra", 'listauth', ('CODEREF' => 'CmdListAuth',
183 'Identifier' => 'search', Module => 'factoids',
184 'Help' => 'listauth') );
185 &addCmdHook("extra", 'quote', ('CODEREF' => 'Quote::Quote',
186 'Forker' => 1, 'Identifier' => 'quote',
187 'Help' => 'quote', 'Cmdstats' => 'Quote') );
188 &addCmdHook("extra", 'countdown', ('CODEREF' => 'Countdown',
189 'Module' => 'countdown', 'Identifier' => 'countdown',
190 'Cmdstats' => 'Countdown') );
191 &addCmdHook("extra", 'lart', ('CODEREF' => 'lart',
192 'Identifier' => 'lart', 'Help' => 'lart') );
193 &addCmdHook("extra", 'convert', ('CODEREF' => 'convert',
194 'Forker' => 1, 'Identifier' => 'units',
195 'Help' => 'convert') );
196 &addCmdHook("extra", '(cookie|random)', ('CODEREF' => 'cookie',
197 'Forker' => 1, 'Identifier' => 'factoids') );
198 &addCmdHook("extra", 'u(ser)?info', ('CODEREF' => 'userinfo',
199 'Identifier' => 'userinfo', 'Help' => 'userinfo',
200 'Module' => 'userinfo') );
201 &addCmdHook("extra", 'rootWarn', ('CODEREF' => 'CmdrootWarn',
202 'Identifier' => 'rootWarn', 'Module' => 'rootwarn') );
203 &addCmdHook("extra", 'seen', ('CODEREF' => 'seen', 'Identifier' =>
205 &addCmdHook("extra", 'dict', ('CODEREF' => 'Dict::Dict',
206 'Identifier' => 'dict', 'Help' => 'dict',
207 'Forker' => 1, 'Cmdstats' => 'Dict') );
208 &addCmdHook("extra", 'slashdot', ('CODEREF' => 'Slashdot::Slashdot',
209 'Identifier' => 'slashdot', 'Forker' => 1,
210 'Cmdstats' => 'Slashdot') );
211 &addCmdHook("extra", 'plug', ('CODEREF' => 'Plug::Plug',
212 'Identifier' => 'plug', 'Forker' => 1,
213 'Cmdstats' => 'Plug') );
214 &addCmdHook("extra", 'uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
215 'Cmdstats' => 'Uptime') );
216 &addCmdHook("extra", 'nullski', ('CODEREF' => 'nullski', ) );
217 &addCmdHook("extra", '(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
218 'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
219 'Forker' => 1, 'Help' => 'freshmeat') );
220 &addCmdHook("extra", 'verstats', ('CODEREF' => 'do_verstats' ) );
221 &addCmdHook("extra", 'weather', ('CODEREF' => 'Weather::Weather',
222 'Identifier' => 'weather', 'Help' => 'weather',
223 'Cmdstats' => 'weather', 'Forker' => 1) );
224 &addCmdHook("extra", 'bzflist', ('CODEREF' => 'BZFlag::list',
225 'Identifier' => 'bzflag', 'Cmdstats' => 'BZFlag',
227 &addCmdHook("extra", 'bzfquery', ('CODEREF' => 'BZFlag::query',
228 'Identifier' => 'bzflag', 'Cmdstats' => 'BZFlag',
229 'Forker' => 1, 'Help' => 'bzflag') );
230 &addCmdHook("extra", 'zfi', ('CODEREF' => 'zfi::query',
231 'Identifier' => 'zfi', 'Cmdstats' => 'zfi',
233 &addCmdHook("extra", '(zippy|yow)', ('CODEREF' => 'zippy::get',
234 'Identifier' => 'zippy', 'Cmdstats' => 'zippy',
236 &addCmdHook("extra", 'zsi', ('CODEREF' => 'zsi::query',
237 'Identifier' => 'zsi', 'Cmdstats' => 'zsi',
239 &addCmdHook("extra", '(ex)?change', ('CODEREF' => 'Exchange::query',
240 'Identifier' => 'exchange', 'Cmdstats' => 'exchange',
244 ### END OF ADDING HOOKS.
246 &status("CMD: loaded ".scalar(keys %hooks_extra)." EXTRA command hooks.");
249 if (!defined $message) {
250 &WARN("Modules: message is undefined. should never happen.");
254 # babel bot: Jonathan Feinberg++
257 (?:babel(?:fish)?|x|xlate|translate)
259 ($babel_lang_regex)\w* # from language?
261 ($babel_lang_regex)\w* # to language?
263 (.+) # The phrase to be translated
265 return unless (&hasParam("babelfish"));
267 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
269 $cmdstats{'BabelFish'}++;
273 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
274 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
276 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
277 return unless (&hasParam("debian"));
280 if (defined $package) {
281 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
289 # google searching. Simon++
290 if ($message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)["']?\s*\?*$/i) {
291 return unless (&hasParam("wwwsearch"));
293 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
295 $cmdstats{'WWWSearch'}++;
299 # text counters. (eg: hehstats)
301 $itc = &getChanConf("ircTextCounters");
302 $itc = &findChanConf("ircTextCounters") unless ($itc);
304 $itc =~ s/([^\w\s])/\\$1/g;
305 my $z = join '|', split ' ', $itc;
307 if ($msgType eq "privmsg" and $message =~ / ($mask{chan})$/) {
308 &DEBUG("ircTC: privmsg detected; chan = $1");
312 if ($message =~ /^_stats(\s+(\S+))$/i) {
317 if ($message =~ /^($z)stats(\s+(\S+))?$/i) {
321 # even more uglier with channel/time arguments.
323 # my $c = $chan || "PRIVATE";
324 my $where = "type=".&dbQuote($type);
325 $where .= " AND channel=".&dbQuote($c) if (defined $c);
326 &DEBUG("not using chan arg") if (!defined $c);
327 my $sum = (&dbRawReturn("SELECT SUM(counter) FROM stats"
328 ." WHERE ".$where ))[0];
330 if (!defined $arg or $arg =~ /^\s*$/) {
331 # this is way fucking ugly.
333 my %hash = &dbGetCol("stats", "nick,counter",
334 $where." ORDER BY counter DESC LIMIT 3", 1);
338 # unfortunately we have to sort it again!
339 # todo: make dbGetCol return hash and array? too much effort.
341 foreach $i (sort { $b <=> $a } keys %hash) {
342 foreach (keys %{ $hash{$i} }) {
343 my $p = sprintf("%.01f", 100*$i/$sum);
345 push(@top, "\002$_\002 -- $i ($p%)");
349 &DEBUG("*stats: tp => $tp");
351 $topstr = ". Top ".scalar(@top).": ".join(', ', @top);
355 &pSReply("total count of \037$type\037 on \002$c\002: $sum$topstr");
357 &pSReply("zero counter for \037$type\037.");
360 my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats".
361 " WHERE $where AND nick=".&dbQuote($arg) ))[0];
363 if (!defined $x) { # !defined.
364 &pSReply("$arg has not said $type yet.");
369 my @array = &dbGet("stats", "nick",
370 $where." ORDER BY counter", 1);
373 for($i=0; $i<scalar @array; $i++) {
374 next unless ($array[0] =~ /^\Q$who\E$/);
380 my $total = scalar(@array);
382 if ($total and $good) {
383 my $pct = sprintf("%.01f", 100*(1+$total-$i)/$total);
384 $xtra = ", ranked $i\002/\002$total (percentile: \002$pct\002 %)";
387 my $pct1 = sprintf("%.01f", 100*$x/$sum);
388 &pSReply("\002$arg\002 has said \037$type\037 \002$x\002 times (\002$pct1\002 %)$xtra");
395 &DEBUG("regex failed: $@");
400 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
401 if ($message =~ /^list(\S+)(\s+(.*))?$/i) {
402 return unless (&hasParam("search"));
407 $thiscmd =~ s/^vals$/values/;
408 # $args =~ s/\s+$//g;
409 return if ($thiscmd ne "keys" && $thiscmd ne "values");
412 if (!defined $args or $args =~ /^\s*$/) {
413 &help("list". $thiscmd);
417 # suggested by asuffield and \broken.
418 if ($args =~ /^["']/ and $args =~ /["']$/) {
419 &DEBUG("list*: removed quotes.");
420 $args =~ s/^["']|["']$//g;
423 if (length $args == 1) {
424 &msg($who,"search string is too short.");
428 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
430 $cmdstats{'Factoid Search'}++;
434 # Nickometer. Adam Spiers++
435 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
436 return unless (&hasParam("nickometer"));
438 my $term = (lc $1 eq 'me') ? $who : $1;
440 &loadMyModule($myModules{'nickometer'});
442 if ($term =~ /^$mask{chan}$/) {
443 &status("Doing nickometer for chan $term.");
445 if (!&validChan($term)) {
446 &msg($who, "error: channel is invalid.");
452 foreach (keys %{ $channels{lc $term}{''} }) {
455 &WARN("nickometer: nick in chan $term undefined?");
459 my $value = &nickometer($str);
460 $nickometer{$value}{$str} = 1;
464 ### TODO: compact with map?
466 foreach (sort {$b <=> $a} keys %nickometer) {
467 my $str = join(", ", sort keys %{ $nickometer{$_} });
468 push(@list, "$str ($_%)");
471 &pSReply( &formListReply(0, "Nickometer list for $term ", @list) );
477 my $percentage = &nickometer($term);
479 if ($percentage =~ /NaN/) {
480 $percentage = "off the scale";
482 $percentage = sprintf("%0.4f", $percentage);
483 $percentage =~ s/\.?0+$//;
487 if ($msgType eq 'public') {
488 &say("'$term' is $percentage lame, $who");
490 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
496 # Topic management. xk++
497 # may want to add a userflags for topic. -xk
498 if ($message =~ /^topic(\s+(.*))?$/i) {
499 return unless (&hasParam("topic"));
501 my $chan = $talkchannel;
502 my @args = split / /, $2 || "";
505 &msg($who,"Try 'help topic'");
509 $chan = lc(shift @args) if ($msgType eq 'private');
510 my $thiscmd = shift @args;
513 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
514 &msg($who, "error: channel argument is not required.");
515 &msg($who, "\002Usage\002: topic <CMD>");
519 # topic over private:
520 if ($msgType eq 'private' && $chan !~ /^#/) {
521 &msg($who, "error: channel argument is required.");
522 &msg($who, "\002Usage\002: topic #channel <CMD>");
526 if (&validChan($chan) == 0) {
527 &msg($who,"error: invalid channel \002$chan\002");
531 # for semi-outsiders.
532 if (!&IsNickInChan($who,$chan)) {
533 &msg($who, "Failed. You ($who) are not in $chan, hey?");
538 &loadMyModule($myModules{'topic'});
539 &Topic($chan, $thiscmd, join(' ', @args));
540 $cmdstats{'Topic'}++;
545 if ($message =~ /^wingate$/i) {
546 return unless (&hasParam("wingate"));
548 my $reply = "Wingate statistics: scanned \002"
549 .scalar(keys %wingate)."\002 hosts";
550 my $queue = scalar(keys %wingateToDo);
552 $reply .= ". I have \002$queue\002 hosts in the queue";
553 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
561 # do nothing and let the other routines have a go
569 if (!defined $query) {
571 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
575 &Freshmeat::Freshmeat($query);
581 &msg($who, "- Uptime for $ident -");
582 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
584 foreach (&uptimeGetInfo()) {
586 my $time = &Time2String($1);
589 &msg($who, "$count: $time $2");
596 my($person) = lc shift;
599 if (!defined $person or $person =~ /^$/) {
602 my $i = &countKeys("seen");
603 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
604 "seen ". &fixPlural("entry",$i) ." that I know of.");
611 &seenFlush(); # very evil hack. oh well, better safe than sorry.
613 ### TODO: Support &dbGetColInfo(); like in &FactInfo();
614 my $select = "nick,time,channel,host,message";
615 if ($person eq "random") {
616 @seen = &randKey("seen", $select);
618 @seen = &dbGet("seen", $select, "nick=".&dbQuote($person) );
621 if (scalar @seen < 2) {
623 &DEBUG("seen: _ => '$_'.");
625 &performReply("i haven't seen '$person'");
631 ### TODO: multi channel support. may require &IsNick() to return
632 ### all channels or something.
633 my @chans = &getNickInChans($seen[0]);
635 $reply = "$seen[0] is currently on";
639 next unless (exists $userstats{lc $seen[0]}{'Join'});
640 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
643 if (&IsParam("seenStats")) {
645 $i = $userstats{lc $seen[0]}{'Count'};
646 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
647 $i = $userstats{lc $seen[0]}{'Time'};
648 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
651 my $howlong = &Time2String(time() - $seen[1]);
652 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
653 "in channel $seen[2], $howlong ago, ".
654 "saying\002:\002 '$seen[4]'.";
661 # User Information Services. requested by Flugh.
663 my ($arg) = join(' ',@_);
665 if ($arg =~ /^set(\s+(.*))?$/i) {
668 &help("userinfo set");
672 &UserInfoSet(split /\s+/, $arg, 2);
673 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
676 &help("userinfo unset");
680 &UserInfoSet($arg, "");
686 # cookie (random). xk++
690 # lets find that secret cookie.
691 my $target = ($msgType ne 'public') ? $who : $talkchannel;
692 my $cookiemsg = &getRandom(keys %{ $lang{'cookie'} });
695 ### WILL CHEW TONS OF MEM.
696 ### TODO: convert this to a Forker function!
698 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
699 $key = &getRandom(@list);
700 $val = &getFactInfo("factoids", $key, "factoid_value");
702 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
706 s/##KEY/\002$key\002/;
709 s/\$who/$who/; # cheap fix.
710 s/(\S+)?\s*<\S+>/$1 /;
714 if ($cookiemsg =~ s/^ACTION //i) {
715 &action($target, $cookiemsg);
717 &msg($target, $cookiemsg);
722 my $arg = join(' ',@_);
723 my ($from,$to) = ('','');
725 ($from,$to) = ($1,$2) if ($arg =~ /^(.*?) to (.*)$/i);
726 ($from,$to) = ($2,$1) if ($arg =~ /^(.*?) from (.*)$/i);
728 if (!$to or !$from) {
729 &msg($who, "Invalid format!");
734 &Units::convertUnits($from, $to);
740 my ($target) = &fixString($_[0]);
742 my $chan = $talkchannel;
744 if ($msgType eq 'private') {
745 if ($target =~ /^($mask{chan})\s+(.*)$/) {
750 &msg($who, "error: invalid format or missing arguments.");
756 my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.lart");
758 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
759 $line =~ s/WHO/$who/g;
761 $line =~ s/WHO/$target/g;
763 $line .= ", courtesy of $who" if ($extra);
765 &action($chan, $line);
767 &status("lart: error reading file?");
772 my $idx = "debian/Packages-sid.idx";
777 $error++ unless ( -e $idx);
778 $error++ unless ( -e "$idx-old");
781 $error = "no sid/sid-old index file found.";
782 &ERROR("Debian: $error");
788 open(IDX2, "$idx-old");
802 next if (exists $pkg{$_});
808 &::pSReply( &::formListReply(0, "New debian packages:", @new) );
814 if (!defined $chan) {
819 if (!&validChan($chan)) {
820 &msg($who, "chan $chan is invalid.");
824 if (scalar @vernick > scalar(keys %{ $channels{lc $chan}{''} })/4) {
825 &msg($who, "verstats already in progress for someone else.");
829 &msg($who, "Sending CTCP VERSION to #$chan...");
830 $conn->ctcp("VERSION", $chan);
831 $cache{verstats}{chan} = $chan;
832 $cache{verstats}{who} = $who;
833 $cache{verstats}{msgType} = $msgType;
835 $conn->schedule(30, sub {
836 my $c = lc $cache{verstats}{chan};
839 foreach (keys %{ $channels{$c}{''} } ) {
840 next if (grep /^\Q$_\E$/i, @vernick);
841 push(@vernicktodo, $_);
847 $conn->schedule(60, sub {
849 my $c = lc $cache{verstats}{chan};
850 my $total = keys %{ $channels{$c}{''} };
852 $who = $cache{verstats}{who};
853 $msgType = $cache{verstats}{msgType};
854 delete $cache{verstats}; # sufficient?
856 foreach (keys %ver) {
857 $vtotal += scalar keys %{ $ver{$_} };
861 my $unknown = $total - $vtotal;
862 my $perc = sprintf("%.1f", $unknown * 100 / $total);
864 $sorted{$perc}{"unknown/cloak"} = "$unknown ($perc%)" if ($unknown);
866 foreach (keys %ver) {
867 my $count = scalar keys %{ $ver{$_} };
868 $perc = sprintf("%.01f", $count * 100 / $total);
869 $perc =~ s/.0$//; # lame compression.
871 $sorted{$perc}{$_} = "$count ($perc%)";
874 ### can be compressed to a map?
876 foreach ( sort { $b <=> $a } keys %sorted ) {
878 foreach (sort keys %{ $sorted{$perc} }) {
879 push(@list, "$_ - $sorted{$perc}{$_}");
883 &pSReply( &formListReply(0, "IRC Client versions for $c ", @list) );
885 # clean up not-needed data structures.
895 last unless (scalar @vernicktodo);
897 my $n = shift(@vernicktodo);
898 $conn->ctcp("VERSION", $n);
901 return unless (scalar @vernicktodo);
903 $conn->schedule(3, \&verstats_flush() );
909 # even more uglier with channel/time arguments.
911 # my $c = $chan || "PRIVATE";
912 my $where = "channel=".&dbQuote($c) if (defined $c);
913 &DEBUG("not using chan arg") if (!defined $c);
914 my $sum = (&dbRawReturn("SELECT SUM(counter) FROM stats"
915 ." WHERE ".$where ))[0];
917 if (!defined $arg or $arg =~ /^\s*$/) {
918 # this is way fucking ugly.
919 &DEBUG("_stats: !arg");
921 my %hash = &dbGetCol("stats", "nick,counter",
922 $where." ORDER BY counter DESC LIMIT 3", 1);
926 # unfortunately we have to sort it again!
927 # todo: make dbGetCol return hash and array? too much effort.
929 foreach $i (sort { $b <=> $a } keys %hash) {
930 foreach (keys %{ $hash{$i} }) {
931 my $p = sprintf("%.01f", 100*$i/$sum);
933 push(@top, "\002$_\002 -- $i ($p%)");
938 &DEBUG("*stats: tp => $tp");
940 $topstr = ". Top ".scalar(@top).": ".join(', ', @top);
944 &pSReply("total count of \037$type\037 on \002$c\002: $sum$topstr");
946 &pSReply("zero counter for \037$type\037.");
949 my %hash = &dbGetCol("stats", "type,counter",
950 "$where AND nick=".&dbQuote($arg) );
952 foreach (keys %hash) {
953 &DEBUG("_stats: hash{$_} => $hash{$_}");
955 my @array = &dbGet("stats", "nick",
956 $where." ORDER BY counter", 1);
959 for($i=0; $i<scalar @array; $i++) {
960 next unless ($array[0] =~ /^\Q$who\E$/);
966 my $total = scalar(@array);
967 &DEBUG(" i => $i, good => $good, total => $total");
972 if (!defined $x) { # !defined.
973 &pSReply("$arg has not said $type yet.");
978 if ($total and $good) {
979 my $pct = sprintf("%.01f", 100*(1+$total-$i)/$total);
980 $xtra = ", ranked $i\002/\002$total (percentile: \002$pct\002 %)";
983 my $pct1 = sprintf("%.01f", 100*$x/$sum);
984 &pSReply("\002$arg\002 has said \037$type\037 \002$x\002 times (\002$pct1\002 %)$xtra");
988 sub nullski { my ($arg) = @_; return unless (defined $arg);
989 foreach (`$arg`) { &msg($who,$_); } }