if (&IsParam("useStrict")) { use strict; }
-use vars qw(@W3Search_engines $W3Search_regex);
-@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', (
-# CODEREF => \&debianFind(),
-# Forker => 1,
-# Identifier => "debian",
-# Help => "dfind",
-# Cmdstats => "Debian Search",) );
-### NOTES:
-# * viable solution?
###
sub addCmdHook {
my ($ident, %hash) = @_;
- &DEBUG("aCH: added $ident to command hooks.");
+ &VERB("aCH: added $ident",2); # use $hash{'Identifier'}?
$cmdhooks{$ident} = \%hash;
}
# RUN IF ADDRESSED.
sub parseCmdHook {
+ my @args = split(' ', $message);
+ my $cmd = shift(@args);
+
+ &shmFlush();
+
foreach (keys %cmdhooks) {
- &DEBUG("cmdhooks{$_} => ...");
- my %hash = \%{ $cmdhooks{$_} };
+ my $ident = $_;
+
+ next unless ($cmd =~ /^$ident$/i);
+
+ &DEBUG("pCH: $cmd matched $ident");
+ my %hash = %{ $cmdhooks{$ident} };
+
+ ### DEBUG.
foreach (keys %hash) {
- &DEBUG(" '$_' => '$hash{$_}'.");
+ &DEBUG(" $cmd->$_ => '$hash{$_}'.");
+ }
+
+ ### HELP.
+ if (exists $hash{'Help'} and !scalar(@args)) {
+ &help( $hash{'Help'} );
+ return 1;
+ }
+
+ ### IDENTIFIER.
+ if (exists $hash{'Identifier'}) {
+ return $noreply unless (&hasParam($hash{'Identifier'}));
+ }
+
+ ### FORKER,IDENTIFIER,CODEREF.
+ if (exists $hash{'Forker'}) {
+ &Forker($hash{'Identifier'}, sub { \&{$hash{'CODEREF'}}(@args) } );
+ } else {
+ if (exists $hash{'Module'}) {
+ &loadMyModule($myModules{ $hash{'Module'} });
+ }
+
+ ### TODO: check if CODEREF exists.
+
+### ANY PROBLEMS WITH THIS? if so, add option to do either.
+### &{$hash{'CODEREF'}}(@args);
+ &{$hash{'CODEREF'}}(join ' ', @args);
}
+
+ ### CMDSTATS.
+ if (exists $hash{'Cmdstats'}) {
+ $cmdstats{$hash{'Cmdstats'}}++;
+ }
+
+ &DEBUG("pCH: ended.");
+
+ return 1;
}
- &DEBUG("pCH: ended.");
+ return 0;
}
+&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.");
+
+
sub Modules {
if (!defined $message) {
&WARN("Modules: message is undefined. should never happen.");
return $noreply;
}
- # cookie (random). xk++
- if ($message =~ /^(cookie|random)(\s+(.*))?$/i) {
- return $noreply unless (&hasParam("cookie"));
-
- my $arg = $3;
-
- # lets find that secret cookie.
- my $target = $talkchannel;
- $target = $who if ($msgType ne 'public');
-
- 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");
- }
-
- $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);
- }
-
- $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;
- }
-
- &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("debian", sub { &Debian::generateIncoming(); } );
-
- $cmdstats{'Debian Incoming Search'}++;
- return $noreply;
- }
-
- # Debian Distro(Package) Stats
- if ($message =~ /^dstats(\s+(.*))?$/i) {
- return $noreply unless (&hasParam("debian"));
- my $dist = $2 || $Debian::defaultdist;
-
- &Forker("debian", sub { &Debian::infoStats($dist); } );
-
- $cmdstats{'Debian Statistics'}++;
- return $noreply;
- }
-
- # Debian Contents search.
- if ($message =~ /^d?contents(\s+(.*))?$/i) {
- return $noreply unless (&hasParam("debian"));
-
- my $query = $2;
- if (!defined $query) {
- &help("contents");
- return $noreply;
- }
-
- &Forker("debian", sub { &Debian::searchContents($query); } );
-
- $cmdstats{'Debian Contents Search'}++;
- return $noreply;
- }
-
- # Debian Package info.
- if ($message =~ /^d?find(\s+(.*))?$/i and &IsParam("debian")) {
- my $string = $2;
-
- if (!defined $string) {
- &help("find");
- return $noreply;
- }
-
- &Forker("debian", sub { &Debian::DebianFind($string); } );
- return $noreply;
- }
-
if (&IsParam("debian")) {
my $debiancmd = 'conflicts?|depends?|desc|file|info|provides?';
$debiancmd .= '|recommends?|suggests?|maint|maintainer';
}
}
- # 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;
- }
-
- &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) {
+ if (&IsParam("wwwsearch") and $message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)['"]?\s*\?*$/i) {
return $noreply unless (&hasParam("wwwsearch"));
- &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2,$param{'wwwsearch'}); } );
+ &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } );
$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($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?");
- }
-
- 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;
- }
-
# list{keys|values}. xk++. Idea taken from #linuxwarez@EFNET
if ($message =~ /^list(\S+)( (.*))?$/i) {
return $noreply unless (&hasParam("search"));
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;
}
- # 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;
- }
-
# Topic management. xk++
# may want to add a flag(??) for topic in the near future. -xk
if ($message =~ /^topic(\s+(.*))?$/i) {
return $noreply;
}
- # Countdown.
- if ($message =~ /^countdown(\s+(\S+))?$/i) {
- return $noreply unless (&hasParam("countdown"));
-
- my $query = $2;
+ # wingate.
+ if ($message =~ /^wingate$/i) {
+ return $noreply unless (&hasParam("wingate"));
- &loadMyModule($myModules{'countdown'});
- &Countdown($query);
+ 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";
+ }
- $cmdstats{'Countdown'}++;
+ &performStrictReply("$reply.");
return $noreply;
}
- # User Information Services. requested by Flugh.
- if ($message =~ /^u(ser)?info(\s+(.*))?$/i) {
- return $noreply unless (&hasParam("userinfo"));
- &loadMyModule($myModules{'userinfo'});
+ # do nothing and let the other routines have a go
+ return '';
+}
- my $arg = $3;
- if (!defined $arg or $arg eq "") {
- &help("userinfo");
- return $noreply;
- }
+# Freshmeat. xk++
+sub freshmeat {
+ my ($query) = @_;
- if ($arg =~ /^set(\s+(.*))?$/i) {
- $arg = $2;
- if (!defined $arg) {
- &help("userinfo set");
- return $noreply;
- }
+ if (!defined $query) {
+ &help("freshmeat");
+ &msg($who, "I have \002".&countKeys("freshmeat")."\002 entries.");
+ return $noreply;
+ }
- &UserInfoSet(split /\s+/, $arg, 2);
- } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
- $arg = $2;
- if (!defined $arg) {
- &help("userinfo unset");
- return $noreply;
- }
+ &Freshmeat::Freshmeat($query);
+}
- &UserInfoSet($arg, "");
- } else {
- &UserInfoGet($arg);
- }
+# Uptime. xk++
+sub uptime {
+ my $count = 1;
+ &msg($who, "- Uptime for $ident -");
+ &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
- $cmdstats{'UIS'}++;
- return $noreply;
+ foreach (&uptimeGetInfo()) {
+ /^(\d+)\.\d+ (.*)/;
+ my $time = &Time2String($1);
+ my $info = $2;
+
+ &msg($who, "$count: $time $2");
+ $count++;
}
+}
- # Uptime. xk++
- if ($message =~ /^uptime$/i) {
- return $noreply unless (&hasParam("uptime"));
+# seen.
+sub seen {
+ my($person) = @_;
- my $count = 1;
- &msg($who, "- Uptime for $ident -");
- &msg($who, "Now: ". &Time2String(&uptimeNow()) ." running $bot_version");
- foreach (&uptimeGetInfo()) {
- /^(\d+)\.\d+ (.*)/;
- my $time = &Time2String($1);
- my $info = $2;
+ if (!defined $person) {
+ &help("seen");
- &msg($who, "$count: $time $2");
- $count++;
- }
+ my $i = &countKeys("seen");
+ &msg($who,"there ". &fixPlural("is",$i) ." \002$i\002 ".
+ "seen ". &fixPlural("entry",$i) ." that I know of.");
- $cmdstats{'Uptime'}++;
return $noreply;
}
- # wingate.
- if ($message =~ /^wingate$/i) {
- return $noreply unless (&hasParam("wingate"));
+ my @seen;
+ $person =~ s/\?*$//;
- 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";
- }
+ &seenFlush(); # very evil hack. oh well, better safe than sorry.
- &performStrictReply("$reply.");
+ ### 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;
}
- # convert.
- if ($message =~ /^convert(\s+(.*))?$/i) {
- return $noreply unless (&hasParam("units"));
+ # 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;
+}
+
+# User Information Services. requested by Flugh.
+sub userinfo {
+ my ($arg) = join(' ',@_);
- my $str = $2;
- if (!defined $str) {
- &help("convert");
+ if ($arg =~ /^set(\s+(.*))?$/i) {
+ $arg = $2;
+ if (!defined $arg) {
+ &help("userinfo set");
return $noreply;
}
- 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");
+ &UserInfoSet(split /\s+/, $arg, 2);
+ } elsif ($arg =~ /^unset(\s+(.*))?$/i) {
+ $arg = $2;
+ if (!defined $arg) {
+ &help("userinfo unset");
return $noreply;
}
- &Forker("units", sub { &Units::convertUnits($from, $to); } );
+ &UserInfoSet($arg, "");
+ } else {
+ &UserInfoGet($arg);
+ }
+}
+
+# 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");
+ }
+
+ 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;
+ }
+
+ if ($cookiemsg =~ s/^ACTION //i) {
+ &action($target, $cookiemsg);
+ } else {
+ &msg($target, $cookiemsg);
+ }
+}
+
+sub convert {
+ my $arg = join(' ',@_);
+ my ($from,$to) = ('','');
+ ($from,$to) = ($1,$2) if ($arg =~ /^(.*?) to (.*)$/i);
+ ($from,$to) = ($2,$1) if ($arg =~ /^(.*?) from (.*)$/i);
+
+ 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;