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