2 # User Command Extension Stubs
5 if (&IsParam("useStrict")) { use strict; }
7 use vars qw(@W3Search_engines $W3Search_regex);
8 @W3Search_engines = qw(AltaVista Dejanews Excite Gopher HotBot Infoseek
9 Lycos Magellan PLweb SFgate Simple Verity Google);
10 $W3Search_regex = join '|', @W3Search_engines;
11 $babel::lang_regex = ""; # lame fix.
13 ### PROPOSED COMMAND HOOK IMPLEMENTATION.
14 # addCmdHook('TEXT_HOOK', $code_ref,
17 # Identifier => 'config_label',
18 # Help => 'help_label',
19 # Cmdstats => 'text_label',)
22 # addCmdHook('d?find', (
23 # CODEREF => \&debianFind(),
25 # Forker => 1, # if simple function.
26 # Identifier => "debian",
28 # Cmdstats => "Debian Search",) );
34 my ($ident, %hash) = @_;
36 &DEBUG("aCH: added $ident to command hooks.");
37 $cmdhooks{$ident} = \%hash;
42 my @args = split(' ', $message);
44 foreach (keys %cmdhooks) {
46 &DEBUG("cmdhooks{$ident} => ...");
48 next unless ($args[0] =~ /^$ident$/i);
50 &DEBUG("pCH: MATCHED!");
51 my %hash = %{ $cmdhooks{$ident} };
54 foreach (keys %hash) {
55 &DEBUG(" $ident->$_ => '$hash{$_}'.");
59 if (exists $hash{'Identifier'}) {
60 return $noreply unless (&hasParam($hash{'Identifier'}));
63 ### FORKER,IDENTIFIER,CODEREF.
64 if (exists $hash{'Forker'}) {
65 &Forker($hash{'Identifier'}, \&{$hash{'CODEREF'}});
69 if (exists $hash{'Cmdstats'}) {
70 $cmdstats{$hash{'Cmdstats'}}++;
74 &DEBUG("pCH: ended.");
77 &addCmdHook('d?bugs', ('CODEREF' => 'debianBugs',
78 'Forker' => 1, 'Identifier' => 'debianExtra', 'Cmdstats' => 1) );
81 if (!defined $message) {
82 &WARN("Modules: message is undefined. should never happen.");
86 # babel bot: Jonathan Feinberg++
87 if (&IsParam("babelfish") and $message =~ m{
89 (?:babel(?:fish)?|x|xlate|translate)
91 (to|from) # direction of translation (through)
93 ($babel::lang_regex)\w* # which language?
95 (.+) # The phrase to be translated
98 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
100 $cmdstats{'BabelFish'}++;
104 # cookie (random). xk++
105 if ($message =~ /^(cookie|random)(\s+(.*))?$/i) {
106 return $noreply unless (&hasParam("cookie"));
110 # lets find that secret cookie.
111 my $target = $talkchannel;
112 $target = $who if ($msgType ne 'public');
114 my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
116 ### WILL CHEW TONS OF MEM.
117 ### TODO: convert this to a Forker function!
119 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
120 $key = &getRandom(@list);
121 $val = &getFactInfo("factoids", $key, "factoid_value");
123 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
126 $cookiemsg =~ s/##KEY/\002$key\002/;
127 $cookiemsg =~ s/##VALUE/$value/;
128 $cookiemsg =~ s/##WHO/$who/;
129 $cookiemsg =~ s/\$who/$who/; # cheap fix.
130 $cookiemsg =~ s/(\S+)?\s*<\S+>/$1 /;
131 $cookiemsg =~ s/\s+/ /g;
133 if ($cookiemsg =~ s/^ACTION //i) {
134 &action($target, $cookiemsg);
136 &msg($target, $cookiemsg);
139 $cmdstats{'Random Cookie'}++;
143 if ($message =~ /^d?bugs$/i) {
144 return $noreply unless (&hasParam("debianExtra"));
146 &Forker("debianExtra", sub { &debianBugs(); } );
148 $cmdstats{'Debian Bugs'}++;
152 # Debian Author Search.
153 if ($message =~ /^dauthor(\s+(.*))?$/i) {
154 return $noreply unless (&hasParam("debian"));
157 if (!defined $query) {
162 &Forker("debian", sub { &Debian::searchAuthor($query); } );
164 $cmdstats{'Debian Author Search'}++;
168 # Debian Author Search.
169 if ($message =~ /^(d|search)desc(\s+(.*))?$/i) {
170 return $noreply unless (&hasParam("debian"));
173 if (!defined $query) {
178 &Forker("debian", sub { &Debian::searchDesc($query); } );
180 $cmdstats{'Debian Desc Search'}++;
184 # Debian Incoming Search.
185 if ($message =~ /^dincoming$/i) {
186 return $noreply unless (&hasParam("debian"));
188 &Forker("debian", sub { &Debian::generateIncoming(); } );
190 $cmdstats{'Debian Incoming Search'}++;
194 # Debian Distro(Package) Stats
195 if ($message =~ /^dstats(\s+(.*))?$/i) {
196 return $noreply unless (&hasParam("debian"));
197 my $dist = $2 || $Debian::defaultdist;
199 &Forker("debian", sub { &Debian::infoStats($dist); } );
201 $cmdstats{'Debian Statistics'}++;
205 # Debian Contents search.
206 if ($message =~ /^d?contents(\s+(.*))?$/i) {
207 return $noreply unless (&hasParam("debian"));
210 if (!defined $query) {
215 &Forker("debian", sub { &Debian::searchContents($query); } );
217 $cmdstats{'Debian Contents Search'}++;
221 # Debian Package info.
222 if ($message =~ /^d?find(\s+(.*))?$/i and &IsParam("debian")) {
225 if (!defined $string) {
230 &Forker("debian", sub { &Debian::DebianFind($string); } );
234 if (&IsParam("debian")) {
235 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
236 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
237 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
240 if (defined $package) {
241 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
251 if ($message =~ /^dict(\s+(.*))?$/i) {
252 return $noreply unless (&hasParam("dict"));
255 $query =~ s/^[\s\t]+//;
256 $query =~ s/[\s\t]+$//;
257 $query =~ s/[\s\t]+/ /;
259 if (!defined $query) {
264 if (length $query > 30) {
265 &msg($who,"dictionary word is too long.");
269 &Forker("dict", sub { &Dict::Dict($query); } );
276 if ($message =~ /^(fm|freshmeat)(\s+(.*))?$/i) {
277 return $noreply unless (&hasParam("freshmeat"));
281 if (!defined $query) {
283 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
287 &loadMyModule($myModules{'freshmeat'});
288 &Freshmeat::Freshmeat($query);
290 $cmdstats{'Freshmeat'}++;
294 # google searching. Simon++
295 if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?($W3Search_regex)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
296 return $noreply unless (&hasParam("wwwsearch"));
298 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2,$param{'wwwsearch'}); } );
300 $cmdstats{'WWWSearch'}++;
304 # insult server. patch thanks to michael@limit.org
305 if ($message =~ /^insult(\s+(\S+))?$/) {
306 return $noreply unless (&hasParam("insult"));
309 if (!defined $person) {
314 &Forker("insult", sub { &Insult::Insult($person); } );
320 if ($message =~ /^kernel$/i) {
321 return $noreply unless (&hasParam("kernel"));
323 &Forker("kernel", sub { &Kernel::Kernel(); } );
325 $cmdstats{'Kernel'}++;
329 # LART. originally by larne/cerb.
330 if ($message =~ /^lart(\s+(.*))?$/i) {
331 return $noreply unless (&hasParam("lart"));
332 my ($target) = &fixString($2);
334 if (!defined $target) {
340 my $chan = $talkchannel;
341 if ($msgType eq 'private') {
342 if ($target =~ /^($mask{chan})\s+(.*)$/) {
347 &msg($who, "error: invalid format or missing arguments.");
353 my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
355 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
356 $line =~ s/WHO/$who/g;
358 $line =~ s/WHO/$target/g;
360 $line .= ", courtesy of $who" if ($extra);
362 &action($chan, $line);
364 &status("lart: error reading file?");
370 # Search factoid extensions by 'author'. xk++
371 if ($message =~ /^listauth(\s+(\S+))?$/i) {
372 return $noreply unless (&hasParam("search"));
376 if (!defined $query) {
381 &loadMyModule($myModules{'factoids'});
382 &performStrictReply( &CmdListAuth($query) );
386 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
387 if ($message =~ /^list(\S+)( (.*))?$/i) {
388 return $noreply unless (&hasParam("search"));
390 my $thiscmd = lc($1);
393 $thiscmd =~ s/^vals$/values/;
394 return $noreply if ($thiscmd ne "keys" && $thiscmd ne "values");
397 if (!defined $args) {
398 &help("list". $thiscmd);
402 if (length $args == 1) {
403 &msg($who,"search string is too short.");
407 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
409 $cmdstats{'Factoid Search'}++;
413 # Nickometer. Adam Spiers++
414 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
415 return $noreply unless (&hasParam("nickometer"));
417 my $term = (lc $1 eq 'me') ? $who : $1;
420 &loadMyModule($myModules{'nickometer'});
421 my $percentage = &nickometer($term);
423 if ($percentage =~ /NaN/) {
424 $percentage = "off the scale";
426 $percentage = sprintf("%0.4f", $percentage);
427 $percentage =~ s/\.?0+$//;
431 if ($msgType eq 'public') {
432 &say("'$term' is $percentage lame, $who");
434 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
441 if ($message =~ /^quote(\s+(\S+))?$/i) {
442 return $noreply unless (&hasParam("quote"));
451 &Forker("quote", sub { &Quote::Quote($query); } );
453 $cmdstats{'Quote'}++;
458 if ($message =~ /^rootWarn$/i) {
459 return $noreply unless (&hasParam("rootWarn"));
461 &loadMyModule($myModules{'rootwarn'});
462 &performStrictReply( &CmdrootWarn() );
467 if ($message =~ /^seen(\s+(\S+))?$/) {
468 return $noreply unless (&hasParam("seen"));
471 if (!defined $person) {
474 my $i = &countKeys("seen");
475 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
476 "seen ". &fixPlural("entry",$i) ." that I know of.");
484 &seenFlush(); # very evil hack. oh well, better safe than sorry.
486 ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
487 my $select = "nick,time,channel,host,message";
488 if ($person eq "random") {
489 @seen = &randKey("seen", $select);
491 @seen = &dbGet("seen", "nick", $person, $select);
494 if (scalar @seen < 2) {
496 &DEBUG("seen: _ => '$_'.");
498 &performReply("i haven't seen '$person'");
504 ### TODO: multi channel support. may require &IsNick() to return
505 ### all channels or something.
506 my @chans = &GetNickInChans($seen[0]);
508 $reply = "$seen[0] is currently on";
512 next unless (exists $userstats{lc $seen[0]}{'Join'});
513 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
516 if (&IsParam("seenStats")) {
518 $i = $userstats{lc $seen[0]}{'Count'};
519 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
520 $i = $userstats{lc $seen[0]}{'Time'};
521 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
524 my $howlong = &Time2String(time() - $seen[1]);
525 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
526 "in channel $seen[2], $howlong ago, ".
527 "saying\002:\002 '$seen[4]'.";
530 &performStrictReply($reply);
534 # slashdot headlines: from Chris Tessone.
535 if ($message =~ /^slashdot$/i) {
536 return $noreply unless (&hasParam("slashdot"));
538 &Forker("slashdot", sub { &Slashdot::Slashdot() });
540 $cmdstats{'Slashdot'}++;
544 # Topic management. xk++
545 # may want to add a flag(??) for topic in the near future. -xk
546 if ($message =~ /^topic(\s+(.*))?$/i) {
547 return $noreply unless (&hasParam("topic"));
549 my $chan = $talkchannel;
550 my @args = split(/ /, $2);
553 &msg($who,"Try 'help topic'");
557 $chan = lc(shift @args) if ($msgType eq 'private');
558 my $thiscmd = shift @args;
561 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
562 &msg($who, "error: channel argument is not required.");
563 &msg($who, "\002Usage\002: topic <CMD>");
567 # topic over private:
568 if ($msgType eq 'private' && $chan !~ /^#/) {
569 &msg($who, "error: channel argument is required.");
570 &msg($who, "\002Usage\002: topic #channel <CMD>");
574 if (&validChan($chan) == 0) {
575 &msg($who,"error: invalid channel \002$chan\002");
579 # for semi-outsiders.
580 if (!&IsNickInChan($who,$chan)) {
581 &msg($who, "Failed. You ($who) are not in $chan, hey?");
586 &loadMyModule($myModules{'topic'});
587 &Topic($chan, $thiscmd, join(' ', @args));
588 $cmdstats{'Topic'}++;
593 if ($message =~ /^countdown(\s+(\S+))?$/i) {
594 return $noreply unless (&hasParam("countdown"));
598 &loadMyModule($myModules{'countdown'});
601 $cmdstats{'Countdown'}++;
606 # User Information Services. requested by Flugh.
607 if ($message =~ /^u(ser)?info(\s+(.*))?$/i) {
608 return $noreply unless (&hasParam("userinfo"));
609 &loadMyModule($myModules{'userinfo'});
612 if (!defined $arg or $arg eq "") {
617 if ($arg =~ /^set(\s+(.*))?$/i) {
620 &help("userinfo set");
624 &UserInfoSet(split /\s+/, $arg, 2);
625 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
628 &help("userinfo unset");
632 &UserInfoSet($arg, "");
642 if ($message =~ /^uptime$/i) {
643 return $noreply unless (&hasParam("uptime"));
646 &msg($who, "- Uptime for $ident -");
647 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
648 foreach (&uptimeGetInfo()) {
650 my $time = &Time2String($1);
653 &msg($who, "$count: $time $2");
657 $cmdstats{'Uptime'}++;
662 if ($message =~ /^wingate$/i) {
663 return $noreply unless (&hasParam("wingate"));
665 my $reply = "Wingate statistics: scanned \002"
666 .scalar(keys %wingate)."\002 hosts";
667 my $queue = scalar(keys %wingateToDo);
669 $reply .= ". I have \002$queue\002 hosts in the queue";
670 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
673 &performStrictReply("$reply.");
679 if ($message =~ /^convert(\s+(.*))?$/i) {
680 return $noreply unless (&hasParam("units"));
689 ($from,$to) = ($1,$2) if ($str =~ /^(.*) to (.*)$/);
690 ($from,$to) = ($2,$1) if ($str =~ /^(.*) from (.*)$/);
691 if (!defined $from or !defined $to or $to eq "" or $from eq "") {
692 &msg($who, "Invalid format!");
697 &Forker("units", sub { &Units::convertUnits($from, $to); } );
702 # do nothing and let the other routines have a go