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',
17 # CheckModule => 1, # ???
18 # Module => 'blah.pl' # preload module.
19 # Identifier => 'config_label', # change to Config?
20 # Help => 'help_label',
21 # Cmdstats => 'text_label',)
26 my ($ident, %hash) = @_;
28 &VERB("aCH: added $ident",2); # use $hash{'Identifier'}?
29 $cmdhooks{$ident} = \%hash;
34 my @args = split(' ', $message);
38 foreach (keys %cmdhooks) {
41 next unless ($args[0] =~ /^$ident$/i);
42 shift(@args); # just gotta do it.
44 &DEBUG("pCH: found $ident");
45 my %hash = %{ $cmdhooks{$ident} };
48 foreach (keys %hash) {
49 &DEBUG(" $ident->$_ => '$hash{$_}'.");
53 if (exists $hash{'Help'} and !scalar(@args)) {
54 &help( $hash{'Help'} );
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'}, sub { \&{$hash{'CODEREF'}}(@args) } );
67 if (exists $hash{'Module'}) {
68 &loadMyModule($myModules{ $hash{'Module'} });
71 ### TODO: check if CODEREF exists.
73 &{$hash{'CODEREF'}}(@args);
77 if (exists $hash{'Cmdstats'}) {
78 $cmdstats{$hash{'Cmdstats'}}++;
84 &DEBUG("pCH: ended.");
88 &addCmdHook('d?bugs', ('CODEREF' => 'debianBugs',
89 'Forker' => 1, 'Identifier' => 'debianExtra',
90 'Cmdstats' => 'Debian Bugs') );
91 &addCmdHook('dauthor', ('CODEREF' => 'Debian::searchAuthor',
92 'Forker' => 1, 'Identifier' => 'debian',
93 'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) );
94 &addCmdHook('(d|search)desc', ('CODEREF' => 'Debian::searchDesc',
95 'Forker' => 1, 'Identifier' => 'debian',
96 'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) );
97 &addCmdHook('dincoming', ('CODEREF' => 'Debian::generateIncoming',
98 'Forker' => 1, 'Identifier' => 'debian' ) );
99 &addCmdHook('dstats', ('CODEREF' => 'Debian::infoStats',
100 'Forker' => 1, 'Identifier' => 'debian',
101 'Cmdstats' => 'Debian Statistics' ) );
102 &addCmdHook('d?contents', ('CODEREF' => 'Debian::searchContents',
103 'Forker' => 1, 'Identifier' => 'debian',
104 'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) );
105 &addCmdHook('d?find', ('CODEREF' => 'Debian::DebianFind',
106 'Forker' => 1, 'Identifier' => 'debian',
107 'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
108 &addCmdHook('insult', ('CODEREF' => 'Insult::Insult',
109 'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
110 &addCmdHook('kernel', ('CODEREF' => 'Kernel::Kernel',
111 'Forker' => 1, 'Identifier' => 'kernel',
112 'Cmdstats' => 'Kernel') );
113 &addCmdHook('listauth', ('CODEREF' => 'CmdListAuth',
114 'Identifier' => 'search', Module => 'factoids',
115 'Help' => 'listauth') );
116 &addCmdHook('quote', ('CODEREF' => 'Quote::Quote',
117 'Forker' => 1, 'Identifier' => 'quote',
118 'Help' => 'quote', 'Cmdstats' => 'Quote') );
119 &addCmdHook('countdown', ('CODEREF' => 'Countdown',
120 'Module' => 'countdown', 'Identifier' => 'countdown',
121 'Cmdstats' => 'Countdown') );
122 &addCmdHook('lart', ('CODEREF' => 'lart',
123 'Identifier' => 'lart', 'Help' => 'lart') );
124 &addCmdHook('convert', ('CODEREF' => 'convert',
125 'Forker' => 1, 'Identifier' => 'units',
126 'Help' => 'convert') );
127 &addCmdHook('(cookie|random)', ('CODEREF' => 'cookie',
128 'Forker' => 1, 'Identifier' => 'factoids') );
129 &addCmdHook('u(ser)?info', ('CODEREF' => 'userinfo',
130 'Identifier' => 'userinfo', 'Help' => 'userinfo',
131 'Module' => 'userinfo') );
132 &addCmdHook('rootWarn', ('CODEREF' => 'CmdrootWarn',
133 'Identifier' => 'rootWarn', 'Module' => 'rootwarn') );
135 &status("CMD: loaded ".scalar(keys %cmdhooks)." command hooks.");
139 if (!defined $message) {
140 &WARN("Modules: message is undefined. should never happen.");
144 # babel bot: Jonathan Feinberg++
145 if (&IsParam("babelfish") and $message =~ m{
147 (?:babel(?:fish)?|x|xlate|translate)
149 (to|from) # direction of translation (through)
151 ($babel::lang_regex)\w* # which language?
153 (.+) # The phrase to be translated
156 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
158 $cmdstats{'BabelFish'}++;
162 if (&IsParam("debian")) {
163 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
164 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
165 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
168 if (defined $package) {
169 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
179 if ($message =~ /^dict(\s+(.*))?$/i) {
180 return $noreply unless (&hasParam("dict"));
183 $query =~ s/^[\s\t]+//;
184 $query =~ s/[\s\t]+$//;
185 $query =~ s/[\s\t]+/ /;
187 if (!defined $query) {
192 if (length $query > 30) {
193 &msg($who,"dictionary word is too long.");
197 &Forker("dict", sub { &Dict::Dict($query); } );
204 if ($message =~ /^(fm|freshmeat)(\s+(.*))?$/i) {
205 return $noreply unless (&hasParam("freshmeat"));
209 if (!defined $query) {
211 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
215 &loadMyModule($myModules{'freshmeat'});
216 &Freshmeat::Freshmeat($query);
218 $cmdstats{'Freshmeat'}++;
222 # google searching. Simon++
223 if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?($W3Search_regex)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
224 return $noreply unless (&hasParam("wwwsearch"));
226 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2,$param{'wwwsearch'}); } );
228 $cmdstats{'WWWSearch'}++;
232 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
233 if ($message =~ /^list(\S+)( (.*))?$/i) {
234 return $noreply unless (&hasParam("search"));
236 my $thiscmd = lc($1);
239 $thiscmd =~ s/^vals$/values/;
240 return $noreply if ($thiscmd ne "keys" && $thiscmd ne "values");
243 if (!defined $args) {
244 &help("list". $thiscmd);
248 if (length $args == 1) {
249 &msg($who,"search string is too short.");
253 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
255 $cmdstats{'Factoid Search'}++;
259 # Nickometer. Adam Spiers++
260 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
261 return $noreply unless (&hasParam("nickometer"));
263 my $term = (lc $1 eq 'me') ? $who : $1;
266 &loadMyModule($myModules{'nickometer'});
267 my $percentage = &nickometer($term);
269 if ($percentage =~ /NaN/) {
270 $percentage = "off the scale";
272 $percentage = sprintf("%0.4f", $percentage);
273 $percentage =~ s/\.?0+$//;
277 if ($msgType eq 'public') {
278 &say("'$term' is $percentage lame, $who");
280 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
287 if ($message =~ /^seen(\s+(\S+))?$/) {
288 return $noreply unless (&hasParam("seen"));
291 if (!defined $person) {
294 my $i = &countKeys("seen");
295 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
296 "seen ". &fixPlural("entry",$i) ." that I know of.");
304 &seenFlush(); # very evil hack. oh well, better safe than sorry.
306 ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
307 my $select = "nick,time,channel,host,message";
308 if ($person eq "random") {
309 @seen = &randKey("seen", $select);
311 @seen = &dbGet("seen", "nick", $person, $select);
314 if (scalar @seen < 2) {
316 &DEBUG("seen: _ => '$_'.");
318 &performReply("i haven't seen '$person'");
324 ### TODO: multi channel support. may require &IsNick() to return
325 ### all channels or something.
326 my @chans = &GetNickInChans($seen[0]);
328 $reply = "$seen[0] is currently on";
332 next unless (exists $userstats{lc $seen[0]}{'Join'});
333 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
336 if (&IsParam("seenStats")) {
338 $i = $userstats{lc $seen[0]}{'Count'};
339 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
340 $i = $userstats{lc $seen[0]}{'Time'};
341 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
344 my $howlong = &Time2String(time() - $seen[1]);
345 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
346 "in channel $seen[2], $howlong ago, ".
347 "saying\002:\002 '$seen[4]'.";
350 &performStrictReply($reply);
354 # slashdot headlines: from Chris Tessone.
355 if ($message =~ /^slashdot$/i) {
356 return $noreply unless (&hasParam("slashdot"));
358 &Forker("slashdot", sub { &Slashdot::Slashdot() });
360 $cmdstats{'Slashdot'}++;
364 # Topic management. xk++
365 # may want to add a flag(??) for topic in the near future. -xk
366 if ($message =~ /^topic(\s+(.*))?$/i) {
367 return $noreply unless (&hasParam("topic"));
369 my $chan = $talkchannel;
370 my @args = split(/ /, $2);
373 &msg($who,"Try 'help topic'");
377 $chan = lc(shift @args) if ($msgType eq 'private');
378 my $thiscmd = shift @args;
381 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
382 &msg($who, "error: channel argument is not required.");
383 &msg($who, "\002Usage\002: topic <CMD>");
387 # topic over private:
388 if ($msgType eq 'private' && $chan !~ /^#/) {
389 &msg($who, "error: channel argument is required.");
390 &msg($who, "\002Usage\002: topic #channel <CMD>");
394 if (&validChan($chan) == 0) {
395 &msg($who,"error: invalid channel \002$chan\002");
399 # for semi-outsiders.
400 if (!&IsNickInChan($who,$chan)) {
401 &msg($who, "Failed. You ($who) are not in $chan, hey?");
406 &loadMyModule($myModules{'topic'});
407 &Topic($chan, $thiscmd, join(' ', @args));
408 $cmdstats{'Topic'}++;
413 if ($message =~ /^uptime$/i) {
414 return $noreply unless (&hasParam("uptime"));
417 &msg($who, "- Uptime for $ident -");
418 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
419 foreach (&uptimeGetInfo()) {
421 my $time = &Time2String($1);
424 &msg($who, "$count: $time $2");
428 $cmdstats{'Uptime'}++;
433 if ($message =~ /^wingate$/i) {
434 return $noreply unless (&hasParam("wingate"));
436 my $reply = "Wingate statistics: scanned \002"
437 .scalar(keys %wingate)."\002 hosts";
438 my $queue = scalar(keys %wingateToDo);
440 $reply .= ". I have \002$queue\002 hosts in the queue";
441 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
444 &performStrictReply("$reply.");
449 # do nothing and let the other routines have a go
453 # User Information Services. requested by Flugh.
455 my ($arg) = join(' ',@_);
457 if ($arg =~ /^set(\s+(.*))?$/i) {
460 &help("userinfo set");
464 &UserInfoSet(split /\s+/, $arg, 2);
465 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
468 &help("userinfo unset");
472 &UserInfoSet($arg, "");
478 # cookie (random). xk++
482 # lets find that secret cookie.
483 my $target = ($msgType ne 'public') ? $who : $talkchannel;
484 my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
487 ### WILL CHEW TONS OF MEM.
488 ### TODO: convert this to a Forker function!
490 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
491 $key = &getRandom(@list);
492 $val = &getFactInfo("factoids", $key, "factoid_value");
494 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
498 s/##KEY/\002$key\002/;
501 s/\$who/$who/; # cheap fix.
502 s/(\S+)?\s*<\S+>/$1 /;
506 if ($cookiemsg =~ s/^ACTION //i) {
507 &action($target, $cookiemsg);
509 &msg($target, $cookiemsg);
516 ($from,$to) = ($args[0],$args[2]) if ($args[1] =~ /^from$/i);
517 ($from,$to) = ($args[2],$args[0]) if ($args[1] =~ /^to$/i);
519 if (!defined $from or !defined $to or $to eq "" or $from eq "") {
520 &msg($who, "Invalid format!");
525 &Units::convertUnits($from, $to);
531 my ($target) = &fixString($_[0]);
533 my $chan = $talkchannel;
535 if ($msgType eq 'private') {
536 if ($target =~ /^($mask{chan})\s+(.*)$/) {
541 &msg($who, "error: invalid format or missing arguments.");
547 my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
549 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
550 $line =~ s/WHO/$who/g;
552 $line =~ s/WHO/$target/g;
554 $line .= ", courtesy of $who" if ($extra);
556 &action($chan, $line);
558 &status("lart: error reading file?");