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);
35 my $cmd = shift(@args);
39 foreach (keys %cmdhooks) {
42 next unless ($cmd =~ /^$ident$/i);
44 &DEBUG("pCH: $cmd matched $ident");
45 my %hash = %{ $cmdhooks{$ident} };
48 foreach (keys %hash) {
49 &DEBUG(" $cmd->$_ => '$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 ### ANY PROBLEMS WITH THIS? if so, add option to do either.
74 ### &{$hash{'CODEREF'}}(@args);
75 &{$hash{'CODEREF'}}(join ' ', @args);
79 if (exists $hash{'Cmdstats'}) {
80 $cmdstats{$hash{'Cmdstats'}}++;
83 &DEBUG("pCH: ended.");
91 &addCmdHook('d?bugs', ('CODEREF' => 'debianBugs',
92 'Forker' => 1, 'Identifier' => 'debianExtra',
93 'Cmdstats' => 'Debian Bugs') );
94 &addCmdHook('dauthor', ('CODEREF' => 'Debian::searchAuthor',
95 'Forker' => 1, 'Identifier' => 'debian',
96 'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) );
97 &addCmdHook('(d|search)desc', ('CODEREF' => 'Debian::searchDesc',
98 'Forker' => 1, 'Identifier' => 'debian',
99 'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) );
100 &addCmdHook('dincoming', ('CODEREF' => 'Debian::generateIncoming',
101 'Forker' => 1, 'Identifier' => 'debian' ) );
102 &addCmdHook('dstats', ('CODEREF' => 'Debian::infoStats',
103 'Forker' => 1, 'Identifier' => 'debian',
104 'Cmdstats' => 'Debian Statistics' ) );
105 &addCmdHook('d?contents', ('CODEREF' => 'Debian::searchContents',
106 'Forker' => 1, 'Identifier' => 'debian',
107 'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) );
108 &addCmdHook('d?find', ('CODEREF' => 'Debian::DebianFind',
109 'Forker' => 1, 'Identifier' => 'debian',
110 'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
111 &addCmdHook('insult', ('CODEREF' => 'Insult::Insult',
112 'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
113 &addCmdHook('kernel', ('CODEREF' => 'Kernel::Kernel',
114 'Forker' => 1, 'Identifier' => 'kernel',
115 'Cmdstats' => 'Kernel') );
116 &addCmdHook('listauth', ('CODEREF' => 'CmdListAuth',
117 'Identifier' => 'search', Module => 'factoids',
118 'Help' => 'listauth') );
119 &addCmdHook('quote', ('CODEREF' => 'Quote::Quote',
120 'Forker' => 1, 'Identifier' => 'quote',
121 'Help' => 'quote', 'Cmdstats' => 'Quote') );
122 &addCmdHook('countdown', ('CODEREF' => 'Countdown',
123 'Module' => 'countdown', 'Identifier' => 'countdown',
124 'Cmdstats' => 'Countdown') );
125 &addCmdHook('lart', ('CODEREF' => 'lart',
126 'Identifier' => 'lart', 'Help' => 'lart') );
127 &addCmdHook('convert', ('CODEREF' => 'convert',
128 'Forker' => 1, 'Identifier' => 'units',
129 'Help' => 'convert') );
130 &addCmdHook('(cookie|random)', ('CODEREF' => 'cookie',
131 'Forker' => 1, 'Identifier' => 'factoids') );
132 &addCmdHook('u(ser)?info', ('CODEREF' => 'userinfo',
133 'Identifier' => 'userinfo', 'Help' => 'userinfo',
134 'Module' => 'userinfo') );
135 &addCmdHook('rootWarn', ('CODEREF' => 'CmdrootWarn',
136 'Identifier' => 'rootWarn', 'Module' => 'rootwarn') );
137 &addCmdHook('seen', ('CODEREF' => 'seen', 'Identifier' => 'seen') );
138 &addCmdHook('dict', ('CODEREF' => 'Dict::Dict',
139 'Identifier' => 'dict', 'Help' => 'dict',
140 'Forker' => 1, 'Cmdstats' => 'Dict') );
141 &addCmdHook('slashdot', ('CODEREF' => 'Slashdot::Slashdot',
142 'Identifier' => 'slashdot', 'Forker' => 1,
143 'Cmdstats' => 'Slashdot') );
144 &addCmdHook('uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
145 'Cmdstats' => 'Uptime') );
146 &addCmdHook('nullski', ('CODEREF' => 'nullski', ) );
147 &addCmdHook('crash', ('CODEREF' => 'crash' ) );
148 sub nullski { my ($arg) = @_; foreach (`$arg`) { &msg($who,$_); } }
149 &addCmdHook('(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
150 'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
151 'Forker' => 1, 'Help' => 'freshmeat') );
156 &status("CMD: loaded ".scalar(keys %cmdhooks)." command hooks.");
160 if (!defined $message) {
161 &WARN("Modules: message is undefined. should never happen.");
165 # babel bot: Jonathan Feinberg++
166 if (&IsParam("babelfish") and $message =~ m{
168 (?:babel(?:fish)?|x|xlate|translate)
170 (to|from) # direction of translation (through)
172 ($babel::lang_regex)\w* # which language?
174 (.+) # The phrase to be translated
177 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
179 $cmdstats{'BabelFish'}++;
183 if (&IsParam("debian")) {
184 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
185 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
186 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
189 if (defined $package) {
190 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
199 # google searching. Simon++
200 if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?($W3Search_regex)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
201 return $noreply unless (&hasParam("wwwsearch"));
203 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2,$param{'wwwsearch'}); } );
205 $cmdstats{'WWWSearch'}++;
209 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
210 if ($message =~ /^list(\S+)( (.*))?$/i) {
211 return $noreply unless (&hasParam("search"));
213 my $thiscmd = lc($1);
216 $thiscmd =~ s/^vals$/values/;
217 return $noreply if ($thiscmd ne "keys" && $thiscmd ne "values");
220 if (!defined $args) {
221 &help("list". $thiscmd);
225 if (length $args == 1) {
226 &msg($who,"search string is too short.");
230 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
232 $cmdstats{'Factoid Search'}++;
236 # Nickometer. Adam Spiers++
237 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
238 return $noreply unless (&hasParam("nickometer"));
240 my $term = (lc $1 eq 'me') ? $who : $1;
243 &loadMyModule($myModules{'nickometer'});
244 my $percentage = &nickometer($term);
246 if ($percentage =~ /NaN/) {
247 $percentage = "off the scale";
249 $percentage = sprintf("%0.4f", $percentage);
250 $percentage =~ s/\.?0+$//;
254 if ($msgType eq 'public') {
255 &say("'$term' is $percentage lame, $who");
257 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
263 # Topic management. xk++
264 # may want to add a flag(??) for topic in the near future. -xk
265 if ($message =~ /^topic(\s+(.*))?$/i) {
266 return $noreply unless (&hasParam("topic"));
268 my $chan = $talkchannel;
269 my @args = split(/ /, $2);
272 &msg($who,"Try 'help topic'");
276 $chan = lc(shift @args) if ($msgType eq 'private');
277 my $thiscmd = shift @args;
280 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
281 &msg($who, "error: channel argument is not required.");
282 &msg($who, "\002Usage\002: topic <CMD>");
286 # topic over private:
287 if ($msgType eq 'private' && $chan !~ /^#/) {
288 &msg($who, "error: channel argument is required.");
289 &msg($who, "\002Usage\002: topic #channel <CMD>");
293 if (&validChan($chan) == 0) {
294 &msg($who,"error: invalid channel \002$chan\002");
298 # for semi-outsiders.
299 if (!&IsNickInChan($who,$chan)) {
300 &msg($who, "Failed. You ($who) are not in $chan, hey?");
305 &loadMyModule($myModules{'topic'});
306 &Topic($chan, $thiscmd, join(' ', @args));
307 $cmdstats{'Topic'}++;
312 if ($message =~ /^wingate$/i) {
313 return $noreply unless (&hasParam("wingate"));
315 my $reply = "Wingate statistics: scanned \002"
316 .scalar(keys %wingate)."\002 hosts";
317 my $queue = scalar(keys %wingateToDo);
319 $reply .= ". I have \002$queue\002 hosts in the queue";
320 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
323 &performStrictReply("$reply.");
328 # do nothing and let the other routines have a go
336 if (!defined $query) {
338 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
342 &Freshmeat::Freshmeat($query);
348 &msg($who, "- Uptime for $ident -");
349 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
351 foreach (&uptimeGetInfo()) {
353 my $time = &Time2String($1);
356 &msg($who, "$count: $time $2");
365 if (!defined $person) {
368 my $i = &countKeys("seen");
369 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
370 "seen ". &fixPlural("entry",$i) ." that I know of.");
378 &seenFlush(); # very evil hack. oh well, better safe than sorry.
380 ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
381 my $select = "nick,time,channel,host,message";
382 if ($person eq "random") {
383 @seen = &randKey("seen", $select);
385 @seen = &dbGet("seen", "nick", $person, $select);
388 if (scalar @seen < 2) {
390 &DEBUG("seen: _ => '$_'.");
392 &performReply("i haven't seen '$person'");
398 ### TODO: multi channel support. may require &IsNick() to return
399 ### all channels or something.
400 my @chans = &GetNickInChans($seen[0]);
402 $reply = "$seen[0] is currently on";
406 next unless (exists $userstats{lc $seen[0]}{'Join'});
407 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
410 if (&IsParam("seenStats")) {
412 $i = $userstats{lc $seen[0]}{'Count'};
413 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
414 $i = $userstats{lc $seen[0]}{'Time'};
415 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
418 my $howlong = &Time2String(time() - $seen[1]);
419 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
420 "in channel $seen[2], $howlong ago, ".
421 "saying\002:\002 '$seen[4]'.";
424 &performStrictReply($reply);
428 # User Information Services. requested by Flugh.
430 my ($arg) = join(' ',@_);
432 if ($arg =~ /^set(\s+(.*))?$/i) {
435 &help("userinfo set");
439 &UserInfoSet(split /\s+/, $arg, 2);
440 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
443 &help("userinfo unset");
447 &UserInfoSet($arg, "");
453 # cookie (random). xk++
457 # lets find that secret cookie.
458 my $target = ($msgType ne 'public') ? $who : $talkchannel;
459 my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
462 ### WILL CHEW TONS OF MEM.
463 ### TODO: convert this to a Forker function!
465 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
466 $key = &getRandom(@list);
467 $val = &getFactInfo("factoids", $key, "factoid_value");
469 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
473 s/##KEY/\002$key\002/;
476 s/\$who/$who/; # cheap fix.
477 s/(\S+)?\s*<\S+>/$1 /;
481 if ($cookiemsg =~ s/^ACTION //i) {
482 &action($target, $cookiemsg);
484 &msg($target, $cookiemsg);
489 my $arg = join(' ',@_);
490 my ($from,$to) = ('','');
492 ($from,$to) = ($1,$2) if ($arg =~ /^(.*?) to (.*)$/i);
493 ($from,$to) = ($2,$1) if ($arg =~ /^(.*?) from (.*)$/i);
495 if (!$to or !$from) {
496 &msg($who, "Invalid format!");
501 &Units::convertUnits($from, $to);
507 my ($target) = &fixString($_[0]);
509 my $chan = $talkchannel;
511 if ($msgType eq 'private') {
512 if ($target =~ /^($mask{chan})\s+(.*)$/) {
517 &msg($who, "error: invalid format or missing arguments.");
523 my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
525 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
526 $line =~ s/WHO/$who/g;
528 $line =~ s/WHO/$target/g;
530 $line .= ", courtesy of $who" if ($extra);
532 &action($chan, $line);
534 &status("lart: error reading file?");