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