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,
16 # Identifier => 'config_label',
17 # Help => 'help_label',
18 # Cmdstats => 'text_label',)
21 # addCmdHook('d?find', (
22 # CODEREF => \&debianFind(),
24 # Identifier => "debian",
26 # Cmdstats => "Debian Search",) );
32 my ($ident, %hash) = @_;
34 &DEBUG("aCH: added $ident to command hooks.");
35 $cmdhooks{$ident} = \%hash;
40 foreach (keys %cmdhooks) {
41 &DEBUG("cmdhooks{$_} => ...");
42 my %hash = \%{ $cmdhooks{$_} };
43 foreach (keys %hash) {
44 &DEBUG(" '$_' => '$hash{$_}'.");
48 &DEBUG("pCH: ended.");
52 if (!defined $message) {
53 &WARN("Modules: message is undefined. should never happen.");
57 # babel bot: Jonathan Feinberg++
58 if (&IsParam("babelfish") and $message =~ m{
60 (?:babel(?:fish)?|x|xlate|translate)
62 (to|from) # direction of translation (through)
64 ($babel::lang_regex)\w* # which language?
66 (.+) # The phrase to be translated
69 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
71 $cmdstats{'BabelFish'}++;
75 # cookie (random). xk++
76 if ($message =~ /^(cookie|random)(\s+(.*))?$/i) {
77 return $noreply unless (&hasParam("cookie"));
81 # lets find that secret cookie.
82 my $target = $talkchannel;
83 $target = $who if ($msgType ne 'public');
85 my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
87 ### WILL CHEW TONS OF MEM.
88 ### TODO: convert this to a Forker function!
90 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
91 $key = &getRandom(@list);
92 $val = &getFactInfo("factoids", $key, "factoid_value");
94 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
97 $cookiemsg =~ s/##KEY/\002$key\002/;
98 $cookiemsg =~ s/##VALUE/$value/;
99 $cookiemsg =~ s/##WHO/$who/;
100 $cookiemsg =~ s/\$who/$who/; # cheap fix.
101 $cookiemsg =~ s/(\S+)?\s*<\S+>/$1 /;
102 $cookiemsg =~ s/\s+/ /g;
104 if ($cookiemsg =~ s/^ACTION //i) {
105 &action($target, $cookiemsg);
107 &msg($target, $cookiemsg);
110 $cmdstats{'Random Cookie'}++;
114 if ($message =~ /^d?bugs$/i) {
115 return $noreply unless (&hasParam("debianExtra"));
117 &Forker("debianExtra", sub { &debianBugs(); } );
119 $cmdstats{'Debian Bugs'}++;
123 # Debian Author Search.
124 if ($message =~ /^dauthor(\s+(.*))?$/i) {
125 return $noreply unless (&hasParam("debian"));
128 if (!defined $query) {
133 &Forker("debian", sub { &Debian::searchAuthor($query); } );
135 $cmdstats{'Debian Author Search'}++;
139 # Debian Incoming Search.
140 if ($message =~ /^dincoming$/i) {
141 return $noreply unless (&hasParam("debian"));
143 &Forker("debian", sub { &Debian::generateIncoming(); } );
145 $cmdstats{'Debian Incoming Search'}++;
149 # Debian Distro(Package) Stats
150 if ($message =~ /^dstats(\s+(.*))?$/i) {
151 return $noreply unless (&hasParam("debian"));
152 my $dist = $2 || $Debian::defaultdist;
154 &Forker("debian", sub { &Debian::infoStats($dist); } );
156 $cmdstats{'Debian Statistics'}++;
160 # Debian Contents search.
161 if ($message =~ /^d?contents(\s+(.*))?$/i) {
162 return $noreply unless (&hasParam("debian"));
165 if (!defined $query) {
170 &Forker("debian", sub { &Debian::searchContents($query); } );
172 $cmdstats{'Debian Contents Search'}++;
176 # Debian Package info.
177 if ($message =~ /^d?find(\s+(.*))?$/i and &IsParam("debian")) {
180 if (!defined $string) {
185 &Forker("debian", sub { &Debian::DebianFind($string); } );
189 if (&IsParam("debian")) {
190 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
191 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
192 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
195 if (defined $package) {
196 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
206 if ($message =~ /^dict(\s+(.*))?$/i) {
207 return $noreply unless (&hasParam("dict"));
210 $query =~ s/^[\s\t]+//;
211 $query =~ s/[\s\t]+$//;
212 $query =~ s/[\s\t]+/ /;
214 if (!defined $query) {
219 if (length $query > 30) {
220 &msg($who,"dictionary word is too long.");
224 &Forker("dict", sub { &Dict::Dict($query); } );
231 if ($message =~ /^(fm|freshmeat)(\s+(.*))?$/i) {
232 return $noreply unless (&hasParam("freshmeat"));
236 if (!defined $query) {
238 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
242 &loadMyModule($myModules{'freshmeat'});
243 &Freshmeat::Freshmeat($query);
245 $cmdstats{'Freshmeat'}++;
249 # google searching. Simon++
250 if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?($W3Search_regex)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
251 return $noreply unless (&hasParam("wwwsearch"));
253 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2,$param{'wwwsearch'}); } );
255 $cmdstats{'WWWSearch'}++;
259 # insult server. patch thanks to michael@limit.org
260 if ($message =~ /^insult(\s+(\S+))?$/) {
261 return $noreply unless (&hasParam("insult"));
264 if (!defined $person) {
269 &Forker("insult", sub { &Insult::Insult($person); } );
275 if ($message =~ /^kernel$/i) {
276 return $noreply unless (&hasParam("kernel"));
278 &Forker("kernel", sub { &Kernel::Kernel(); } );
280 $cmdstats{'Kernel'}++;
284 # LART. originally by larne/cerb.
285 if ($message =~ /^lart(\s+(.*))?$/i) {
286 return $noreply unless (&hasParam("lart"));
287 my ($target) = &fixString($2);
289 if (!defined $target) {
295 my $chan = $talkchannel;
296 if ($msgType eq 'private') {
297 if ($target =~ /^($mask{chan})\s+(.*)$/) {
302 &msg($who, "error: invalid format or missing arguments.");
308 my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
310 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
311 $line =~ s/WHO/$who/g;
313 $line =~ s/WHO/$target/g;
315 $line .= ", courtesy of $who" if ($extra);
317 &action($chan, $line);
319 &status("lart: error reading file?");
325 # Search factoid extensions by 'author'. xk++
326 if ($message =~ /^listauth(\s+(\S+))?$/i) {
327 return $noreply unless (&hasParam("search"));
331 if (!defined $query) {
336 &loadMyModule($myModules{'factoids'});
337 &performStrictReply( &CmdListAuth($query) );
341 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
342 if ($message =~ /^list(\S+)( (.*))?$/i) {
343 return $noreply unless (&hasParam("search"));
345 my $thiscmd = lc($1);
348 $thiscmd =~ s/^vals$/values/;
349 return $noreply if ($thiscmd ne "keys" && $thiscmd ne "values");
352 if (!defined $args) {
353 &help("list". $thiscmd);
357 if (length $args == 1) {
358 &msg($who,"search string is too short.");
362 ### chews up to 4megs => use forker :)
363 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
364 # &loadMyModule($myModules{'search'});
365 # &Search::Search($thiscmd, $args);
367 $cmdstats{'Factoid Search'}++;
371 # Nickometer. Adam Spiers++
372 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
373 return $noreply unless (&hasParam("nickometer"));
375 my $term = (lc $1 eq 'me') ? $who : $1;
378 &loadMyModule($myModules{'nickometer'});
379 my $percentage = &nickometer($term);
381 if ($percentage =~ /NaN/) {
382 $percentage = "off the scale";
384 $percentage = sprintf("%0.4f", $percentage);
385 $percentage =~ s/\.?0+$//;
389 if ($msgType eq 'public') {
390 &say("'$term' is $percentage lame, $who");
392 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
399 if ($message =~ /^quote(\s+(\S+))?$/i) {
400 return $noreply unless (&hasParam("quote"));
409 &Forker("quote", sub { &Quote::Quote($query); } );
411 $cmdstats{'Quote'}++;
416 if ($message =~ /^rootWarn$/i) {
417 return $noreply unless (&hasParam("rootWarn"));
419 &loadMyModule($myModules{'rootwarn'});
420 &performStrictReply( &CmdrootWarn() );
425 if ($message =~ /^seen(\s+(\S+))?$/) {
426 return $noreply unless (&hasParam("seen"));
429 if (!defined $person) {
432 my $i = &countKeys("seen");
433 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
434 "seen ". &fixPlural("entry",$i) ." that I know of.");
442 &seenFlush(); # very evil hack. oh well, better safe than sorry.
444 ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
445 my $select = "nick,time,channel,host,message";
446 if ($person eq "random") {
447 @seen = &randKey("seen", $select);
449 @seen = &dbGet("seen", "nick", $person, $select);
452 if (scalar @seen < 2) {
454 &DEBUG("seen: _ => '$_'.");
456 &performReply("i haven't seen '$person'");
462 ### TODO: multi channel support. may require &IsNick() to return
463 ### all channels or something.
464 my @chans = &GetNickInChans($seen[0]);
466 $reply = "$seen[0] is currently on";
470 next unless (exists $userstats{lc $seen[0]}{'Join'});
471 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
474 if (&IsParam("seenStats")) {
476 $i = $userstats{lc $seen[0]}{'Count'};
477 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
478 $i = $userstats{lc $seen[0]}{'Time'};
479 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
482 my $howlong = &Time2String(time() - $seen[1]);
483 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
484 "in channel $seen[2], $howlong ago, ".
485 "saying\002:\002 '$seen[4]'.";
488 &performStrictReply($reply);
492 # slashdot headlines: from Chris Tessone.
493 if ($message =~ /^slashdot$/i) {
494 return $noreply unless (&hasParam("slashdot"));
496 &Forker("slashdot", sub { &Slashdot::Slashdot() });
498 $cmdstats{'Slashdot'}++;
502 # Topic management. xk++
503 # may want to add a flag(??) for topic in the near future. -xk
504 if ($message =~ /^topic(\s+(.*))?$/i) {
505 return $noreply unless (&hasParam("topic"));
507 my $chan = $talkchannel;
508 my @args = split(/ /, $2);
511 &msg($who,"Try 'help topic'");
515 $chan = lc(shift @args) if ($msgType eq 'private');
516 my $thiscmd = shift @args;
519 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
520 &msg($who, "error: channel argument is not required.");
521 &msg($who, "\002Usage\002: topic <CMD>");
525 # topic over private:
526 if ($msgType eq 'private' && $chan !~ /^#/) {
527 &msg($who, "error: channel argument is required.");
528 &msg($who, "\002Usage\002: topic #channel <CMD>");
532 if (&validChan($chan) == 0) {
533 &msg($who,"error: invalid channel \002$chan\002");
537 # for semi-outsiders.
538 if (!&IsNickInChan($who,$chan)) {
539 &msg($who, "Failed. You ($who) are not in $chan, hey?");
544 &loadMyModule($myModules{'topic'});
545 &Topic($chan, $thiscmd, join(' ', @args));
546 $cmdstats{'Topic'}++;
551 if ($message =~ /^countdown(\s+(\S+))?$/i) {
552 return $noreply unless (&hasParam("countdown"));
556 &loadMyModule($myModules{'countdown'});
559 $cmdstats{'Countdown'}++;
564 # User Information Services. requested by Flugh.
565 if ($message =~ /^u(ser)?info(\s+(.*))?$/i) {
566 return $noreply unless (&hasParam("userinfo"));
567 &loadMyModule($myModules{'userinfo'});
570 if (!defined $arg or $arg eq "") {
575 if ($arg =~ /^set(\s+(.*))?$/i) {
578 &help("userinfo set");
582 &UserInfoSet(split /\s+/, $arg, 2);
583 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
586 &help("userinfo unset");
590 &UserInfoSet($arg, "");
600 if ($message =~ /^uptime$/i) {
601 return $noreply unless (&hasParam("uptime"));
604 &msg($who, "- Uptime for $ident -");
605 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
606 foreach (&uptimeGetInfo()) {
608 my $time = &Time2String($1);
611 &msg($who, "$count: $time $2");
615 $cmdstats{'Uptime'}++;
620 if ($message =~ /^wingate$/i) {
621 return $noreply unless (&hasParam("wingate"));
623 my $reply = "Wingate statistics: scanned \002"
624 .scalar(keys %wingate)."\002 hosts";
625 my $queue = scalar(keys %wingateToDo);
627 $reply .= ". I have \002$queue\002 hosts in the queue";
628 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
631 &performStrictReply("$reply.");
637 if ($message =~ /^convert(\s+(.*))?$/i) {
638 return $noreply unless (&hasParam("units"));
647 ($from,$to) = ($1,$2) if ($str =~ /^(.*) to (.*)$/);
648 ($from,$to) = ($2,$1) if ($str =~ /^(.*) from (.*)$/);
649 if (!defined $from or !defined $to or $to eq "" or $from eq "") {
650 &msg($who, "Invalid format!");
655 &Forker("units", sub { &Units::convertUnits($from, $to); } );
660 # do nothing and let the other routines have a go