2 # Infobot user 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;
12 ### PROPOSED COMMAND HOOK IMPLEMENTATION.
13 # addCmdHook('TEXT_HOOK', $code_ref,
15 # Identifier => 'config_label',
16 # Help => 'help_label',
17 # Cmdstats => 'text_label',)
20 # addCmdHook('d?find', \&debianFind(), (
22 # Identifier => "debian",
24 # Cmdstats => "Debian Search",) );
30 if (!defined $message) {
31 &WARN("Modules: message is undefined. should never happen.");
35 # babel bot: Jonathan Feinberg++
36 if (&IsParam("babelfish") and $message =~ m{
38 (?:babel(?:fish)?|x|xlate|translate)
40 (to|from) # direction of translation (through)
42 ($babel::lang_regex)\w* # which language?
44 (.+) # The phrase to be translated
47 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
49 $cmdstats{'BabelFish'}++;
53 # cookie (random). xk++
54 if ($message =~ /^(cookie|random)(\s+(.*))?$/i) {
55 return 'NOREPLY' unless (&hasParam("cookie"));
59 # lets find that secret cookie.
60 my $target = $talkchannel;
61 $target = $who if ($msgType ne 'public');
63 my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
65 ### WILL CHEW TONS OF MEM.
66 ### TODO: convert this to a Forker function!
68 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
69 $key = &getRandom(@list);
70 $val = &getFactInfo("factoids", $key, "factoid_value");
72 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
75 $cookiemsg =~ s/##KEY/\002$key\002/;
76 $cookiemsg =~ s/##VALUE/$value/;
77 $cookiemsg =~ s/##WHO/$who/;
78 $cookiemsg =~ s/\$who/$who/; # cheap fix.
79 $cookiemsg =~ s/(\S+)?\s*<\S+>/$1 /;
80 $cookiemsg =~ s/\s+/ /g;
82 if ($cookiemsg =~ s/^ACTION //i) {
83 &action($target, $cookiemsg);
85 &msg($target, $cookiemsg);
88 $cmdstats{'Random Cookie'}++;
92 if ($message =~ /^d?bugs$/i) {
93 return 'NOREPLY' unless (&hasParam("debianExtra"));
95 &Forker("debianExtra", sub { &debianBugs(); } );
97 $cmdstats{'Debian Bugs'}++;
101 # Debian Author Search.
102 if ($message =~ /^dauthor(\s+(.*))?$/i) {
103 return 'NOREPLY' unless (&hasParam("debian"));
106 if (!defined $query) {
111 &Forker("debian", sub { &Debian::searchAuthor($query); } );
113 $cmdstats{'Debian Author Search'}++;
117 # Debian Incoming Search.
118 if ($message =~ /^dincoming$/i) {
119 return 'NOREPLY' unless (&hasParam("debian"));
121 &Forker("debian", sub { &Debian::generateIncoming(); } );
123 $cmdstats{'Debian Incoming Search'}++;
127 # Debian Distro(Package) Stats
128 if ($message =~ /^dstats(\s+(.*))?$/i) {
129 return 'NOREPLY' unless (&hasParam("debian"));
130 my $dist = $2 || $Debian::defaultdist;
132 &Forker("debian", sub { &Debian::infoStats($dist); } );
134 $cmdstats{'Debian Statistics'}++;
138 # Debian Contents search.
139 if ($message =~ /^d?contents(\s+(.*))?$/i) {
140 return 'NOREPLY' unless (&hasParam("debian"));
143 if (!defined $query) {
148 &Forker("debian", sub { &Debian::searchContents($query); } );
150 $cmdstats{'Debian Contents Search'}++;
154 # Debian Package info.
155 if ($message =~ /^d?find(\s+(.*))?$/i and &IsParam("debian")) {
158 if (!defined $string) {
163 &Forker("debian", sub { &Debian::DebianFind($string); } );
167 if (&IsParam("debian")) {
168 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
169 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
170 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
173 if (defined $package) {
174 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
184 if ($message =~ /^dict(\s+(.*))?$/i) {
185 return 'NOREPLY' unless (&hasParam("dict"));
188 $query =~ s/^[\s\t]+//;
189 $query =~ s/[\s\t]+$//;
190 $query =~ s/[\s\t]+/ /;
192 if (!defined $query) {
197 if (length $query > 30) {
198 &msg($who,"dictionary word is too long.");
202 &Forker("dict", sub { &Dict::Dict($query); } );
209 if ($message =~ /^(fm|freshmeat)(\s+(.*))?$/i) {
210 return 'NOREPLY' unless (&hasParam("freshmeat"));
214 if (!defined $query) {
216 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
220 &loadMyModule($myModules{'freshmeat'});
221 &Freshmeat::Freshmeat($query);
223 $cmdstats{'Freshmeat'}++;
227 # google searching. Simon++
228 if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?($W3Search_regex)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
229 return 'NOREPLY' unless (&hasParam("wwwsearch"));
231 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2,$param{'wwwsearch'}); } );
233 $cmdstats{'WWWSearch'}++;
237 # insult server. patch thanks to michael@limit.org
238 if ($message =~ /^insult(\s+(\S+))?$/) {
239 return 'NOREPLY' unless (&hasParam("insult"));
242 if (!defined $person) {
247 &Forker("insult", sub { &Insult::Insult($person); } );
253 if ($message =~ /^kernel$/i) {
254 return 'NOREPLY' unless (&hasParam("kernel"));
256 &Forker("kernel", sub { &Kernel::Kernel(); } );
258 $cmdstats{'Kernel'}++;
262 # LART. originally by larne/cerb.
263 if ($message =~ /^lart(\s+(.*))?$/i) {
264 return 'NOREPLY' unless (&hasParam("lart"));
265 my ($target) = &fixString($2);
267 if (!defined $target) {
273 my $chan = $talkchannel;
274 if ($msgType eq 'private') {
275 if ($target =~ /^($mask{chan})\s+(.*)$/) {
280 &msg($who, "error: invalid format or missing arguments.");
286 my $line = &getRandomLineFromFile($infobot_misc_dir. "/infobot.lart");
288 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
289 $line =~ s/WHO/$who/g;
291 $line =~ s/WHO/$target/g;
293 $line .= ", courtesy of $who" if ($extra);
295 &action($chan, $line);
297 &status("lart: error reading file?");
303 # Search factoid extensions by 'author'. xk++
304 if ($message =~ /^listauth(\s+(\S+))?$/i) {
305 return 'NOREPLY' unless (&hasParam("search"));
309 if (!defined $query) {
314 &loadMyModule($myModules{'factoids'});
315 &performStrictReply( &CmdListAuth($query) );
319 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
320 if ($message =~ /^list(\S+)( (.*))?$/i) {
321 return 'NOREPLY' unless (&hasParam("search"));
323 my $thiscmd = lc($1);
326 $thiscmd =~ s/^vals$/values/;
327 return 'NOREPLY' if ($thiscmd ne "keys" && $thiscmd ne "values");
330 if (!defined $args) {
331 &help("list". $thiscmd);
335 if (length $args == 1) {
336 &msg($who,"search string is too short.");
340 ### chews up to 4megs => use forker :)
341 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
342 # &loadMyModule($myModules{'search'});
343 # &Search::Search($thiscmd, $args);
345 $cmdstats{'Factoid Search'}++;
349 # Nickometer. Adam Spiers++
350 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
351 return 'NOREPLY' unless (&hasParam("nickometer"));
353 my $term = (lc $1 eq 'me') ? $who : $1;
356 &loadMyModule($myModules{'nickometer'});
357 my $percentage = &nickometer($term);
359 if ($percentage =~ /NaN/) {
360 $percentage = "off the scale";
362 $percentage = sprintf("%0.4f", $percentage);
363 $percentage =~ s/\.?0+$//;
367 if ($msgType eq 'public') {
368 &say("'$term' is $percentage lame, $who");
370 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
377 if ($message =~ /^quote(\s+(\S+))?$/i) {
378 return 'NOREPLY' unless (&hasParam("quote"));
387 &Forker("quote", sub { &Quote::Quote($query); } );
389 $cmdstats{'Quote'}++;
394 if ($message =~ /^rootWarn$/i) {
395 return 'NOREPLY' unless (&hasParam("rootWarn"));
397 &loadMyModule($myModules{'rootwarn'});
398 &performStrictReply( &CmdrootWarn() );
403 if ($message =~ /^seen(\s+(\S+))?$/) {
404 return 'NOREPLY' unless (&hasParam("seen"));
407 if (!defined $person) {
410 my $i = &countKeys("seen");
411 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
412 "seen ". &fixPlural("entry",$i) ." that I know of.");
420 &seenFlush(); # very evil hack. oh well, better safe than sorry.
422 ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
423 my $select = "nick,time,channel,host,message";
424 if ($person eq "random") {
425 @seen = &randKey("seen", $select);
427 @seen = &dbGet("seen", "nick", $person, $select);
430 if (scalar @seen < 2) {
432 &DEBUG("seen: _ => '$_'.");
434 &performReply("i haven't seen '$person'");
440 ### TODO: multi channel support. may require &IsNick() to return
441 ### all channels or something.
442 my @chans = &GetNickInChans($seen[0]);
444 $reply = "$seen[0] is currently on";
448 next unless (exists $userstats{lc $seen[0]}{'Join'});
449 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
452 if (&IsParam("seenStats")) {
454 $i = $userstats{lc $seen[0]}{'Count'};
455 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
456 $i = $userstats{lc $seen[0]}{'Time'};
457 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
460 my $howlong = &Time2String(time() - $seen[1]);
461 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
462 "in channel $seen[2], $howlong ago, ".
463 "saying\002:\002 '$seen[4]'.";
466 &performStrictReply($reply);
470 # slashdot headlines: from Chris Tessone.
471 if ($message =~ /^slashdot$/i) {
472 return 'NOREPLY' unless (&hasParam("slashdot"));
474 &Forker("slashdot", sub { &Slashdot::Slashdot() });
476 $cmdstats{'Slashdot'}++;
480 # Topic management. xk++
481 # may want to add a flag(??) for topic in the near future. -xk
482 if ($message =~ /^topic(\s+(.*))?$/i) {
483 return 'NOREPLY' unless (&hasParam("topic"));
485 my $chan = $talkchannel;
486 my @args = split(/ /, $2);
489 &msg($who,"Try 'help topic'");
493 $chan = lc(shift @args) if ($msgType eq 'private');
494 my $thiscmd = shift @args;
497 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
498 &msg($who, "error: channel argument is not required.");
499 &msg($who, "\002Usage\002: topic <CMD>");
503 # topic over private:
504 if ($msgType eq 'private' && $chan !~ /^#/) {
505 &msg($who, "error: channel argument is required.");
506 &msg($who, "\002Usage\002: topic #channel <CMD>");
510 if (&validChan($chan) == 0) {
511 &msg($who,"error: invalid channel \002$chan\002");
515 # for semi-outsiders.
516 if (!&IsNickInChan($who,$chan)) {
517 &msg($who, "Failed. You ($who) are not in $chan, hey?");
522 &loadMyModule($myModules{'topic'});
523 &Topic($chan, $thiscmd, join(' ', @args));
524 $cmdstats{'Topic'}++;
529 if ($message =~ /^countdown(\s+(\S+))?$/i) {
530 return 'NOREPLY' unless (&hasParam("countdown"));
534 &loadMyModule($myModules{'countdown'});
537 $cmdstats{'Countdown'}++;
542 # User Information Services. requested by Flugh.
543 if ($message =~ /^uinfo(\s+(.*))?$/i) {
544 return 'NOREPLY' unless (&hasParam("userinfo"));
545 &loadMyModule($myModules{'userinfo'});
548 if (!defined $arg or $arg eq "") {
553 if ($arg =~ /^set(\s+(.*))?$/i) {
556 &help("userinfo set");
560 &UserInfoSet(split /\s+/, $arg, 2);
561 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
564 &help("userinfo unset");
568 &UserInfoSet($arg, "");
578 if ($message =~ /^uptime$/i) {
579 return 'NOREPLY' unless (&hasParam("uptime"));
582 &msg($who, "- Uptime for $ident -");
583 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $infobot_version");
584 foreach (&uptimeGetInfo()) {
586 my $time = &Time2String($1);
589 &msg($who, "$count: $time $2");
593 $cmdstats{'Uptime'}++;
598 if ($message =~ /^wingate$/i) {
599 return 'NOREPLY' unless (&hasParam("wingate"));
601 my $reply = "Wingate statistics: scanned \002"
602 .scalar(keys %wingate)."\002 hosts";
603 my $queue = scalar(keys %wingateToDo);
605 $reply .= ". I have \002$queue\002 hosts in the queue";
606 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
609 &performStrictReply("$reply.");
615 if ($message =~ /^convert(\s+(.*))?$/i) {
616 return 'NOREPLY' unless (&hasParam("units"));
625 ($from,$to) = ($1,$2) if ($str =~ /^(.*) to (.*)$/);
626 ($from,$to) = ($2,$1) if ($str =~ /^(.*) from (.*)$/);
627 if (!defined $from or !defined $to or $to eq "" or $from eq "") {
628 &msg($who, "Invalid format!");
633 &Forker("units", sub { &Units::convertUnits($from, $to); } );
638 # do nothing and let the other routines have a go