]> git.donarmstrong.com Git - infobot.git/blob - src/CommandStubs.pl
- use &hasParam() instead of IsChanConf for more commands
[infobot.git] / src / CommandStubs.pl
1 #
2 # User Command Extension Stubs
3 # WARN: this file does not reload on HUP.
4 #
5
6 if (&IsParam("useStrict")) { use strict; }
7
8 $babel_lang_regex = "fr|sp|po|pt|it|ge|de|gr|en";
9
10 ### COMMAND HOOK IMPLEMENTATION.
11 # addCmdHook("SECTION", 'TEXT_HOOK',
12 #       (CODEREF        => 'Blah', 
13 #       Forker          => 1,
14 #       CheckModule     => 1,                   # ???
15 #       Module          => 'blah.pl'            # preload module.
16 #       Identifier      => 'config_label',      # change to Config?
17 #       Help            => 'help_label',
18 #       Cmdstats        => 'text_label',)
19 #}
20 ###
21
22 sub addCmdHook {
23     my ($hashname, $ident, %hash) = @_;
24
25     if (exists ${"hooks_$hashname"}{$ident}) {
26 ###     &WARN("aCH: cmd hooks \%$hashname{$ident} already exists.");
27         return;
28     }
29
30     &VERB("aCH: added $ident",2);       # use $hash{'Identifier'}?
31     ### hrm... prevent warnings?
32     ${"hooks_$hashname"}{$ident} = \%hash;
33 }
34
35 # RUN IF ADDRESSED.
36 sub parseCmdHook {
37     my ($hashname, $line) = @_;
38     $line =~ /^(\S+)( (.*))?$/;
39     my $cmd     = $1;   # command name is whitespaceless.
40     my $flatarg = $3;
41     my @args    = split(/\s+/, $flatarg || '');
42     my $done    = 0;
43
44     &shmFlush();
45
46     if (!defined %{"hooks_$hashname"}) {
47         &WARN("cmd hooks \%$hashname does not exist.");
48         return 0;
49     }
50
51     foreach (keys %{"hooks_$hashname"}) {
52         # rename to something else!
53         my $ident = $_;
54
55         next unless ($cmd =~ /^$ident$/i);
56
57         if ($done) {
58             &WARN("pCH: Multiple hook match: $ident");
59             next;
60         }
61
62         &status("hooks($hashname): $cmd matched '$ident'");
63         my %hash = %{ ${"hooks_$hashname"}{$ident} };
64
65         if (!scalar keys %hash) {
66             &WARN("CmdHook: hash is NULL?");
67             return 1;
68         }
69
70         if ($hash{NoArgs} and $flatarg) {
71             &DEBUG("cmd $ident does not take args; skipping.");
72             next;
73         }
74
75         if (!exists $hash{CODEREF}) {
76             &ERROR("CODEREF undefined for $cmd or $ident.");
77             return 1;
78         }
79
80         ### DEBUG.
81         foreach (keys %hash) {
82             &VERB(" $cmd->$_ => '$hash{$_}'.",2);
83         }
84
85         ### HELP.
86         if (exists $hash{'Help'} and !scalar(@args)) {
87             &help( $hash{'Help'} );
88             return 1;
89         }
90
91         ### IDENTIFIER.
92         if (exists $hash{'Identifier'}) {
93             return 1 unless (&hasParam($hash{'Identifier'}));
94         }
95
96         ### USER FLAGS.
97         if (exists $hash{'UserFlag'}) {
98             return 1 unless (&hasFlag($hash{'UserFlag'}));
99         }
100
101         ### FORKER,IDENTIFIER,CODEREF.
102         if (exists $hash{'Forker'}) {
103             $hash{'Identifier'} .= "-" if ($hash{'Forker'} eq "NULL");
104
105             if (exists $hash{'ArrayArgs'}) {
106                 &Forker($hash{'Identifier'}, sub { \&{ $hash{'CODEREF'} }(@args) } );
107             } else {
108                 &Forker($hash{'Identifier'}, sub { \&{ $hash{'CODEREF'} }($flatarg) } );
109             }
110
111         } else {
112             if (exists $hash{'Module'}) {
113                 &loadMyModule($myModules{ $hash{'Module'} });
114             }
115
116             # check if CODEREF exists.
117             if (!defined &{ $hash{'CODEREF'} }) {
118                 &WARN("coderef $hash{'CODEREF'} don't exist.");
119                 if (defined $who) {
120                     &msg($who, "coderef does not exist for $ident.");
121                 }
122
123                 return 1;
124             }
125
126             if (exists $hash{'ArrayArgs'}) {
127                 &{ $hash{'CODEREF'} }(@args);
128             } else {
129                 &{ $hash{'CODEREF'} }($flatarg);
130             }
131         }
132
133         ### CMDSTATS.
134         if (exists $hash{'Cmdstats'}) {
135             $cmdstats{ $hash{'Cmdstats'} }++;
136         }
137
138         &VERB("hooks: End of command.",2);
139
140         $done = 1;
141     }
142
143     return 1 if ($done);
144     return 0;
145 }
146
147 ###
148 ### START ADDING HOOKS.
149 ###
150 &addCmdHook("extra", 'd?bugs', ('CODEREF' => 'DBugs::Parse',
151         'Forker' => 1, 'Identifier' => 'debianExtra',
152         'Cmdstats' => 'Debian Bugs') );
153 &addCmdHook("extra", 'dauthor', ('CODEREF' => 'Debian::searchAuthor',
154         'Forker' => 1, 'Identifier' => 'debian',
155         'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) );
156 &addCmdHook("extra", '(d|search)desc', ('CODEREF' => 'Debian::searchDescFE',
157         'Forker' => 1, 'Identifier' => 'debian',
158         'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) );
159 &addCmdHook("extra", 'dnew', ('CODEREF' => 'DebianNew',
160         'Identifier' => 'debian' ) );
161 &addCmdHook("extra", 'dincoming', ('CODEREF' => 'Debian::generateIncoming',
162         'Forker' => 1, 'Identifier' => 'debian' ) );
163 &addCmdHook("extra", 'dstats', ('CODEREF' => 'Debian::infoStats',
164         'Forker' => 1, 'Identifier' => 'debian',
165         'Cmdstats' => 'Debian Statistics' ) );
166 &addCmdHook("extra", 'd?contents', ('CODEREF' => 'Debian::searchContents',
167         'Forker' => 1, 'Identifier' => 'debian',
168         'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) );
169 &addCmdHook("extra", 'd?find', ('CODEREF' => 'Debian::DebianFind',
170         'Forker' => 1, 'Identifier' => 'debian',
171         'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
172 &addCmdHook("extra", 'insult', ('CODEREF' => 'Insult::Insult',
173         'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
174 &addCmdHook("extra", 'kernel', ('CODEREF' => 'Kernel::Kernel',
175         'Forker' => 1, 'Identifier' => 'kernel',
176         'Cmdstats' => 'Kernel', 'NoArgs' => 1) );
177 &addCmdHook("extra", 'listauth', ('CODEREF' => 'CmdListAuth',
178         'Identifier' => 'search', Module => 'factoids', 
179         'Help' => 'listauth') );
180 &addCmdHook("extra", 'quote', ('CODEREF' => 'Quote::Quote',
181         'Forker' => 1, 'Identifier' => 'quote',
182         'Help' => 'quote', 'Cmdstats' => 'Quote') );
183 &addCmdHook("extra", 'countdown', ('CODEREF' => 'Countdown',
184         'Module' => 'countdown', 'Identifier' => 'countdown',
185         'Cmdstats' => 'Countdown') );
186 &addCmdHook("extra", 'lart', ('CODEREF' => 'lart',
187         'Identifier' => 'lart', 'Help' => 'lart') );
188 &addCmdHook("extra", 'convert', ('CODEREF' => 'convert',
189         'Forker' => 1, 'Identifier' => 'units',
190         'Help' => 'convert') );
191 &addCmdHook("extra", '(cookie|random)', ('CODEREF' => 'cookie',
192         'Forker' => 1, 'Identifier' => 'factoids') );
193 &addCmdHook("extra", 'u(ser)?info', ('CODEREF' => 'userinfo',
194         'Identifier' => 'userinfo', 'Help' => 'userinfo',
195         'Module' => 'userinfo') );
196 &addCmdHook("extra", 'rootWarn', ('CODEREF' => 'CmdrootWarn',
197         'Identifier' => 'rootWarn', 'Module' => 'rootwarn') );
198 &addCmdHook("extra", 'seen', ('CODEREF' => 'seen', 'Identifier' =>
199         'seen') );
200 &addCmdHook("extra", 'dict', ('CODEREF' => 'Dict::Dict',
201         'Identifier' => 'dict', 'Help' => 'dict',
202         'Forker' => 1, 'Cmdstats' => 'Dict') );
203 &addCmdHook("extra", 'slashdot', ('CODEREF' => 'Slashdot::Slashdot',
204         'Identifier' => 'slashdot', 'Forker' => 1,
205         'Cmdstats' => 'Slashdot') );
206 &addCmdHook("extra", 'uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
207         'Cmdstats' => 'Uptime') );
208 &addCmdHook("extra", 'nullski', ('CODEREF' => 'nullski', ) );
209 &addCmdHook("extra", '(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
210         'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
211         'Forker' => 1, 'Help' => 'freshmeat') );
212 &addCmdHook("extra", 'verstats', ('CODEREF' => 'do_verstats' ) );
213
214 ###
215 ### END OF ADDING HOOKS.
216 ###
217 &status("CMD: loaded ".scalar(keys %hooks_extra)." EXTRA command hooks.");
218
219 sub Modules {
220     if (!defined $message) {
221         &WARN("Modules: message is undefined. should never happen.");
222         return;
223     }
224
225     # babel bot: Jonathan Feinberg++
226     if ($message =~ m{
227                 ^\s*
228                 (?:babel(?:fish)?|x|xlate|translate)
229                 \s+
230                 (to|from)               # direction of translation (through)
231                 \s+
232                 ($babel_lang_regex)\w*  # which language?
233                 \s*
234                 (.+)                    # The phrase to be translated
235     }xoi) {
236         return unless (&hasParam("babelfish"));
237
238         &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
239
240         $cmdstats{'BabelFish'}++;
241         return;
242     }
243
244     my $debiancmd        = 'conflicts?|depends?|desc|file|info|provides?';
245     $debiancmd          .= '|recommends?|suggests?|maint|maintainer';
246
247     if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
248         return unless (&hasParam("debian"));
249         my $package = lc $3;
250
251         if (defined $package) {
252             &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
253         } else {
254             &help($1);
255         }
256
257         return;
258     }
259
260     # google searching. Simon++
261     if ($message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
262         return unless (&hasParam("wwwsearch"));
263
264         &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
265
266         $cmdstats{'WWWSearch'}++;
267         return;
268     }
269
270     # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
271     if ($message =~ /^list(\S+)( (.*))?$/i) {
272         return unless (&hasParam("search"));
273
274         my $thiscmd     = lc($1);
275         my $args        = $3;
276         $args           =~ s/\s+$//g;
277         # suggested by asuffield nad \broken.
278         if ($args =~ /^["']/ and $args =~ /["']$/) {
279             &DEBUG("list*: removed quotes.");
280             $args       =~ s/^["']|["']$//g;
281         }
282
283         $thiscmd =~ s/^vals$/values/;
284         return if ($thiscmd ne "keys" && $thiscmd ne "values");
285
286         # Usage:
287         if (!defined $args) {
288             &help("list". $thiscmd);
289             return;
290         }
291
292         if (length $args == 1) {
293             &msg($who,"search string is too short.");
294             return;
295         }
296
297         &Forker("search", sub { &Search::Search($thiscmd, $args); } );
298
299         $cmdstats{'Factoid Search'}++;
300         return;
301     }
302
303     # Nickometer. Adam Spiers++
304     if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
305         return unless (&hasParam("nickometer"));
306
307         my $term = (lc $1 eq 'me') ? $who : $1;
308
309         &loadMyModule($myModules{'nickometer'});
310
311         if ($term =~ /^$mask{chan}$/) {
312             &status("Doing nickometer for chan $term.");
313
314             if (!&validChan($term)) {
315                 &msg($who, "error: channel is invalid.");
316                 return;
317             }
318
319             # step 1.
320             my %nickometer;
321             foreach (keys %{ $channels{lc $term}{''} }) {
322                 my $str   = $_;
323                 if (!defined $str) {
324                     &WARN("nickometer: nick in chan $term undefined?");
325                     next;
326                 }
327
328                 my $value = &nickometer($str);
329                 $nickometer{$value}{$str} = 1;
330             }
331
332             # step 2.
333             ### TODO: compact with map?
334             my @list;
335             foreach (sort {$b <=> $a} keys %nickometer) {
336                 my $str = join(", ", sort keys %{ $nickometer{$_} });
337                 push(@list, "$str ($_%)");
338             }
339
340             &pSReply( &formListReply(0, "Nickometer list for $term ", @list) );
341             &DEBUG("test.");
342
343             return;
344         }
345
346         my $percentage = &nickometer($term);
347
348         if ($percentage =~ /NaN/) {
349             $percentage = "off the scale";
350         } else {
351             $percentage = sprintf("%0.4f", $percentage);
352             $percentage =~ s/\.?0+$//;
353             $percentage .= '%';
354         }
355
356         if ($msgType eq 'public') {
357             &say("'$term' is $percentage lame, $who");
358         } else {
359             &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
360         }
361
362         return;
363     }
364
365     # Topic management. xk++
366     # may want to add a flag(??) for topic in the near future. -xk
367     if ($message =~ /^topic(\s+(.*))?$/i) {
368         return unless (&hasParam("topic"));
369
370         my $chan        = $talkchannel;
371         my @args        = split / /, $2 || "";
372
373         if (!scalar @args) {
374             &msg($who,"Try 'help topic'");
375             return;
376         }
377
378         $chan           = lc(shift @args) if ($msgType eq 'private');
379         my $thiscmd     = shift @args;
380
381         # topic over public:
382         if ($msgType eq 'public' && $thiscmd =~ /^#/) {
383             &msg($who, "error: channel argument is not required.");
384             &msg($who, "\002Usage\002: topic <CMD>");
385             return;
386         }
387
388         # topic over private:
389         if ($msgType eq 'private' && $chan !~ /^#/) {
390             &msg($who, "error: channel argument is required.");
391             &msg($who, "\002Usage\002: topic #channel <CMD>");
392             return;
393         }
394
395         if (&validChan($chan) == 0) {
396             &msg($who,"error: invalid channel \002$chan\002");
397             return;
398         }
399
400         # for semi-outsiders.
401         if (!&IsNickInChan($who,$chan)) {
402             &msg($who, "Failed. You ($who) are not in $chan, hey?");
403             return;
404         }
405
406         # now lets do it.
407         &loadMyModule($myModules{'topic'});
408         &Topic($chan, $thiscmd, join(' ', @args));
409         $cmdstats{'Topic'}++;
410         return;
411     }
412
413     # wingate.
414     if ($message =~ /^wingate$/i) {
415         return unless (&hasParam("wingate"));
416
417         my $reply = "Wingate statistics: scanned \002"
418                         .scalar(keys %wingate)."\002 hosts";
419         my $queue = scalar(keys %wingateToDo);
420         if ($queue) {
421             $reply .= ".  I have \002$queue\002 hosts in the queue";
422             $reply .= ".  Started the scan ".&Time2String(time() - $wingaterun)." ago";
423         }
424
425         &performStrictReply("$reply.");
426
427         return;
428     }
429
430     # do nothing and let the other routines have a go
431     return "CONTINUE";
432 }
433
434 # Freshmeat. xk++
435 sub freshmeat {
436     my ($query) = @_;
437
438     if (!defined $query) {
439         &help("freshmeat");
440         &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
441         return;
442     }
443
444     &Freshmeat::Freshmeat($query);
445 }
446
447 # Uptime. xk++
448 sub uptime {
449     my $count = 1;
450     &msg($who, "- Uptime for $ident -");
451     &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
452
453     foreach (&uptimeGetInfo()) {
454         /^(\d+)\.\d+ (.*)/;
455         my $time = &Time2String($1);
456         my $info = $2;
457
458         &msg($who, "$count: $time $2");
459         $count++;
460     }
461 }
462
463 # seen.
464 sub seen {
465     my($person) = @_;
466
467     if (!defined $person or $person =~ /^$/) {
468         &help("seen");
469
470         my $i = &countKeys("seen");
471         &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
472                 "seen ". &fixPlural("entry",$i) ." that I know of.");
473
474         return;
475     }
476
477     my @seen;
478     $person =~ s/\?*$//;
479
480     &seenFlush();       # very evil hack. oh well, better safe than sorry.
481
482     ### TODO: Support &dbGetColInfo(); like in &FactInfo();
483     my $select = "nick,time,channel,host,message";
484     if ($person eq "random") {
485         @seen = &randKey("seen", $select);
486     } else {
487         @seen = &dbGet("seen", "nick", $person, $select);
488     }
489
490     if (scalar @seen < 2) {
491         foreach (@seen) {
492             &DEBUG("seen: _ => '$_'.");
493         }
494         &performReply("i haven't seen '$person'");
495         return;
496     }
497
498     # valid seen.
499     my $reply;
500     ### TODO: multi channel support. may require &IsNick() to return
501     ### all channels or something.
502     my @chans = &getNickInChans($seen[0]);
503     if (scalar @chans) {
504         $reply = "$seen[0] is currently on";
505
506         foreach (@chans) {
507             $reply .= " ".$_;
508             next unless (exists $userstats{lc $seen[0]}{'Join'});
509             $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
510         }
511
512         if (&IsParam("seenStats")) {
513             my $i;
514             $i = $userstats{lc $seen[0]}{'Count'};
515             $reply .= ".  Has said a total of \002$i\002 messages" if (defined $i);
516             $i = $userstats{lc $seen[0]}{'Time'};
517             $reply .= ".  Is idling for ".&Time2String(time() - $i) if (defined $i);
518         }
519     } else {
520         my $howlong = &Time2String(time() - $seen[1]);
521         $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
522                  "in channel $seen[2], $howlong ago, ".
523                  "saying\002:\002 '$seen[4]'.";
524     }
525
526     &performStrictReply($reply);
527     return;
528 }
529
530 # User Information Services. requested by Flugh.
531 sub userinfo {
532     my ($arg) = join(' ',@_);
533
534     if ($arg =~ /^set(\s+(.*))?$/i) {
535         $arg = $2;
536         if (!defined $arg) {
537             &help("userinfo set");
538             return;
539         }
540
541         &UserInfoSet(split /\s+/, $arg, 2);
542     } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
543         $arg = $2;
544         if (!defined $arg) {
545             &help("userinfo unset");
546             return;
547         }
548
549         &UserInfoSet($arg, "");
550     } else {
551         &UserInfoGet($arg);
552     }
553 }
554
555 # cookie (random). xk++
556 sub cookie {
557     my ($arg) = @_;
558
559     # lets find that secret cookie.
560     my $target          = ($msgType ne 'public') ? $who : $talkchannel;
561     my $cookiemsg       = &getRandom(keys %{ $lang{'cookie'} });
562     my ($key,$value);
563
564     ### WILL CHEW TONS OF MEM.
565     ### TODO: convert this to a Forker function!
566     if ($arg) {
567         my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
568         $key  = &getRandom(@list);
569         $val  = &getFactInfo("factoids", $key, "factoid_value");
570     } else {
571         ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
572     }
573
574     for ($cookiemsg) {
575         s/##KEY/\002$key\002/;
576         s/##VALUE/$value/;
577         s/##WHO/$who/;
578         s/\$who/$who/;  # cheap fix.
579         s/(\S+)?\s*<\S+>/$1 /;
580         s/\s+/ /g;
581     }
582
583     if ($cookiemsg =~ s/^ACTION //i) {
584         &action($target, $cookiemsg);
585     } else {
586         &msg($target, $cookiemsg);
587     }
588 }
589
590 sub convert {
591     my $arg = join(' ',@_);
592     my ($from,$to) = ('','');
593
594     ($from,$to) = ($1,$2) if ($arg =~ /^(.*?) to (.*)$/i);
595     ($from,$to) = ($2,$1) if ($arg =~ /^(.*?) from (.*)$/i);
596
597     if (!$to or !$from) {
598         &msg($who, "Invalid format!");
599         &help("convert");
600         return;
601     }
602
603     &Units::convertUnits($from, $to);
604
605     return;
606 }
607
608 sub lart {
609     my ($target) = &fixString($_[0]);
610     my $extra   = 0;
611     my $chan    = $talkchannel;
612
613     if ($msgType eq 'private') {
614         if ($target =~ /^($mask{chan})\s+(.*)$/) {
615             $chan       = $1;
616             $target     = $2;
617             $extra      = 1;
618         } else {
619             &msg($who, "error: invalid format or missing arguments.");
620             &help("lart");
621             return;
622         }
623     }
624
625     my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
626     if (defined $line) {
627         if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
628             $line =~ s/WHO/$who/g;
629         } else {
630             $line =~ s/WHO/$target/g;
631         }
632         $line .= ", courtesy of $who" if ($extra);
633
634         &action($chan, $line);
635     } else {
636         &status("lart: error reading file?");
637     }
638 }
639
640 sub DebianNew {
641     my $idx   = "debian/Packages-woody.idx";
642     my $error = 0;
643     my %pkg;
644     my @new;
645
646     $error++ unless ( -e $idx);
647     $error++ unless ( -e "$idx-old");
648
649     if ($error) {
650         $error = "no woody/woody-old index file found.";
651         &ERROR("Debian: $error");
652         &msg($who, $error);
653         return;
654     }
655
656     open(IDX1, $idx);
657     open(IDX2, "$idx-old");
658
659     while (<IDX2>) {
660         chop;
661         next if (/^\*/);
662
663         $pkg{$_} = 1;
664     }
665     close IDX2;
666
667     open(IDX1,$idx);
668     while (<IDX1>) {
669         chop;
670         next if (/^\*/);
671         next if (exists $pkg{$_});
672
673         push(@new);
674     }
675     close IDX1;
676
677     &::performStrictReply( &::formListReply(0, "New debian packages:", @new) );
678 }
679
680 sub do_verstats {
681     my ($chan)  = @_;
682
683     if (!defined $chan) {
684         &help("verstats");
685         return;
686     }
687
688     if (!&validChan($chan)) {
689         &msg($who, "chan $chan is invalid.");
690         return;
691     }
692
693     if (scalar @vernick > scalar(keys %{ $channels{lc $chan}{''} })/4) {
694         &msg($who, "verstats already in progress for someone else.");
695         return;
696     }
697
698     &msg($who, "Sending CTCP VERSION...");
699     $conn->ctcp("VERSION", $chan);
700     $cache{verstats}{chan}      = $chan;
701     $cache{verstats}{who}       = $who;
702     $cache{verstats}{msgType}   = $msgType;
703
704     $conn->schedule(60, sub {
705         my $vtotal      = 0;
706         my $c           = lc $cache{verstats}{chan};
707         my $total       = keys %{ $channels{$c}{''} };
708         $chan           = $c;
709         $who            = $cache{verstats}{who};
710         $msgType        = $cache{verstats}{msgType};
711         delete $cache{verstats};        # sufficient?
712
713         foreach (keys %ver) {
714             $vtotal     += scalar keys %{ $ver{$_} };
715         }
716
717         my %sorted;
718         my $unknown     = $total - $vtotal;
719         my $perc        = sprintf("%.1f", $unknown * 100 / $total);
720         $perc           =~ s/.0$//;
721         $sorted{$perc}{"unknown/cloak"} = "$unknown ($perc%)";
722
723         foreach (keys %ver) {
724             my $count   = scalar keys %{ $ver{$_} };
725             $perc       = sprintf("%.01f", $count * 100 / $total);
726             $perc       =~ s/.0$//;     # lame compression.
727
728             $sorted{$perc}{$_} = "$count ($perc%)";
729         }
730
731         ### can be compressed to a map?
732         my @list;
733         foreach ( sort { $b <=> $a } keys %sorted ) {
734             my $perc = $_;
735             foreach (sort keys %{ $sorted{$perc} }) {
736                 push(@list, "$_ - $sorted{$perc}{$_}");
737             }
738         }
739
740         &pSReply( &formListReply(0, "IRC Client versions for $c ", @list) );
741
742         # clean up not-needed data structures.
743         undef %ver;
744         undef @vernick;
745     } );
746
747     return;
748 }
749
750 sub nullski { my ($arg) = @_; return unless (defined $arg);
751         foreach (`$arg`) { &msg($who,$_); } }
752
753 1;