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'}}++;
81 &DEBUG("pCH: ended.");
89 &addCmdHook('d?bugs', ('CODEREF' => 'debianBugs',
90 'Forker' => 1, 'Identifier' => 'debianExtra',
91 'Cmdstats' => 'Debian Bugs') );
92 &addCmdHook('dauthor', ('CODEREF' => 'Debian::searchAuthor',
93 'Forker' => 1, 'Identifier' => 'debian',
94 'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) );
95 &addCmdHook('(d|search)desc', ('CODEREF' => 'Debian::searchDesc',
96 'Forker' => 1, 'Identifier' => 'debian',
97 'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) );
98 &addCmdHook('dincoming', ('CODEREF' => 'Debian::generateIncoming',
99 'Forker' => 1, 'Identifier' => 'debian' ) );
100 &addCmdHook('dstats', ('CODEREF' => 'Debian::infoStats',
101 'Forker' => 1, 'Identifier' => 'debian',
102 'Cmdstats' => 'Debian Statistics' ) );
103 &addCmdHook('d?contents', ('CODEREF' => 'Debian::searchContents',
104 'Forker' => 1, 'Identifier' => 'debian',
105 'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) );
106 &addCmdHook('d?find', ('CODEREF' => 'Debian::DebianFind',
107 'Forker' => 1, 'Identifier' => 'debian',
108 'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
109 &addCmdHook('insult', ('CODEREF' => 'Insult::Insult',
110 'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
111 &addCmdHook('kernel', ('CODEREF' => 'Kernel::Kernel',
112 'Forker' => 1, 'Identifier' => 'kernel',
113 'Cmdstats' => 'Kernel') );
114 &addCmdHook('listauth', ('CODEREF' => 'CmdListAuth',
115 'Identifier' => 'search', Module => 'factoids',
116 'Help' => 'listauth') );
117 &addCmdHook('quote', ('CODEREF' => 'Quote::Quote',
118 'Forker' => 1, 'Identifier' => 'quote',
119 'Help' => 'quote', 'Cmdstats' => 'Quote') );
120 &addCmdHook('countdown', ('CODEREF' => 'Countdown',
121 'Module' => 'countdown', 'Identifier' => 'countdown',
122 'Cmdstats' => 'Countdown') );
123 &addCmdHook('lart', ('CODEREF' => 'lart',
124 'Identifier' => 'lart', 'Help' => 'lart') );
125 &addCmdHook('convert', ('CODEREF' => 'convert',
126 'Forker' => 1, 'Identifier' => 'units',
127 'Help' => 'convert') );
128 &addCmdHook('(cookie|random)', ('CODEREF' => 'cookie',
129 'Forker' => 1, 'Identifier' => 'factoids') );
130 &addCmdHook('u(ser)?info', ('CODEREF' => 'userinfo',
131 'Identifier' => 'userinfo', 'Help' => 'userinfo',
132 'Module' => 'userinfo') );
133 &addCmdHook('rootWarn', ('CODEREF' => 'CmdrootWarn',
134 'Identifier' => 'rootWarn', 'Module' => 'rootwarn') );
135 &addCmdHook('seen', ('CODEREF' => 'seen', 'Identifier' => 'seen') );
136 &addCmdHook('dict', ('CODEREF' => 'Dict::Dict',
137 'Identifier' => 'dict', 'Help' => 'dict',
138 'Forker' => 1, 'Cmdstats' => 'Dict') );
139 &addCmdHook('slashdot', ('CODEREF' => 'Slashdot::Slashdot',
140 'Identifier' => 'slashdot', 'Forker' => 1,
141 'Cmdstats' => 'Slashdot') );
142 &addCmdHook('uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
143 'Cmdstats' => 'Uptime') );
144 &addCmdHook('freshmeat', ('CODEREF' => 'Freshmeat::Freshmeat',
145 'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
146 'Module' => 'freshmeat', 'Help' => 'freshmeat') );
151 &status("CMD: loaded ".scalar(keys %cmdhooks)." command hooks.");
155 if (!defined $message) {
156 &WARN("Modules: message is undefined. should never happen.");
160 # babel bot: Jonathan Feinberg++
161 if (&IsParam("babelfish") and $message =~ m{
163 (?:babel(?:fish)?|x|xlate|translate)
165 (to|from) # direction of translation (through)
167 ($babel::lang_regex)\w* # which language?
169 (.+) # The phrase to be translated
172 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
174 $cmdstats{'BabelFish'}++;
178 if (&IsParam("debian")) {
179 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
180 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
181 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
184 if (defined $package) {
185 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
194 # google searching. Simon++
195 if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?($W3Search_regex)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
196 return $noreply unless (&hasParam("wwwsearch"));
198 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2,$param{'wwwsearch'}); } );
200 $cmdstats{'WWWSearch'}++;
204 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
205 if ($message =~ /^list(\S+)( (.*))?$/i) {
206 return $noreply unless (&hasParam("search"));
208 my $thiscmd = lc($1);
211 $thiscmd =~ s/^vals$/values/;
212 return $noreply if ($thiscmd ne "keys" && $thiscmd ne "values");
215 if (!defined $args) {
216 &help("list". $thiscmd);
220 if (length $args == 1) {
221 &msg($who,"search string is too short.");
225 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
227 $cmdstats{'Factoid Search'}++;
231 # Nickometer. Adam Spiers++
232 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
233 return $noreply unless (&hasParam("nickometer"));
235 my $term = (lc $1 eq 'me') ? $who : $1;
238 &loadMyModule($myModules{'nickometer'});
239 my $percentage = &nickometer($term);
241 if ($percentage =~ /NaN/) {
242 $percentage = "off the scale";
244 $percentage = sprintf("%0.4f", $percentage);
245 $percentage =~ s/\.?0+$//;
249 if ($msgType eq 'public') {
250 &say("'$term' is $percentage lame, $who");
252 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
258 # Topic management. xk++
259 # may want to add a flag(??) for topic in the near future. -xk
260 if ($message =~ /^topic(\s+(.*))?$/i) {
261 return $noreply unless (&hasParam("topic"));
263 my $chan = $talkchannel;
264 my @args = split(/ /, $2);
267 &msg($who,"Try 'help topic'");
271 $chan = lc(shift @args) if ($msgType eq 'private');
272 my $thiscmd = shift @args;
275 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
276 &msg($who, "error: channel argument is not required.");
277 &msg($who, "\002Usage\002: topic <CMD>");
281 # topic over private:
282 if ($msgType eq 'private' && $chan !~ /^#/) {
283 &msg($who, "error: channel argument is required.");
284 &msg($who, "\002Usage\002: topic #channel <CMD>");
288 if (&validChan($chan) == 0) {
289 &msg($who,"error: invalid channel \002$chan\002");
293 # for semi-outsiders.
294 if (!&IsNickInChan($who,$chan)) {
295 &msg($who, "Failed. You ($who) are not in $chan, hey?");
300 &loadMyModule($myModules{'topic'});
301 &Topic($chan, $thiscmd, join(' ', @args));
302 $cmdstats{'Topic'}++;
307 if ($message =~ /^wingate$/i) {
308 return $noreply unless (&hasParam("wingate"));
310 my $reply = "Wingate statistics: scanned \002"
311 .scalar(keys %wingate)."\002 hosts";
312 my $queue = scalar(keys %wingateToDo);
314 $reply .= ". I have \002$queue\002 hosts in the queue";
315 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
318 &performStrictReply("$reply.");
323 # do nothing and let the other routines have a go
331 if (!defined $query) {
333 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
337 &Freshmeat::Freshmeat($query);
343 &msg($who, "- Uptime for $ident -");
344 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
346 foreach (&uptimeGetInfo()) {
348 my $time = &Time2String($1);
351 &msg($who, "$count: $time $2");
360 if (!defined $person) {
363 my $i = &countKeys("seen");
364 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
365 "seen ". &fixPlural("entry",$i) ." that I know of.");
373 &seenFlush(); # very evil hack. oh well, better safe than sorry.
375 ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
376 my $select = "nick,time,channel,host,message";
377 if ($person eq "random") {
378 @seen = &randKey("seen", $select);
380 @seen = &dbGet("seen", "nick", $person, $select);
383 if (scalar @seen < 2) {
385 &DEBUG("seen: _ => '$_'.");
387 &performReply("i haven't seen '$person'");
393 ### TODO: multi channel support. may require &IsNick() to return
394 ### all channels or something.
395 my @chans = &GetNickInChans($seen[0]);
397 $reply = "$seen[0] is currently on";
401 next unless (exists $userstats{lc $seen[0]}{'Join'});
402 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
405 if (&IsParam("seenStats")) {
407 $i = $userstats{lc $seen[0]}{'Count'};
408 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
409 $i = $userstats{lc $seen[0]}{'Time'};
410 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
413 my $howlong = &Time2String(time() - $seen[1]);
414 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
415 "in channel $seen[2], $howlong ago, ".
416 "saying\002:\002 '$seen[4]'.";
419 &performStrictReply($reply);
423 # User Information Services. requested by Flugh.
425 my ($arg) = join(' ',@_);
427 if ($arg =~ /^set(\s+(.*))?$/i) {
430 &help("userinfo set");
434 &UserInfoSet(split /\s+/, $arg, 2);
435 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
438 &help("userinfo unset");
442 &UserInfoSet($arg, "");
448 # cookie (random). xk++
452 # lets find that secret cookie.
453 my $target = ($msgType ne 'public') ? $who : $talkchannel;
454 my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
457 ### WILL CHEW TONS OF MEM.
458 ### TODO: convert this to a Forker function!
460 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
461 $key = &getRandom(@list);
462 $val = &getFactInfo("factoids", $key, "factoid_value");
464 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
468 s/##KEY/\002$key\002/;
471 s/\$who/$who/; # cheap fix.
472 s/(\S+)?\s*<\S+>/$1 /;
476 if ($cookiemsg =~ s/^ACTION //i) {
477 &action($target, $cookiemsg);
479 &msg($target, $cookiemsg);
486 ($from,$to) = ($args[0],$args[2]) if ($args[1] =~ /^from$/i);
487 ($from,$to) = ($args[2],$args[0]) if ($args[1] =~ /^to$/i);
489 if (!defined $from or !defined $to or $to eq "" or $from eq "") {
490 &msg($who, "Invalid format!");
495 &Units::convertUnits($from, $to);
501 my ($target) = &fixString($_[0]);
503 my $chan = $talkchannel;
505 if ($msgType eq 'private') {
506 if ($target =~ /^($mask{chan})\s+(.*)$/) {
511 &msg($who, "error: invalid format or missing arguments.");
517 my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
519 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
520 $line =~ s/WHO/$who/g;
522 $line =~ s/WHO/$target/g;
524 $line .= ", courtesy of $who" if ($extra);
526 &action($chan, $line);
528 &status("lart: error reading file?");