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