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