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 $line =~ /^(\S+)( (.*))?$/;
33 my @args = split(' ', $3 || '');
35 my $cmd = $1; # command name is whitespaceless.
40 # if (!exists %{"hooks_$hashname"}) {
41 # &WARN("cmd hooks \%$hashname does not exist.");
45 foreach (keys %{"hooks_$hashname"}) {
48 next unless ($cmd =~ /^$ident$/i);
50 &DEBUG("pCH(hooks_$hashname): $cmd matched $ident");
51 my %hash = %{ ${"hooks_$hashname"}{$ident} };
53 if (!scalar keys %hash) {
54 &WARN("CmdHook: hash is NULL?");
58 if (!exists $hash{CODEREF}) {
59 &ERROR("CODEREF undefined for $cmd or $ident.");
64 foreach (keys %hash) {
65 &DEBUG(" $cmd->$_ => '$hash{$_}'.");
69 if (exists $hash{'Help'} and !scalar(@args)) {
70 &help( $hash{'Help'} );
75 if (exists $hash{'Identifier'}) {
76 return $noreply unless (&hasParam($hash{'Identifier'}));
80 if (exists $hash{'UserFlag'}) {
81 return $noreply unless (&hasFlag($hash{'UserFlag'}));
84 ### FORKER,IDENTIFIER,CODEREF.
85 if (exists $hash{'Forker'}) {
86 $hash{'Identifier'} .= "-" if ($hash{'Forker'} eq "NULL");
88 ### FLAT_ARG / ARRAY option.
90 &Forker($hash{'Identifier'}, sub { \&{$hash{'CODEREF'}}(@args) } );
92 if (exists $hash{'Module'}) {
93 &loadMyModule($myModules{ $hash{'Module'} });
96 ### TODO: check if CODEREF exists.
98 if (exists $hash{'FlatArg'} and $hash{'FlatArg'} == 0) {
99 &status("CmdHook: using args as array.");
100 &{$hash{'CODEREF'}}(@args);
102 &{$hash{'CODEREF'}}($flatarg);
107 if (exists $hash{'Cmdstats'}) {
108 ${"hooks_$hashname"}{$hash{'Cmdstats'}}++;
111 &DEBUG("pCH: ended.");
120 ### START ADDING HOOKS.
122 &addCmdHook("extra", 'd?bugs', ('CODEREF' => 'debianBugs',
123 'Forker' => 1, 'Identifier' => 'debianExtra',
124 'Cmdstats' => 'Debian Bugs') );
125 &addCmdHook("extra", 'dauthor', ('CODEREF' => 'Debian::searchAuthor',
126 'Forker' => 1, 'Identifier' => 'debian',
127 'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) );
128 &addCmdHook("extra", '(d|search)desc', ('CODEREF' => 'Debian::searchDesc',
129 'Forker' => 1, 'Identifier' => 'debian',
130 'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) );
131 &addCmdHook("extra", 'dnew', ('CODEREF' => 'DebianNew',
132 'Identifier' => 'debian' ) );
133 &addCmdHook("extra", 'dincoming', ('CODEREF' => 'Debian::generateIncoming',
134 'Forker' => 1, 'Identifier' => 'debian' ) );
135 &addCmdHook("extra", 'dstats', ('CODEREF' => 'Debian::infoStats',
136 'Forker' => 1, 'Identifier' => 'debian',
137 'Cmdstats' => 'Debian Statistics' ) );
138 &addCmdHook("extra", 'd?contents', ('CODEREF' => 'Debian::searchContents',
139 'Forker' => 1, 'Identifier' => 'debian',
140 'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) );
141 &addCmdHook("extra", 'd?find', ('CODEREF' => 'Debian::DebianFind',
142 'Forker' => 1, 'Identifier' => 'debian',
143 'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
144 &addCmdHook("extra", 'insult', ('CODEREF' => 'Insult::Insult',
145 'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
146 &addCmdHook("extra", 'kernel', ('CODEREF' => 'Kernel::Kernel',
147 'Forker' => 1, 'Identifier' => 'kernel',
148 'Cmdstats' => 'Kernel') );
149 &addCmdHook("extra", 'listauth', ('CODEREF' => 'CmdListAuth',
150 'Identifier' => 'search', Module => 'factoids',
151 'Help' => 'listauth') );
152 &addCmdHook("extra", 'quote', ('CODEREF' => 'Quote::Quote',
153 'Forker' => 1, 'Identifier' => 'quote',
154 'Help' => 'quote', 'Cmdstats' => 'Quote') );
155 &addCmdHook("extra", 'countdown', ('CODEREF' => 'Countdown',
156 'Module' => 'countdown', 'Identifier' => 'countdown',
157 'Cmdstats' => 'Countdown') );
158 &addCmdHook("extra", 'lart', ('CODEREF' => 'lart',
159 'Identifier' => 'lart', 'Help' => 'lart') );
160 &addCmdHook("extra", 'convert', ('CODEREF' => 'convert',
161 'Forker' => 1, 'Identifier' => 'units',
162 'Help' => 'convert') );
163 &addCmdHook("extra", '(cookie|random)', ('CODEREF' => 'cookie',
164 'Forker' => 1, 'Identifier' => 'factoids') );
165 &addCmdHook("extra", 'u(ser)?info', ('CODEREF' => 'userinfo',
166 'Identifier' => 'userinfo', 'Help' => 'userinfo',
167 'Module' => 'userinfo') );
168 &addCmdHook("extra", 'rootWarn', ('CODEREF' => 'CmdrootWarn',
169 'Identifier' => 'rootWarn', 'Module' => 'rootwarn') );
170 &addCmdHook("extra", 'seen', ('CODEREF' => 'seen', 'Identifier' =>
172 &addCmdHook("extra", 'dict', ('CODEREF' => 'Dict::Dict',
173 'Identifier' => 'dict', 'Help' => 'dict',
174 'Forker' => 1, 'Cmdstats' => 'Dict') );
175 &addCmdHook("extra", 'slashdot', ('CODEREF' => 'Slashdot::Slashdot',
176 'Identifier' => 'slashdot', 'Forker' => 1,
177 'Cmdstats' => 'Slashdot') );
178 &addCmdHook("extra", 'uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
179 'Cmdstats' => 'Uptime') );
180 &addCmdHook("extra", 'nullski', ('CODEREF' => 'nullski', ) );
181 &addCmdHook("extra", 'crash', ('CODEREF' => 'crash' ) );
182 sub nullski { my ($arg) = @_; foreach (`$arg`) { &msg($who,$_); } }
183 &addCmdHook("extra", '(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
184 'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
185 'Forker' => 1, 'Help' => 'freshmeat') );
187 ### END OF ADDING HOOKS.
189 &status("CMD: loaded ".scalar(keys %hooks_extra)." EXTRA command hooks.");
192 if (!defined $message) {
193 &WARN("Modules: message is undefined. should never happen.");
197 # babel bot: Jonathan Feinberg++
198 if (&IsParam("babelfish") and $message =~ m{
200 (?:babel(?:fish)?|x|xlate|translate)
202 (to|from) # direction of translation (through)
204 ($babel::lang_regex)\w* # which language?
206 (.+) # The phrase to be translated
209 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
211 $cmdstats{'BabelFish'}++;
215 if (&IsParam("debian")) {
216 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
217 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
218 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
221 if (defined $package) {
222 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
231 # google searching. Simon++
232 if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
233 return $noreply unless (&hasParam("wwwsearch"));
235 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
237 $cmdstats{'WWWSearch'}++;
241 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
242 if ($message =~ /^list(\S+)( (.*))?$/i) {
243 return $noreply unless (&hasParam("search"));
245 my $thiscmd = lc($1);
248 $thiscmd =~ s/^vals$/values/;
249 return $noreply if ($thiscmd ne "keys" && $thiscmd ne "values");
252 if (!defined $args) {
253 &help("list". $thiscmd);
257 if (length $args == 1) {
258 &msg($who,"search string is too short.");
262 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
264 $cmdstats{'Factoid Search'}++;
268 # Nickometer. Adam Spiers++
269 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
270 return $noreply unless (&hasParam("nickometer"));
272 my $term = (lc $1 eq 'me') ? $who : $1;
275 &loadMyModule($myModules{'nickometer'});
276 my $percentage = &nickometer($term);
278 if ($percentage =~ /NaN/) {
279 $percentage = "off the scale";
281 $percentage = sprintf("%0.4f", $percentage);
282 $percentage =~ s/\.?0+$//;
286 if ($msgType eq 'public') {
287 &say("'$term' is $percentage lame, $who");
289 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
295 # Topic management. xk++
296 # may want to add a flag(??) for topic in the near future. -xk
297 if ($message =~ /^topic(\s+(.*))?$/i) {
298 return $noreply unless (&hasParam("topic"));
300 my $chan = $talkchannel;
301 my @args = split(/ /, $2);
304 &msg($who,"Try 'help topic'");
308 $chan = lc(shift @args) if ($msgType eq 'private');
309 my $thiscmd = shift @args;
312 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
313 &msg($who, "error: channel argument is not required.");
314 &msg($who, "\002Usage\002: topic <CMD>");
318 # topic over private:
319 if ($msgType eq 'private' && $chan !~ /^#/) {
320 &msg($who, "error: channel argument is required.");
321 &msg($who, "\002Usage\002: topic #channel <CMD>");
325 if (&validChan($chan) == 0) {
326 &msg($who,"error: invalid channel \002$chan\002");
330 # for semi-outsiders.
331 if (!&IsNickInChan($who,$chan)) {
332 &msg($who, "Failed. You ($who) are not in $chan, hey?");
337 &loadMyModule($myModules{'topic'});
338 &Topic($chan, $thiscmd, join(' ', @args));
339 $cmdstats{'Topic'}++;
344 if ($message =~ /^wingate$/i) {
345 return $noreply unless (&hasParam("wingate"));
347 my $reply = "Wingate statistics: scanned \002"
348 .scalar(keys %wingate)."\002 hosts";
349 my $queue = scalar(keys %wingateToDo);
351 $reply .= ". I have \002$queue\002 hosts in the queue";
352 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
355 &performStrictReply("$reply.");
360 # do nothing and let the other routines have a go
368 if (!defined $query) {
370 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
374 &Freshmeat::Freshmeat($query);
380 &msg($who, "- Uptime for $ident -");
381 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
383 foreach (&uptimeGetInfo()) {
385 my $time = &Time2String($1);
388 &msg($who, "$count: $time $2");
397 if (!defined $person) {
400 my $i = &countKeys("seen");
401 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
402 "seen ". &fixPlural("entry",$i) ." that I know of.");
410 &seenFlush(); # very evil hack. oh well, better safe than sorry.
412 ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
413 my $select = "nick,time,channel,host,message";
414 if ($person eq "random") {
415 @seen = &randKey("seen", $select);
417 @seen = &dbGet("seen", "nick", $person, $select);
420 if (scalar @seen < 2) {
422 &DEBUG("seen: _ => '$_'.");
424 &performReply("i haven't seen '$person'");
430 ### TODO: multi channel support. may require &IsNick() to return
431 ### all channels or something.
432 my @chans = &GetNickInChans($seen[0]);
434 $reply = "$seen[0] is currently on";
438 next unless (exists $userstats{lc $seen[0]}{'Join'});
439 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
442 if (&IsParam("seenStats")) {
444 $i = $userstats{lc $seen[0]}{'Count'};
445 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
446 $i = $userstats{lc $seen[0]}{'Time'};
447 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
450 my $howlong = &Time2String(time() - $seen[1]);
451 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
452 "in channel $seen[2], $howlong ago, ".
453 "saying\002:\002 '$seen[4]'.";
456 &performStrictReply($reply);
460 # User Information Services. requested by Flugh.
462 my ($arg) = join(' ',@_);
464 if ($arg =~ /^set(\s+(.*))?$/i) {
467 &help("userinfo set");
471 &UserInfoSet(split /\s+/, $arg, 2);
472 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
475 &help("userinfo unset");
479 &UserInfoSet($arg, "");
485 # cookie (random). xk++
489 # lets find that secret cookie.
490 my $target = ($msgType ne 'public') ? $who : $talkchannel;
491 my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
494 ### WILL CHEW TONS OF MEM.
495 ### TODO: convert this to a Forker function!
497 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
498 $key = &getRandom(@list);
499 $val = &getFactInfo("factoids", $key, "factoid_value");
501 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
505 s/##KEY/\002$key\002/;
508 s/\$who/$who/; # cheap fix.
509 s/(\S+)?\s*<\S+>/$1 /;
513 if ($cookiemsg =~ s/^ACTION //i) {
514 &action($target, $cookiemsg);
516 &msg($target, $cookiemsg);
521 my $arg = join(' ',@_);
522 my ($from,$to) = ('','');
524 ($from,$to) = ($1,$2) if ($arg =~ /^(.*?) to (.*)$/i);
525 ($from,$to) = ($2,$1) if ($arg =~ /^(.*?) from (.*)$/i);
527 if (!$to or !$from) {
528 &msg($who, "Invalid format!");
533 &Units::convertUnits($from, $to);
539 my ($target) = &fixString($_[0]);
541 my $chan = $talkchannel;
543 if ($msgType eq 'private') {
544 if ($target =~ /^($mask{chan})\s+(.*)$/) {
549 &msg($who, "error: invalid format or missing arguments.");
555 my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
557 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
558 $line =~ s/WHO/$who/g;
560 $line =~ s/WHO/$target/g;
562 $line .= ", courtesy of $who" if ($extra);
564 &action($chan, $line);
566 &status("lart: error reading file?");
571 my $idx = "debian/Packages-woody.idx";
576 $error++ unless ( -e $idx);
577 $error++ unless ( -e "$idx-old");
580 $error = "no woody/woody-old index file found.";
581 &ERROR("Debian: $error");
587 open(IDX2, "$idx-old");
601 next if (exists $pkg{$_});
607 &main::performStrictReply( &main::formListReply(0, "New debian packages:", @new) );