2 # User Command Extension Stubs
3 # WARN: this file does not reload on HUP.
8 use vars qw($who $msgType $conn $chan $message $ident $talkchannel
9 $bot_version $babel_lang_regex $bot_data_dir);
10 use vars qw(@vernick @vernicktodo);
11 use vars qw(%channels %cache %mask %userstats %myModules %cmdstats
12 %hooks_extra %lang %ver);
14 use vars qw($total $x $type $i $good);
16 $babel_lang_regex = "fr|sp|es|po|pt|it|ge|de|gr|en|zh|ja|jp|ko|kr|ru";
18 ### COMMAND HOOK IMPLEMENTATION.
19 # addCmdHook("SECTION", 'TEXT_HOOK',
22 # CheckModule => 1, # ???
23 # Module => 'blah.pl' # preload module.
24 # Identifier => 'config_label', # change to Config?
25 # Help => 'help_label',
26 # Cmdstats => 'text_label',)
31 my ($hashname, $ident, %hash) = @_;
33 if (exists ${"hooks_$hashname"}{$ident}) {
34 ### &WARN("aCH: cmd hooks \%$hashname{$ident} already exists.");
38 &VERB("aCH: added $ident",2); # use $hash{'Identifier'}?
39 ### hrm... prevent warnings?
40 ${"hooks_$hashname"}{$ident} = \%hash;
45 my ($hashname, $line) = @_;
46 $line =~ /^(\S+)( (.*))?$/;
47 my $cmd = $1; # command name is whitespaceless.
49 my @args = split(/\s+/, $flatarg || '');
54 if (!defined %{"hooks_$hashname"}) {
55 &WARN("cmd hooks \%$hashname does not exist.");
60 &WARN("cstubs: cmd == NULL.");
64 foreach (keys %{"hooks_$hashname"}) {
65 # rename to something else! like $id or $label?
68 next unless ($cmd =~ /^$ident$/i);
71 &WARN("pCH: Multiple hook match: $ident");
75 &status("hooks($hashname): $cmd matched '$ident'");
76 my %hash = %{ ${"hooks_$hashname"}{$ident} };
78 if (!scalar keys %hash) {
79 &WARN("CmdHook: hash is NULL?");
83 if ($hash{NoArgs} and $flatarg) {
84 &DEBUG("cmd $ident does not take args ('$flatarg'); skipping.");
88 if (!exists $hash{CODEREF}) {
89 &ERROR("CODEREF undefined for $cmd or $ident.");
94 foreach (keys %hash) {
95 &VERB(" $cmd->$_ => '$hash{$_}'.",2);
99 if (exists $hash{'Help'} and !scalar(@args)) {
100 &help( $hash{'Help'} );
105 if (exists $hash{'Identifier'}) {
106 return 1 unless (&hasParam($hash{'Identifier'}));
110 if (exists $hash{'UserFlag'}) {
111 return 1 unless (&hasFlag($hash{'UserFlag'}));
114 ### FORKER,IDENTIFIER,CODEREF.
115 if (exists $hash{'Forker'}) {
116 $hash{'Identifier'} .= "-" if ($hash{'Forker'} eq "NULL");
118 if (exists $hash{'ArrayArgs'}) {
119 &Forker($hash{'Identifier'}, sub { \&{ $hash{'CODEREF'} }(@args) } );
121 &Forker($hash{'Identifier'}, sub { \&{ $hash{'CODEREF'} }($flatarg) } );
125 if (exists $hash{'Module'}) {
126 &loadMyModule($myModules{ $hash{'Module'} });
129 # check if CODEREF exists.
130 if (!defined &{ $hash{'CODEREF'} }) {
131 &WARN("coderef $hash{'CODEREF'} does not exist.");
133 &msg($who, "coderef does not exist for $ident.");
139 if (exists $hash{'ArrayArgs'}) {
140 &{ $hash{'CODEREF'} }(@args);
142 &{ $hash{'CODEREF'} }($flatarg);
147 if (exists $hash{'Cmdstats'}) {
148 $cmdstats{ $hash{'Cmdstats'} }++;
151 &VERB("hooks: End of command.",2);
161 ### START ADDING HOOKS.
163 &addCmdHook("extra", 'd?bugs', ('CODEREF' => 'DBugs::Parse',
164 'Forker' => 1, 'Identifier' => 'debianExtra',
165 'Cmdstats' => 'Debian Bugs') );
166 &addCmdHook("extra", 'dauthor', ('CODEREF' => 'Debian::searchAuthor',
167 'Forker' => 1, 'Identifier' => 'debian',
168 'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) );
169 &addCmdHook("extra", '(d|search)desc', ('CODEREF' => 'Debian::searchDescFE',
170 'Forker' => 1, 'Identifier' => 'debian',
171 'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) );
172 &addCmdHook("extra", 'dnew', ('CODEREF' => 'DebianNew',
173 'Identifier' => 'debian' ) );
174 &addCmdHook("extra", 'dincoming', ('CODEREF' => 'Debian::generateIncoming',
175 'Forker' => 1, 'Identifier' => 'debian' ) );
176 &addCmdHook("extra", 'dstats', ('CODEREF' => 'Debian::infoStats',
177 'Forker' => 1, 'Identifier' => 'debian',
178 'Cmdstats' => 'Debian Statistics' ) );
179 &addCmdHook("extra", 'd?contents', ('CODEREF' => 'Debian::searchContents',
180 'Forker' => 1, 'Identifier' => 'debian',
181 'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) );
182 &addCmdHook("extra", 'd?find', ('CODEREF' => 'Debian::DebianFind',
183 'Forker' => 1, 'Identifier' => 'debian',
184 'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
185 &addCmdHook("extra", 'insult', ('CODEREF' => 'Insult::Insult',
186 'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
187 &addCmdHook("extra", 'kernel', ('CODEREF' => 'Kernel::Kernel',
188 'Forker' => 1, 'Identifier' => 'kernel',
189 'Cmdstats' => 'Kernel', 'NoArgs' => 1) );
190 &addCmdHook("extra", 'listauth', ('CODEREF' => 'CmdListAuth',
191 'Identifier' => 'search', Module => 'factoids',
192 'Help' => 'listauth') );
193 &addCmdHook("extra", 'quote', ('CODEREF' => 'Quote::Quote',
194 'Forker' => 1, 'Identifier' => 'quote',
195 'Help' => 'quote', 'Cmdstats' => 'Quote') );
196 &addCmdHook("extra", 'countdown', ('CODEREF' => 'Countdown',
197 'Module' => 'countdown', 'Identifier' => 'countdown',
198 'Cmdstats' => 'Countdown') );
199 &addCmdHook("extra", 'lart', ('CODEREF' => 'lart',
200 'Identifier' => 'lart', 'Help' => 'lart') );
201 &addCmdHook("extra", 'convert', ('CODEREF' => 'convert',
202 'Forker' => 1, 'Identifier' => 'units',
203 'Help' => 'convert') );
204 &addCmdHook("extra", '(cookie|random)', ('CODEREF' => 'cookie',
205 'Forker' => 1, 'Identifier' => 'factoids') );
206 &addCmdHook("extra", 'u(ser)?info', ('CODEREF' => 'userinfo',
207 'Identifier' => 'userinfo', 'Help' => 'userinfo',
208 'Module' => 'userinfo') );
209 &addCmdHook("extra", 'rootWarn', ('CODEREF' => 'CmdrootWarn',
210 'Identifier' => 'rootWarn', 'Module' => 'rootwarn') );
211 &addCmdHook("extra", 'seen', ('CODEREF' => 'seen', 'Identifier' =>
213 &addCmdHook("extra", 'dict', ('CODEREF' => 'Dict::Dict',
214 'Identifier' => 'dict', 'Help' => 'dict',
215 'Forker' => 1, 'Cmdstats' => 'Dict') );
216 &addCmdHook("extra", 'slashdot', ('CODEREF' => 'Slashdot::Slashdot',
217 'Identifier' => 'slashdot', 'Forker' => 1,
218 'Cmdstats' => 'Slashdot') );
219 &addCmdHook("extra", 'plug', ('CODEREF' => 'Plug::Plug',
220 'Identifier' => 'plug', 'Forker' => 1,
221 'Cmdstats' => 'Plug') );
222 &addCmdHook("extra", 'uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
223 'Cmdstats' => 'Uptime') );
224 &addCmdHook("extra", 'nullski', ('CODEREF' => 'nullski', ) );
225 &addCmdHook("extra", '(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
226 'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
227 'Forker' => 1, 'Help' => 'freshmeat') );
228 &addCmdHook("extra", 'verstats', ('CODEREF' => 'do_verstats' ) );
229 &addCmdHook("extra", 'weather', ('CODEREF' => 'Weather::Weather',
230 'Identifier' => 'weather', 'Help' => 'weather',
231 'Cmdstats' => 'weather', 'Forker' => 1) );
232 &addCmdHook("extra", 'bzflist', ('CODEREF' => 'BZFlag::list',
233 'Identifier' => 'bzflag', 'Cmdstats' => 'BZFlag',
235 &addCmdHook("extra", 'bzfquery', ('CODEREF' => 'BZFlag::query',
236 'Identifier' => 'bzflag', 'Cmdstats' => 'BZFlag',
237 'Forker' => 1, 'Help' => 'bzflag') );
238 &addCmdHook("extra", 'zfi', ('CODEREF' => 'zfi::query',
239 'Identifier' => 'zfi', 'Cmdstats' => 'zfi',
241 &addCmdHook("extra", '(zippy|yow)', ('CODEREF' => 'zippy::get',
242 'Identifier' => 'zippy', 'Cmdstats' => 'zippy',
244 &addCmdHook("extra", 'zsi', ('CODEREF' => 'zsi::query',
245 'Identifier' => 'zsi', 'Cmdstats' => 'zsi',
247 &addCmdHook("extra", '(ex)?change', ('CODEREF' => 'Exchange::query',
248 'Identifier' => 'exchange', 'Cmdstats' => 'exchange',
250 &addCmdHook("extra", 'botmail', ('CODEREF' => 'botmail::parse',
251 'Identifier' => 'botmail', 'Cmdstats' => 'botmail') );
254 ### END OF ADDING HOOKS.
256 &status("CMD: loaded ".scalar(keys %hooks_extra)." EXTRA command hooks.");
259 if (!defined $message) {
260 &WARN("Modules: message is undefined. should never happen.");
264 # babel bot: Jonathan Feinberg++
267 (?:babel(?:fish)?|x|xlate|translate)
269 ($babel_lang_regex)\w* # from language?
271 ($babel_lang_regex)\w* # to language?
273 (.+) # The phrase to be translated
275 return unless (&hasParam("babelfish"));
277 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
279 $cmdstats{'BabelFish'}++;
283 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
284 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
286 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
287 return unless (&hasParam("debian"));
290 if (defined $package) {
291 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
299 # google searching. Simon++
300 if ($message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)["']?\s*\?*$/i) {
301 return unless (&hasParam("wwwsearch"));
303 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
305 $cmdstats{'WWWSearch'}++;
309 # text counters. (eg: hehstats)
311 $itc = &getChanConf("ircTextCounters");
312 $itc = &findChanConf("ircTextCounters") unless ($itc);
314 $itc =~ s/([^\w\s])/\\$1/g;
315 my $z = join '|', split ' ', $itc;
317 if ($msgType eq "privmsg" and $message =~ / ($mask{chan})$/) {
318 &DEBUG("ircTC: privmsg detected; chan = $1");
322 if ($message =~ /^_stats(\s+(\S+))$/i) {
327 if ($message =~ /^($z)stats(\s+(\S+))?$/i) {
331 # even more uglier with channel/time arguments.
333 # my $c = $chan || "PRIVATE";
334 my $where = "type=".&sqlQuote($type);
335 $where .= " AND channel=".&sqlQuote($c) if (defined $c);
336 &DEBUG("not using chan arg") if (!defined $c);
337 my $sum = (&sqlRawReturn("SELECT SUM(counter) FROM stats"
338 ." WHERE ".$where ))[0];
340 if (!defined $arg or $arg =~ /^\s*$/) {
341 # this is way fucking ugly.
343 my %hash = &sqlSelectColHash("stats", "nick,counter",
345 $where." ORDER BY counter DESC LIMIT 3", 1
350 # unfortunately we have to sort it again!
351 # todo: make dbGetCol return hash and array? too much effort.
353 foreach $i (sort { $b <=> $a } keys %hash) {
354 foreach (keys %{ $hash{$i} }) {
355 my $p = sprintf("%.01f", 100*$i/$sum);
357 push(@top, "\002$_\002 -- $i ($p%)");
361 &DEBUG("*stats: tp => $tp");
363 $topstr = ". Top ".scalar(@top).": ".join(', ', @top);
367 &pSReply("total count of \037$type\037 on \002$c\002: $sum$topstr");
369 &pSReply("zero counter for \037$type\037.");
372 my $x = (&sqlRawReturn("SELECT SUM(counter) FROM stats".
373 " WHERE $where AND nick=".&sqlQuote($arg) ))[0];
375 if (!defined $x) { # !defined.
376 &pSReply("$arg has not said $type yet.");
381 my @array = &sqlSelect("stats", "nick", undef,
382 $where." ORDER BY counter", 1
386 for($i=0; $i<scalar @array; $i++) {
387 next unless ($array[0] =~ /^\Q$who\E$/);
393 my $total = scalar(@array);
395 if ($total and $good) {
396 my $pct = sprintf("%.01f", 100*(1+$total-$i)/$total);
397 $xtra = ", ranked $i\002/\002$total (percentile: \002$pct\002 %)";
400 my $pct1 = sprintf("%.01f", 100*$x/$sum);
401 &pSReply("\002$arg\002 has said \037$type\037 \002$x\002 times (\002$pct1\002 %)$xtra");
408 &DEBUG("regex failed: $@");
413 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
414 if ($message =~ /^list(\S+)(\s+(.*))?$/i) {
415 return unless (&hasParam("search"));
420 $thiscmd =~ s/^vals$/values/;
421 return if ($thiscmd ne "keys" && $thiscmd ne "values");
424 if (!defined $args or $args =~ /^\s*$/) {
425 &help("list". $thiscmd);
429 # suggested by asuffield and \broken.
430 if ($args =~ /^["']/ and $args =~ /["']$/) {
431 &DEBUG("list*: removed quotes.");
432 $args =~ s/^["']|["']$//g;
435 if (length $args == 1) {
436 &msg($who,"search string is too short.");
440 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
442 $cmdstats{'Factoid Search'}++;
446 # Nickometer. Adam Spiers++
447 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
448 return unless (&hasParam("nickometer"));
450 my $term = (lc $1 eq 'me') ? $who : $1;
452 &loadMyModule($myModules{'nickometer'});
454 if ($term =~ /^$mask{chan}$/) {
455 &status("Doing nickometer for chan $term.");
457 if (!&validChan($term)) {
458 &msg($who, "error: channel is invalid.");
464 foreach (keys %{ $channels{lc $term}{''} }) {
467 &WARN("nickometer: nick in chan $term undefined?");
471 my $value = &nickometer($str);
472 $nickometer{$value}{$str} = 1;
476 ### TODO: compact with map?
478 foreach (sort {$b <=> $a} keys %nickometer) {
479 my $str = join(", ", sort keys %{ $nickometer{$_} });
480 push(@list, "$str ($_%)");
483 &pSReply( &formListReply(0, "Nickometer list for $term ", @list) );
489 my $percentage = &nickometer($term);
491 if ($percentage =~ /NaN/) {
492 $percentage = "off the scale";
494 $percentage = sprintf("%0.4f", $percentage);
495 $percentage =~ s/(\.\d+)0+$/$1/;
499 if ($msgType eq 'public') {
500 &say("'$term' is $percentage lame, $who");
502 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
508 # Topic management. xk++
509 # may want to add a userflags for topic. -xk
510 if ($message =~ /^topic(\s+(.*))?$/i) {
511 return unless (&hasParam("topic"));
513 my $chan = $talkchannel;
514 my @args = split / /, $2 || "";
517 &msg($who,"Try 'help topic'");
521 $chan = lc(shift @args) if ($msgType eq 'private');
522 my $thiscmd = shift @args;
525 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
526 &msg($who, "error: channel argument is not required.");
527 &msg($who, "\002Usage\002: topic <CMD>");
531 # topic over private:
532 if ($msgType eq 'private' && $chan !~ /^#/) {
533 &msg($who, "error: channel argument is required.");
534 &msg($who, "\002Usage\002: topic #channel <CMD>");
538 if (&validChan($chan) == 0) {
539 &msg($who,"error: invalid channel \002$chan\002");
543 # for semi-outsiders.
544 if (!&IsNickInChan($who,$chan)) {
545 &msg($who, "Failed. You ($who) are not in $chan, hey?");
550 &loadMyModule($myModules{'topic'});
551 &Topic($chan, $thiscmd, join(' ', @args));
552 $cmdstats{'Topic'}++;
557 if ($message =~ /^wingate$/i) {
558 return unless (&hasParam("wingate"));
560 my $reply = "Wingate statistics: scanned \002"
561 .scalar(keys %wingate)."\002 hosts";
562 my $queue = scalar(keys %wingateToDo);
564 $reply .= ". I have \002$queue\002 hosts in the queue";
565 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
573 # do nothing and let the other routines have a go
581 if (!defined $query) {
583 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
587 &Freshmeat::Freshmeat($query);
593 &msg($who, "- Uptime for $ident -");
594 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
596 foreach (&uptimeGetInfo()) {
598 my $time = &Time2String($1);
601 &msg($who, "$count: $time $2");
608 my($person) = lc shift;
611 if (!defined $person or $person =~ /^$/) {
614 my $i = &countKeys("seen");
615 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
616 "seen ". &fixPlural("entry",$i) ." that I know of.");
623 &seenFlush(); # very evil hack. oh well, better safe than sorry.
625 # TODO: convert to &sqlSelectRowHash();
626 my $select = "nick,time,channel,host,message";
627 if ($person eq "random") {
628 @seen = &randKey("seen", $select);
630 @seen = &sqlSelect("seen", $select, { nick => $person } );
633 if (scalar @seen < 2) {
635 &DEBUG("seen: _ => '$_'.");
637 &performReply("i haven't seen '$person'");
643 ### TODO: multi channel support. may require &IsNick() to return
644 ### all channels or something.
645 my @chans = &getNickInChans($seen[0]);
647 $reply = "$seen[0] is currently on";
651 next unless (exists $userstats{lc $seen[0]}{'Join'});
652 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
655 if (&IsParam("seenStats")) {
657 $i = $userstats{lc $seen[0]}{'Count'};
658 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
659 $i = $userstats{lc $seen[0]}{'Time'};
660 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
663 my $howlong = &Time2String(time() - $seen[1]);
664 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
665 "in channel $seen[2], $howlong ago, ".
666 "saying\002:\002 '$seen[4]'.";
673 # User Information Services. requested by Flugh.
675 my ($arg) = join(' ',@_);
677 if ($arg =~ /^set(\s+(.*))?$/i) {
680 &help("userinfo set");
684 &UserInfoSet(split /\s+/, $arg, 2);
685 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
688 &help("userinfo unset");
692 &UserInfoSet($arg, "");
698 # cookie (random). xk++
702 # lets find that secret cookie.
703 my $target = ($msgType ne 'public') ? $who : $talkchannel;
704 my $cookiemsg = &getRandom(keys %{ $lang{'cookie'} });
707 ### WILL CHEW TONS OF MEM.
708 ### TODO: convert this to a Forker function!
710 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
711 $key = &getRandom(@list);
712 $value = &getFactInfo($key, "factoid_value");
714 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
718 s/##KEY/\002$key\002/;
721 s/\$who/$who/; # cheap fix.
722 s/(\S+)?\s*<\S+>/$1 /;
726 if ($cookiemsg =~ s/^ACTION //i) {
727 &action($target, $cookiemsg);
729 &msg($target, $cookiemsg);
734 my $arg = join(' ',@_);
735 my ($from,$to) = ('','');
737 ($from,$to) = ($1,$2) if ($arg =~ /^(.*?) to (.*)$/i);
738 ($from,$to) = ($2,$1) if ($arg =~ /^(.*?) from (.*)$/i);
740 if (!$to or !$from) {
741 &msg($who, "Invalid format!");
746 &Units::convertUnits($from, $to);
752 my ($target) = &fixString($_[0]);
754 my $chan = $talkchannel;
756 if ($msgType eq 'private') {
757 if ($target =~ /^($mask{chan})\s+(.*)$/) {
762 &msg($who, "error: invalid format or missing arguments.");
768 my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.lart");
770 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
771 $line =~ s/WHO/$who/g;
773 $line =~ s/WHO/$target/g;
775 $line .= ", courtesy of $who" if ($extra);
777 &action($chan, $line);
779 &status("lart: error reading file?");
784 my $idx = "debian/Packages-sid.idx";
789 $error++ unless ( -e $idx);
790 $error++ unless ( -e "$idx-old");
793 $error = "no sid/sid-old index file found.";
794 &ERROR("Debian: $error");
800 open(IDX2, "$idx-old");
814 next if (exists $pkg{$_});
820 &::pSReply( &::formListReply(0, "New debian packages:", @new) );
826 if (!defined $chan) {
831 if (!&validChan($chan)) {
832 &msg($who, "chan $chan is invalid.");
836 if (scalar @vernick > scalar(keys %{ $channels{lc $chan}{''} })/4) {
837 &msg($who, "verstats already in progress for someone else.");
841 &msg($who, "Sending CTCP VERSION to $chan; results in 60s.");
842 $conn->ctcp("VERSION", $chan);
843 $cache{verstats}{chan} = $chan;
844 $cache{verstats}{who} = $who;
845 $cache{verstats}{msgType} = $msgType;
847 $conn->schedule(30, sub {
848 my $c = lc $cache{verstats}{chan};
851 foreach (keys %{ $channels{$c}{''} } ) {
852 next if (grep /^\Q$_\E$/i, @vernick);
853 push(@vernicktodo, $_);
859 $conn->schedule(60, sub {
861 my $c = lc $cache{verstats}{chan};
862 my $total = keys %{ $channels{$c}{''} };
864 $who = $cache{verstats}{who};
865 $msgType = $cache{verstats}{msgType};
866 delete $cache{verstats}; # sufficient?
868 foreach (keys %ver) {
869 $vtotal += scalar keys %{ $ver{$_} };
873 my $unknown = $total - $vtotal;
874 my $perc = sprintf("%.1f", $unknown * 100 / $total);
876 $sorted{$perc}{"unknown/cloak"} = "$unknown ($perc%)" if ($unknown);
878 foreach (keys %ver) {
879 my $count = scalar keys %{ $ver{$_} };
880 $perc = sprintf("%.01f", $count * 100 / $total);
881 $perc =~ s/.0$//; # lame compression.
883 $sorted{$perc}{$_} = "$count ($perc%)";
886 ### can be compressed to a map?
888 foreach ( sort { $b <=> $a } keys %sorted ) {
890 foreach (sort keys %{ $sorted{$perc} }) {
891 push(@list, "$_ - $sorted{$perc}{$_}");
895 # hack. this is one major downside to scheduling.
897 &pSReply( &formListReply(0, "IRC Client versions for $c ", @list) );
899 # clean up not-needed data structures.
909 last unless (scalar @vernicktodo);
911 my $n = shift(@vernicktodo);
912 $conn->ctcp("VERSION", $n);
915 return unless (scalar @vernicktodo);
917 $conn->schedule(3, \&verstats_flush() );
923 # even more uglier with channel/time arguments.
925 # my $c = $chan || "PRIVATE";
926 &DEBUG("not using chan arg") if (!defined $c);
928 # example of converting from RawReturn to sqlSelect.
929 my $where_href = (defined $c) ? { channel => $c } : "";
930 my $sum = &sqlSelect("stats", "SUM(counter)", $where_href);
932 if (!defined $arg or $arg =~ /^\s*$/) {
933 # this is way fucking ugly.
934 &DEBUG("_stats: !arg");
936 my %hash = &sqlSelectColHash("stats", "nick,counter",
938 " ORDER BY counter DESC LIMIT 3", 1
943 # unfortunately we have to sort it again!
944 # todo: make dbGetCol return hash and array? too much effort.
946 foreach $i (sort { $b <=> $a } keys %hash) {
947 foreach (keys %{ $hash{$i} }) {
948 my $p = sprintf("%.01f", 100*$i/$sum);
950 push(@top, "\002$_\002 -- $i ($p%)");
955 &DEBUG("*stats: tp => $tp");
957 $topstr = ". Top ".scalar(@top).": ".join(', ', @top);
961 &pSReply("total count of \037$type\037 on \002$c\002: $sum$topstr");
963 &pSReply("zero counter for \037$type\037.");
966 my %hash = &sqlSelectColHash("stats", "type,counter",
967 $where_href, " AND nick=".&sqlQuote($arg)
969 # this is totally fucked... needs to be fixed... and cleaned up.
975 foreach (keys %hash) {
976 &DEBUG("_stats: hash{$_} => $hash{$_}");
978 my @array = &sqlSelect("stats", "nick", undef,
979 $where." ORDER BY counter", 1);
982 for(my $i=0; $i<scalar @array; $i++) {
983 next unless ($array[0] =~ /^\Q$who\E$/);
989 $total = scalar(@array);
990 &DEBUG(" i => $i, good => $good, total => $total");
991 $x .= " ".$total."blah blah";
996 if (!defined $x) { # !defined.
997 &pSReply("$arg has not said $type yet.");
1002 if ($total and $good) {
1003 my $pct = sprintf("%.01f", 100*(1+$total-$ii)/$total);
1004 $xtra = ", ranked $ii\002/\002$total (percentile: \002$pct\002 %)";
1007 my $pct1 = sprintf("%.01f", 100*$x/$sum);
1008 &pSReply("\002$arg\002 has said \037$type\037 \002$x\002 times (\002$pct1\002 %)$xtra");
1012 sub nullski { my ($arg) = @_; return unless (defined $arg);
1013 foreach (`$arg`) { &msg($who,$_); } }