#
-# Infobot user extension stubs
+# User Command Extension Stubs
#
if (&IsParam("useStrict")) { use strict; }
@W3Search_engines = qw(AltaVista Dejanews Excite Gopher HotBot Infoseek
Lycos Magellan PLweb SFgate Simple Verity Google);
$W3Search_regex = join '|', @W3Search_engines;
+$babel::lang_regex = ""; # lame fix.
### PROPOSED COMMAND HOOK IMPLEMENTATION.
-# addCmdHook('TEXT_HOOK', $code_ref,
-# (Forker => 1,
-# Identifier => 'config_label',
+# addCmdHook('TEXT_HOOK',
+# (CODEREF => 'Blah',
+# Forker => 1,
+# CheckModule => 1, # ???
+# Module => 'blah.pl' # preload module.
+# Identifier => 'config_label', # change to Config?
# Help => 'help_label',
# Cmdstats => 'text_label',)
#}
-### EXAMPLE
-# addCmdHook('d?find', \&debianFind(), (
-# Forker => 1,
-# Identifier => "debian",
-# Help => "dfind",
-# Cmdstats => "Debian Search",) );
-### NOTES:
-# * viable solution?
###
-sub Modules {
- if (!defined $message) {
- &WARN("Modules: message is undefined. should never happen.");
- return;
- }
+sub addCmdHook {
+ my ($ident, %hash) = @_;
- # babel bot: Jonathan Feinberg++
- if (&IsParam("babelfish") and $message =~ m{
- ^\s*
- (?:babel(?:fish)?|x|xlate|translate)
- \s+
- (to|from) # direction of translation (through)
- \s+
- ($babel::lang_regex)\w* # which language?
- \s*
- (.+) # The phrase to be translated
- }xoi) {
+ &VERB("aCH: added $ident",2); # use $hash{'Identifier'}?
+ $cmdhooks{$ident} = \%hash;
+}
- &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
+# RUN IF ADDRESSED.
+sub parseCmdHook {
+ my @args = split(' ', $message);
+ my $cmd = shift(@args);
- $cmdstats{'BabelFish'}++;
- return 'NOREPLY';
- }
+ &shmFlush();
- # cookie (random). xk++
- if ($message =~ /^(cookie|random)(\s+(.*))?$/i) {
- return 'NOREPLY' unless (&hasParam("cookie"));
+ foreach (keys %cmdhooks) {
+ my $ident = $_;
- my $arg = $3;
+ next unless ($cmd =~ /^$ident$/i);
- # lets find that secret cookie.
- my $target = $talkchannel;
- $target = $who if ($msgType ne 'public');
+ &DEBUG("pCH: $cmd matched $ident");
+ my %hash = %{ $cmdhooks{$ident} };
- my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
- my ($key,$value);
- ### WILL CHEW TONS OF MEM.
- ### TODO: convert this to a Forker function!
- if ($arg) {
- my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
- $key = &getRandom(@list);
- $val = &getFactInfo("factoids", $key, "factoid_value");
- } else {
- ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
+ ### DEBUG.
+ foreach (keys %hash) {
+ &DEBUG(" $cmd->$_ => '$hash{$_}'.");
}
- $cookiemsg =~ s/##KEY/\002$key\002/;
- $cookiemsg =~ s/##VALUE/$value/;
- $cookiemsg =~ s/##WHO/$who/;
- $cookiemsg =~ s/\$who/$who/; # cheap fix.
- $cookiemsg =~ s/(\S+)?\s*<\S+>/$1 /;
- $cookiemsg =~ s/\s+/ /g;
-
- if ($cookiemsg =~ s/^ACTION //i) {
- &action($target, $cookiemsg);
- } else {
- &msg($target, $cookiemsg);
+ ### HELP.
+ if (exists $hash{'Help'} and !scalar(@args)) {
+ &help( $hash{'Help'} );
+ return 1;
}
- $cmdstats{'Random Cookie'}++;
- return 'NOREPLY';
- }
-
- if ($message =~ /^d?bugs$/i) {
- return 'NOREPLY' unless (&hasParam("debianExtra"));
-
- &Forker("debianExtra", sub { &debianBugs(); } );
-
- $cmdstats{'Debian Bugs'}++;
- return 'NOREPLY';
- }
-
- # Debian Author Search.
- if ($message =~ /^dauthor(\s+(.*))?$/i) {
- return 'NOREPLY' unless (&hasParam("debian"));
-
- my $query = $2;
- if (!defined $query) {
- &help("dauthor");
- return 'NOREPLY';
+ ### IDENTIFIER.
+ if (exists $hash{'Identifier'}) {
+ return $noreply unless (&hasParam($hash{'Identifier'}));
}
- &Forker("debian", sub { &Debian::searchAuthor($query); } );
-
- $cmdstats{'Debian Author Search'}++;
- return 'NOREPLY';
- }
-
- # Debian Incoming Search.
- if ($message =~ /^dincoming$/i) {
- return 'NOREPLY' unless (&hasParam("debian"));
+ ### FORKER,IDENTIFIER,CODEREF.
+ if (exists $hash{'Forker'}) {
+ &Forker($hash{'Identifier'}, sub { \&{$hash{'CODEREF'}}(@args) } );
+ } else {
+ if (exists $hash{'Module'}) {
+ &loadMyModule($myModules{ $hash{'Module'} });
+ }
- &Forker("debian", sub { &Debian::generateIncoming(); } );
+ ### TODO: check if CODEREF exists.
- $cmdstats{'Debian Incoming Search'}++;
- return 'NOREPLY';
- }
+### ANY PROBLEMS WITH THIS? if so, add option to do either.
+### &{$hash{'CODEREF'}}(@args);
+ &{$hash{'CODEREF'}}(join ' ', @args);
+ }
- # Debian Distro(Package) Stats
- if ($message =~ /^dstats(\s+(.*))?$/i) {
- return 'NOREPLY' unless (&hasParam("debian"));
- my $dist = $2 || $Debian::defaultdist;
+ ### CMDSTATS.
+ if (exists $hash{'Cmdstats'}) {
+ $cmdstats{$hash{'Cmdstats'}}++;
+ }
- &Forker("debian", sub { &Debian::infoStats($dist); } );
+ &DEBUG("pCH: ended.");
- $cmdstats{'Debian Statistics'}++;
- return 'NOREPLY';
+ return 1;
}
- # Debian Contents search.
- if ($message =~ /^d?contents(\s+(.*))?$/i) {
- return 'NOREPLY' unless (&hasParam("debian"));
+ return 0;
+}
- my $query = $2;
- if (!defined $query) {
- &help("contents");
- return 'NOREPLY';
- }
+&addCmdHook('d?bugs', ('CODEREF' => 'debianBugs',
+ 'Forker' => 1, 'Identifier' => 'debianExtra',
+ 'Cmdstats' => 'Debian Bugs') );
+&addCmdHook('dauthor', ('CODEREF' => 'Debian::searchAuthor',
+ 'Forker' => 1, 'Identifier' => 'debian',
+ 'Cmdstats' => 'Debian Author Search', 'Help' => "dauthor" ) );
+&addCmdHook('(d|search)desc', ('CODEREF' => 'Debian::searchDesc',
+ 'Forker' => 1, 'Identifier' => 'debian',
+ 'Cmdstats' => 'Debian Desc Search', 'Help' => "ddesc" ) );
+&addCmdHook('dincoming', ('CODEREF' => 'Debian::generateIncoming',
+ 'Forker' => 1, 'Identifier' => 'debian' ) );
+&addCmdHook('dstats', ('CODEREF' => 'Debian::infoStats',
+ 'Forker' => 1, 'Identifier' => 'debian',
+ 'Cmdstats' => 'Debian Statistics' ) );
+&addCmdHook('d?contents', ('CODEREF' => 'Debian::searchContents',
+ 'Forker' => 1, 'Identifier' => 'debian',
+ 'Cmdstats' => 'Debian Contents Search', 'Help' => "contents" ) );
+&addCmdHook('d?find', ('CODEREF' => 'Debian::DebianFind',
+ 'Forker' => 1, 'Identifier' => 'debian',
+ 'Cmdstats' => 'Debian Search', 'Help' => "find" ) );
+&addCmdHook('insult', ('CODEREF' => 'Insult::Insult',
+ 'Forker' => 1, 'Identifier' => 'insult', 'Help' => "insult" ) );
+&addCmdHook('kernel', ('CODEREF' => 'Kernel::Kernel',
+ 'Forker' => 1, 'Identifier' => 'kernel',
+ 'Cmdstats' => 'Kernel') );
+&addCmdHook('listauth', ('CODEREF' => 'CmdListAuth',
+ 'Identifier' => 'search', Module => 'factoids',
+ 'Help' => 'listauth') );
+&addCmdHook('quote', ('CODEREF' => 'Quote::Quote',
+ 'Forker' => 1, 'Identifier' => 'quote',
+ 'Help' => 'quote', 'Cmdstats' => 'Quote') );
+&addCmdHook('countdown', ('CODEREF' => 'Countdown',
+ 'Module' => 'countdown', 'Identifier' => 'countdown',
+ 'Cmdstats' => 'Countdown') );
+&addCmdHook('lart', ('CODEREF' => 'lart',
+ 'Identifier' => 'lart', 'Help' => 'lart') );
+&addCmdHook('convert', ('CODEREF' => 'convert',
+ 'Forker' => 1, 'Identifier' => 'units',
+ 'Help' => 'convert') );
+&addCmdHook('(cookie|random)', ('CODEREF' => 'cookie',
+ 'Forker' => 1, 'Identifier' => 'factoids') );
+&addCmdHook('u(ser)?info', ('CODEREF' => 'userinfo',
+ 'Identifier' => 'userinfo', 'Help' => 'userinfo',
+ 'Module' => 'userinfo') );
+&addCmdHook('rootWarn', ('CODEREF' => 'CmdrootWarn',
+ 'Identifier' => 'rootWarn', 'Module' => 'rootwarn') );
+&addCmdHook('seen', ('CODEREF' => 'seen', 'Identifier' => 'seen') );
+&addCmdHook('dict', ('CODEREF' => 'Dict::Dict',
+ 'Identifier' => 'dict', 'Help' => 'dict',
+ 'Forker' => 1, 'Cmdstats' => 'Dict') );
+&addCmdHook('slashdot', ('CODEREF' => 'Slashdot::Slashdot',
+ 'Identifier' => 'slashdot', 'Forker' => 1,
+ 'Cmdstats' => 'Slashdot') );
+&addCmdHook('uptime', ('CODEREF' => 'uptime', 'Identifier' => 'uptime',
+ 'Cmdstats' => 'Uptime') );
+&addCmdHook('nullski', ('CODEREF' => 'nullski', ) );
+&addCmdHook('crash', ('CODEREF' => 'crash' ) );
+sub nullski { my ($arg) = @_; foreach (`$arg`) { &msg($who,$_); } }
+&addCmdHook('(fm|freshmeat)', ('CODEREF' => 'Freshmeat::Freshmeat',
+ 'Identifier' => 'freshmeat', 'Cmdstats' => 'Freshmeat',
+ 'Forker' => 1, 'Help' => 'freshmeat') );
+
+
+
+
+&status("CMD: loaded ".scalar(keys %cmdhooks)." command hooks.");
- &Forker("debian", sub { &Debian::searchContents($query); } );
- $cmdstats{'Debian Contents Search'}++;
- return 'NOREPLY';
+sub Modules {
+ if (!defined $message) {
+ &WARN("Modules: message is undefined. should never happen.");
+ return;
}
- # Debian Package info.
- if ($message =~ /^d?find(\s+(.*))?$/i and &IsParam("debian")) {
- my $string = $2;
+ # babel bot: Jonathan Feinberg++
+ if (&IsParam("babelfish") and $message =~ m{
+ ^\s*
+ (?:babel(?:fish)?|x|xlate|translate)
+ \s+
+ (to|from) # direction of translation (through)
+ \s+
+ ($babel::lang_regex)\w* # which language?
+ \s*
+ (.+) # The phrase to be translated
+ }xoi) {
- if (!defined $string) {
- &help("find");
- return 'NOREPLY';
- }
+ &Forker("babelfish", sub { &babel::babelfish(lc $1, lc $2, $3); } );
- &Forker("debian", sub { &Debian::DebianFind($string); } );
- return 'NOREPLY';
+ $cmdstats{'BabelFish'}++;
+ return $noreply;
}
if (&IsParam("debian")) {
&help($1);
}
- return 'NOREPLY';
- }
- }
-
- # Dict. xk++
- if ($message =~ /^dict(\s+(.*))?$/i) {
- return 'NOREPLY' unless (&hasParam("dict"));
-
- my $query = $2;
- $query =~ s/^[\s\t]+//;
- $query =~ s/[\s\t]+$//;
- $query =~ s/[\s\t]+/ /;
-
- if (!defined $query) {
- &help("dict");
- return 'NOREPLY';
- }
-
- if (length $query > 30) {
- &msg($who,"dictionary word is too long.");
- return 'NOREPLY';
+ return $noreply;
}
-
- &Forker("dict", sub { &Dict::Dict($query); } );
-
- $cmdstats{'Dict'}++;
- return 'NOREPLY';
- }
-
- # Freshmeat. xk++
- if ($message =~ /^(fm|freshmeat)(\s+(.*))?$/i) {
- return 'NOREPLY' unless (&hasParam("freshmeat"));
-
- my $query = $3;
-
- if (!defined $query) {
- &help("freshmeat");
- &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
- return 'NOREPLY';
- }
-
- &loadMyModule($myModules{'freshmeat'});
- &Freshmeat::Freshmeat($query);
-
- $cmdstats{'Freshmeat'}++;
- return 'NOREPLY';
}
# google searching. Simon++
if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?($W3Search_regex)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
- return 'NOREPLY' unless (&hasParam("wwwsearch"));
+ return $noreply unless (&hasParam("wwwsearch"));
&Forker("wwwsearch", sub { &W3Search::W3Search($1,$2,$param{'wwwsearch'}); } );
$cmdstats{'WWWSearch'}++;
- return 'NOREPLY';
- }
-
- # insult server. patch thanks to michael@limit.org
- if ($message =~ /^insult(\s+(\S+))?$/) {
- return 'NOREPLY' unless (&hasParam("insult"));
-
- my $person = $2;
- if (!defined $person) {
- &help("insult");
- return 'NOREPLY';
- }
-
- &Forker("insult", sub { &Insult::Insult($person); } );
-
- return 'NOREPLY';
- }
-
- # Kernel. xk++
- if ($message =~ /^kernel$/i) {
- return 'NOREPLY' unless (&hasParam("kernel"));
-
- &Forker("kernel", sub { &Kernel::Kernel(); } );
-
- $cmdstats{'Kernel'}++;
- return 'NOREPLY';
- }
-
- # LART. originally by larne/cerb.
- if ($message =~ /^lart(\s+(.*))?$/i) {
- return 'NOREPLY' unless (&hasParam("lart"));
- my ($target) = &fixString($2);
-
- if (!defined $target) {
- &help("lart");
- return 'NOREPLY';
- }
- my $extra = 0;
-
- my $chan = $talkchannel;
- if ($msgType eq 'private') {
- if ($target =~ /^($mask{chan})\s+(.*)$/) {
- $chan = $1;
- $target = $2;
- $extra = 1;
- } else {
- &msg($who, "error: invalid format or missing arguments.");
- &help("lart");
- return 'NOREPLY';
- }
- }
-
- my $line = &getRandomLineFromFile($infobot_misc_dir. "/infobot.lart");
- if (defined $line) {
- if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
- $line =~ s/WHO/$who/g;
- } else {
- $line =~ s/WHO/$target/g;
- }
- $line .= ", courtesy of $who" if ($extra);
-
- &action($chan, $line);
- } else {
- &status("lart: error reading file?");
- }
-
- return 'NOREPLY';
- }
-
- # Search factoid extensions by 'author'. xk++
- if ($message =~ /^listauth(\s+(\S+))?$/i) {
- return 'NOREPLY' unless (&hasParam("search"));
-
- my $query = $2;
-
- if (!defined $query) {
- &help("listauth");
- return 'NOREPLY';
- }
-
- &loadMyModule($myModules{'factoids'});
- &performStrictReply( &CmdListAuth($query) );
- return 'NOREPLY';
+ return $noreply;
}
# list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
if ($message =~ /^list(\S+)( (.*))?$/i) {
- return 'NOREPLY' unless (&hasParam("search"));
+ return $noreply unless (&hasParam("search"));
my $thiscmd = lc($1);
my $args = $3;
$thiscmd =~ s/^vals$/values/;
- return 'NOREPLY' if ($thiscmd ne "keys" && $thiscmd ne "values");
+ return $noreply if ($thiscmd ne "keys" && $thiscmd ne "values");
# Usage:
if (!defined $args) {
&help("list". $thiscmd);
- return 'NOREPLY';
+ return $noreply;
}
if (length $args == 1) {
&msg($who,"search string is too short.");
- return 'NOREPLY';
+ return $noreply;
}
- ### chews up to 4megs => use forker :)
&Forker("search", sub { &Search::Search($thiscmd, $args); } );
-# &loadMyModule($myModules{'search'});
-# &Search::Search($thiscmd, $args);
$cmdstats{'Factoid Search'}++;
- return 'NOREPLY';
+ return $noreply;
}
# Nickometer. Adam Spiers++
if ($message =~ /^(?:lame|nick)ometer(?: for)? (\S+)/i) {
- return 'NOREPLY' unless (&hasParam("nickometer"));
+ return $noreply unless (&hasParam("nickometer"));
my $term = (lc $1 eq 'me') ? $who : $1;
$term =~ s/\?+\s*//;
&msg($who, "the 'lame nick-o-meter' reading for $term is $percentage, $who");
}
- return 'NOREPLY';
- }
-
- # Quotes. mu++
- if ($message =~ /^quote(\s+(\S+))?$/i) {
- return 'NOREPLY' unless (&hasParam("quote"));
-
- my $query = $2;
-
- if ($query eq "") {
- &help("quote");
- return 'NOREPLY';
- }
-
- &Forker("quote", sub { &Quote::Quote($query); } );
-
- $cmdstats{'Quote'}++;
- return 'NOREPLY';
- }
-
- # rootWarn. xk++
- if ($message =~ /^rootWarn$/i) {
- return 'NOREPLY' unless (&hasParam("rootWarn"));
-
- &loadMyModule($myModules{'rootwarn'});
- &performStrictReply( &CmdrootWarn() );
- return 'NOREPLY';
- }
-
- # seen.
- if ($message =~ /^seen(\s+(\S+))?$/) {
- return 'NOREPLY' unless (&hasParam("seen"));
-
- my $person = $2;
- if (!defined $person) {
- &help("seen");
-
- my $i = &countKeys("seen");
- &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
- "seen ". &fixPlural("entry",$i) ." that I know of.");
-
- return 'NOREPLY';
- }
-
- my @seen;
- $person =~ s/\?*$//;
-
- &seenFlush(); # very evil hack. oh well, better safe than sorry.
-
- ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
- my $select = "nick,time,channel,host,message";
- if ($person eq "random") {
- @seen = &randKey("seen", $select);
- } else {
- @seen = &dbGet("seen", "nick", $person, $select);
- }
-
- if (scalar @seen < 2) {
- foreach (@seen) {
- &DEBUG("seen: _ => '$_'.");
- }
- &performReply("i haven't seen '$person'");
- return 'NOREPLY';
- }
-
- # valid seen.
- my $reply;
- ### TODO: multi channel support. may require &IsNick() to return
- ### all channels or something.
- my @chans = &GetNickInChans($seen[0]);
- if (scalar @chans) {
- $reply = "$seen[0] is currently on";
-
- foreach (@chans) {
- $reply .= " ".$_;
- next unless (exists $userstats{lc $seen[0]}{'Join'});
- $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
- }
-
- if (&IsParam("seenStats")) {
- my $i;
- $i = $userstats{lc $seen[0]}{'Count'};
- $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
- $i = $userstats{lc $seen[0]}{'Time'};
- $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
- }
- } else {
- my $howlong = &Time2String(time() - $seen[1]);
- $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
- "in channel $seen[2], $howlong ago, ".
- "saying\002:\002 '$seen[4]'.";
- }
-
- &performStrictReply($reply);
- return 'NOREPLY';
- }
-
- # slashdot headlines: from Chris Tessone.
- if ($message =~ /^slashdot$/i) {
- return 'NOREPLY' unless (&hasParam("slashdot"));
-
- &Forker("slashdot", sub { &Slashdot::Slashdot() });
-
- $cmdstats{'Slashdot'}++;
- return 'NOREPLY';
+ return $noreply;
}
# Topic management. xk++
# may want to add a flag(??) for topic in the near future. -xk
if ($message =~ /^topic(\s+(.*))?$/i) {
- return 'NOREPLY' unless (&hasParam("topic"));
+ return $noreply unless (&hasParam("topic"));
my $chan = $talkchannel;
my @args = split(/ /, $2);
if (!scalar @args) {
&msg($who,"Try 'help topic'");
- return 'NOREPLY';
+ return $noreply;
}
$chan = lc(shift @args) if ($msgType eq 'private');
if ($msgType eq 'public' && $thiscmd =~ /^#/) {
&msg($who, "error: channel argument is not required.");
&msg($who, "\002Usage\002: topic <CMD>");
- return 'NOREPLY';
+ return $noreply;
}
# topic over private:
if ($msgType eq 'private' && $chan !~ /^#/) {
&msg($who, "error: channel argument is required.");
&msg($who, "\002Usage\002: topic #channel <CMD>");
- return 'NOREPLY';
+ return $noreply;
}
if (&validChan($chan) == 0) {
&msg($who,"error: invalid channel \002$chan\002");
- return 'NOREPLY';
+ return $noreply;
}
# for semi-outsiders.
if (!&IsNickInChan($who,$chan)) {
&msg($who, "Failed. You ($who) are not in $chan, hey?");
- return 'NOREPLY';
+ return $noreply;
}
# now lets do it.
&loadMyModule($myModules{'topic'});
&Topic($chan, $thiscmd, join(' ', @args));
$cmdstats{'Topic'}++;
- return 'NOREPLY';
+ return $noreply;
}
- # Countdown.
- if ($message =~ /^countdown(\s+(\S+))?$/i) {
- return 'NOREPLY' unless (&hasParam("countdown"));
+ # wingate.
+ if ($message =~ /^wingate$/i) {
+ return $noreply unless (&hasParam("wingate"));
- my $query = $2;
+ my $reply = "Wingate statistics: scanned \002"
+ .scalar(keys %wingate)."\002 hosts";
+ my $queue = scalar(keys %wingateToDo);
+ if ($queue) {
+ $reply .= ". I have \002$queue\002 hosts in the queue";
+ $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
+ }
- &loadMyModule($myModules{'countdown'});
- &Countdown($query);
+ &performStrictReply("$reply.");
- $cmdstats{'Countdown'}++;
+ return $noreply;
+ }
- return 'NOREPLY';
+ # do nothing and let the other routines have a go
+ return '';
+}
+
+# Freshmeat. xk++
+sub freshmeat {
+ my ($query) = @_;
+
+ if (!defined $query) {
+ &help("freshmeat");
+ &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
+ return $noreply;
}
- # User Information Services. requested by Flugh.
- if ($message =~ /^uinfo(\s+(.*))?$/i) {
- return 'NOREPLY' unless (&hasParam("userinfo"));
- &loadMyModule($myModules{'userinfo'});
+ &Freshmeat::Freshmeat($query);
+}
- my $arg = $1;
- if (!defined $arg or $arg eq "") {
- &help("uinfo");
- return 'NOREPLY';
- }
+# Uptime. xk++
+sub uptime {
+ my $count = 1;
+ &msg($who, "- Uptime for $ident -");
+ &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
- if ($arg =~ /^set(\s+(.*))?$/i) {
- $arg = $2;
- if (!defined $arg) {
- &help("userinfo set");
- return 'NOREPLY';
- }
+ foreach (&uptimeGetInfo()) {
+ /^(\d+)\.\d+ (.*)/;
+ my $time = &Time2String($1);
+ my $info = $2;
- &UserInfoSet(split /\s+/, $arg, 2);
- } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
- $arg = $2;
- if (!defined $arg) {
- &help("userinfo unset");
- return 'NOREPLY';
- }
+ &msg($who, "$count: $time $2");
+ $count++;
+ }
+}
- &UserInfoSet($arg, "");
- } else {
- &UserInfoGet($arg);
- }
+# seen.
+sub seen {
+ my($person) = @_;
+
+ if (!defined $person) {
+ &help("seen");
+
+ my $i = &countKeys("seen");
+ &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
+ "seen ". &fixPlural("entry",$i) ." that I know of.");
- $cmdstats{'UIS'}++;
- return 'NOREPLY';
+ return $noreply;
}
- # Uptime. xk++
- if ($message =~ /^uptime$/i) {
- return 'NOREPLY' unless (&hasParam("uptime"));
+ my @seen;
+ $person =~ s/\?*$//;
- my $count = 1;
- &msg($who, "- Uptime for $ident -");
- &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $infobot_version");
- foreach (&uptimeGetInfo()) {
- /^(\d+)\.\d+ (.*)/;
- my $time = &Time2String($1);
- my $info = $2;
+ &seenFlush(); # very evil hack. oh well, better safe than sorry.
- &msg($who, "$count: $time $2");
- $count++;
+ ### TODO: Support &dbGetRowInfo(); like in &FactInfo();
+ my $select = "nick,time,channel,host,message";
+ if ($person eq "random") {
+ @seen = &randKey("seen", $select);
+ } else {
+ @seen = &dbGet("seen", "nick", $person, $select);
+ }
+
+ if (scalar @seen < 2) {
+ foreach (@seen) {
+ &DEBUG("seen: _ => '$_'.");
}
+ &performReply("i haven't seen '$person'");
+ return $noreply;
+ }
- $cmdstats{'Uptime'}++;
- return 'NOREPLY';
+ # valid seen.
+ my $reply;
+ ### TODO: multi channel support. may require &IsNick() to return
+ ### all channels or something.
+ my @chans = &GetNickInChans($seen[0]);
+ if (scalar @chans) {
+ $reply = "$seen[0] is currently on";
+
+ foreach (@chans) {
+ $reply .= " ".$_;
+ next unless (exists $userstats{lc $seen[0]}{'Join'});
+ $reply .= " (".&Time2String(time() - $userstats{lc $seen[0]}{'Join'}).")";
+ }
+
+ if (&IsParam("seenStats")) {
+ my $i;
+ $i = $userstats{lc $seen[0]}{'Count'};
+ $reply .= ". Has said a total of \002$i\002 messages" if (defined $i);
+ $i = $userstats{lc $seen[0]}{'Time'};
+ $reply .= ". Is idling for ".&Time2String(time() - $i) if (defined $i);
+ }
+ } else {
+ my $howlong = &Time2String(time() - $seen[1]);
+ $reply = "$seen[0] <$seen[3]> was last seen on IRC ".
+ "in channel $seen[2], $howlong ago, ".
+ "saying\002:\002 '$seen[4]'.";
}
- # wingate.
- if ($message =~ /^wingate$/i) {
- return 'NOREPLY' unless (&hasParam("wingate"));
+ &performStrictReply($reply);
+ return $noreply;
+}
- my $reply = "Wingate statistics: scanned \002"
- .scalar(keys %wingate)."\002 hosts";
- my $queue = scalar(keys %wingateToDo);
- if ($queue) {
- $reply .= ". I have \002$queue\002 hosts in the queue";
- $reply .= ". Started the scan ".&Time2String(time() - $wingaterun)." ago";
+# User Information Services. requested by Flugh.
+sub userinfo {
+ my ($arg) = join(' ',@_);
+
+ if ($arg =~ /^set(\s+(.*))?$/i) {
+ $arg = $2;
+ if (!defined $arg) {
+ &help("userinfo set");
+ return $noreply;
}
- &performStrictReply("$reply.");
+ &UserInfoSet(split /\s+/, $arg, 2);
+ } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
+ $arg = $2;
+ if (!defined $arg) {
+ &help("userinfo unset");
+ return $noreply;
+ }
- return 'NOREPLY';
+ &UserInfoSet($arg, "");
+ } else {
+ &UserInfoGet($arg);
}
+}
- # convert.
- if ($message =~ /^convert(\s+(.*))?$/i) {
- return 'NOREPLY' unless (&hasParam("units"));
+# cookie (random). xk++
+sub cookie {
+ my ($arg) = @_;
+
+ # lets find that secret cookie.
+ my $target = ($msgType ne 'public') ? $who : $talkchannel;
+ my $cookiemsg = &getRandom(keys %{$lang{'cookie'}});
+ my ($key,$value);
+
+ ### WILL CHEW TONS OF MEM.
+ ### TODO: convert this to a Forker function!
+ if ($arg) {
+ my @list = &searchTable("factoids", "factoid_key", "factoid_value", $arg);
+ $key = &getRandom(@list);
+ $val = &getFactInfo("factoids", $key, "factoid_value");
+ } else {
+ ($key,$value) = &randKey("factoids","factoid_key,factoid_value");
+ }
- my $str = $2;
- if (!defined $str) {
- &help("convert");
- return 'NOREPLY';
- }
+ for ($cookiemsg) {
+ s/##KEY/\002$key\002/;
+ s/##VALUE/$value/;
+ s/##WHO/$who/;
+ s/\$who/$who/; # cheap fix.
+ s/(\S+)?\s*<\S+>/$1 /;
+ s/\s+/ /g;
+ }
- my ($from,$to);
- ($from,$to) = ($1,$2) if ($str =~ /^(.*) to (.*)$/);
- ($from,$to) = ($2,$1) if ($str =~ /^(.*) from (.*)$/);
- if (!defined $from or !defined $to or $to eq "" or $from eq "") {
- &msg($who, "Invalid format!");
- &help("convert");
- return 'NOREPLY';
- }
+ if ($cookiemsg =~ s/^ACTION //i) {
+ &action($target, $cookiemsg);
+ } else {
+ &msg($target, $cookiemsg);
+ }
+}
+
+sub convert {
+ my $arg = join(' ',@_);
+ my ($from,$to) = ('','');
- &Forker("units", sub { &Units::convertUnits($from, $to); } );
+ ($from,$to) = ($1,$2) if ($arg =~ /^(.*?) to (.*)$/i);
+ ($from,$to) = ($2,$1) if ($arg =~ /^(.*?) from (.*)$/i);
- return 'NOREPLY';
+ if (!$to or !$from) {
+ &msg($who, "Invalid format!");
+ &help("convert");
+ return $noreply;
}
- # do nothing and let the other routines have a go
- return '';
+ &Units::convertUnits($from, $to);
+
+ return $noreply;
+}
+
+sub lart {
+ my ($target) = &fixString($_[0]);
+ my $extra = 0;
+ my $chan = $talkchannel;
+
+ if ($msgType eq 'private') {
+ if ($target =~ /^($mask{chan})\s+(.*)$/) {
+ $chan = $1;
+ $target = $2;
+ $extra = 1;
+ } else {
+ &msg($who, "error: invalid format or missing arguments.");
+ &help("lart");
+ return $noreply;
+ }
+ }
+
+ my $line = &getRandomLineFromFile($bot_misc_dir. "/blootbot.lart");
+ if (defined $line) {
+ if ($target =~ /^(me|you|itself|\Q$ident\E)$/i) {
+ $line =~ s/WHO/$who/g;
+ } else {
+ $line =~ s/WHO/$target/g;
+ }
+ $line .= ", courtesy of $who" if ($extra);
+
+ &action($chan, $line);
+ } else {
+ &status("lart: error reading file?");
+ }
}
1;