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 Author Search.
140 if ($message =~ /^(d|search)desc(\s+(.*))?$/i) {
141 return $noreply unless (&hasParam("debian"));
144 if (!defined $query) {
149 &Forker("debian", sub { &Debian::searchDesc($query); } );
151 $cmdstats{'Debian Desc Search'}++;
155 # Debian Incoming Search.
156 if ($message =~ /^dincoming$/i) {
157 return $noreply unless (&hasParam("debian"));
159 &Forker("debian", sub { &Debian::generateIncoming(); } );
161 $cmdstats{'Debian Incoming Search'}++;
165 # Debian Distro(Package) Stats
166 if ($message =~ /^dstats(\s+(.*))?$/i) {
167 return $noreply unless (&hasParam("debian"));
168 my $dist = $2 || $Debian::defaultdist;
170 &Forker("debian", sub { &Debian::infoStats($dist); } );
172 $cmdstats{'Debian Statistics'}++;
176 # Debian Contents search.
177 if ($message =~ /^d?contents(\s+(.*))?$/i) {
178 return $noreply unless (&hasParam("debian"));
181 if (!defined $query) {
186 &Forker("debian", sub { &Debian::searchContents($query); } );
188 $cmdstats{'Debian Contents Search'}++;
192 # Debian Package info.
193 if ($message =~ /^d?find(\s+(.*))?$/i and &IsParam("debian")) {
196 if (!defined $string) {
201 &Forker("debian", sub { &Debian::DebianFind($string); } );
205 if (&IsParam("debian")) {
206 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
207 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
208 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
211 if (defined $package) {
212 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
222 if ($message =~ /^dict(\s+(.*))?$/i) {
223 return $noreply unless (&hasParam("dict"));
226 $query =~ s/^[\s\t]+//;
227 $query =~ s/[\s\t]+$//;
228 $query =~ s/[\s\t]+/ /;
230 if (!defined $query) {
235 if (length $query > 30) {
236 &msg($who,"dictionary word is too long.");
240 &Forker("dict", sub { &Dict::Dict($query); } );
247 if ($message =~ /^(fm|freshmeat)(\s+(.*))?$/i) {
248 return $noreply unless (&hasParam("freshmeat"));
252 if (!defined $query) {
254 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
258 &loadMyModule($myModules{'freshmeat'});
259 &Freshmeat::Freshmeat($query);
261 $cmdstats{'Freshmeat'}++;
265 # google searching. Simon++
266 if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?($W3Search_regex)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
267 return $noreply unless (&hasParam("wwwsearch"));
269 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2,$param{'wwwsearch'}); } );
271 $cmdstats{'WWWSearch'}++;
275 # insult server. patch thanks to michael@limit.org
276 if ($message =~ /^insult(\s+(\S+))?$/) {
277 return $noreply unless (&hasParam("insult"));
280 if (!defined $person) {
285 &Forker("insult", sub { &Insult::Insult($person); } );
291 if ($message =~ /^kernel$/i) {
292 return $noreply unless (&hasParam("kernel"));
294 &Forker("kernel", sub { &Kernel::Kernel(); } );
296 $cmdstats{'Kernel'}++;
300 # LART. originally by larne/cerb.
301 if ($message =~ /^lart(\s+(.*))?$/i) {
302 return $noreply unless (&hasParam("lart"));
303 my ($target) = &fixString($2);
305 if (!defined $target) {
311 my $chan = $talkchannel;
312 if ($msgType eq 'private') {
313 if ($target =~ /^($mask{chan})\s+(.*)$/) {
318 &msg($who, "error: invalid format or missing arguments.");
324 my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
326 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
327 $line =~ s/WHO/$who/g;
329 $line =~ s/WHO/$target/g;
331 $line .= ", courtesy of $who" if ($extra);
333 &action($chan, $line);
335 &status("lart: error reading file?");
341 # Search factoid extensions by 'author'. xk++
342 if ($message =~ /^listauth(\s+(\S+))?$/i) {
343 return $noreply unless (&hasParam("search"));
347 if (!defined $query) {
352 &loadMyModule($myModules{'factoids'});
353 &performStrictReply( &CmdListAuth($query) );
357 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
358 if ($message =~ /^list(\S+)( (.*))?$/i) {
359 return $noreply unless (&hasParam("search"));
361 my $thiscmd = lc($1);
364 $thiscmd =~ s/^vals$/values/;
365 return $noreply if ($thiscmd ne "keys" && $thiscmd ne "values");
368 if (!defined $args) {
369 &help("list". $thiscmd);
373 if (length $args == 1) {
374 &msg($who,"search string is too short.");
378 ### chews up to 4megs => use forker :)
379 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
380 # &loadMyModule($myModules{'search'});
381 # &Search::Search($thiscmd, $args);
383 $cmdstats{'Factoid Search'}++;
387 # Nickometer. Adam Spiers++
388 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
389 return $noreply unless (&hasParam("nickometer"));
391 my $term = (lc $1 eq 'me') ? $who : $1;
394 &loadMyModule($myModules{'nickometer'});
395 my $percentage = &nickometer($term);
397 if ($percentage =~ /NaN/) {
398 $percentage = "off the scale";
400 $percentage = sprintf("%0.4f", $percentage);
401 $percentage =~ s/\.?0+$//;
405 if ($msgType eq 'public') {
406 &say("'$term' is $percentage lame, $who");
408 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
415 if ($message =~ /^quote(\s+(\S+))?$/i) {
416 return $noreply unless (&hasParam("quote"));
425 &Forker("quote", sub { &Quote::Quote($query); } );
427 $cmdstats{'Quote'}++;
432 if ($message =~ /^rootWarn$/i) {
433 return $noreply unless (&hasParam("rootWarn"));
435 &loadMyModule($myModules{'rootwarn'});
436 &performStrictReply( &CmdrootWarn() );
441 if ($message =~ /^seen(\s+(\S+))?$/) {
442 return $noreply unless (&hasParam("seen"));
445 if (!defined $person) {
448 my $i = &countKeys("seen");
449 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
450 "seen ". &fixPlural("entry",$i) ." that I know of.");
458 &seenFlush(); # very evil hack. oh well, better safe than sorry.
460 ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
461 my $select = "nick,time,channel,host,message";
462 if ($person eq "random") {
463 @seen = &randKey("seen", $select);
465 @seen = &dbGet("seen", "nick", $person, $select);
468 if (scalar @seen < 2) {
470 &DEBUG("seen: _ => '$_'.");
472 &performReply("i haven't seen '$person'");
478 ### TODO: multi channel support. may require &IsNick() to return
479 ### all channels or something.
480 my @chans = &GetNickInChans($seen[0]);
482 $reply = "$seen[0] is currently on";
486 next unless (exists $userstats{lc $seen[0]}{'Join'});
487 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
490 if (&IsParam("seenStats")) {
492 $i = $userstats{lc $seen[0]}{'Count'};
493 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
494 $i = $userstats{lc $seen[0]}{'Time'};
495 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
498 my $howlong = &Time2String(time() - $seen[1]);
499 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
500 "in channel $seen[2], $howlong ago, ".
501 "saying\002:\002 '$seen[4]'.";
504 &performStrictReply($reply);
508 # slashdot headlines: from Chris Tessone.
509 if ($message =~ /^slashdot$/i) {
510 return $noreply unless (&hasParam("slashdot"));
512 &Forker("slashdot", sub { &Slashdot::Slashdot() });
514 $cmdstats{'Slashdot'}++;
518 # Topic management. xk++
519 # may want to add a flag(??) for topic in the near future. -xk
520 if ($message =~ /^topic(\s+(.*))?$/i) {
521 return $noreply unless (&hasParam("topic"));
523 my $chan = $talkchannel;
524 my @args = split(/ /, $2);
527 &msg($who,"Try 'help topic'");
531 $chan = lc(shift @args) if ($msgType eq 'private');
532 my $thiscmd = shift @args;
535 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
536 &msg($who, "error: channel argument is not required.");
537 &msg($who, "\002Usage\002: topic <CMD>");
541 # topic over private:
542 if ($msgType eq 'private' && $chan !~ /^#/) {
543 &msg($who, "error: channel argument is required.");
544 &msg($who, "\002Usage\002: topic #channel <CMD>");
548 if (&validChan($chan) == 0) {
549 &msg($who,"error: invalid channel \002$chan\002");
553 # for semi-outsiders.
554 if (!&IsNickInChan($who,$chan)) {
555 &msg($who, "Failed. You ($who) are not in $chan, hey?");
560 &loadMyModule($myModules{'topic'});
561 &Topic($chan, $thiscmd, join(' ', @args));
562 $cmdstats{'Topic'}++;
567 if ($message =~ /^countdown(\s+(\S+))?$/i) {
568 return $noreply unless (&hasParam("countdown"));
572 &loadMyModule($myModules{'countdown'});
575 $cmdstats{'Countdown'}++;
580 # User Information Services. requested by Flugh.
581 if ($message =~ /^u(ser)?info(\s+(.*))?$/i) {
582 return $noreply unless (&hasParam("userinfo"));
583 &loadMyModule($myModules{'userinfo'});
586 if (!defined $arg or $arg eq "") {
591 if ($arg =~ /^set(\s+(.*))?$/i) {
594 &help("userinfo set");
598 &UserInfoSet(split /\s+/, $arg, 2);
599 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
602 &help("userinfo unset");
606 &UserInfoSet($arg, "");
616 if ($message =~ /^uptime$/i) {
617 return $noreply unless (&hasParam("uptime"));
620 &msg($who, "- Uptime for $ident -");
621 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
622 foreach (&uptimeGetInfo()) {
624 my $time = &Time2String($1);
627 &msg($who, "$count: $time $2");
631 $cmdstats{'Uptime'}++;
636 if ($message =~ /^wingate$/i) {
637 return $noreply unless (&hasParam("wingate"));
639 my $reply = "Wingate statistics: scanned \002"
640 .scalar(keys %wingate)."\002 hosts";
641 my $queue = scalar(keys %wingateToDo);
643 $reply .= ". I have \002$queue\002 hosts in the queue";
644 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
647 &performStrictReply("$reply.");
653 if ($message =~ /^convert(\s+(.*))?$/i) {
654 return $noreply unless (&hasParam("units"));
663 ($from,$to) = ($1,$2) if ($str =~ /^(.*) to (.*)$/);
664 ($from,$to) = ($2,$1) if ($str =~ /^(.*) from (.*)$/);
665 if (!defined $from or !defined $to or $to eq "" or $from eq "") {
666 &msg($who, "Invalid format!");
671 &Forker("units", sub { &Units::convertUnits($from, $to); } );
676 # do nothing and let the other routines have a go