]> git.donarmstrong.com Git - infobot.git/blob - src/UserExtra.pl
- updated apt's source to cvs, undefined values here and there popped
[infobot.git] / src / UserExtra.pl
1 #
2 # UserExtra.pl: User Commands, Public.
3 #       Author: dms
4 #      Version: v0.2b (20000707)
5 #      Created: 20000107
6 #
7
8 #use strict;
9 use vars qw($message $arg $qWord $verb $lobotomized);
10 use vars qw(%channels %chanstats %cmdstats);
11
12 ###
13 ### Start of command hooks for UserExtra.
14 ###
15
16 &addCmdHook("main", 'chan(stats|info)', ('CODEREF' => 'chaninfo', ) );
17 &addCmdHook("main", 'cmd(stats|info)', ('CODEREF' => 'cmdstats', ) );
18 &addCmdHook("main", 'factinfo', ('CODEREF' => 'factinfo', 
19         'Cmdstats' => 'Factoid Info', Module => 'factoids', ) );
20 &addCmdHook("main", 'factstats?', ('CODEREF' => 'factstats', 
21         'Cmdstats' => 'Factoid Statistics', Help => "factstats", 
22         Forker => 1, 'Identifier' => 'factoids', ) );
23 &addCmdHook("main", 'help', ('CODEREF' => 'help', 
24         'Cmdstats' => 'Help', ) );
25 &addCmdHook("main", 'karma', ('CODEREF' => 'karma', ) );
26 &addCmdHook("main", 'i?spell', ('CODEREF' => 'ispell', 
27         Help => 'spell', Identifier => 'spell', ) );
28 &addCmdHook("main", 'd?nslookup', ('CODEREF' => 'DNS', 
29         Help => 'nslookup', Identifier => 'allowDNS',
30         Forker => "NULL", ) );
31 &addCmdHook("main", 'tell|explain', ('CODEREF' => 'tell', 
32         Help => 'tell', Identifier => 'allowTelling',
33         Cmdstats => 'Tell') );
34 &addCmdHook("main", 'news', ('CODEREF' => 'News::Parse', 
35         Module => 'news', 'Cmdstats' => 'News' ) );
36 &addCmdHook("main", 'countrystats', ('CODEREF' => 'countryStats', 
37 #       Forker => "NULL",
38  ) );
39
40 &status("CMD: loaded ".scalar(keys %hooks_main)." MAIN command hooks.");
41
42 ###
43 ### Start of commands for hooks.
44 ###
45
46 sub chaninfo {
47     my $chan = lc shift(@_);
48     my $mode;
49
50     if ($chan eq "") {          # all channels.
51         my $i           = keys %channels;
52         my $reply       = "i am on \002$i\002 ".&fixPlural("channel",$i);
53         my $tucount     = 0;    # total user count.
54         my $uucount     = 0;    # unique user count.
55         my @array;
56
57         ### line 1.
58         foreach (sort keys %channels) {
59             if (/^\s*$/ or / /) {
60                 &status("chanstats: fe channels: chan == NULL.");
61                 &ircCheck();
62                 next;
63             }
64             push(@array, "$_ (".scalar(keys %{ $channels{$_}{''} }).")");
65         }
66         &pSReply($reply.": ".join(' ', @array));
67
68         ### total user count.
69         foreach $chan (keys %channels) {
70             $tucount += scalar(keys %{ $channels{$chan}{''} });
71         }
72
73         ### unique user count.
74         my @nicks;
75         foreach $chan (keys %channels) {
76             foreach (keys %{ $channels{$chan}{''} }) {
77                 next if (grep /^\Q$_\E$/, @nicks);
78                 $uucount++;
79                 push(@nicks, $_);
80             }
81         }
82         &DEBUG("nicks => '".scalar(@nicks)."'...");
83         if (scalar @nicks != $uucount) {
84             &DEBUG("nicks != uucount...");
85         }
86
87         my $chans = scalar(keys %channels);
88         &pSReply(
89             "i've cached \002$tucount\002 ". &fixPlural("user",$tucount).
90             ", \002$uucount\002 unique ". &fixPlural("user",$uucount).
91             ", distributed over \002$chans\002 ".
92             &fixPlural("channel", $chans)."."
93         );
94
95         return;
96     }
97
98     # channel specific.
99
100     if (&validChan($chan) == 0) {
101         &msg($who,"error: invalid channel \002$chan\002");
102         return;
103     }
104
105     # Step 1:
106     my @array;
107     foreach (sort keys %{ $chanstats{$chan} }) {
108         my $int = $chanstats{$chan}{$_};
109         next unless ($int);
110
111         push(@array, "\002$int\002 ". &fixPlural($_,$int));
112     }
113     my $reply = "On \002$chan\002, there ".
114                 &fixPlural("has",scalar(@array)). " been ".
115                 &IJoin(@array);
116
117     # Step 1b: check channel inconstencies.
118     $chanstats{$chan}{'Join'}           ||= 0;
119     $chanstats{$chan}{'SignOff'}        ||= 0;
120     $chanstats{$chan}{'Part'}           ||= 0;
121
122     my $delta_stats = $chanstats{$chan}{'Join'}
123                 - $chanstats{$chan}{'SignOff'}
124                 - $chanstats{$chan}{'Part'};
125
126     if ($delta_stats) {
127         my $total = scalar(keys %{ $channels{$chan}{''} });
128         &status("chaninfo: join ~= signoff + part (drift of $delta_stats < $total).");
129
130         if ($delta_stats > $total) {
131             &ERROR("chaninfo: delta_stats exceeds total users.");
132         }
133     }
134
135     # Step 2:
136     undef @array;
137     my $type;
138     foreach ("v","o","") {
139         my $int = scalar(keys %{ $channels{$chan}{$_} });
140         next unless ($int);
141
142         $type = "Voice" if ($_ eq "v");
143         $type = "Opped" if ($_ eq "o");
144         $type = "Total" if ($_ eq "");
145
146         push(@array,"\002$int\002 $type");
147     }
148     $reply .= ".  At the moment, ". &IJoin(@array);
149
150     # Step 3:
151     my %new;
152     foreach (keys %userstats) {
153         next unless (exists $userstats{$_}{'Count'});
154         if ($userstats{$_}{'Count'} =~ /^\D+$/) {
155             &WARN("userstats{$_}{Count} is non-digit.");
156             next;
157         }
158
159         $new{$_} = $userstats{$_}{'Count'};
160     }
161
162     # todo: show top 3 with percentages?
163     my($count) = (sort { $new{$a} <=> $new{$b} } keys %new)[0];
164     if ($count) {
165         $reply .= ".  \002$count\002 has said the most with a total of \002$new{$count}\002 messages";
166     }
167     &pSReply("$reply.");
168 }
169
170 # Command statistics.
171 sub cmdstats {
172     my @array;
173
174     if (!scalar(keys %cmdstats)) {
175         &performReply("no-one has run any commands yet");
176         return;
177     }
178
179     my %countstats;
180     foreach (keys %cmdstats) {
181         $countstats{ $cmdstats{$_} }{$_} = 1;
182     }
183
184     foreach (sort {$b <=> $a} keys %countstats) {
185         my $int = $_;
186         next unless ($int);
187
188         foreach (keys %{ $countstats{$int} }) {
189             push(@array, "\002$int\002 of $_");
190         }
191     }
192     &pSReply("command usage include ". &IJoin(@array).".");
193 }
194
195 # Factoid extension info. xk++
196 sub factinfo {
197     my $faqtoid = lc shift(@_);
198     my $query   = "";
199
200     if ($faqtoid =~ /^\-(\S+)(\s+(.*))$/) {
201         &msg($who,"error: individual factoid info queries not supported as yet.");
202         &msg($who,"it's possible that the factoid mistakenly begins with '-'.");
203         return;
204
205         $query   = lc $1;
206         $faqtoid = lc $3;
207     }
208
209     &CmdFactInfo($faqtoid, $query);
210 }
211
212 sub factstats {
213     my $type = shift(@_);
214
215     &Forker("factoids", sub {
216         &pSReply( &CmdFactStats($type) );
217     } );
218 }
219
220 sub karma {
221     my $target  = lc( shift || $who );
222     my $karma   = &dbGet("stats", "counter", "nick=".
223                         &dbQuote($target)." AND type='karma'") || 0; 
224
225     if ($karma != 0) {
226         &pSReply("$target has karma of $karma");
227     } else {
228         &pSReply("$target has neutral karma");
229     }
230 }
231
232 sub ispell {
233     my $query = shift;
234
235     if (! -x "/usr/bin/ispell") {
236         &msg($who, "no binary found.");
237         return;
238     }
239
240     if (!&validExec($query)) {
241         &msg($who,"argument appears to be fuzzy.");
242         return;
243     }
244
245     my $reply = "I can't find alternate spellings for '$query'";
246
247     foreach (`/bin/echo '$query' | /usr/bin/ispell -a -S`) {
248         chop;
249         last if !length;                # end of query.
250
251         if (/^\@/) {            # intro line.
252             next;
253         } elsif (/^\*/) {               # possibly correct.
254             $reply = "'$query' may be spelled correctly";
255             last;
256         } elsif (/^\&/) {               # possible correction(s).
257             s/^\& (\S+) \d+ \d+: //;
258             my @array = split(/,? /);
259
260             $reply = "possible spellings for $query: @array";
261             last;
262         } elsif (/^\+/) {
263             &DEBUG("spell: '+' found => '$_'.");
264             last;
265         } elsif (/^# (.*?) 0$/) {
266             # none found.
267             last;
268         } else {
269             &DEBUG("spell: unknown: '$_'.");
270         }
271     }
272
273     &pSReply($reply);
274 }
275
276 sub nslookup {
277     my $query = shift;
278     &status("DNS Lookup: $query");
279     &DNS($query);
280 }
281
282 sub tell {
283     my $args = shift;
284     my ($target, $tell_obj) = ('','');
285     my $dont_tell_me    = 0;
286     my $reply;
287
288     ### is this fixed elsewhere?
289     $args =~ s/\s+/ /g;         # fix up spaces.
290     $args =~ s/^\s+|\s+$//g;    # again.
291
292     # this one catches most of them
293     if ($args =~ /^(\S+) (-?)about (.*)$/i) {
294         $target         = $1;
295         $tell_obj       = $3;
296         $dont_tell_me   = ($2) ? 1 : 0;
297
298         $tell_obj       = $who  if ($tell_obj =~ /^(me|myself)$/i);
299         $query          = $tell_obj;
300     } elsif ($args =~ /^(\S+) where (\S+) can (\S+) (.*)$/i) {
301         # i'm sure this could all be nicely collapsed
302         $target         = $1;
303         $tell_obj       = $4;
304         $query          = $tell_obj;
305
306     } elsif ($args =~ /^(\S+) (what|where) (.*?) (is|are)[.?!]*$/i) {
307         $target         = $1;
308         $qWord          = $2;
309         $tell_obj       = $3;
310         $verb           = $4;
311         $query          = "$qWord $verb $tell_obj";
312
313     } elsif ($args =~ /^(.*?) to (\S+)$/i) {
314         $target         = $3;
315         $tell_obj       = $2;
316         $query          = $tell_obj;
317     }
318
319     # check target type. Deny channel targets.
320     if ($target !~ /^$mask{nick}$/ or $target =~ /^$mask{chan}$/) {
321         &msg($who,"No, $who, I won't. (target invalid?)");
322         return;
323     }
324
325     $target     = $talkchannel  if ($target =~ /^us$/i);
326     $target     = $who          if ($target =~ /^(me|myself)$/i);
327
328     &status("tell: target = $target, query = $query");  
329
330     # "intrusive".
331 #    if ($target !~ /^$mask{chan}$/ and !&IsNickInAnyChan($target)) {
332 #       &msg($who, "No, $target is not in any of my chans.");
333 #       return;
334 #    }
335
336     # self.
337     if ($target =~  /^\Q$ident\E$/i) {
338         &msg($who, "Isn't that a bit silly?");
339         return;
340     }
341
342     my $oldwho          = $who;
343     my $oldmtype        = $msgType;
344     $who                = $target;
345     my $result = &doQuestion($tell_obj);
346         # ^ returns '0' if nothing was found.
347     $who                = $oldwho;
348
349     # no such factoid.
350     if (!defined $result || $result =~ /^0?$/) {
351         $who            = $target;
352         $msgType        = "private";
353
354         # support command redirection.
355         # recursive cmdHooks aswell :)
356         my $done = 0;
357         $done++ if &parseCmdHook("main", $tell_obj);
358         $done++ if &parseCmdHook("extra", $tell_obj);
359         $message        = $tell_obj;
360         $done++ unless (&Modules());
361
362         &VERB("tell: setting old values of who and msgType.",2);
363         $who            = $oldwho;
364         $msgType        = $oldmtype;
365
366         if ($done) {
367             &msg($who, "told $target about CMD '$tell_obj'");
368         } else {
369             &msg($who, "i dunno what is '$tell_obj'.");
370         }
371
372         return;
373     }
374
375     # success.
376     &status("tell: <$who> telling $target about $tell_obj.");
377     if ($who ne $target) {
378         if ($dont_tell_me) {
379             &msg($who, "told $target about $tell_obj.");
380         } else {
381             &msg($who, "told $target about $tell_obj ($result)");
382         }
383
384         $reply = "$who wants you to know: $result";
385     } else {
386         $reply = "telling yourself: $result";
387     }
388
389     &msg($target, $reply);
390 }
391
392 sub DNS {
393     my $dns = shift;
394     my($match, $x, $y, $result);
395     my $pid;
396     $dns =~ s/^\s+|\s+$//g;
397
398     if (!defined $dns or $dns =~ /^\s*$/ or $dns =~ / /) {
399         &help("dns");
400         return;
401     }
402
403     if ($dns =~ /(\d+\.\d+\.\d+\.\d+)/) {
404         $match = $1;
405         &status("DNS query by IP address: $match");
406
407         $y = pack('C4', split(/\./, $match));
408         $x = (gethostbyaddr($y, &AF_INET));
409
410         if ($x !~ /^\s*$/) {
411             $result = $match." is ".$x unless ($x =~ /^\s*$/);
412         } else {
413             $result = "I can't seem to find that address in DNS";
414         }
415
416     } else {
417
418         &status("DNS query by name: $dns");
419         $x = join('.',unpack('C4',(gethostbyname($dns))[4]));
420
421         if ($x !~ /^\s*$/) {
422             $result = $dns." is ".$x;
423         } else {
424             $result = "I can\'t find that machine name";
425         }
426     }
427
428     &performReply($result);
429 }
430
431 sub countryStats {
432     if (exists $cache{countryStats}) {
433         &msg($who,"countrystats is already running!");
434         return;
435     }
436
437     if ($chan eq "") {
438         $chan = $_[0];
439     }
440
441     if ($chan eq "") {
442         &help("countrystats");
443         return;
444     }
445
446     $conn->who($chan);
447     $cache{countryStats}{chan}  = $chan;
448     $cache{countryStats}{mtype} = $msgType;
449     $cache{countryStats}{who}   = $who;
450     $cache{on_who_Hack}         = 1;
451 }
452
453 sub do_countrystats {
454     $chan       = $cache{countryStats}{chan};
455     $msgType    = $cache{countryStats}{mtype};
456     $who        = $cache{countryStats}{who};
457
458     my $total   = 0;
459     my %cstats;
460     foreach (keys %{ $cache{nuhInfo} }) {
461         my $h = $cache{nuhInfo}{$_}{Host};
462
463         if ($h =~ /^.*\.(\D+)$/) {      # host
464             $cstats{$1}++;
465         } else {                        # ip
466             $cstats{unresolve}++;
467         }
468         $total++;
469     }
470     my %count;
471     foreach (keys %cstats) {
472         $count{ $cstats{$_} }{$_} = 1;
473     }
474
475     my @list;
476     foreach (sort {$b <=> $a} keys %count) {
477         my $str = join(", ", sort keys %{ $count{$_} });
478 #       push(@list, "$str ($_)");
479         my $perc        = sprintf("%.01f", 100 * $_ / $total);
480         $perc           =~ s/\.0+$//;
481         push(@list, "$str ($_, $perc %)");
482     }
483
484     # todo: move this into a scheduler like nickometer
485     $msgType    = "private";
486     &pSReply( &formListReply(0, "Country Stats ", @list) );
487
488     delete $cache{countryStats};
489     delete $cache{on_who_Hack};
490 }
491
492 ###
493 ### amalgamated commands.
494 ###
495
496 sub userCommands {
497     # conversion: ascii.
498     if ($message =~ /^(asci*|chr) (\d+)$/) {
499         &DEBUG("ascii/chr called ...");
500         return unless (&hasParam("allowConv"));
501
502         &DEBUG("ascii/chr called");
503
504         $arg    = $2;
505         $result = chr($arg);
506         $result = "NULL"        if ($arg == 0);
507
508         &performReply( sprintf("ascii %s is '%s'", $arg, $result) );
509
510         return;
511     }
512
513     # conversion: ord.
514     if ($message =~ /^ord(\s+(.*))$/) {
515         return unless (&hasParam("allowConv"));
516
517         $arg = $2;
518
519         if (!defined $arg or length $arg != 1) {
520             &help("ord");
521             return;
522         }
523
524         if (ord($arg) < 32) {
525             $arg = chr(ord($arg) + 64);
526             if ($arg eq chr(64)) {
527                 $arg = 'NULL';
528             } else {
529                 $arg = '^'.$arg;
530             }
531         }
532
533         &performReply( sprintf("'%s' is ascii %s", $arg, ord $1) );
534         return;
535     }
536
537     # hex.
538     if ($message =~ /^hex(\s+(.*))?$/i) {
539         return unless (&hasParam("allowConv"));
540         my $arg = $2;
541
542         if (!defined $arg) {
543             &help("hex");
544             return;
545         }
546
547         if (length $arg > 80) {
548             &msg($who, "Too long.");
549             return;
550         }
551
552         my $retval;
553         foreach (split //, $arg) {
554             $retval .= sprintf(" %X", ord($_));
555         }
556
557         &pSReply("$arg is$retval");
558
559         return;
560     }
561
562     # crypt.
563     if ($message =~ /^crypt(\s+(.*))?$/i) {
564         my @args        = split /\s+/, $2;
565
566         if (!scalar @args or scalar @args > 2) {
567             &help("crypt");
568             return;
569         }
570
571         if (scalar @args == 2) {
572             if (length $args[0] != 2) {
573                 &msg($who, "invalid format...");
574                 return;
575             }
576
577             &pSReply( crypt($args[1], $args[0]) );
578         } else {
579             &pSReply( &mkcrypt($args[0]) );
580         }
581
582         return;
583     }
584
585     # cycle.
586     if ($message =~ /^(cycle)(\s+(\S+))?$/i) {
587         return unless (&hasFlag("o"));
588         my $chan = lc $3;
589
590         if ($chan eq "") {
591             if ($msgType =~ /public/) {
592                 $chan = $talkchannel;
593                 &DEBUG("cycle: setting chan to '$chan'.");
594             } else {
595                 &help("cycle");
596                 return;
597             }
598         }
599
600         if (&validChan($chan) == 0) {
601             &msg($who,"error: invalid channel \002$chan\002");
602             return;
603         }
604
605         &msg($chan, "I'm coming back. (courtesy of $who)");
606         &part($chan);
607 ###     &ScheduleThis(5, "getNickInUse") if (@_);
608         &status("Schedule rejoin in 5secs to $chan by $who.");
609         $conn->schedule(5, sub { &joinchan($chan); });
610
611         return;
612     }
613
614     # reload.
615     if ($message =~ /^reload$/i) {
616         return unless (&hasFlag("n"));
617
618         &status("USER reload $who");
619         &pSReply("reloading...");
620         &reloadAllModules();
621         &pSReply("reloaded.");
622         return;
623     }
624
625     # redir.
626     if ($message =~ /^redir(\s+(.*))?/i) {
627         return unless (&hasFlag("o"));
628         my $factoid = $2;
629
630         if (!defined $factoid) {
631             &help("redir");
632             return;
633         }
634
635         my $val  = &getFactInfo($factoid, "factoid_value");
636         if (!defined $val or $val eq "") {
637             &msg($who, "error: '$factoid' does not exist.");
638             return;
639         }
640         &DEBUG("val => '$val'.");
641         my @list = &searchTable("factoids", "factoid_key",
642                                         "factoid_value", "^$val\$");
643
644         if (scalar @list == 1) {
645             &msg($who, "hrm... '$factoid' is unique.");
646             return;
647         }
648         if (scalar @list > 5) {
649             &msg($who, "A bit too many factoids to be redirected, hey?");
650             return;
651         }
652
653         my @redir;
654         &status("Redirect '$factoid' (". ($#list) .")...");
655         for (@list) {
656             my $x = $_;
657             next if (/^\Q$factoid\E$/i);
658
659             &status("  Redirecting '$_'.");
660             my $was = &getFactoid($_);
661             if ($was =~ /<REPLY> see/i) {
662                 &status("warn: not redirecting a redirection.");
663                 next;
664             }
665
666             &DEBUG("  was '$was'.");
667             push(@redir,$x);
668             &setFactInfo($x, "factoid_value", "<REPLY> see $factoid");
669         }
670         &status("Done.");
671
672         &msg($who, &formListReply(0, "'$factoid' is redirected to by '", @redir));
673
674         return;
675     }
676
677     # rot13 it.
678     if ($message =~ /^rot13(\s+(.*))?/i) {
679         my $reply = $2;
680
681         if (!defined $reply) {
682             &help("rot13");
683             return;
684         }
685
686         $reply =~ y/A-Za-z/N-ZA-Mn-za-m/;
687         &pSReply($reply);
688
689         return;
690     }
691
692     # cpustats.
693     if ($message =~ /^cpustats$/i) {
694         if ($^O !~ /linux/) {
695             &ERROR("cpustats: your OS is not supported yet.");
696             return;
697         }
698
699         ### poor method to get info out of file, please fix.
700         open(STAT,"/proc/$$/stat");
701         my $line = <STAT>;
702         chop $line;
703         my @data = split(/ /, $line);
704         close STAT;
705
706         # utime(13) + stime(14).
707         my $cpu_usage   = sprintf("%.01f", ($data[13]+$data[14]) / 100 );
708         # cutime(15) + cstime (16).
709         my $cpu_usage2  = sprintf("%.01f", ($data[15]+$data[16]) / 100 );
710         my $time        = time() - $^T;
711         my $raw_perc    = $cpu_usage*100/$time;
712         my $raw_perc2   = $cpu_usage2*100/$time;
713         my $perc;
714         my $perc2;
715         my $total;
716         my $ratio;
717
718         if ($raw_perc > 1) {
719             $perc       = sprintf("%.01f", $raw_perc);
720             $perc2      = sprintf("%.01f", $raw_perc2);
721             $total      = sprintf("%.01f", $raw_perc+$raw_perc2);
722         } elsif ($raw_perc > 0.1) {
723             $perc       = sprintf("%.02f", $raw_perc);
724             $perc2      = sprintf("%.02f", $raw_perc2);
725             $total      = sprintf("%.02f", $raw_perc+$raw_perc2);
726         } else {                        # <=0.1
727             $perc       = sprintf("%.03f", $raw_perc);
728             $perc2      = sprintf("%.03f", $raw_perc2);
729             $total      = sprintf("%.03f", $raw_perc+$raw_perc2);
730         }
731         $ratio  = sprintf("%.01f", 100*$perc/($perc+$perc2) );
732
733         &pSReply("Total CPU usage: \002$cpu_usage\002 s ... ".
734                 "Total used: \002$total\002 % ".
735                 "(parent/child ratio: $ratio %)"
736         );
737
738         return;
739     }
740
741     # ircstats.
742     if ($message =~ /^ircstats?$/i) {
743         $ircstats{'TotalTime'}  ||= 0;
744         $ircstats{'OffTime'}    ||= 0;
745
746         my $count       = $ircstats{'ConnectCount'};
747         my $format_time = &Time2String(time() - $ircstats{'ConnectTime'});
748         my $total_time  = time() - $ircstats{'ConnectTime'} +
749                                 $ircstats{'TotalTime'};
750         my $reply;
751
752         my $connectivity = 100 * ($total_time - $ircstats{'OffTime'}) /
753                                 $total_time;
754         my $p = sprintf("%.03f", $connectivity);
755         $p =~ s/(\.\d*)0+$/$1/;
756         if ($p =~ s/\.0$//) {
757             # this should not happen... but why...
758         } else {
759             $p =~ s/\.$//
760         }
761
762         if ($total_time != (time() - $ircstats{'ConnectTime'}) ) {
763             my $tt_format = &Time2String($total_time);
764             &DEBUG("tt_format => $tt_format");
765         }
766
767         ### RECONNECT COUNT.
768         if ($count == 1) {      # good.
769             $reply = "I'm connected to $ircstats{'Server'} and have been so".
770                 " for $format_time";
771         } else {
772             $reply = "Currently I'm hooked up to $ircstats{'Server'} but only".
773                 " for $format_time.  ".
774                 "I had to reconnect \002$count\002 times.".
775                 "   Connectivity: $p %";
776         }
777
778         ### REASON.
779         my $reason = $ircstats{'DisconnectReason'};
780         if (defined $reason) {
781             $reply .= ".  I was last disconnected for '$reason'.";
782         }
783
784         &pSReply($reply);
785                 
786         return;
787     }
788
789     # status.
790     if ($message =~ /^statu?s$/i) {
791         my $startString = scalar(localtime $^T);
792         my $upString    = &Time2String(time() - $^T);
793         my $count       = &countKeys("factoids");
794
795         $count{'Commands'}      = 0;
796         foreach (keys %cmdstats) {
797             $count{'Commands'} += $cmdstats{$_};
798         }
799
800         &pSReply(
801         "Since $startString, there have been".
802           " \002$count{'Update'}\002 ".
803                 &fixPlural("modification", $count{'Update'}).
804           " and \002$count{'Question'}\002 ".
805                 &fixPlural("question",$count{'Question'}).
806           " and \002$count{'Dunno'}\002 ".
807                 &fixPlural("dunno",$count{'Dunno'}).
808           " and \002$count{'Moron'}\002 ".
809                 &fixPlural("moron",$count{'Moron'}).
810           " and \002$count{'Commands'}\002 ".
811                 &fixPlural("command",$count{'Commands'}).
812           ".  I have been awake for $upString this session, and ".
813           "currently reference \002$count\002 factoids.  ".
814           "I'm using about \002$memusage\002 ".
815           "kB of memory."
816         );
817
818         # todo: make dbGetColNiceHash().
819         my %hash = &dbGetCol("stats", "nick,counter", "type='cmdstats'".
820 #                       " ORDER BY counter DESC LIMIT 3", 1);
821                         " ORDER BY counter DESC", 1);
822
823         foreach (keys %hash) {
824             my $i = $_;
825             foreach (keys %{ $hash{$i} }) {
826                 &DEBUG("cmdstats: $hash{$i}{$_} = $_");
827             }
828         }
829         &DEBUG("end of cmdstats.");
830
831         return;
832     }
833
834     # wantNick. xk++
835     if ($message =~ /^wantNick$/i) {
836         if ($param{'ircNick'} eq $ident) {
837             &msg($who, "I hope you're right. I'll try anyway.");
838         }
839         &DEBUG("ircNick => $param{'ircNick'}");
840         &DEBUG("ident => $ident");
841
842         if (! &IsNickInAnyChan( $param{ircNick} ) ) {
843             my $str = "attempting to change nick to $param{'ircNick'}";
844             &status($str);
845             &msg($who, $str);
846             &nick($param{'ircNick'});
847         } else {
848             &msg($who, "hrm.. I shouldn't do it (BUG?) but doing it anyway!");
849             &DEBUG("wN: nick is somewhere... should try later.");
850             &nick($param{'ircNick'});
851         }
852
853         return;
854     }
855
856     return "CONTINUE";
857 }
858
859 1;