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 if (exists ${"hooks_$hashname"}{$ident}) {
25 ### &WARN("aCH: cmd hooks \%$hashname{$ident} already exists.");
29 &VERB("aCH: added $ident",2); # use $hash{'Identifier'}?
30 ### hrm... prevent warnings?
31 ${"hooks_$hashname"}{$ident} = \%hash;
36 my ($hashname, $line) = @_;
37 $line =~ /^(\S+)( (.*))?$/;
38 my @args = split(' ', $3 || '');
40 my $cmd = $1; # command name is whitespaceless.
45 if (!defined %{"hooks_$hashname"}) {
46 &WARN("cmd hooks \%$hashname does not exist.");
50 foreach (keys %{"hooks_$hashname"}) {
53 next unless ($cmd =~ /^$ident$/i);
56 &WARN("pCH: Multiple hook match: $ident");
60 &DEBUG("pCH(hooks_$hashname): $cmd matched $ident");
61 my %hash = %{ ${"hooks_$hashname"}{$ident} };
63 if (!scalar keys %hash) {
64 &WARN("CmdHook: hash is NULL?");
68 if (!exists $hash{CODEREF}) {
69 &ERROR("CODEREF undefined for $cmd or $ident.");
74 foreach (keys %hash) {
75 &DEBUG(" $cmd->$_ => '$hash{$_}'.");
79 if (exists $hash{'Help'} and !scalar(@args)) {
80 &help( $hash{'Help'} );
85 if (exists $hash{'Identifier'}) {
86 return unless (&hasParam($hash{'Identifier'}));
90 if (exists $hash{'UserFlag'}) {
91 return unless (&hasFlag($hash{'UserFlag'}));
94 ### FORKER,IDENTIFIER,CODEREF.
95 if (exists $hash{'Forker'}) {
96 $hash{'Identifier'} .= "-" if ($hash{'Forker'} eq "NULL");
98 ### FLAT_ARG / ARRAY option.
100 &Forker($hash{'Identifier'}, sub { \&{$hash{'CODEREF'}}(@args) } );
102 if (exists $hash{'Module'}) {
103 &loadMyModule($myModules{ $hash{'Module'} });
106 ### TODO: check if CODEREF exists.
108 if (exists $hash{'FlatArg'} and $hash{'FlatArg'} == 0) {
109 &status("CmdHook: using args as array.");
110 &{$hash{'CODEREF'}}(@args);
112 &{$hash{'CODEREF'}}($flatarg);
117 if (exists $hash{'Cmdstats'}) {
118 $cmdstats{ $hash{'Cmdstats'} }++;
121 &DEBUG("pCH: ended.");
131 ### START ADDING HOOKS.
133 &addCmdHook("extra", 'd?bugs', ('CODEREF' => 'debianBugs',
134 'Forker' => 1, 'Identifier' => 'debianExtra',
135 'Cmdstats' => 'Debian Bugs') );
136 &addCmdHook("extra", 'dauthor', ('CODEREF' => 'Debian::searchAuthor',
137 'Forker' => 1, 'Identifier' => 'debian',
138 'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) );
139 &addCmdHook("extra", '(d|search)desc', ('CODEREF' => 'Debian::searchDesc',
140 'Forker' => 1, 'Identifier' => 'debian',
141 'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) );
142 &addCmdHook("extra", 'dnew', ('CODEREF' => 'DebianNew',
143 'Identifier' => 'debian' ) );
144 &addCmdHook("extra", 'dincoming', ('CODEREF' => 'Debian::generateIncoming',
145 'Forker' => 1, 'Identifier' => 'debian' ) );
146 &addCmdHook("extra", 'dstats', ('CODEREF' => 'Debian::infoStats',
147 'Forker' => 1, 'Identifier' => 'debian',
148 'Cmdstats' => 'Debian Statistics' ) );
149 &addCmdHook("extra", 'd?contents', ('CODEREF' => 'Debian::searchContents',
150 'Forker' => 1, 'Identifier' => 'debian',
151 'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) );
152 &addCmdHook("extra", 'd?find', ('CODEREF' => 'Debian::DebianFind',
153 'Forker' => 1, 'Identifier' => 'debian',
154 'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
155 &addCmdHook("extra", 'insult', ('CODEREF' => 'Insult::Insult',
156 'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
157 &addCmdHook("extra", 'kernel', ('CODEREF' => 'Kernel::Kernel',
158 'Forker' => 1, 'Identifier' => 'kernel',
159 'Cmdstats' => 'Kernel') );
160 &addCmdHook("extra", 'listauth', ('CODEREF' => 'CmdListAuth',
161 'Identifier' => 'search', Module => 'factoids',
162 'Help' => 'listauth') );
163 &addCmdHook("extra", 'quote', ('CODEREF' => 'Quote::Quote',
164 'Forker' => 1, 'Identifier' => 'quote',
165 'Help' => 'quote', 'Cmdstats' => 'Quote') );
166 &addCmdHook("extra", 'countdown', ('CODEREF' => 'Countdown',
167 'Module' => 'countdown', 'Identifier' => 'countdown',
168 'Cmdstats' => 'Countdown') );
169 &addCmdHook("extra", 'lart', ('CODEREF' => 'lart',
170 'Identifier' => 'lart', 'Help' => 'lart') );
171 &addCmdHook("extra", 'convert', ('CODEREF' => 'convert',
172 'Forker' => 1, 'Identifier' => 'units',
173 'Help' => 'convert') );
174 &addCmdHook("extra", '(cookie|random)', ('CODEREF' => 'cookie',
175 'Forker' => 1, 'Identifier' => 'factoids') );
176 &addCmdHook("extra", 'u(ser)?info', ('CODEREF' => 'userinfo',
177 'Identifier' => 'userinfo', 'Help' => 'userinfo',
178 'Module' => 'userinfo') );
179 &addCmdHook("extra", 'rootWarn', ('CODEREF' => 'CmdrootWarn',
180 'Identifier' => 'rootWarn', 'Module' => 'rootwarn') );
181 &addCmdHook("extra", 'seen', ('CODEREF' => 'seen', 'Identifier' =>
183 &addCmdHook("extra", 'dict', ('CODEREF' => 'Dict::Dict',
184 'Identifier' => 'dict', 'Help' => 'dict',
185 'Forker' => 1, 'Cmdstats' => 'Dict') );
186 &addCmdHook("extra", 'slashdot', ('CODEREF' => 'Slashdot::Slashdot',
187 'Identifier' => 'slashdot', 'Forker' => 1,
188 'Cmdstats' => 'Slashdot') );
189 &addCmdHook("extra", 'uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
190 'Cmdstats' => 'Uptime') );
191 &addCmdHook("extra", 'nullski', ('CODEREF' => 'nullski', ) );
192 &addCmdHook("extra", 'crash', ('CODEREF' => 'crash' ) );
193 sub nullski { my ($arg) = @_; foreach (`$arg`) { &msg($who,$_); } }
194 &addCmdHook("extra", '(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
195 'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
196 'Forker' => 1, 'Help' => 'freshmeat') );
198 ### END OF ADDING HOOKS.
200 &status("CMD: loaded ".scalar(keys %hooks_extra)." EXTRA command hooks.");
203 if (!defined $message) {
204 &WARN("Modules: message is undefined. should never happen.");
208 # babel bot: Jonathan Feinberg++
209 if (&IsParam("babelfish") and $message =~ m{
211 (?:babel(?:fish)?|x|xlate|translate)
213 (to|from) # direction of translation (through)
215 ($babel::lang_regex)\w* # which language?
217 (.+) # The phrase to be translated
220 &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
222 $cmdstats{'BabelFish'}++;
226 if (&IsParam("debian")) {
227 my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
228 $debiancmd .= '|recommends?|suggests?|maint|maintainer';
229 if ($message =~ /^($debiancmd)(\s+(.*))?$/i) {
232 if (defined $package) {
233 &Forker("debian", sub { &Debian::infoPackages($1, $package); } );
242 # google searching. Simon++
243 if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
244 return unless (&hasParam("wwwsearch"));
246 &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
248 $cmdstats{'WWWSearch'}++;
252 # list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
253 if ($message =~ /^list(\S+)( (.*))?$/i) {
254 return unless (&hasParam("search"));
256 my $thiscmd = lc($1);
259 $thiscmd =~ s/^vals$/values/;
260 return if ($thiscmd ne "keys" && $thiscmd ne "values");
263 if (!defined $args) {
264 &help("list". $thiscmd);
268 if (length $args == 1) {
269 &msg($who,"search string is too short.");
273 &Forker("search", sub { &Search::Search($thiscmd, $args); } );
275 $cmdstats{'Factoid Search'}++;
279 # Nickometer. Adam Spiers++
280 if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
281 return unless (&hasParam("nickometer"));
283 my $term = (lc $1 eq 'me') ? $who : $1;
285 &loadMyModule($myModules{'nickometer'});
287 if ($term =~ /^$mask{chan}$/) {
288 &DEBUG("nickometer: term == chan.");
290 if (!&validChan($term)) {
291 &msg($who, "error: channel is invalid.");
297 foreach (keys %{ $channels{lc $term}{''} }) {
299 &WARN("nickometer: _ is undefined.");
303 my $value = &nickometer($_);
304 $nickometer{$value}{$_} = 1;
307 ### TODO: compact with map?
309 foreach (sort {$a <=> $b} keys %nickometer) {
310 my $str = join(", ", sort keys %{$nickometer{$_}});
311 push(@list, "$str ($_)");
314 &pSReply( &formListReply(0, "Nickometer list for $term ", @list) );
319 my $percentage = &nickometer($term);
321 if ($percentage =~ /NaN/) {
322 $percentage = "off the scale";
324 $percentage = sprintf("%0.4f", $percentage);
325 $percentage =~ s/\.?0+$//;
329 if ($msgType eq 'public') {
330 &say("'$term' is $percentage lame, $who");
332 &msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
338 # Topic management. xk++
339 # may want to add a flag(??) for topic in the near future. -xk
340 if ($message =~ /^topic(\s+(.*))?$/i) {
341 return unless (&hasParam("topic"));
343 my $chan = $talkchannel;
344 my @args = split(/ /, $2);
347 &msg($who,"Try 'help topic'");
351 $chan = lc(shift @args) if ($msgType eq 'private');
352 my $thiscmd = shift @args;
355 if ($msgType eq 'public' && $thiscmd =~ /^#/) {
356 &msg($who, "error: channel argument is not required.");
357 &msg($who, "\002Usage\002: topic <CMD>");
361 # topic over private:
362 if ($msgType eq 'private' && $chan !~ /^#/) {
363 &msg($who, "error: channel argument is required.");
364 &msg($who, "\002Usage\002: topic #channel <CMD>");
368 if (&validChan($chan) == 0) {
369 &msg($who,"error: invalid channel \002$chan\002");
373 # for semi-outsiders.
374 if (!&IsNickInChan($who,$chan)) {
375 &msg($who, "Failed. You ($who) are not in $chan, hey?");
380 &loadMyModule($myModules{'topic'});
381 &Topic($chan, $thiscmd, join(' ', @args));
382 $cmdstats{'Topic'}++;
387 if ($message =~ /^wingate$/i) {
388 return unless (&hasParam("wingate"));
390 my $reply = "Wingate statistics: scanned \002"
391 .scalar(keys %wingate)."\002 hosts";
392 my $queue = scalar(keys %wingateToDo);
394 $reply .= ". I have \002$queue\002 hosts in the queue";
395 $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
398 &performStrictReply("$reply.");
403 # do nothing and let the other routines have a go
411 if (!defined $query) {
413 &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
417 &Freshmeat::Freshmeat($query);
423 &msg($who, "- Uptime for $ident -");
424 &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
426 foreach (&uptimeGetInfo()) {
428 my $time = &Time2String($1);
431 &msg($who, "$count: $time $2");
440 if (!defined $person) {
443 my $i = &countKeys("seen");
444 &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
445 "seen ". &fixPlural("entry",$i) ." that I know of.");
453 &seenFlush(); # very evil hack. oh well, better safe than sorry.
455 ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
456 my $select = "nick,time,channel,host,message";
457 if ($person eq "random") {
458 @seen = &randKey("seen", $select);
460 @seen = &dbGet("seen", "nick", $person, $select);
463 if (scalar @seen < 2) {
465 &DEBUG("seen: _ => '$_'.");
467 &performReply("i haven't seen '$person'");
473 ### TODO: multi channel support. may require &IsNick() to return
474 ### all channels or something.
475 my @chans = &GetNickInChans($seen[0]);
477 $reply = "$seen[0] is currently on";
481 next unless (exists $userstats{lc $seen[0]}{'Join'});
482 $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
485 if (&IsParam("seenStats")) {
487 $i = $userstats{lc $seen[0]}{'Count'};
488 $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
489 $i = $userstats{lc $seen[0]}{'Time'};
490 $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
493 my $howlong = &Time2String(time() - $seen[1]);
494 $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
495 "in channel $seen[2], $howlong ago, ".
496 "saying\002:\002 '$seen[4]'.";
499 &performStrictReply($reply);
503 # User Information Services. requested by Flugh.
505 my ($arg) = join(' ',@_);
507 if ($arg =~ /^set(\s+(.*))?$/i) {
510 &help("userinfo set");
514 &UserInfoSet(split /\s+/, $arg, 2);
515 } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
518 &help("userinfo unset");
522 &UserInfoSet($arg, "");
528 # cookie (random). xk++
532 # lets find that secret cookie.
533 my $target = ($msgType ne 'public') ? $who : $talkchannel;
534 my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
537 ### WILL CHEW TONS OF MEM.
538 ### TODO: convert this to a Forker function!
540 my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
541 $key = &getRandom(@list);
542 $val = &getFactInfo("factoids", $key, "factoid_value");
544 ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
548 s/##KEY/\002$key\002/;
551 s/\$who/$who/; # cheap fix.
552 s/(\S+)?\s*<\S+>/$1 /;
556 if ($cookiemsg =~ s/^ACTION //i) {
557 &action($target, $cookiemsg);
559 &msg($target, $cookiemsg);
564 my $arg = join(' ',@_);
565 my ($from,$to) = ('','');
567 ($from,$to) = ($1,$2) if ($arg =~ /^(.*?) to (.*)$/i);
568 ($from,$to) = ($2,$1) if ($arg =~ /^(.*?) from (.*)$/i);
570 if (!$to or !$from) {
571 &msg($who, "Invalid format!");
576 &Units::convertUnits($from, $to);
582 my ($target) = &fixString($_[0]);
584 my $chan = $talkchannel;
586 if ($msgType eq 'private') {
587 if ($target =~ /^($mask{chan})\s+(.*)$/) {
592 &msg($who, "error: invalid format or missing arguments.");
598 my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
600 if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
601 $line =~ s/WHO/$who/g;
603 $line =~ s/WHO/$target/g;
605 $line .= ", courtesy of $who" if ($extra);
607 &action($chan, $line);
609 &status("lart: error reading file?");
614 my $idx = "debian/Packages-woody.idx";
619 $error++ unless ( -e $idx);
620 $error++ unless ( -e "$idx-old");
623 $error = "no woody/woody-old index file found.";
624 &ERROR("Debian: $error");
630 open(IDX2, "$idx-old");
644 next if (exists $pkg{$_});
650 &::performStrictReply( &::formListReply(0, "New debian packages:", @new) );