simbot-commits Mailing List for SimBot (Page 2)
Status: Abandoned
Brought to you by:
kstange
This list is closed, nobody may subscribe to it.
| 2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(88) |
Jun
(11) |
Jul
(64) |
Aug
(74) |
Sep
(1) |
Oct
(4) |
Nov
(12) |
Dec
(4) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(7) |
Feb
(1) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(3) |
Oct
(1) |
Nov
(4) |
Dec
|
| 2007 |
Jan
(5) |
Feb
(3) |
Mar
(1) |
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Kevin S. <ks...@us...> - 2006-01-19 23:54:24
|
Update of /cvsroot/simbot/simbot/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13201/plugins Modified Files: rss.pl Log Message: "whiskey tango foxtrot" Index: rss.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/rss.pl,v retrieving revision 1.71 retrieving revision 1.72 diff -u -d -p -r1.71 -r1.72 --- rss.pl 19 Jan 2006 13:50:06 -0000 1.71 +++ rss.pl 19 Jan 2006 23:53:59 -0000 1.72 @@ -401,7 +401,7 @@ sub latest_headlines { # yay, we know about the feed # is the cache up to date? - if(!defined $last_update || $last_update > time - EXPIRE) { + if(!defined $last_update || $last_update < time - EXPIRE) { # cache is stale or missing &debug(4, "rss: $feed is old or missing.\n"); my $request = HTTP::Request->new(GET => $url); |
|
From: Kevin S. <ks...@us...> - 2006-01-19 23:33:35
|
Update of /cvsroot/simbot/simbot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7139 Modified Files: config.default.ini Log Message: Where did Fark go? Found you! Index: config.default.ini =================================================================== RCS file: /cvsroot/simbot/simbot/config.default.ini,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -p -r1.31 -r1.32 --- config.default.ini 16 Aug 2005 17:02:39 -0000 1.31 +++ config.default.ini 19 Jan 2006 23:33:23 -0000 1.32 @@ -181,7 +181,7 @@ word=asshole # and make available to be checked with the %rss command. # This is in the form of <key>=<url>. Keys must be unique. slashdot=http://slashdot.org/index.rss -fark=http://www.pluck.com/rss/fark.rss +fark=http://www.fark.com/fark.rss ala=http://www.alistapart.com/rss.xml [plugin.rss] |
|
From: Pete P. <fou...@us...> - 2006-01-19 13:50:36
|
Update of /cvsroot/simbot/simbot/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28323/plugins Modified Files: rss.pl Log Message: Sanity check. We'll no longer announce the entire damn feed when the URL format changes or SimBot gets otherwise confused. Index: rss.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/rss.pl,v retrieving revision 1.70 retrieving revision 1.71 diff -u -d -p -r1.70 -r1.71 --- rss.pl 10 Nov 2005 13:02:15 -0000 1.70 +++ rss.pl 19 Jan 2006 13:50:06 -0000 1.71 @@ -12,7 +12,7 @@ # * DBI, DBM::SQLite # # COPYRIGHT: -# Copyright (C) 2004-05, Pete Pearson <http://fourohfour.info/> +# Copyright (C) 2004-06, Pete Pearson <http://fourohfour.info/> # # This program is free software; you can redistribute and/or modify it # under the terms of version 2 of the GNU General Public License as @@ -364,8 +364,13 @@ sub got_response { &SimBot::send_message(CHANNEL, &SimBot::parse_style(&colorize_feed($feed_name) . " has been updated! Here's what's new:")); + my $postCount=0; foreach(@newPosts) { - &SimBot::send_message(CHANNEL, $_); + if(++$postCount<=5) { + &SimBot::send_message(CHANNEL, $_); + } else { + last; + } } } } |
|
From: Kevin S. <ks...@us...> - 2006-01-17 11:22:09
|
Update of /cvsroot/simbot/simbot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19667 Modified Files: simbot.pl Log Message: Put our lib directory first, so as to override any Net::Dict found on the system. Index: simbot.pl =================================================================== RCS file: /cvsroot/simbot/simbot/simbot.pl,v retrieving revision 1.145 retrieving revision 1.146 diff -u -d -p -r1.145 -r1.146 --- simbot.pl 17 Dec 2005 10:11:56 -0000 1.145 +++ simbot.pl 17 Jan 2006 11:22:00 -0000 1.146 @@ -25,7 +25,7 @@ package SimBot; BEGIN { - push (@INC, "./lib"); + unshift (@INC, "./lib"); } use SimBot::Util; |
|
From: Kevin S. <ks...@us...> - 2006-01-17 11:17:32
|
Update of /cvsroot/simbot/simbot/lib/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18381/lib/Net Added Files: Dict.diff Dict.pm Log Message: SimBot now ships with a modified Net::Dict. You no longer need to have your own Net::Dict. This has been done because the patch I submitted to fix hyphenated dictionary names was apparently ignored. The diff file included contains the microscopic modification. --- NEW FILE: Dict.diff --- --- Net/Dict.pm.old 2003-05-05 18:55:14.000000000 -0500 +++ Net/Dict.pm 2005-05-04 21:34:16.000000000 -0500 @@ -222,7 +222,7 @@ my ($defNum) = ($self->message =~ /^\d{3} (\d+) /); foreach (0..$defNum-1) { - my ($d) = ($self->getline =~ /^\d{3} ".*" (\w+) /); + my ($d) = ($self->getline =~ /^\d{3} ".*" ([\w-]+) /); my ($def) = join '', @{$self->read_until_dot}; push @defs, [$d, $def]; } --- NEW FILE: Dict.pm --- # # Net::Dict.pm # # Copyright (C) 2001-2003 Neil Bowers <ne...@bo...> # Copyright (c) 1998 Dmitry Rubinstein <di...@wi...>. # # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl # itself. # # $Id: Dict.pm,v 1.1 2006/01/17 11:17:19 kstange Exp $ # package Net::Dict; use strict; use IO::Socket; use Net::Cmd; use Carp; use vars qw(@ISA $VERSION $debug); $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/); #----------------------------------------------------------------------- # Default values for arguments to new(). We also use this to # determine valid argument names - if it's not a key of this hash, # then it's not a valid argument. #----------------------------------------------------------------------- my %ARG_DEFAULT = ( Port => 2628, Timeout => 120, Debug => 0, Client => "Net::Dict v$VERSION", ); @ISA = qw(Net::Cmd IO::Socket::INET); #======================================================================= # # new() # # constructor - open connection to host, get a list of databases, # and send CLIENT identification command. # #======================================================================= sub new { @_ > 1 or croak 'usage: Net::Dict->new() takes at least a HOST name'; my $class = shift; my $host = shift; int(@_) % 2 == 0 or croak 'Net::Dict->new(): odd number of arguments'; my %inargs = @_; my $self; my $argref; return undef unless defined $host; #------------------------------------------------------------------- # Process arguments, setting defaults if needed #------------------------------------------------------------------- $argref = {}; foreach my $arg (keys %ARG_DEFAULT) { $argref->{$arg} = exists $inargs{$arg} ? $inargs{$arg} : $ARG_DEFAULT{$arg}; delete $inargs{$arg}; } if (keys(%inargs) > 0) { croak "Net::Dict->new(): unknown argument - ", join(', ', keys %inargs); } #------------------------------------------------------------------- # Make the connection #------------------------------------------------------------------- $self = $class->SUPER::new(PeerAddr => $host, PeerPort => $argref->{Port}, Proto => 'tcp', Timeout => $argref->{Timeout} ); return undef unless defined $self; ${*$self}{'net_dict_host'} = $host; $self->autoflush(1); $self->debug($argref->{Debug}); if ($self->response() != CMD_OK) { $self->close(); return undef; } # parse the initial 220 response $self->_parse_banner($self->message); #------------------------------------------------------------------- # Send the CLIENT command which identifies the connecting client #------------------------------------------------------------------- $self->_CLIENT($argref->{Client}); #------------------------------------------------------------------- # The default - search ALL dictionaries #------------------------------------------------------------------- $self->setDicts('*'); return $self; } sub dbs { @_ == 1 or croak 'usage: $dict->dbs() - takes no arguments'; my $self = shift; $self->_get_database_list(); return %{${*$self}{'net_dict_dbs'}}; } sub setDicts { my $self = shift; @{${*$self}{'net_dict_userdbs'}} = @_; } sub serverInfo { @_ == 1 or croak 'usage: $dict->serverInfo()'; my $self = shift; return 0 unless $self->_SHOW_SERVER(); my $info = join('', @{$self->read_until_dot}); $self->getline(); $info; } sub dbInfo { @_ == 2 or croak 'usage: $dict->dbInfo($dbname) - one argument only'; my $self = shift; if ($self->_SHOW_INFO(@_)) { return join('', @{$self->read_until_dot()}); } else { return undef; } } sub dbTitle { @_ == 2 or croak 'dbTitle() method expects one argument - DB name'; my $self = shift; my $dbname = shift; $self->_get_database_list(); if (exists ${${*$self}{'net_dict_dbs'}}{$dbname}) { return ${${*$self}{'net_dict_dbs'}}{$dbname}; } else { carp 'dbTitle(): unknown database name' if $self->debug; return undef; } } sub strategies { @_ == 1 or croak 'usage: $dict->strategies()'; my $self = shift; return 0 unless $self->_SHOW_STRAT(); my(%strats, $name, $desc); foreach (@{$self->read_until_dot()}) { ($name, $desc) = (split /\s/, $_, 2); chomp $desc; $strats{$name} = _unquote($desc); } $self->getline(); %strats; } sub define { @_ >= 2 or croak 'usage: $dict->define($word [, @dbs]) - takes at least one argument'; my $self = shift; my $word = shift; my @dbs = (@_ > 0) ? @_ : @{${*$self}{'net_dict_userdbs'}}; croak 'select some dictionaries with setDicts or supply as argument to define' unless @dbs; my($db, @defs); #------------------------------------------------------------------- # check whether we got an empty word #------------------------------------------------------------------- if (!defined($word) || $word eq '') { carp "empty word passed to define() method"; return undef; } foreach $db (@dbs) { next unless $self->_DEFINE($db, $word); my ($defNum) = ($self->message =~ /^\d{3} (\d+) /); foreach (0..$defNum-1) { my ($d) = ($self->getline =~ /^\d{3} ".*" ([\w-]+) /); my ($def) = join '', @{$self->read_until_dot}; push @defs, [$d, $def]; } $self->getline(); } \@defs; } sub match { @_ >= 3 or croak 'usage: $self->match($word, $strat [, @dbs]) - takes at least two arguments'; my $self = shift; my $word = shift; my $strat = shift; my @dbs = (@_ > 0) ? @_ : @{${*$self}{'net_dict_userdbs'}}; croak 'define some dictionaries by setDicts or supply as argument to define' unless @dbs; my ($db, @matches); #------------------------------------------------------------------- # check whether we got an empty pattern #------------------------------------------------------------------- if (!defined($word) || $word eq '') { carp "empty pattern passed to match() method"; return undef; } foreach $db (@dbs) { next unless $self->_MATCH($db, $strat, $word); my ($db, $w); foreach (@{$self->read_until_dot}) { ($db, $w) = split /\s/, $_, 2; chomp $w; push @matches, [$db, _unquote($w)]; } $self->getline(); } \@matches; } sub auth { @_ == 3 or croak 'usage: $dict->auth() - takes two arguments'; my $self = shift; my $user = shift; my $pass_phrase = shift; my $auth_string; my $string; my $ctx; require Digest::MD5; $string = $self->msg_id().$pass_phrase; $auth_string = Digest::MD5::md5_hex($string); if ($self->_AUTH($user, $auth_string)) { #--------------------------------------------------------------- # clear the cache of database names # next time a method needs them, this will cause us to go # back to the server, and thus pick up any AUTH-restricted DBs #--------------------------------------------------------------- delete ${*$self}{'net_dict_dbs'}; } else { carp "auth() failed with error code ".$self->code() if $self->debug(); return; } } sub status { @_ == 1 or croak 'usage: $dict->status() - takes no arguments'; my $self = shift; my $message; $self->_STATUS() || return 0; chomp($message = $self->message); $message =~ s/^\d{3} //; return $message; } sub capabilities { @_ == 1 or croak 'usage: $dict->capabilities() - takes no arguments'; my $self = shift; return @{ ${*$self}{'net_dict_capabilities'} }; } sub has_capability { @_ == 2 or croak 'usage: $dict->has_capability() - takes one argument'; my $self = shift; my $cap = shift; return grep(lc($cap) eq $_, $self->capabilities()); } sub msg_id { @_ == 1 or croak 'usage: $dict->msg_id() - takes no arguments'; my $self = shift; return ${*$self}{'net_dict_msgid'}; } sub _DEFINE { shift->command('DEFINE', map { '"'.$_.'"' } @_)->response() == CMD_INFO } sub _MATCH { shift->command('MATCH', map { '"'.$_.'"' } @_)->response() == CMD_INFO } sub _SHOW_DB { shift->command('SHOW DB')->response() == CMD_INFO } sub _SHOW_STRAT { shift->command('SHOW STRAT')->response() == CMD_INFO } sub _SHOW_INFO { shift->command('SHOW INFO', @_)->response() == CMD_INFO } sub _SHOW_SERVER { shift->command('SHOW SERVER')->response() == CMD_INFO } sub _CLIENT { shift->command('CLIENT', @_)->response() == CMD_OK } sub _STATUS { shift->command('STATUS')->response() == CMD_OK } sub _HELP { shift->command('HELP')->response() == CMD_INFO } sub _QUIT { shift->command('QUIT')->response() == CMD_OK } sub _OPTION_MIME { shift->command('OPTION MIME')->response() == CMD_OK } sub _AUTH { shift->command('AUTH', @_)->response() == CMD_OK } sub _SASLAUTH { shift->command('SASLAUTH', @_)->response() == CMD_OK } sub _SASLRESP { shift->command('SASLRESP', @_)->response() == CMD_OK } sub quit { my $self = shift; $self->_QUIT; $self->close; } sub DESTROY { my $self = shift; if (defined fileno($self)) { $self->quit; } } sub response { my $self = shift; my $str = $self->getline() || return undef; if ($self->debug) { $self->debug_print(0,$str); } my($code) = ($str =~ /^(\d+) /); ${*$self}{'net_cmd_resp'} = [ $str ]; ${*$self}{'net_cmd_code'} = $code; substr($code,0,1); } #======================================================================= # # _unquote # # Private function used to remove quotation marks from around # a string. # #======================================================================= sub _unquote { my $string = shift; if ($string =~ /^"/) { $string =~ s/^"//; $string =~ s/"$//; } return $string; } #======================================================================= # # _parse_banner # # Parse the initial response banner the server sends when we connect. # Hoping for: # 220 blah blah <auth.mime> <msgid> # The <auth.mime> string gives a list of supported extensions. # The last bit is a msg-id, which identifies this connection, # and is used in authentication, for example. # #======================================================================= sub _parse_banner { my $self = shift; my $banner = shift; my ($code, $capstring, $msgid); ${*$self}{'net_dict_banner'} = $banner; ${*$self}{'net_dict_capabilities'} = []; if ($banner =~ /^(\d{3}) (.*) (<[^<>]*>)?\s+(<[^<>]+>)\s*$/) { ${*$self}{'net_dict_msgid'} = $4; ($capstring = $3) =~ s/[<>]//g; if (length($capstring) > 0) { ${*$self}{'net_dict_capabilities'} = [split(/\./, $capstring)]; } } else { carp "unexpected format for welcome banner on connection:\n", $banner if $self->debug; } } #======================================================================= # # _get_database_list # # Get the list of databases on the remote server. # We cache them in the instance data object, so that dbTitle() # and databases() don't have to go to the server every time. # # We check to see whether we've already got the databases first, # and do nothing if so. This means that this private method # can just be invoked in the public methods. # #======================================================================= sub _get_database_list { my $self = shift; return if exists ${*$self}{'net_dict_dbs'}; if ($self->_SHOW_DB) { my($dbNum)= ($self->message =~ /^\d{3} (\d+)/); my($name, $descr); foreach (0..$dbNum-1) { ($name, $descr) = (split /\s/, $self->getline, 2); chomp $descr; ${${*$self}{'net_dict_dbs'}}{$name} = _unquote($descr); } # Is there a way to do it right? Reading the dot line and the # status line afterwards? Maybe I should use read_until_dot? $self->getline(); $self->getline(); } } #----------------------------------------------------------------------- # Method aliases for backwards compatibility #----------------------------------------------------------------------- *strats = \&strategies; 1; |
|
From: Kevin S. <ks...@us...> - 2006-01-17 11:17:32
|
Update of /cvsroot/simbot/simbot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18381 Modified Files: INSTALL Log Message: SimBot now ships with a modified Net::Dict. You no longer need to have your own Net::Dict. This has been done because the patch I submitted to fix hyphenated dictionary names was apparently ignored. The diff file included contains the microscopic modification. Index: INSTALL =================================================================== RCS file: /cvsroot/simbot/simbot/INSTALL,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -p -r1.27 -r1.28 --- INSTALL 9 Aug 2005 01:12:59 -0000 1.27 +++ INSTALL 17 Jan 2006 11:17:19 -0000 1.28 @@ -49,10 +49,6 @@ intend to use any of the stock plugins p * Required by: rss -[ Net::Dict ] - - * Required by: dict - [ Text::Aspell ] * Required by: aspell |
|
From: Kevin S. <ks...@us...> - 2006-01-17 11:12:20
|
Update of /cvsroot/simbot/simbot/lib/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17591/Net Log Message: Directory /cvsroot/simbot/simbot/lib/Net added to the repository |
|
From: Kevin S. <ks...@us...> - 2005-12-17 10:12:04
|
Update of /cvsroot/simbot/simbot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26844 Modified Files: simbot.pl Log Message: I have no idea how I randomly capitalized this letter 'm', but I did. Index: simbot.pl =================================================================== RCS file: /cvsroot/simbot/simbot/simbot.pl,v retrieving revision 1.144 retrieving revision 1.145 diff -u -d -p -r1.144 -r1.145 --- simbot.pl 17 Dec 2005 10:07:21 -0000 1.144 +++ simbot.pl 17 Dec 2005 10:11:56 -0000 1.145 @@ -1058,7 +1058,7 @@ sub send_message { $text = &char_sub($text); $text = &Encode::encode(TARGET_ENCODING, $text); $kernel->post(bot => privmsg => $dest, $text); - My $public = 0; + my $public = 0; if(@{$dest}) { foreach(@{$dest}) { if($_ =~ /[\#\&].+/) { |
|
From: Kevin S. <ks...@us...> - 2005-12-17 10:07:29
|
Update of /cvsroot/simbot/simbot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26260 Modified Files: simbot.pl Log Message: Plug the other warning too. Index: simbot.pl =================================================================== RCS file: /cvsroot/simbot/simbot/simbot.pl,v retrieving revision 1.143 retrieving revision 1.144 diff -u -d -p -r1.143 -r1.144 --- simbot.pl 17 Dec 2005 10:04:56 -0000 1.143 +++ simbot.pl 17 Dec 2005 10:07:21 -0000 1.144 @@ -1058,7 +1058,7 @@ sub send_message { $text = &char_sub($text); $text = &Encode::encode(TARGET_ENCODING, $text); $kernel->post(bot => privmsg => $dest, $text); - my $public = 0; + My $public = 0; if(@{$dest}) { foreach(@{$dest}) { if($_ =~ /[\#\&].+/) { @@ -1716,6 +1716,9 @@ sub server_supports { &debug(DEBUG_INFO, "Server supports: " . (defined $message ? $message : "nothing") . "\n"); + # Server supports... NOTHING! + return if (!defined $message); + foreach my $cur_block (split(/ /, $message)) { if(my ($ircd) = $cur_block =~ m/^IRCD=(\S+)/) { if($ircd =~ m/dancer/) { |
|
From: Kevin S. <ks...@us...> - 2005-12-17 10:05:14
|
Update of /cvsroot/simbot/simbot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26038 Modified Files: simbot.pl Log Message: The freenode sink server seems to send the supports numeric with an empty message; plug a resulting warning. Index: simbot.pl =================================================================== RCS file: /cvsroot/simbot/simbot/simbot.pl,v retrieving revision 1.142 retrieving revision 1.143 diff -u -d -p -r1.142 -r1.143 --- simbot.pl 12 Dec 2005 02:39:41 -0000 1.142 +++ simbot.pl 17 Dec 2005 10:04:56 -0000 1.143 @@ -1713,7 +1713,8 @@ sub server_banned { # Also, could be used to push ignores serverside with the SILENCE command sub server_supports { my ($message) = $_[ARG1] =~ m/^(.*):.*?$/; - &debug(DEBUG_INFO, "Server supports: ${message}\n"); + &debug(DEBUG_INFO, "Server supports: " . + (defined $message ? $message : "nothing") . "\n"); foreach my $cur_block (split(/ /, $message)) { if(my ($ircd) = $cur_block =~ m/^IRCD=(\S+)/) { |
|
From: Kevin S. <ks...@us...> - 2005-12-12 02:39:52
|
Update of /cvsroot/simbot/simbot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17060 Modified Files: simbot.pl Log Message: Let's reduce the message size allowance from 440 to 425. This should hopefully prevent truncation that we seem to be seeing on freenode. Index: simbot.pl =================================================================== RCS file: /cvsroot/simbot/simbot/simbot.pl,v retrieving revision 1.141 retrieving revision 1.142 diff -u -d -p -r1.141 -r1.142 --- simbot.pl 15 Nov 2005 12:53:00 -0000 1.141 +++ simbot.pl 12 Dec 2005 02:39:41 -0000 1.142 @@ -1163,7 +1163,7 @@ sub send_pieces { ### cont_send_pieces # This is called by POE to break the message up into pieces of no more -# than 440 characters. This accommodates the message length limitation +# than 425 characters. This accommodates the message length limitation # on most IRC networks. # # Arguments: @@ -1192,7 +1192,7 @@ sub cont_send_pieces { my $nextWord; ($curWord, $nextWord) = ($1, $2); unshift(@words, $nextWord); - if(length($line) + length($curWord) <= 440) { + if(length($line) + length($curWord) <= 425) { $line .= $curWord; $kernel->delay('cont_send_pieces', 1, $type, $dest, $prefix, join('', @words)); @@ -1201,7 +1201,7 @@ sub cont_send_pieces { ("$curWord\n" . join('', @words))); } last; - } elsif(length($line) + length($curWord) <= 440) { + } elsif(length($line) + length($curWord) <= 425) { $line .= $curWord; } else { # next word would make the line too long. |
|
From: Kevin S. <ks...@us...> - 2005-11-15 12:53:09
|
Update of /cvsroot/simbot/simbot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29771 Modified Files: simbot.pl Log Message: I could plug a warning, but instead I'm leaving a reminder to fix the problem the right way. Index: simbot.pl =================================================================== RCS file: /cvsroot/simbot/simbot/simbot.pl,v retrieving revision 1.140 retrieving revision 1.141 diff -u -d -p -r1.140 -r1.141 --- simbot.pl 10 Nov 2005 13:02:12 -0000 1.140 +++ simbot.pl 15 Nov 2005 12:53:00 -0000 1.141 @@ -1506,6 +1506,7 @@ sub channel_join { foreach(keys(%event_channel_mejoin)) { &plugin_callback($_, $event_channel_mejoin{$_}, ($nick, $chan, 'JOINED')); } + # TODO: hostmask cache table should be created with NAMES from channel } else { &debug(DEBUG_STD, "$nick has joined $chan.\n"); foreach(keys(%event_channel_join)) { |
|
From: Kevin S. <ks...@us...> - 2005-11-14 07:40:20
|
Update of /cvsroot/simbot/simbot/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20910/plugins Modified Files: httpd.pl Log Message: If the HTTPd receives a request for something without a leading slash, avoid a warning. Not that this should happen unless we get probed by someone looking for open HTTP proxies. Index: httpd.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/httpd.pl,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -p -r1.23 -r1.24 --- httpd.pl 10 Nov 2005 13:23:25 -0000 1.23 +++ httpd.pl 14 Nov 2005 07:40:11 -0000 1.24 @@ -62,7 +62,7 @@ sub index_handler { &debug( 3, 'httpd: handling request for ' . $request->uri - . ", req root $req_root\n" ); + . (defined $req_root ? ", req root $req_root\n" : "\n")); my $code = 500; # An error by default. if ( $req_root && defined $SimBot::hash_plugin_httpd_pages{$req_root} ) { |
|
From: Kevin S. <ks...@us...> - 2005-11-10 13:40:20
|
Update of /cvsroot/simbot/simbot/lib/SimBot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2835/lib/SimBot Modified Files: Util.pm Log Message: These particular variables don't need to be globals, just to be available to all the functions in Util.pm. Index: Util.pm =================================================================== RCS file: /cvsroot/simbot/simbot/lib/SimBot/Util.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- Util.pm 10 Nov 2005 13:23:25 -0000 1.3 +++ Util.pm 10 Nov 2005 13:40:05 -0000 1.4 @@ -41,14 +41,17 @@ use charnames ':full'; use strict; use warnings; +use vars qw ( + %args %conf $color @named_colors + %numbers_groups %numbers_tens %numbers_digits %numbers_other + ); + # Support for Terminal Colors -our $color = eval { +$color = eval { use Term::ANSIColor; $Term::ANSIColor::AUTORESET = 1; }; -use vars qw ( %args %conf ); - # Software Name use constant PROJECT => "SimBot"; # Software Version @@ -78,32 +81,33 @@ use constant DEBUG_COLORS use constant VERBOSE => 3; # Number data for the numberize function -our %numbers_groups = ( - trillion => 1000000000000, billion => 1000000000, - million => 1000000, thousand => 1000, - hundred => 100, "hundred and" => 100, - ); +%numbers_groups = ( + trillion => 1000000000000, billion => 1000000000, + million => 1000000, thousand => 1000, + hundred => 100, "hundred and" => 100, + ); -our %numbers_tens = ( - twenty => 20, thirty => 30, forty => 40, fifty => 50, - sixty => 60, seventy => 70, eighty => 80, ninety => 90, - ); +%numbers_tens = ( + twenty => 20, thirty => 30, forty => 40, fifty => 50, + sixty => 60, seventy => 70, eighty => 80, ninety => 90, + ); -our %numbers_other = ( - zero => 0, a => 1, ten => 10, - eleven => 11, twelve => 12, thirteen => 13, - fourteen => 14, fifteen => 15, sixteen => 16, - seventeen => 17, eighteen => 18, nineteen => 19, - ); +%numbers_other = ( + zero => 0, a => 1, ten => 10, + eleven => 11, twelve => 12, thirteen => 13, + fourteen => 14, fifteen => 15, sixteen => 16, + seventeen => 17, eighteen => 18, nineteen => 19, + ); -our %numbers_digits = (one => 1, two => 2, three => 3, four => 4, five => 5, - six => 6, seven => 7, eight => 8, nine => 9, - ); +%numbers_digits = ( + one => 1, two => 2, three => 3, four => 4, five => 5, + six => 6, seven => 7, eight => 8, nine => 9, + ); -our @named_colors = ("white", "black", "navy", "green", "red", "maroon", - "purple", "orange", "yellow", "lightgreen", "teal", - "cyan", "blue", "magenta", "gray", "silver"); +@named_colors = ("white", "black", "navy", "green", "red", "maroon", + "purple", "orange", "yellow", "lightgreen", "teal", + "cyan", "blue", "magenta", "gray", "silver"); ## debug ( level, message, flags ); returns ( ); # |
|
From: Kevin S. <ks...@us...> - 2005-11-10 13:23:39
|
Update of /cvsroot/simbot/simbot/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32409/plugins Modified Files: httpd.pl tinyurl.pl Log Message: debug() calls are supposed to end with a newline! Index: httpd.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/httpd.pl,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -p -r1.22 -r1.23 --- httpd.pl 10 Nov 2005 13:20:32 -0000 1.22 +++ httpd.pl 10 Nov 2005 13:23:25 -0000 1.23 @@ -186,7 +186,7 @@ sub admin_page { if ( $request->uri =~ m|\?restart$| ) { if ( !defined $kernel ) { - &debug(DEBUG_WARN, "Trying to restart simbot without a kernel"); + &debug(DEBUG_WARN, "Trying to restart simbot without a kernel\n"); } POE::Kernel->post( 'simbot', 'restart', "web admin" ); $response->code(RC_OK); Index: tinyurl.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/tinyurl.pl,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -p -r1.11 -r1.12 --- tinyurl.pl 10 Nov 2005 13:20:32 -0000 1.11 +++ tinyurl.pl 10 Nov 2005 13:23:25 -0000 1.12 @@ -130,7 +130,7 @@ sub handle_chat { &SimBot::send_message($channel, 'TinyURL points to ' . &shorten_url($to_url)); } else { - &debug(3, " failed! (no redirect)\n"); + &debug(3, " failed! (no redirect)\n"); } } else { # not a HTTP redirect, maybe a META? @@ -144,7 +144,7 @@ sub handle_chat { . &shorten_url($to_url)); } else { &debug(3, " failed!\n"); - &debug(DEBUG_WARN, $response->content); + &debug(DEBUG_WARN, $response->content . "\n"); } } } |
|
From: Kevin S. <ks...@us...> - 2005-11-10 13:23:39
|
Update of /cvsroot/simbot/simbot/lib/SimBot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32409/lib/SimBot Modified Files: Util.pm Log Message: debug() calls are supposed to end with a newline! Index: Util.pm =================================================================== RCS file: /cvsroot/simbot/simbot/lib/SimBot/Util.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- Util.pm 10 Nov 2005 13:20:31 -0000 1.2 +++ Util.pm 10 Nov 2005 13:23:25 -0000 1.3 @@ -502,7 +502,7 @@ sub timeago { my $hidemode = (defined $_[1] ? $_[1] : 0); if($_[0] > $now) { - &debug(DEBUG_WARN, "Trying to use timeago on a time in the future! Now is ${now}, Then is $_[0]"); + &debug(DEBUG_WARN, "Trying to use timeago on a time in the future! Now is ${now}, Then is $_[0]\n"); } if($seconds >= 60) { $minutes = int $seconds / 60; |
|
From: Kevin S. <ks...@us...> - 2005-11-10 13:20:45
|
Update of /cvsroot/simbot/simbot/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31802/plugins Modified Files: httpd.pl tinyurl.pl Log Message: Get rid of some warn calls and replace them with debug(DEBUG_WARN, blah); I left weather.pl alone in case 404 is planning to make a perl module out of it. :P Index: httpd.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/httpd.pl,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -p -r1.21 -r1.22 --- httpd.pl 10 Nov 2005 13:02:15 -0000 1.21 +++ httpd.pl 10 Nov 2005 13:20:32 -0000 1.22 @@ -186,7 +186,7 @@ sub admin_page { if ( $request->uri =~ m|\?restart$| ) { if ( !defined $kernel ) { - warn "Trying to restart simbot without a kernel"; + &debug(DEBUG_WARN, "Trying to restart simbot without a kernel"); } POE::Kernel->post( 'simbot', 'restart', "web admin" ); $response->code(RC_OK); Index: tinyurl.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/tinyurl.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -p -r1.10 -r1.11 --- tinyurl.pl 10 Nov 2005 13:02:15 -0000 1.10 +++ tinyurl.pl 10 Nov 2005 13:20:32 -0000 1.11 @@ -144,7 +144,7 @@ sub handle_chat { . &shorten_url($to_url)); } else { &debug(3, " failed!\n"); - warn $response->content; + &debug(DEBUG_WARN, $response->content); } } } |
|
From: Kevin S. <ks...@us...> - 2005-11-10 13:20:40
|
Update of /cvsroot/simbot/simbot/lib/SimBot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31802/lib/SimBot Modified Files: Util.pm Log Message: Get rid of some warn calls and replace them with debug(DEBUG_WARN, blah); I left weather.pl alone in case 404 is planning to make a perl module out of it. :P Index: Util.pm =================================================================== RCS file: /cvsroot/simbot/simbot/lib/SimBot/Util.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- Util.pm 10 Nov 2005 13:02:15 -0000 1.1 +++ Util.pm 10 Nov 2005 13:20:31 -0000 1.2 @@ -502,7 +502,7 @@ sub timeago { my $hidemode = (defined $_[1] ? $_[1] : 0); if($_[0] > $now) { - warn "Trying to use timeago on a time in the future! Now is ${now}, Then is $_[0]"; + &debug(DEBUG_WARN, "Trying to use timeago on a time in the future! Now is ${now}, Then is $_[0]"); } if($seconds >= 60) { $minutes = int $seconds / 60; |
|
From: Kevin S. <ks...@us...> - 2005-11-10 13:02:56
|
Update of /cvsroot/simbot/simbot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23423 Modified Files: ChangeLog simbot.pl Log Message: Added SimBot::Util module which is now used by literally everything. It's nice because it allows the plugins to use in their namespace several handy utility functions, while also allowing us to truly hide functions and variables that plugins shouldn't be accessing directly. This module can also be used by scripts in tools/ if they should want to use any utility functions we have created. It is a completely independent perl module. I will likely be adding SimBot::Plugin and attempting to migrate the plugin functions and data into that file if possible as my next step. The other thing I'd like to do fairly soon is get the main database into SQLite. We'll see... :) Index: ChangeLog =================================================================== RCS file: /cvsroot/simbot/simbot/ChangeLog,v retrieving revision 1.81 retrieving revision 1.82 diff -u -d -p -r1.81 -r1.82 --- ChangeLog 10 Aug 2005 11:50:59 -0000 1.81 +++ ChangeLog 10 Nov 2005 13:02:12 -0000 1.82 @@ -1,3 +1,11 @@ +Version 1.0 alpha: (10 Nov 2005) + * lib/SimBot/Util.pm: + - Moved several functions into SimBot::Util, which can be used by + plugins. Other scripts could also use this functions externally. + - This allows utility functions to be called without a namespace and + also prevents plugins from being able to access things we don't + want exported from the namespace. + Version 1.0 alpha: (09 Aug 2005) * templates/irclog.default.tmpl: - Template used for making the HTML version of the IRC log. Don't like Index: simbot.pl =================================================================== RCS file: /cvsroot/simbot/simbot/simbot.pl,v retrieving revision 1.139 retrieving revision 1.140 diff -u -d -p -r1.139 -r1.140 --- simbot.pl 26 Aug 2005 07:45:38 -0000 1.139 +++ simbot.pl 10 Nov 2005 13:02:12 -0000 1.140 @@ -24,6 +24,12 @@ # Hi, my name(space) is: package SimBot; +BEGIN { + push (@INC, "./lib"); +} + +use SimBot::Util; + use Data::Dumper; # Sometimes we end up in Unicode. Since IRC and Unicode are not good @@ -33,10 +39,6 @@ use Data::Dumper; use Encode; use constant TARGET_ENCODING => 'iso-8859-1'; -# to make our own character substitutions easier to read, let's -# be able to use character names -use charnames ':full'; - # We hold our code up to some standards. # For some well-meaning reason, strict does not allow the use of strings # for literal references to functions and objects so we'll just tell Perl @@ -50,70 +52,10 @@ no strict 'refs'; # **************************************** # Variables we want to use without an explicit package name -use vars qw( %conf %chat_words $chosen_nick $chosen_server $alarm_sched_60 - %plugin_help %plugin_params %hostmask_cache +use vars qw( %chat_words $chosen_nick $chosen_server $alarm_sched_60 + %plugin_help %plugin_params %hostmask_cache @servers ); -# Debug Constants -use constant DEBUG_PREFIX - => ('', 'ERROR: ', 'ALERT: ', '', 'DEBUG: ', 'SPAM: '); - -use constant DEBUG_NONE => 0; -use constant DEBUG_ERR => 1; -use constant DEBUG_WARN => 2; -use constant DEBUG_STD => 3; -use constant DEBUG_INFO => 4; -use constant DEBUG_SPAM => 5; - -use constant DEBUG_NO_PREFIX => 0x001; - -use constant DEBUG_COLORS - => ("bold green", "bold red", "red", "", "bold blue", "blue"); - -# Terminal Colors -use Term::ANSIColor; -$Term::ANSIColor::AUTORESET = 1; - -# Default verbosity level -# 0 is silent, 1 shows errors, 2 shows alert, 3 shows normal information, -# 4 shows debug information, and 5 everything you never wanted to see. -use constant VERBOSE => 3; - -# Software Name -use constant PROJECT => "SimBot"; -# Software Version -use constant VERSION => "1.0 alpha"; -# Software Home -use constant HOME_PAGE => 'http://simbot.sf.net/'; - - -our %numbers_groups = ( - trillion => 1000000000000, billion => 1000000000, - million => 1000000, thousand => 1000, - hundred => 100, "hundred and" => 100, - ); - -our %numbers_tens = ( - twenty => 20, thirty => 30, forty => 40, fifty => 50, - sixty => 60, seventy => 70, eighty => 80, ninety => 90, - ); - -our %numbers_other = ( - zero => 0, a => 1, ten => 10, - eleven => 11, twelve => 12, thirteen => 13, - fourteen => 14, fifteen => 15, sixteen => 16, - seventeen => 17, eighteen => 18, nineteen => 19, - ); - -our %numbers_digits = (one => 1, two => 2, three => 3, four => 4, five => 5, - six => 6, seven => 7, eight => 8, nine => 9, - ); - - -our @named_colors = ("white", "black", "navy", "green", "red", "maroon", - "purple", "orange", "yellow", "lightgreen", "teal", - "cyan", "blue", "magenta", "gray", "silver"); - # **************************************** # ************ Start of Script *********** # **************************************** @@ -121,21 +63,7 @@ our @named_colors = ("white", "black", " &debug(DEBUG_NONE, PROJECT . " " . VERSION . "\n\n"); # Read command line options -our %args = (); - -foreach (@ARGV) { - if (m/^--/) { - my ($flag, $value) = split(/=/); - $flag =~ s/^--//; - $value = 1 if (!defined $value); - $args{$flag} = $value; - } elsif (m/^-/) { - my (@params) = split(//); - foreach (@params) { - $args{$_} = 1 unless $_ eq "-"; - } - } -} +my %args = &get_args(); # Help output if (defined $args{help}) { @@ -297,23 +225,23 @@ opendir(DIR, "./plugins"); foreach my $plugin (readdir(DIR)) { if($plugin =~ /.*\.pl$/) { if($plugin =~ /^services\.(.+)\.pl$/) { - debug(DEBUG_SPAM, "$1 services plugin found.\n"); + &debug(DEBUG_SPAM, "$1 services plugin found.\n"); if (option('services','type') eq $1) { - debug(DEBUG_SPAM, "$1 services plugin was selected. Attempting to load...\n"); + &debug(DEBUG_SPAM, "$1 services plugin was selected. Attempting to load...\n"); if (eval { require "./plugins/$plugin"; }) { - debug(DEBUG_STD, "$1 services plugin loaded successfully.\n"); + &debug(DEBUG_STD, "$1 services plugin loaded successfully.\n"); } else { - debug(DEBUG_ERR, "$@"); - debug(DEBUG_WARN, "$1 service plugin did not load due to errors.\n"); + &debug(DEBUG_ERR, "$@"); + &debug(DEBUG_WARN, "$1 service plugin did not load due to errors.\n"); } } else { - debug(DEBUG_SPAM, "$1 services plugin was not selected.\n"); + &debug(DEBUG_SPAM, "$1 services plugin was not selected.\n"); } } elsif(eval { require "./plugins/$plugin"; }) { - debug(DEBUG_STD, "$plugin plugin loaded successfully.\n"); + &debug(DEBUG_STD, "$plugin plugin loaded successfully.\n"); } else { - debug(DEBUG_ERR, "$@"); - debug(DEBUG_WARN, "$plugin plugin did not load due to errors.\n"); + &debug(DEBUG_ERR, "$@"); + &debug(DEBUG_WARN, "$plugin plugin did not load due to errors.\n"); } } } @@ -338,52 +266,53 @@ use POE; use POE::Component::IRC; # Create a new IRC connection. -POE::Component::IRC->new('bot'); +POE::Component::IRC->spawn(alias => 'bot'); # Add the handlers for different IRC events we want to know about. -POE::Session->new - ( _start => \&initialize, - irc_001 => \&irc_connected, # connected - irc_005 => \&server_supports, # RPL_ISUPPORT - irc_433 => \&pick_new_nick, # nickname in use - irc_socketerr => \&socket_error, # internet wants to yell at us - irc_error => \&server_error, # server wants to yell at us - irc_465 => \&server_banned, # ERR_YOUREBANNEDCREEP - irc_disconnected => \&irc_disconnected, # disconnected - irc_303 => \&server_ison, # check ison reply - irc_352 => \&server_who, # check who reply - irc_nick => \&server_nick_change, - irc_401 => \&server_no_such_nick, # No such nick/chan error - irc_msg => \&private_message, - irc_public => \&channel_message, - irc_kick => \&channel_kick, - irc_join => \&channel_join, - irc_part => \&channel_part, - irc_quit => \&channel_quit, - irc_404 => \&channel_novoice, # we can't speak for some reason - irc_471 => \&channel_nojoin, # channel is at limit - irc_473 => \&channel_nojoin, # channel invite only - irc_474 => \&channel_nojoin, # banned from channel - irc_475 => \&channel_nojoin, # bad channel key - irc_invite => \&channel_invite, - irc_topic => \&channel_topic, - irc_mode => \&channel_mode, - irc_notice => \&process_notice, - irc_ctcp_action => \&process_action, - irc_ctcp_version => \&process_version, - irc_ctcp_time => \&process_time, - irc_ctcp_finger => \&process_finger, - irc_ctcp_ping => \&process_ping, - irc_snotice => \&server_notice, - - # These are our own custom events-- signs that we're using POE correctly. - scheduler_60 => \&run_scheduler_60, # run events every 60 seconds - cont_send_pieces => \&cont_send_pieces, # send all the rest of the pieces +POE::Session->create( + inline_states => { + _start => \&initialize, + irc_001 => \&irc_connected, # connected + irc_005 => \&server_supports, # RPL_ISUPPORT + irc_433 => \&pick_new_nick, # nickname in use + irc_socketerr => \&socket_error, # internet wants to yell at us + irc_error => \&server_error, # server wants to yell at us + irc_465 => \&server_banned, # ERR_YOUREBANNEDCREEP + irc_disconnected => \&irc_disconnected, # disconnected + irc_303 => \&server_ison, # check ison reply + irc_352 => \&server_who, # check who reply + irc_nick => \&server_nick_change, + irc_401 => \&server_no_such_nick, # No such nick/chan error + irc_msg => \&private_message, + irc_public => \&channel_message, + irc_kick => \&channel_kick, + irc_join => \&channel_join, + irc_part => \&channel_part, + irc_quit => \&channel_quit, + irc_404 => \&channel_novoice, # we can't speak for some reason + irc_471 => \&channel_nojoin, # channel is at limit + irc_473 => \&channel_nojoin, # channel invite only + irc_474 => \&channel_nojoin, # banned from channel + irc_475 => \&channel_nojoin, # bad channel key + irc_invite => \&channel_invite, + irc_topic => \&channel_topic, + irc_mode => \&channel_mode, + irc_notice => \&process_notice, + irc_ctcp_action => \&process_action, + irc_ctcp_version => \&process_version, + irc_ctcp_time => \&process_time, + irc_ctcp_finger => \&process_finger, + irc_ctcp_ping => \&process_ping, + irc_snotice => \&server_notice, - quit_session => \&quit_session, # end the session and terminate - restart => \&restart, # end the session and restart - rehash => \&rehash, # reload data files - ); + # Custom Events + scheduler_60 => \&run_scheduler_60, # run events every 60 seconds + cont_send_pieces => \&cont_send_pieces, # send the rest of the pieces + quit_session => \&quit_session, # end the session and terminate + restart => \&restart, # end the session and restart + rehash => \&rehash, # reload data files + }, + ); # **************************************** # ********* Start of Subroutines ********* @@ -391,25 +320,6 @@ POE::Session->new # ########### GENERAL PURPOSE ############ -# DEBUG: Print out messages with the desired verbosity. -sub debug { - if ((!defined $args{debug} && $_[0] <= VERBOSE) || - (defined $args{debug} && $_[0] <= $args{debug})) { - my $bitmask = (defined $_[2] ? $_[2] : 0x000); - my $prefix = ($bitmask & DEBUG_NO_PREFIX ? "" : (DEBUG_PREFIX)[$_[0]]); - if ($_[0] != 3 && $_[0] != 0) { - print STDERR colored ($prefix . $_[1], (DEBUG_COLORS)[$_[0]]); - } else { - print STDOUT colored ($prefix . $_[1], (DEBUG_COLORS)[$_[0]]); - } - } -} - -# PICK: Pick a random item from an array. -sub pick { - return @_[int(rand()*@_)]; -} - # HOSTMASK: Generates a 'type 3' hostmask from a nick!user@host address sub hostmask { my ($nick, $user, $host) = split(/[@!]/, $_[0]); @@ -426,7 +336,7 @@ sub hostmask { foreach my $plugin (keys(%query_userhost_mask)) { my $newmask = &plugin_callback($plugin, $query_userhost_mask{$plugin}, ("$user\@$host")); if (defined $newmask && $newmask =~ /.@./) { - debug(DEBUG_SPAM, "hostmask: the $plugin plugin changed the user\@host mask\n"); + &debug(DEBUG_SPAM, "hostmask: the $plugin plugin changed the user\@host mask\n"); ($user, $host) = split(/@/, $newmask); $changed = 1; last; @@ -446,7 +356,7 @@ sub hostmask { } } - debug(DEBUG_SPAM, "hostmask: returning type 3 hostmask: $nick!$user\@$host\n"); + &debug(DEBUG_SPAM, "hostmask: returning type 3 hostmask: $nick!$user\@$host\n"); return "$nick!$user\@$host"; } @@ -466,294 +376,6 @@ sub get_hostmask { return (defined $hostmask_cache{$nick} ? $hostmask_cache{$nick} : undef); } -# PARSE_style: Parses a string for color codes -# and turns them into color and style. -sub parse_style { - $_ = $_[0]; - # \003 begins a color. Avoid using black and white, as the window - # will likely be either white or black, and you don't know which - - s/%white%/\0030/g; # white - s/%black%/\0031/g; # black - s/%navy%/\0032/g; # navy - s/%green%/\0033/g; # green - s/%red%/\0034/g; # red - s/%maroon%/\0035/g; # maroon - s/%purple%/\0036/g; # purple - s/%orange%/\0037/g; # orange - s/%yellow%/\0038/g; # yellow - s/%l(igh)?tgreen%/\0039/g; # light green (ltgreen, lightgreen) - s/%teal%/\00310/g; # teal - s/%cyan%/\00311/g; # cyan - s/%blue%/\00312/g; # blue - s/%magenta%/\00313/g; # magenta - s/%gray%/\00314/g; # gray - s/%silver%/\00315/g; # silver - - s/%normal%/\017/g; # normal - remove color and style - - s/%bold%/\002/g; # bold - s/%u(nder)?line%/\037/g; # underline (uline) - - - return $_; -} - -# HTMLIZE: Converts IRC color codes, links into HTML. -sub htmlize { - my @lines = split(/\n/, $_[0]); - my $string = ""; - foreach my $line (@lines) { - my $bold = 0; - my $reverse = 0; - my $underline = 0; - my $color = -1; - my $bgcolor = -1; - my $tag = ""; - $line =~ s/&/&/; - $line =~ s/>/>/; - $line =~ s/</</; - $line = "<div>" . $line; - while($line =~ m/[\002\003\017\026\037]+/) { - my $block = $&; - my @codes = split(//, $block); - debug (DEBUG_SPAM, "htmlize: codes: " . (@codes) . "\n"); - foreach my $code (@codes) { - if ($code eq "\002") { - $bold = 1 - $bold; - debug (DEBUG_SPAM, "htmlize: bold: $bold\n"); - } elsif ($code eq "\037") { - $underline = 1 - $underline; - debug (DEBUG_SPAM, "htmlize: underline: $underline\n"); - } elsif ($code eq "\026") { - $reverse = 1 - $reverse; - debug (DEBUG_SPAM, "htmlize: reverse: $reverse\n"); - } elsif ($code eq "\003") { - $line =~ m/\003(\d{1,2})?(,(\d{1,2}))?/; - if ($2) { - $color = $1 if $1; - $bgcolor = $3; - $line =~ s/\003$1$2/\003/; - } elsif ($1) { - $color = $1; - $line =~ s/\003$1/\003/; - } else { - $color = -1; - $bgcolor = -1; - } - debug (DEBUG_SPAM, "htmlize: c: $color; bgc: $bgcolor\n"); - } else { - $bold = 0; - $underline = 0; - $reverse = 0; - $color = -1; - $bgcolor = -1; - debug (DEBUG_SPAM, "htmlize: b: $bold; u: $underline; r $reverse; c: $color; bgc: $bgcolor\n"); - } - } #end foreach code - debug (DEBUG_SPAM, "htmlize: old tag: $tag\n"); - if ($tag =~ /<span style=.*>/) { - $tag = "</span>"; - } else { - $tag = ""; - } - my $css = ($bold ? "font-weight: bold; " : "") - . ($underline ? "text-decoration: underline; " : "") - . ($reverse ? "color: white; background: black; " - : ($color != -1 ? "color: $named_colors[$color]; " : "") - . ($bgcolor != -1 ? "background: $named_colors[$bgcolor]; " : "") - ); - debug (DEBUG_SPAM, "htmlize: css: $css\n"); - $tag .= "<span style=\"$css\">" if ($css ne ""); - debug (DEBUG_SPAM, "htmlize: new tag: $tag\n"); - $line =~ s/$block/$tag/; - } # end while blocks - $line .= "</span>" if ($tag =~ /<span style=.*>/); - $string .= $line . "</div>\n"; - } # end foreach lines - $string =~ s%(http|ftp)://[^\s\n<>]+%<a href="$&">$&</a>%g; - while($string =~ m/\b(\S+@[a-z\-\.]+\.[a-z]+)/i) { - my $email = $&; - my $masked = &html_mask_email($email); - $string =~ s/$email/$masked/g; - } - return $string; -} - -# HTML_MASK_EMAIL: Returns the HTML for a masked email address. -# Currently, we break the address apart into user and host, -# turn each character into its HTML escaped ascii code, -# and return a simple javascript with the address broken up and out of order -# that, when run, outputs the address properly (and properly linked) -# This doesn't make harvesting impossible, but it does make it more difficult. -# Viewers without javascript see [email removed] instead. -sub html_mask_email { - my ($user, $host) = $_[0] =~ m/^(\S+)@(\S+)$/; - my ($nuser, $nhost); - for(my $i = 0; $i < length $user; $i++) { - $nuser .= '&#' . ord(substr($user, $i, 1)) . ';'; - } - for(my $i = 0; $i < length $host; $i++) { - $nhost .= '&#' . ord(substr($host, $i, 1)) . ';'; - } - - return <<EOT; -<script type="text/javascript"> -var p='$nhost'; -var w='to:'; -var l='$nuser'; -var u='ma'; -var s='@'; -var d='il'; -document.write('<a href="'); -document.write(u+d); -document.write(w+l); -document.write(s+p); -document.write('">'); -document.write(l); -document.write(s+p); -document.write('</a>'); -</script><noscript>[email removed]</noscript> -EOT - -} - -# NUMBERIZE: Find all the word-based numbers in a string and replace them -# with digit-based numbers. -sub numberize { - my $string = $_[0]; - debug(DEBUG_SPAM, "numberize: new string: $string\n"); - my $tmatch = "(" . join("|", keys(%numbers_tens)) . ")"; - my $omatch = "(" . join("|", keys(%numbers_other)) . ")"; - my $dmatch = "(" . join("|", keys(%numbers_digits)) . ")"; - while ($string =~ /\b($tmatch[-]$dmatch)\b/) { - my $match = $1; - my $value = ($numbers_tens{$2} + $numbers_digits{$3}); - $string =~ s/$match/$value/g; - debug(DEBUG_SPAM, "numberize: tens-ones: $string\n"); - } - while ($string =~ /\b($tmatch|$omatch|$dmatch)\b/) { - my $match = $1; - my $value = (defined $numbers_tens{$match} ? $numbers_tens{$match} : - (defined $numbers_other{$match} ? $numbers_other{$match} : - $numbers_digits{$match})); - $string =~ s/$match/$value/g; - debug(DEBUG_SPAM, "numberize: numbers: $string\n"); - } - - foreach my $match ("hundred and", "hundred", "thousand", "million", "billion", "trillion") { - while ($string =~ /\b$match\b/) { - my $value = $numbers_groups{$match}; - my $left = "$`"; - my $right = "$'"; - if ($left =~ s/([\s-]*)([0-9]+)\s*$/$1/) { - $value *= $2 if $2; - } - if($right =~ s/^\s*([0-9]+)([\s-]*)/$2/) { - $value += $1; - } - $string = "$left$value$right"; - debug(DEBUG_SPAM, "numberize: groups: $string\n"); - } - } - - debug(DEBUG_SPAM, "numberize: final: $string\n"); - return $string; -} - -# TIMEAGO: Returns a string of how long ago something happened -# timeago(time, specificity) -# specificity: -# 0 shows as needed (1 hour 15 minutes 36 seconds) -# 1 hides seconds (1 hour 15 minutes) -# except if there are only seconds -sub timeago { - my ($seconds, $minutes, $hours, $days, $weeks, $years); - my $now = time; - - $seconds = $now - $_[0]; - my $hidemode = $_[1]; - - if(!defined $hidemode) { $hidemode = 0; } - if($_[0] > $now) { - warn "Trying to use timeago on a time in the future! Now is ${now}, Then is $_[0]"; - } - if($seconds >= 60) { - $minutes = int $seconds / 60; - $seconds %= 60; - if($minutes >= 60) { - $hours = int $minutes / 60; - $minutes %= 60; - if($hours >= 24) { - $days = int $hours / 24; - $hours %= 24; - if($days >= 365) { - $years = int $days/365; - $days %= 365; - } - } - } - } - - my @reply; - push(@reply, "$years year" . (($years == 1) ? '' : 's')) if $years; - push(@reply, "$days day" . (($days == 1) ? '' : 's')) if $days; - push(@reply, "$hours hour" . (($hours == 1) ? '' : 's')) if $hours; - push(@reply, "$minutes minute" . (($minutes == 1) ? '' : 's')) if $minutes; - push(@reply, "$seconds second" . (($seconds == 1) ? '' : 's')) - if $seconds && $hidemode != 1; - if(@reply) { - my $string = join(', ', @reply) . ' ago'; - $string =~ s/(.*),/$1 and/; - return $string; - } else { - return 'very recently'; - } -} - -# CHAR_SUB: Returns the string with some odd unicode replaced with -# more ordinary characters. -sub char_sub { - my $text = $_[0]; - - $text =~ s/\N{HORIZONTAL ELLIPSIS}/.../g; - $text =~ s/\N{TWO DOT LEADER}/../g; - $text =~ s/\N{ONE DOT LEADER}/./g; - $text =~ s/\N{DOUBLE QUESTION MARK}/??/g; - $text =~ s/\N{QUESTION EXCLAMATION MARK}/?!/g; - $text =~ s/\N{EXCLAMATION QUESTION MARK}/!?/g; - - return $text; -} - -# OPTION: Returns the value (or a random value from a list) for a -# for a particular option. -sub option { - my ($sec, $val) = @_; - return "" if (!defined $conf{$sec} || !defined $conf{$sec}{$val}); - return pick(@{$conf{$sec}{$val}}); -} - -# OPTION_LIST: Returns a list of the values set for a particular option. -sub option_list { - my ($sec, $val) = @_; - return () if !defined $conf{$sec}; - if ($sec eq "filters") { - return @{$conf{$sec}}; - } else { - return () if (!defined $conf{$sec}{$val}); - return @{$conf{$sec}{$val}}; - } -} - -# OPTIONS_IN_SECTION: Returns a list of the options that are set in -# a particular section. -sub options_in_section { - my ($sec) = $_[0]; - return () if !defined $conf{$sec}; - return keys %{$conf{$sec}}; -} - # ############ IRC OPERATIONS ############ # These are the functions that a plugin should call to run an IRC operation. @@ -769,13 +391,13 @@ sub send_topic { &{$commands{topic}} sub irc_ops_kick { my ($kernel, $channel, $user, $message) = @_; - debug(DEBUG_INFO, "Irc Ops: attempting to kick $user from $channel ($message)\n"); + &debug(DEBUG_INFO, "Irc Ops: attempting to kick $user from $channel ($message)\n"); $kernel->post(bot => kick => $channel, $user, $message); } sub irc_ops_ban { my ($kernel, $channel, $user, $time, $message) = @_; - debug(DEBUG_INFO, "Irc Ops: attempting to ban $user from $channel ($message)" + &debug(DEBUG_INFO, "Irc Ops: attempting to ban $user from $channel ($message)" . ($time > 0 ? " for $time seconds" : "") . "\n"); $kernel->post(bot => mode => $channel, "+b", hostmask($user)); send_kick($channel, $user, $message); @@ -786,37 +408,37 @@ sub irc_ops_ban { sub irc_ops_unban { my ($kernel, $channel, $user) = @_; - debug(DEBUG_INFO, "Irc Ops: attempting to unban $user from $channel\n"); + &debug(DEBUG_INFO, "Irc Ops: attempting to unban $user from $channel\n"); $kernel->post(bot => mode => $channel, "-b", hostmask($user)); } sub irc_ops_op { my ($kernel, $channel, $user) = @_; - debug(DEBUG_INFO, "Irc Ops: attempting to op $user on $channel\n"); + &debug(DEBUG_INFO, "Irc Ops: attempting to op $user on $channel\n"); $kernel->post(bot => mode => $channel, "+o", $user); } sub irc_ops_deop { my ($kernel, $channel, $user) = @_; - debug(DEBUG_INFO, "Irc Ops: attempting to deop $user on $channel\n"); + &debug(DEBUG_INFO, "Irc Ops: attempting to deop $user on $channel\n"); $kernel->post(bot => mode => $channel, "-o", $user); } sub irc_ops_voice { my ($kernel, $channel, $user) = @_; - debug(DEBUG_INFO, "Irc Ops: attempting to voice $user on $channel\n"); + &debug(DEBUG_INFO, "Irc Ops: attempting to voice $user on $channel\n"); $kernel->post(bot => mode => $channel, "+v", $user); } sub irc_ops_devoice { my ($kernel, $channel, $user) = @_; - debug(DEBUG_INFO, "Irc Ops: attempting to devoice $user on $channel\n"); + &debug(DEBUG_INFO, "Irc Ops: attempting to devoice $user on $channel\n"); $kernel->post(bot => mode => $channel, "-v", $user); } sub irc_ops_topic { my ($kernel, $channel, $topic) = @_; - debug(DEBUG_INFO, "Irc Ops: attempting to set the topic to $topic on $channel\n"); + &debug(DEBUG_INFO, "Irc Ops: attempting to set the topic to $topic on $channel\n"); $kernel->post(bot => topic => $channel, $topic); } @@ -903,72 +525,6 @@ sub save { $items = 0; } -# LOAD_CONFIG: Load the configuration data into %conf. -sub load_config { - debug(DEBUG_STD, "Loading configuration file $_[0]...\n"); - if (open(CONFIG, $_[0])) { - my $section; - foreach (<CONFIG>) { - chomp; - if (m/^#|^\s*$/) { - } elsif (m/^\[(.*)\]$/) { - debug(DEBUG_SPAM, "Begin config section $1.\n"); - $section = $1; - } elsif (m/^(.*?)=(.*)$/) { - if ($section eq "filters") { - if ($1 eq "match") { - push(@{$conf{'filters'}}, qr/$2/i); - debug(DEBUG_SPAM, "$section: loaded match filter for $2\n"); - } elsif ($1 eq "word") { - push(@{$conf{'filters'}}, qr/(^|\b)\Q$2\E(\b|$)/i); - debug(DEBUG_SPAM, "$section: loaded word filter for $2\n"); - } else { - debug(DEBUG_SPAM, "$section: saw unknown filter type $1\n"); - } - } else { - push(@{$conf{$section}{$1}}, "$2"); - debug(DEBUG_SPAM, "$section: loaded option $1 as $2\n"); - } - } - } - undef $section; - close(CONFIG); - - # Set sane defaults for options that might have been omitted - if (!option('global', 'command_prefix')) { - $conf{'global'}{'command_prefix'}[0] = '%'; - debug(DEBUG_WARN, "global/command_prefix missing from config. Using '%'.\n"); - } - if (!defined option('chat', 'new_sentence_chance')) { - $conf{'chat'}{'new_sentence_chance'}[0] = 0; - debug(DEBUG_WARN, "chat/new_sentence_chance missing from config. Using 0 (off).\n"); - } - if (!defined option('chat', 'delete_usage_max')) { - $conf{'chat'}{'delete_usage_max'}[0] = -1; - debug(DEBUG_WARN, "chat/delete_usage_max missing from config. Using -1 (off).\n"); - } - if (!option('network', 'username')) { - $conf{'network'}{'username'}[0] = 'nobody'; - debug(DEBUG_WARN, "network/username missing from config. Using 'nobody'.\n"); - } - - # Once we know the gender, is it his or her (or its)? - if(option('global', 'gender') eq 'M') { - our $hisher = 'his'; - } elsif (option('global', 'gender') eq 'F') { - our $hisher = 'her'; - } else { - our $hisher = 'its'; - } - debug(DEBUG_STD, "Configuration file loaded successfully!\n"); - - } else { - die("\nYour configuration file ($_[0]) is missing or unreadable." - . "\nMake sure you copied and customized the config.default.ini"); - } - -} - # ########### PLUGIN OPERATIONS ############ # PLUGIN_REGISTER: Registers a plugin (or doesn't). @@ -1011,7 +567,7 @@ sub plugin_register { # PLUGIN_CALLBACK: Calls the given plugin function with paramters. sub plugin_callback { my ($plugin, $function, @params) = @_; - debug(DEBUG_SPAM, "Running callback to $function in $plugin.\n"); + &debug(DEBUG_SPAM, "Running callback to $function in $plugin.\n"); return &$function($kernel, @params); } @@ -1021,20 +577,20 @@ sub set_snooze { if (lc($option) eq "off") { if ($snooze) { $snooze = 0; - debug(DEBUG_STD, "snooze: Snooze mode was turned OFF by $nick.\n"); + &debug(DEBUG_STD, "snooze: Snooze mode was turned OFF by $nick.\n"); &send_action($channel, "streches and yawns."); &send_message($channel, "$nick: Thanks for the wake up call. Time to get back to work!"); } else { - debug(DEBUG_INFO, "snooze: Snooze mode was OFF, but $nick wanted to try anyway.\n"); + &debug(DEBUG_INFO, "snooze: Snooze mode was OFF, but $nick wanted to try anyway.\n"); &send_message($channel, "$nick: Do I look like I'm sleeping to you?"); } } elsif (lc($option) eq "on") { if ($snooze) { - debug(DEBUG_INFO, "snooze: Snooze mode was ON, but $nick wanted to try anyway.\n"); + &debug(DEBUG_INFO, "snooze: Snooze mode was ON, but $nick wanted to try anyway.\n"); &send_message($channel, "$nick: You're waking me up to tell me to take a nap? What kind of monster are you!?"); } else { $snooze = 1; - debug(DEBUG_STD, "snooze: Snooze mode was turned ON by $nick.\n"); + &debug(DEBUG_STD, "snooze: Snooze mode was turned ON by $nick.\n"); &send_message($channel, "$nick: You know, a nap sounds great right about now. Wake me if you need anything."); &send_action($channel, "lays down and begins to snore...."); } @@ -1356,7 +912,7 @@ sub build_reply { foreach (keys(%{$chat_words{$newword}})) { $chcount += $chat_words{$newword}{$_}[0] if defined $chat_words{$newword}{$_}[0]; } - debug(DEBUG_SPAM, "$chcount choices for next to $newword\n"); + &debug(DEBUG_SPAM, "$chcount choices for next to $newword\n"); my $try = int(rand()*($chcount))+1; foreach(keys(%{$chat_words{$newword}})) { $try -= $chat_words{$newword}{$_}[0] if defined $chat_words{$newword}{$_}[0]; @@ -1429,14 +985,14 @@ sub find_interesting_word { } } $curWordScore += .7 * length($curWord); - debug(DEBUG_INFO, "$curWord:$curWordScore ", DEBUG_NO_PREFIX); + &debug(DEBUG_INFO, "$curWord:$curWordScore ", DEBUG_NO_PREFIX); if($curWordScore > $highestScore) { $highestScore = $curWordScore; $highestScoreWord = $curWord; } } - debug(DEBUG_INFO, "\n", DEBUG_NO_PREFIX); - debug(DEBUG_INFO, "Using $highestScoreWord\n"); + &debug(DEBUG_INFO, "\n", DEBUG_NO_PREFIX); + &debug(DEBUG_INFO, "Using $highestScoreWord\n"); return $highestScoreWord; } @@ -2034,19 +1590,21 @@ sub initialize { $kernel->post(bot => register => "all"); + @servers = option_list('network', 'server'); + &irc_connect; } # IRC_CONNECT: Creates a connection to IRC. sub irc_connect { $chosen_nick = option('global', 'nickname'); - $chosen_server = option('network', 'server'); + $chosen_server = pick(@servers); my $chosen_port = 6667; if($chosen_server =~ m/^(.*):(\d+)$/) { $chosen_server = $1; $chosen_port = $2; } - + $kernel->post(bot => 'connect', { Nick => $chosen_nick, @@ -2127,16 +1685,16 @@ sub server_notice { # no, really. Numeric 465, ERR_YOUREBANNEDCREEP sub server_banned { &debug(DEBUG_ERR, "Banned from $_[ARG0]: $_[ARG1]\n"); - + if(!defined $chosen_server) { die q($chosen_server is undefined); } - for (my $i = 0; defined @{$conf{'network'}{'server'}}[$i]; $i++) { - if ($chosen_server eq @{$conf{'network'}{'server'}}[$i]) { - splice(@{$conf{'network'}{'server'}}, $i, 1) + for (my $i = 0; defined $servers[$i]; $i++) { + if ($chosen_server eq $servers[$i]) { + splice(@servers, $i, 1) } } - if(!@{$conf{'network'}{'server'}}) { + if(!@servers) { # hmm... we've removed our last server &debug(DEBUG_ERR, "No more servers to connect to! Please add some to config.ini.\n"); $terminating=100; @@ -2155,12 +1713,12 @@ sub server_banned { sub server_supports { my ($message) = $_[ARG1] =~ m/^(.*):.*?$/; &debug(DEBUG_INFO, "Server supports: ${message}\n"); - + foreach my $cur_block (split(/ /, $message)) { if(my ($ircd) = $cur_block =~ m/^IRCD=(\S+)/) { if($ircd =~ m/dancer/) { &debug(DEBUG_STD, "We're on a Dancer IRCD server, setting no-forward user mode\n"); - + # +Q tells the server not to try to forward us to another # channel. # FIXME: Channel forwarding should work, or at least be handled @@ -2171,24 +1729,22 @@ sub server_supports { # support easier in the future. $kernel->post(bot => mode => $chosen_nick => '+Q'); } - + # } elsif(my ($maxwatch) = $cur_block =~ m/^WATCH=(\d+)/) { # hmm... the server supports watch lists # let's use them instead of polling with ison - - - + # } elsif(my ($maxmodes) = $cur_block =~ m/^MODES=(\d+)/) { # This tells us how many mode changes can be done at once. # mode flags count as 1, arguments count as 1 # (so +b foo counts as 2, while +i counts as 1) - + # } elsif(my ($modeflags) = $cur_block =~ m/^STATUSMSG=(\S+)/) { # This tells us what mode flags (+%@ etc) we can stick in front # of a channel name to message that channels voiced/halfops/ops - # + means we can use +#channel to message the channel's voiced, + # + means we can use +#channel to message the channel's voiced, # halfops, and ops. % is halfops and ops, @ is ops. - + # we should use this for any wallchops type command # if the server tells us it can } @@ -2218,7 +1774,7 @@ sub quit_session { $message = option('network', 'quit_default'); } } - + $terminating = 1 unless $terminating > 1; $kernel->post(bot => quit => PROJECT . " " . VERSION |
|
From: Kevin S. <ks...@us...> - 2005-11-10 13:02:27
|
Update of /cvsroot/simbot/simbot/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23423/plugins Modified Files: 8ball.pl aspell.pl dice.pl dict.pl error.pl google.pl httpd.pl info.pl nlp.pl recap.pl rss.pl services.chanserv.pl services.undernet.pl sqlite-logger.pl time.pl tinyurl.pl todo.pl weather.pl Log Message: Added SimBot::Util module which is now used by literally everything. It's nice because it allows the plugins to use in their namespace several handy utility functions, while also allowing us to truly hide functions and variables that plugins shouldn't be accessing directly. This module can also be used by scripts in tools/ if they should want to use any utility functions we have created. It is a completely independent perl module. I will likely be adding SimBot::Plugin and attempting to migrate the plugin functions and data into that file if possible as my next step. The other thing I'd like to do fairly soon is get the main database into SQLite. We'll see... :) Index: 8ball.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/8ball.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- 8ball.pl 14 Aug 2005 01:42:34 -0000 1.4 +++ 8ball.pl 10 Nov 2005 13:02:15 -0000 1.5 @@ -20,6 +20,9 @@ package SimBot::plugin::8ball; use warnings; use strict; +# Use the SimBot Util perl module +use SimBot::Util; + # http://en.wikipedia.org/wiki/Magic_8-ball use constant SAYINGS => ( 'Signs point to yes.', @@ -62,15 +65,15 @@ use constant BLANK_INTROS => sub consult_the_8ball { my ( $kernel, $nick, $channel, undef, $question ) = @_; - &SimBot::debug( 3, "8ball: Consulting the Magic Eight Ball for $nick\n" ); + &debug( 3, "8ball: Consulting the Magic Eight Ball for $nick\n" ); my $message; if ( defined $question ) { - $message = &SimBot::pick( (INTROS) ) . ' ' . &SimBot::pick( (SAYINGS) ); + $message = &pick( (INTROS) ) . ' ' . &pick( (SAYINGS) ); } else { $message = - &SimBot::pick( (BLANK_INTROS) ) . ' ' . &SimBot::pick( (BLANK_SAYINGS) ); + &pick( (BLANK_INTROS) ) . ' ' . &pick( (BLANK_SAYINGS) ); } $message =~ s/\$nick/$nick/g; Index: aspell.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/aspell.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- aspell.pl 25 Jul 2005 09:34:18 -0000 1.7 +++ aspell.pl 10 Nov 2005 13:02:15 -0000 1.8 @@ -38,6 +38,9 @@ use constant CORRECT_SPELLING_BONUS => 0 use warnings; use strict; +# Use the SimBot Util perl module +use SimBot::Util; + use Text::Aspell; use vars qw( $SPELLER %DICTS ); @@ -46,8 +49,8 @@ use vars qw( $SPELLER %DICTS ); sub messup_aspell { $SPELLER = Text::Aspell->new or die "Could not create speller"; $SPELLER->set_option('sug-mode', SUGGESTION_MODE); - $SPELLER->set_option('lang', (&SimBot::option('plugin.aspell', 'lang') - ? &SimBot::option('plugin.aspell', 'lang') + $SPELLER->set_option('lang', (&option('plugin.aspell', 'lang') + ? &option('plugin.aspell', 'lang') : 'en')); my $cur; @@ -100,7 +103,7 @@ sub score_word { my $word = $_[1]; my $score = $_[2]; if($SPELLER->check($word)) { - &SimBot::debug(4, "$word:+" . int(CORRECT_SPELLING_BONUS * $score) . '(aspell) ', SimBot::DEBUG_NO_PREFIX); + &debug(4, "$word:+" . int(CORRECT_SPELLING_BONUS * $score) . '(aspell) ', DEBUG_NO_PREFIX); return int(CORRECT_SPELLING_BONUS * $score); } } Index: dice.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/dice.pl,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -p -r1.23 -r1.24 --- dice.pl 4 May 2005 21:09:54 -0000 1.23 +++ dice.pl 10 Nov 2005 13:02:15 -0000 1.24 @@ -32,6 +32,9 @@ package SimBot::plugin::roll; use strict; use warnings; +# Use the SimBot Util perl module +use SimBot::Util; + # Jeers for Rock Paper Scissors use constant RPS_JEER => ( 'Oh, the horror!', @@ -107,27 +110,27 @@ sub rps_shoot { if (!defined $object || $object eq "") { &SimBot::send_message($channel, "$nick: Well? Rock, paper, or scissors?"); } elsif ($object =~ /^(rock|paper|scissors)$/) { - my $pick = &SimBot::pick(('rock', 'paper','scissors')); + my $pick = &pick(('rock', 'paper','scissors')); $text = "$nick: I picked: $pick. "; if ($pick eq $object) { $text .= "It's a draw! Try again!"; } elsif ($object eq "rock") { if ($pick eq "scissors") { - $text .= "Your rock smashed my scissors. " . &SimBot::pick(RPS_JEER) . " You win!"; + $text .= "Your rock smashed my scissors. " . &pick(RPS_JEER) . " You win!"; } elsif ($pick eq "paper") { - $text .= "My paper covered your rock. " . &SimBot::pick(RPS_CHEER) . " I win!"; + $text .= "My paper covered your rock. " . &pick(RPS_CHEER) . " I win!"; } } elsif ($object eq "paper") { if ($pick eq "rock") { - $text .= "Your paper covered my rock. " . &SimBot::pick((RPS_JEER)) . " You win!"; + $text .= "Your paper covered my rock. " . &pick((RPS_JEER)) . " You win!"; } elsif ($pick eq "scissors") { - $text .= "My scissors cut your paper. " . &SimBot::pick((RPS_CHEER)) . " I win!"; + $text .= "My scissors cut your paper. " . &pick((RPS_CHEER)) . " I win!"; } } elsif ($object eq "scissors") { if ($pick eq "paper") { - $text .= "Your scissors cut my paper. " . &SimBot::pick((RPS_JEER)) . " You win!"; + $text .= "Your scissors cut my paper. " . &pick((RPS_JEER)) . " You win!"; } elsif ($pick eq "rock") { - $text .= "My rock smashed your scissors. " . &SimBot::pick((RPS_CHEER)) . " I win!"; + $text .= "My rock smashed your scissors. " . &pick((RPS_CHEER)) . " I win!"; } } &SimBot::send_message($channel, $text); Index: dict.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/dict.pl,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -p -r1.20 -r1.21 --- dict.pl 5 May 2005 03:48:46 -0000 1.20 +++ dict.pl 10 Nov 2005 13:02:15 -0000 1.21 @@ -22,6 +22,9 @@ package SimBot::plugin::define; use strict; use warnings; +# Use the SimBot Util perl module +use SimBot::Util; + # Support for the Dict protocol is found here: use Net::Dict; @@ -44,15 +47,15 @@ sub look_up { $destination = (defined $6 ? $6 : "default"); } - &SimBot::debug(3, "define: Received request from " . $nick . ".\n"); + &debug(3, "define: Received request from " . $nick . ".\n"); my $dict = Net::Dict->new(DICT_SERVER, - Client => SimBot::PROJECT . " " . SimBot::VERSION, + Client => PROJECT . " " . VERSION, Timeout => 10, ); if (!defined $dict) { - &SimBot::debug(1, "define: Unable to connect to " . DICT_SERVER . "dictionary server.\n"); + &debug(1, "define: Unable to connect to " . DICT_SERVER . "dictionary server.\n"); &SimBot::send_message($channel, "$nick: The dictionary server was unavailable."); return; } @@ -95,11 +98,11 @@ sub look_up { my $definition = ${${$def}[0]}[1]; $dictionary = ${${$def}[0]}[0]; $definition =~ s/\s+/ /g; - $definition = &SimBot::parse_style("%uline%From the $dbs{$dictionary}:%uline% $definition"); + $definition = &parse_style("%uline%From the $dbs{$dictionary}:%uline% $definition"); if ((length($definition) > 440 && $destination eq "default") || (length($definition) > 1320 && $destination eq "publicly")) { - &SimBot::send_message($channel, &SimBot::parse_style("$nick: I found a definition in the $dbs{$dictionary}, but it is too long to display in the channel. Type %bold%" . $command . " \"$term\" in $dictionary privately%bold% to see it privately.")); + &SimBot::send_message($channel, &parse_style("$nick: I found a definition in the $dbs{$dictionary}, but it is too long to display in the channel. Type %bold%" . $command . " \"$term\" in $dictionary privately%bold% to see it privately.")); } elsif ($destination eq "publicly") { &SimBot::send_pieces($channel, "$nick:", $definition); } elsif ($destination eq "privately") { @@ -128,7 +131,7 @@ sub look_up { } } else { - &SimBot::send_message($channel, &SimBot::parse_style("$nick: There is no dictionary called '$dictionary' available. Type %bold%$command%bold% with no parameters to see a list of dictionaries you can use.")); + &SimBot::send_message($channel, &parse_style("$nick: There is no dictionary called '$dictionary' available. Type %bold%$command%bold% with no parameters to see a list of dictionaries you can use.")); } } Index: error.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/error.pl,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -p -r1.12 -r1.13 --- error.pl 6 May 2005 21:10:26 -0000 1.12 +++ error.pl 10 Nov 2005 13:02:15 -0000 1.13 @@ -20,13 +20,16 @@ package SimBot::plugin::error; use strict; use warnings; +# Use the SimBot Util perl module +use SimBot::Util; + sub random_error { my ($kernel, $nick, $channel) = @_; - &SimBot::debug(3, "error: Got error request from " . $nick . ".\n"); + &debug(3, "error: Got error request from " . $nick . ".\n"); open(FILE, "data/errors.db"); my @lines = <FILE>; close(FILE); - my $error = &SimBot::pick(@lines); + my $error = &pick(@lines); chomp($error); $error =~ s/\$nick/$nick/g; &SimBot::send_message($channel, $error); @@ -34,7 +37,7 @@ sub random_error { sub random_quip { my ($nick, $channel) = @_[1,2]; - &SimBot::debug(3, "error: Got list request from " . $nick . ".\n"); + &debug(3, "error: Got list request from " . $nick . ".\n"); my @reply = ( "$nick: HER R TEH FIL3Z!!!! TEH PR1Z3 FOR U! KTHXBYE", "$nick: U R L33T H4X0R!", @@ -45,7 +48,7 @@ sub random_quip { "$nick: Ur Leet-Foo is weak!", "$nick: Like a dagger in teh nite, I catch joo unawarez!", ); - &SimBot::send_message($channel, &SimBot::pick(@reply)); + &SimBot::send_message($channel, &pick(@reply)); } # Register Plugin Index: google.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/google.pl,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -p -r1.20 -r1.21 --- google.pl 13 May 2005 02:03:22 -0000 1.20 +++ google.pl 10 Nov 2005 13:02:15 -0000 1.21 @@ -20,6 +20,9 @@ package SimBot::plugin::find; use strict; use warnings; +# Use the SimBot Util perl module +use SimBot::Util; + # We need these to work with HTML and HTTP use LWP::UserAgent; use HTML::Entities; @@ -30,7 +33,7 @@ sub google_find { shift(@terms); my $query = "@terms"; - &SimBot::debug(3, "google: Got request from " . $nick . ".\n"); + &debug(3, "google: Got request from " . $nick . ".\n"); if (!$query) { &SimBot::send_message($channel, "$nick: Nothing was found. I didn't look, but I think that was a safe bet."); @@ -43,7 +46,7 @@ sub google_find { $query =~ s/\s/+/g; my $url = "http://www.google.com/search?q=" . $query . "&btnI=1&safe=active"; my $useragent = LWP::UserAgent->new(requests_redirectable => undef); - $useragent->agent(SimBot::PROJECT . "/" . SimBot::VERSION); + $useragent->agent(PROJECT . "/" . VERSION); $useragent->timeout(5); my $request = HTTP::Request->new(GET => $url); my $response = $useragent->request($request); Index: httpd.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/httpd.pl,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -p -r1.20 -r1.21 --- httpd.pl 13 Aug 2005 19:20:35 -0000 1.20 +++ httpd.pl 10 Nov 2005 13:02:15 -0000 1.21 @@ -20,6 +20,9 @@ package SimBot::plugin::httpd; use warnings; use strict; +# Use the SimBot Util perl module +use SimBot::Util; + use POE; use POE::Component::Server::TCP; use POE::Filter::HTTPD; @@ -32,8 +35,8 @@ use vars qw( $kernel ); POE::Component::Server::TCP->new( Alias => 'web_server', Port => ( - defined &SimBot::option( 'plugin.httpd', 'port' ) - ? &SimBot::option( 'plugin.httpd', 'port' ) + defined &option( 'plugin.httpd', 'port' ) + ? &option( 'plugin.httpd', 'port' ) : 8000 ), ClientFilter => 'POE::Filter::HTTPD', @@ -56,7 +59,7 @@ sub index_handler { my ($req_root) = $request->uri =~ m|^/([^/\?]*)|; - &SimBot::debug( 3, + &debug( 3, 'httpd: handling request for ' . $request->uri . ", req root $req_root\n" ); @@ -137,7 +140,7 @@ sub get_template { } elsif ( -r "templates/${template}.default.tmpl" ) { $file_name = "templates/${template}.default.tmpl"; } else { - &SimBot::debug( &SimBot::DEBUG_WARN, + &debug( &DEBUG_WARN, "httpd: No template $template available!\n" ); return; } @@ -149,8 +152,8 @@ sub get_template { loop_context_vars => 1, ); $templ_obj->param( - sb_version => &SimBot::PROJECT . ' ' . &SimBot::VERSION, - sb_link => &SimBot::HOME_PAGE, + sb_version => &PROJECT . ' ' . &VERSION, + sb_link => &HOME_PAGE, ); return $templ_obj; } ## end sub get_template @@ -158,8 +161,8 @@ sub get_template { sub admin_page { my ( $request, $response ) = @_; - if ( !defined &SimBot::option( 'plugin.httpd', 'admin_pass' ) ) { - &SimBot::debug( &SimBot::DEBUG_WARN, + if ( !defined &option( 'plugin.httpd', 'admin_pass' ) ) { + &debug( &DEBUG_WARN, "httpd: in admin_page with no password defined!\n" ); return 500; # internal server error } @@ -170,8 +173,8 @@ sub admin_page { return RC_UNAUTHORIZED; } my ( $user, $pass ) = $request->authorization_basic; - if ( $user ne &SimBot::option( 'plugin.httpd', 'admin_user' ) - || $pass ne &SimBot::option( 'plugin.httpd', 'admin_pass' ) ) + if ( $user ne &option( 'plugin.httpd', 'admin_user' ) + || $pass ne &option( 'plugin.httpd', 'admin_pass' ) ) { $response->www_authenticate('Basic realm="simbot admin"'); @@ -192,13 +195,13 @@ sub admin_page { } elsif ( ($say) = $request->uri =~ m|\?say=(\S+)$| ) { $say =~ s/\+/ /g; $say =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; - &SimBot::debug( 3, "Speech requested by web admin\n" ); - &SimBot::send_message( &SimBot::option( 'network', 'channel' ), $say ); + &debug( 3, "Speech requested by web admin\n" ); + &SimBot::send_message( &option( 'network', 'channel' ), $say ); } elsif ( ($say) = $request->uri =~ m|\?action=(\S+)$| ) { $say =~ s/\+/ /g; $say =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; - &SimBot::debug( 3, "Action requested by web admin\n" ); - &SimBot::send_action( &SimBot::option( 'network', 'channel' ), $say ); + &debug( 3, "Action requested by web admin\n" ); + &SimBot::send_action( &option( 'network', 'channel' ), $say ); } $msg .= '<ul><li><a href="/admin?restart">Restart Simbot</a></li>'; $msg .= @@ -249,10 +252,10 @@ sub serve_css { } ## end sub serve_css sub messup_httpd { - if ( defined &SimBot::option( 'plugin.httpd', 'admin_user' ) - && length &SimBot::option( 'plugin.httpd', 'admin_user' ) > 4 - && defined &SimBot::option( 'plugin.httpd', 'admin_pass' ) - && length &SimBot::option( 'plugin.httpd', 'admin_pass' ) > 4 ) + if ( defined &option( 'plugin.httpd', 'admin_user' ) + && length &option( 'plugin.httpd', 'admin_user' ) > 4 + && defined &option( 'plugin.httpd', 'admin_pass' ) + && length &option( 'plugin.httpd', 'admin_pass' ) > 4 ) { $SimBot::hash_plugin_httpd_pages{'admin'} = { 'title' => 'SimBot Administration', @@ -263,9 +266,9 @@ sub messup_httpd { } sub cleanup_httpd { - &SimBot::debug( 3, "httpd: Shutting down..." ); + &debug( 3, "httpd: Shutting down..." ); POE::Kernel->call( 'web_server', 'shutdown' ); - &SimBot::debug( 3, " ok\n" ); + &debug( 3, " ok\n" ); } &SimBot::plugin_register( Index: info.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/info.pl,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -p -r1.44 -r1.45 --- info.pl 16 Aug 2005 17:18:56 -0000 1.44 +++ info.pl 10 Nov 2005 13:02:15 -0000 1.45 @@ -40,10 +40,13 @@ package SimBot::plugin::info; use warnings; use strict; +# Use the SimBot Util perl module +use SimBot::Util; + # Let's declare our globals. use vars qw( %info ); -use constant CMD_PREFIX => SimBot::option( 'global', 'command_prefix' ); +use constant CMD_PREFIX => option( 'global', 'command_prefix' ); # These constants define the phrases simbot will use when responding # to queries. use constant I_DONT_KNOW => ( @@ -154,7 +157,7 @@ sub handle_chat { $person_being_referenced = $1; } if ($being_addressed) { - $person_being_referenced = &SimBot::option( 'global', 'nickname' ); + $person_being_referenced = &option( 'global', 'nickname' ); } if ( $SimBot::snooze && !$being_addressed ) { @@ -175,7 +178,7 @@ sub handle_chat { if ( $info{$key} ) { delete $info{$key}; - &SimBot::debug( 4, "info: Forgot $key (req'd by $nick)\n" ); + &debug( 4, "info: Forgot $key (req'd by $nick)\n" ); &SimBot::send_message( $channel, &parse_message( &SimBot::pick(OK_FORGOTTEN), $nick, $key ) ); } else { @@ -248,7 +251,7 @@ sub handle_chat { &SimBot::send_message( $channel, &parse_message( - &SimBot::pick(BUT_X_IS_MANY), + &pick(BUT_X_IS_MANY), $nick, $key ) ); @@ -264,7 +267,7 @@ sub handle_chat { &SimBot::send_message( $channel, &parse_message( - &SimBot::pick(BUT_X_IS_Y), + &pick(BUT_X_IS_Y), $nick, $key, $isare, $oldFactoid ) ); @@ -298,10 +301,10 @@ sub handle_chat { # if the line contains something on simbot's block list, we # refuse to learn it. If we are being addressed, we give a # nondescript error message. - foreach ( &SimBot::option_list('filters') ) { + foreach ( &option_list('filters') ) { if ( $content =~ /$_/i ) { &SimBot::send_message( $channel, - &parse_message( &SimBot::pick(I_CANNOT), $nick ) ) + &parse_message( &pick(I_CANNOT), $nick ) ) if $being_addressed; return; } @@ -311,7 +314,7 @@ sub handle_chat { &SimBot::send_message( $channel, &parse_message( - &SimBot::pick(X_IS_X), + &pick(X_IS_X), $nick, $key, $isare, $factoid ) ) @@ -336,7 +339,7 @@ sub handle_chat { if ( $info{$key} =~ m/\|\|/ ) { # multiple keys &SimBot::send_message( $channel, - &parse_message( &SimBot::pick(BUT_X_IS_MANY), $nick, $key ) + &parse_message( &pick(BUT_X_IS_MANY), $nick, $key ) ); } else { my ( $keyFlags, $oldFactoid ) = split( /\|/, $info{$key}, 2 ); @@ -349,7 +352,7 @@ sub handle_chat { &SimBot::send_message( $channel, &parse_message( - &SimBot::pick(BUT_X_IS_Y), + &pick(BUT_X_IS_Y), $nick, $key, $isare, $oldFactoid ) ); @@ -416,7 +419,7 @@ sub handle_query { if ( !@factoids ) { @factoids = split( /\|\|/, $info{$query} ); } } ## end if ( ( $flags & PREFER_LOCATION... - ( $factFlags, $factoid ) = split( /\|/, &SimBot::pick(@factoids), 2 ); + ( $factFlags, $factoid ) = split( /\|/, &pick(@factoids), 2 ); my $isare = 'is'; if ( $factFlags & FACT_ARE ) { $isare = 'are'; } @@ -434,14 +437,14 @@ sub handle_query { &SimBot::send_message( $channel, &parse_message( - &SimBot::pick(QUERY_RESPONSE), + &pick(QUERY_RESPONSE), $nick, $query, $isare, $factoid ) ); } elsif ( $flags & BEING_ADDRESSED ) { # we're being addressed, but don't have an answer... &SimBot::send_message( $channel, - &parse_message( &SimBot::pick(I_DONT_KNOW), $nick, $query ) ); + &parse_message( &pick(I_DONT_KNOW), $nick, $query ) ); } } ## end sub handle_query @@ -466,9 +469,9 @@ sub report_learned { else { $flagTxt = '=is=>'; } if ( $flags & FACT_URL ) { $flagTxt .= ' =url='; } - &SimBot::debug( 4, "info: Learning from $nick: $key $flagTxt $factoid\n" ); + &debug( 4, "info: Learning from $nick: $key $flagTxt $factoid\n" ); &SimBot::send_message( $channel, - &parse_message( &SimBot::pick(OK_LEARNED), $nick ) + &parse_message( &pick(OK_LEARNED), $nick ) . " ($key $flagTxt $factoid)" ) if ( $flags & BEING_ADDRESSED ); } ## end sub report_learned @@ -489,7 +492,7 @@ sub report_learned { sub parse_message { my ( $message, $nick, $key, $isare, $factoid ) = @_; - $message = &SimBot::parse_style($message); + $message = &parse_style($message); $message =~ s/\$nick/$nick/g; $message =~ s/\$key/$key/g; Index: nlp.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/nlp.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- nlp.pl 13 Apr 2005 00:06:51 -0000 1.7 +++ nlp.pl 10 Nov 2005 13:02:15 -0000 1.8 @@ -22,6 +22,9 @@ package SimBot::plugin::nlp; use strict; use warnings; +# Use the SimBot Util perl module +use SimBot::Util; + # This function is called back from IRC when it seems that someone is trying # to address the bot. We have a lot to do when that happens. sub process_nlp { @@ -31,7 +34,7 @@ sub process_nlp { my $succeeded_plugin; my $acted = 0; - &SimBot::debug(5, "nlp: full string: $request\n"); + &debug(5, "nlp: full string: $request\n"); # We split on these words in order to break requests up into potentially # several pieces. This allows our processor to recognize more than one @@ -41,7 +44,7 @@ sub process_nlp { foreach my $text (@requests) { next if (!defined $text); - &SimBot::debug(5, "nlp: this segment: $text\n"); + &debug(5, "nlp: this segment: $text\n"); my @matches = (); my @still_matches = (); @@ -51,9 +54,9 @@ sub process_nlp { # If we find none of the verbs requested by a plugin, we don't let # the plugin on to the next round. foreach my $plugin (keys (%{SimBot::hash_plugin_nlp_verbs})) { - &SimBot::debug(5, "nlp: current plugin: $plugin\n"); + &debug(5, "nlp: current plugin: $plugin\n"); foreach my $verb (@{${SimBot::hash_plugin_nlp_verbs}{$plugin}}) { - &SimBot::debug(5, "nlp: current verb: $verb\n"); + &debug(5, "nlp: current verb: $verb\n"); my $verbmatch = $verb . "|" . $verb . "s|" . $verb . "ed|" @@ -65,7 +68,7 @@ sub process_nlp { } } - &SimBot::debug(5, "nlp: verbs passed for: " . join(" ", @matches) . "\n"); + &debug(5, "nlp: verbs passed for: " . join(" ", @matches) . "\n"); # If no plugins are worthy, we'll forget about this segment of the # request right now and skip to the next. If we had a plugin that @@ -172,7 +175,7 @@ sub process_nlp { $type = "command"; } - &SimBot::debug(5, "nlp: query type: $type\n"); + &debug(5, "nlp: query type: $type\n"); # Now we want to eliminate any plugins that don't want queries of # the type we decided we have in this query. This could be carried @@ -189,7 +192,7 @@ sub process_nlp { @matches = @still_matches; @still_matches = (); - &SimBot::debug(5, "nlp: queries passed for: " . join(" ", @matches) . "\n"); + &debug(5, "nlp: queries passed for: " . join(" ", @matches) . "\n"); # If we have no plugins that want the request type and verbs we've # found, let's get the next segment and try again. @@ -216,7 +219,7 @@ sub process_nlp { @matches = @still_matches; @still_matches = (); - &SimBot::debug(5, "nlp: subjects passed for: " . join(" ", @matches) . "\n"); + &debug(5, "nlp: subjects passed for: " . join(" ", @matches) . "\n"); # If no plugins' subjects matched, we'll give up here, and get the # next text segment and test that. @@ -231,7 +234,7 @@ sub process_nlp { # decide which information is relevant or has the highest priority. # Convert word-form numbers into digit-based numbers: - $text = &SimBot::numberize($text); + $text = &numberize($text); foreach my $plugin (@matches) { my @params = (); @@ -273,12 +276,12 @@ sub process_nlp { # to (words indicating target or destination) $format =~ s/\{to\}/(to|into)/g; - &SimBot::debug(5, "nlp: using format: $format\n"); + &debug(5, "nlp: using format: $format\n"); # Push any format matches onto an array which we'll pass to # the plugin's function. if ($text =~ /\b($format)\b/i) { - &SimBot::debug(5, "nlp: param found: $1\n"); + &debug(5, "nlp: param found: $1\n"); push(@params, $1); } } Index: recap.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/recap.pl,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -p -r1.23 -r1.24 --- recap.pl 26 Aug 2005 07:45:38 -0000 1.23 +++ recap.pl 10 Nov 2005 13:02:15 -0000 1.24 @@ -20,6 +20,9 @@ package SimBot::plugin::recap; use strict; use warnings; +# Use the SimBot Util perl module +use SimBot::Util; + use constant MAX_BACKLOG => 30; use constant STD_BACKLOG => 10; @@ -32,14 +35,14 @@ sub send_recap { if (!defined $lines) { if (defined $departs{$nick}) { $lines = $departs{$nick}; - &SimBot::debug(4, "recap: $nick recently departed, recapping from departure point ($lines lines)...\n"); + &debug(4, "recap: $nick recently departed, recapping from departure point ($lines lines)...\n"); } else { $lines = STD_BACKLOG; - &SimBot::debug(4, "recap: $nick did not specify number of lines; using default ($lines lines)...\n"); + &debug(4, "recap: $nick did not specify number of lines; using default ($lines lines)...\n"); } } - &SimBot::debug(3, "recap: Got a request from $nick for $lines lines. The backlog is " . ($#backlog + 1) . " lines.\n"); + &debug(3, "recap: Got a request from $nick for $lines lines. The backlog is " . ($#backlog + 1) . " lines.\n"); if (defined $lines && $lines =~ /^[^0-9]+$/) { &SimBot::send_message($channel, "Try using numbers. I can't count to $lines!"); } elsif ($#backlog + 1 < 1) { @@ -66,7 +69,7 @@ sub record_recap { my ($sec, $min, $hour) = localtime(time); foreach my $departed (keys %departs) { if ($departs{$departed} == MAX_BACKLOG) { - &SimBot::debug(4, "recap: $departed is no longer recently departed.\n"); + &debug(4, "recap: $departed is no longer recently departed.\n"); delete $departs{$departed}; } else { $departs{$departed}++; @@ -103,7 +106,7 @@ sub record_recap { while ($#backlog > MAX_BACKLOG) { shift(@backlog); } - &SimBot::debug(4, "recap: Recorded a line. Backlog is " . ($#backlog + 1) . " lines.\n"); + &debug(4, "recap: Recorded a line. Backlog is " . ($#backlog + 1) . " lines.\n"); } sub nick_change { @@ -119,7 +122,7 @@ sub recap_page { my $template = &$get_template('base'); $template->param( title => 'Recent Chatter', - content => &SimBot::htmlize(join("\n", @backlog)), + content => &htmlize(join("\n", @backlog)), ); $response->content($template->output()); return 200; Index: rss.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/rss.pl,v retrieving revision 1.69 retrieving revision 1.70 diff -u -d -p -r1.69 -r1.70 --- rss.pl 14 Oct 2005 01:56:20 -0000 1.69 +++ rss.pl 10 Nov 2005 13:02:15 -0000 1.70 @@ -39,6 +39,9 @@ package SimBot::plugin::rss; use strict; use warnings; +# Use the SimBot Util perl module +use SimBot::Util; + use XML::RSS; use HTML::Entities; use POE; @@ -55,10 +58,10 @@ use vars qw( %mostRecentPost $session $d $insert_headline_query $update_headline_query $update_feed_title_query $done_initial_update); -use constant CHANNEL => &SimBot::option('network', 'channel'); -use constant FEED_TITLE_STYLE => &SimBot::option('plugin.rss','title_style'); -use constant EXPIRE => (&SimBot::option('plugin.rss', 'expire') ? - &SimBot::option('plugin.rss', 'expire') : 1500); +use constant CHANNEL => &option('network', 'channel'); +use constant FEED_TITLE_STYLE => &option('plugin.rss','title_style'); +use constant EXPIRE => (&option('plugin.rss', 'expire') ? + &option('plugin.rss', 'expire') : 1500); ### messup_rss # This runs when simbot loads. We need to make sure we know the most @@ -139,18 +142,18 @@ EOT ); foreach my $cur_feed - (split(/,/, &SimBot::option('plugin.rss', 'announce'))) { + (split(/,/, &option('plugin.rss', 'announce'))) { $announce_feed{$cur_feed} = 1; } foreach my $cur_feed - (&SimBot::options_in_section('plugin.rss.feeds')) { + (&options_in_section('plugin.rss.feeds')) { $feeds{$cur_feed}=1; $get_feed_info_query->execute($cur_feed); if(my $id = ($get_feed_info_query->fetchrow_array)[0]) { # feed is already in the table, let's update it $update_feed_query->execute( - &SimBot::option('plugin.rss.feeds', $cur_feed), + &option('plugin.rss.feeds', $cur_feed), (defined $announce_feed{$cur_feed} ? 1 : 0), $id ); @@ -158,7 +161,7 @@ EOT # we need to add the feed $insert_feed_query->execute( $cur_feed, - &SimBot::option('plugin.rss.feeds', $cur_feed), + &option('plugin.rss.feeds', $cur_feed), (defined $announce_feed{$cur_feed} ? 1 : 0) ); } @@ -181,7 +184,7 @@ EOT POE::Component::Client::HTTP->spawn ( Alias => 'ua', Timeout => 120, - Agent => SimBot::PROJECT . "/" . SimBot::VERSION, + Agent => PROJECT . "/" . VERSION, FollowRedirects => 2, ); @@ -219,7 +222,7 @@ sub do_rss { my $kernel = $_[KERNEL]; my (@newPosts, $title, $request, $file); my $rss = new XML::RSS; - &SimBot::debug(3, "rss: Updating cache...\n"); + &debug(3, "rss: Updating cache...\n"); $get_all_feeds_info_query->execute; while(my ($id, undef, $key, $last_update, $url, $announce) @@ -266,14 +269,14 @@ sub got_response { my (undef, $feed_name, $key, $last_update, $feed_url, $announce) = $get_feed_by_id_query->fetchrow_array; - &SimBot::debug((($response->code >= 400) ? 1 : 4), + &debug((($response->code >= 400) ? 1 : 4), "rss: fetching feed for $key: " . $response->status_line . "\n"); if($response->code == RC_GONE) { # Server is telling us the file is gone. - &SimBot::debug(1, + &debug(1, "rss: *** FEED $key IS NO LONGER AVAILABLE\n" . " *** Removing $key from cache\n" . " *** Please remove $key from your config file\n"); @@ -302,7 +305,7 @@ sub got_response { uri => 'http://rssnamespace.org/feedburner/ext/1.0', ); if (!eval { $rss->parse($response->decoded_content); }) { - &SimBot::debug(1, "rss: Parse error in $key: $@"); + &debug(1, "rss: Parse error in $key: $@"); return; } $feed_name = $rss->{'channel'}->{'title'}; @@ -384,7 +387,7 @@ sub latest_headlines { my ($item, $title, $link); my $rss = new XML::RSS; - &SimBot::debug(3, "rss: Got request from $nick" . + &debug(3, "rss: Got request from $nick" . (defined $feed ? " for $feed" : "") . "...\n"); $get_feed_info_query->execute($feed); @@ -395,7 +398,7 @@ sub latest_headlines { # is the cache up to date? if(!defined $last_update || $last_update > time - EXPIRE) { # cache is stale or missing - &SimBot::debug(4, "rss: $feed is old or missing.\n"); + &debug(4, "rss: $feed is old or missing.\n"); my $request = HTTP::Request->new(GET => $url); $request->header('Accept-Encoding' => 'gzip, deflate'); $request->if_modified_since($last_update); @@ -403,13 +406,13 @@ sub latest_headlines { $kernel->post('ua' => 'request', 'got_response', $request, "$id!!$nick"); } else { - &SimBot::debug(4, + &debug(4, "rss: $feed is up to date; Displaying.\n"); $kernel->post($session => 'announce_top', $id, $nick, $channel); } } else { - &SimBot::debug(4, "rss: No feed matched request.\n"); + &debug(4, "rss: No feed matched request.\n"); my $message = "$nick: " . ($feed ? "I have no feed $feed." : "What feed do you want latest posts from?") @@ -458,7 +461,7 @@ sub announce_top { } if(@posts) { &SimBot::send_message(CHANNEL, - &SimBot::parse_style("$nick: Here are the latest posts to " + &parse_style("$nick: Here are the latest posts to " . &colorize_feed($feed_name) . ':')); foreach(@posts) { &SimBot::send_message(CHANNEL, $_); Index: services.chanserv.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/services.chanserv.pl,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -p -r1.12 -r1.13 --- services.chanserv.pl 26 Jul 2005 02:12:17 -0000 1.12 +++ services.chanserv.pl 10 Nov 2005 13:02:15 -0000 1.13 @@ -29,6 +29,9 @@ package SimBot::plugin::services::chanse use warnings; use strict; +# Use the SimBot Util perl module +use SimBot::Util; + # Start with the assumption Services are online, we are not locked out, and # we are not logged in, and we are not shut up. our $services_online = 0; @@ -40,21 +43,21 @@ our $shut_up = 0; # password, since logging in would be tricky, at best, without them. sub services_login { my $kernel = $_[0]; - my $pass = &SimBot::option('services', 'pass'); + my $pass = &option('services', 'pass'); if ($pass) { - &SimBot::debug(3, "Logging into services...\n"); + &debug(3, "Logging into services...\n"); $kernel->post(bot => sl => "nickserv identify $pass"); } } sub registration_check { my ($kernel, undef, undef, $newnick) = @_; - my $want = &SimBot::option('global', 'nickname'); + my $want = &option('global', 'nickname'); my $me = $SimBot::chosen_nick; if ($me eq $newnick && $me eq $want) { - &SimBot::debug(3, "Checking nickname availability...\n"); + &debug(3, "Checking nickname availability...\n"); $kernel->post(bot => sl => "nickserv info"); } } @@ -63,23 +66,23 @@ sub registration_check { # something. Here, we handle different possible cases. sub check_response { my ($kernel, $nick, undef, $text) = @_; - my $pass = &SimBot::option('services', 'pass'); + my $pass = &option('services', 'pass'); my $me = $SimBot::chosen_nick; - my $want = &SimBot::option('global', 'nickname'); - my $chan = &SimBot::option('network', 'channel'); + my $want = &option('global', 'nickname'); + my $chan = &option('network', 'channel'); if (lc($nick) eq lc("NickServ")) { $services_online = 1; if ($text =~ /is( not|n\'t) registered/i) { # Try to register!! if ($me eq $want) { - &SimBot::debug(3, "Nickname $me is not registered; trying to register it now...\n"); + &debug(3, "Nickname $me is not registered; trying to register it now...\n"); $kernel->post(bot => sl => "nickserv register $pass"); } } elsif ($text =~ /Nickname: ([^\s]+)/i) { - &SimBot::debug(4, "Nickname $1 is already registered; waiting for nickserv to ask for us to identify...\n"); + &debug(4, "Nickname $1 is already registered; waiting for nickserv to ask for us to identify...\n"); } elsif ($text =~ /Your nickname is now registered/i) { - &SimBot::debug(3, "Nickname $me registered successfully.\n"); + &debug(3, "Nickname $me registered successfully.\n"); $logged_in = 1; if ($locked_out) { &request_unban($kernel, undef, $chan); @@ -89,15 +92,15 @@ sub check_response { } } elsif ($text =~ /Password incorrect/i) { if ($logged_in == 0) { - &SimBot::debug(1, "Services reports login failure.\n"); + &debug(1, "Services reports login failure.\n"); } else { - &SimBot::debug(1, "Services command failed: Incorrect password.\n"); + &debug(1, "Services command failed: Incorrect password.\n"); } } elsif ($text =~ /This nickname is owned by someone else/i) { $logged_in = 0; &services_login($kernel); } elsif ($text =~ /you are now recognized/i) { - &SimBot::debug(3, "Services reports successful login.\n"); + &debug(3, "Services reports successful login.\n"); $logged_in = 1; if ($locked_out) { &request_unban($kernel, undef, $chan); @@ -106,14 +109,14 @@ sub check_response { &request_voice($kernel, undef, $chan); } } elsif ($text =~ /You have already identified/i) { - &SimBot::debug(2, "Services reports already logged in.\n"); + &debug(2, "Services reports already logged in.\n"); $logged_in = 1; } elsif ($text =~ /Access denied/i) { - &SimBot::debug(2, "Services reports not yet logged in.\n"); + &debug(2, "Services reports not yet logged in.\n"); $logged_in = 0; &services_login($kernel); } elsif ($text =~ m/Your nickname is not yet authenticated/i) { - &SimBot::debug(1, "Services reports: $text"); + &debug(1, "Services reports: $text"); } } @@ -121,10 +124,10 @@ sub check_response { $services_online = 1; if ($text =~ /bans matching .* cleared on (\#.*)/i) { my $chan = $1; - &SimBot::debug(3, "Services reports successful unban command.\n"); + &debug(3, "Services reports successful unban command.\n"); $kernel->post(bot => join => $chan); } elsif ($text =~ /Password identification is required/i) { - &SimBot::debug(2, "Services reports not yet logged in.\n"); + &debug(2, "Services reports not yet logged in.\n"); $logged_in = 0; &services_login($kernel); } @@ -135,14 +138,14 @@ sub check_response { # from ChanServ. sub request_unban { my ($kernel, undef, $channel, undef, $msg) = @_; - if (&SimBot::option('services', 'pass')) { + if (&option('services', 'pass')) { $locked_out = 1; if($services_online && $logged_in) { if ($msg =~ /banned/i) { - &SimBot::debug(2, "Could not join. Asking services for unban from $channel...\n"); + &debug(2, "Could not join. Asking services for unban from $channel...\n"); $kernel->post(bot => sl => "chanserv unban $channel"); } else { # Try Invite - &SimBot::debug(2, "Could not join. Asking services for invite to $channel...\n"); + &debug(2, "Could not join. Asking services for invite to $channel...\n"); $kernel->post(bot => sl => "chanserv invite $channel"); } } elsif ($services_online) { @@ -154,10 +157,10 @@ sub request_unban { # REQUEST_VOICE: If the bot was not able to speak, request a voice from ChanServ. sub request_voice { my ($kernel, undef, $channel) = @_; - if (&SimBot::option('services', 'pass')) { + if (&option('services', 'pass')) { $shut_up = 1; if($services_online && $logged_in) { - &SimBot::debug(2, "Could not speak. Asking for voice on $channel...\n"); + &debug(2, "Could not speak. Asking for voice on $channel...\n"); $kernel->post(bot => sl => "chanserv voice $channel"); $shut_up = 0; } elsif ($services_online) { @@ -180,8 +183,8 @@ sub process_notify { my ($kernel, undef, undef, @nicks) = @_; my $found = 0; my $me = $SimBot::chosen_nick; - my $want = &SimBot::option('global', 'nickname'); - my $pass = &SimBot::option('services', 'pass'); + my $want = &option('global', 'nickname'); + my $pass = &option('services', 'pass'); foreach(@nicks) { if($_ eq "NickServ") { @@ -196,7 +199,7 @@ sub process_notify { # XXX: This should probably be delayed. ®istration_check($kernel, undef, undef, $me); } else { - &SimBot::debug(3, "Desired nickname is in use; trying ghost...\n"); + &debug(3, "Desired nickname is in use; trying ghost...\n"); $kernel->post(bot => sl => "nickserv ghost $want $pass"); } } @@ -206,7 +209,7 @@ sub process_notify { # KICK_USER: Kicks a user through ChanServ. sub kick_user { my ($kernel, $channel, $user, $message) = @_; - &SimBot::debug(3, "Asking Channel Service to kick $user from $channel ($message)...\n"); + &debug(3, "Asking Channel Service to kick $user from $channel ($message)...\n"); $kernel->post(bot => sl => "chanserv kick $channel $user $message"); } @@ -214,7 +217,7 @@ sub kick_user { sub ban_user { my ($kernel, $channel, $user, $time, $message) = @_; my $hours = int($time / 3600); - &SimBot::debug(3, "Asking Channel Service to ban $user (" . + &debug(3, "Asking Channel Service to ban $user (" . &SimBot::hostmask($user) . ") from $channel ($message)...\n"); $kernel->post(bot => sl => "chanserv ban $channel " . &SimBot::hostmask($user) . "$message"); @@ -225,7 +228,7 @@ sub ban_user { # UNBAN_USER: Unbans a user through ChanServ. #sub unban_user { # my (undef, $channel, $user, $message) = @_; -# &SimBot::debug(3, "Asking Channel Service to unban $user (" . +# &debug(3, "Asking Channel Service to unban $user (" . # &SimBot::hostmask($user) . # ") from $channel...\n"); # &SimBot::send_message("ChanServ", "unban $channel " . &SimBot::hostmask($user)); Index: services.undernet.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/services.undernet.pl,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -p -r1.12 -r1.13 --- services.undernet.pl 13 Apr 2005 00:06:52 -0000 1.12 +++ services.undernet.pl 10 Nov 2005 13:02:15 -0000 1.13 @@ -20,6 +20,9 @@ package SimBot::plugin::services::undern use warnings; use strict; +# Use the SimBot Util perl module +use SimBot::Util; + # Start with the assumption X is online, we are not locked out, and # we are not logged in, and we are not shut up. our $x_online = 1; @@ -32,15 +35,15 @@ our $shut_up = 0; # We also set the +x mode to mask our hostname for some added security. sub services_login { my ($kernel, undef, $nick) = @_; - my $user = &SimBot::option('services', 'user'); - my $pass = &SimBot::option('services', 'pass'); + my $user = &option('services', 'user'); + my $pass = &option('services', 'pass'); if (defined $nick) { - &SimBot::debug(3, "Setting masked user mode...\n"); + &debug(3, "Setting masked user mode...\n"); $kernel->post(bot => mode => $nick, "+x"); } if ($pass && $user) { - &SimBot::debug(3, "Logging into Channel Service as $user...\n"); + &debug(3, "Logging into Channel Service as $user...\n"); &SimBot::send_message("x\@channels.undernet.org", "login $user $pass"); } } @@ -51,30 +54,30 @@ sub check_response { my ($kernel, $nick, undef, $text) = @_; if ($nick eq "X") { if ($text =~ /AUTHENTICATION SUCCESSFUL as /) { - &SimBot::debug(3, "Channel Service reports successful login.\n"); + &debug(3, "Channel Service reports successful login.\n"); $logged_in = 1; $x_online = 1; if ($locked_out) { - &request_invite($kernel, undef, &SimBot::option('network', 'channel')); + &request_invite($kernel, undef, &option('network', 'channel')); } if ($shut_up) { - &request_voice($kernel, undef, &SimBot::option('network', 'channel')); + &request_voice($kernel, undef, &option('network', 'channel')); } } elsif ($text =~ /AUTHENTICATION FAILED as /) { - &SimBot::debug(2, "Channel Service reports login failure.\n"); + &debug(2, "Channel Service reports login failure.\n"); $logged_in = 0; $x_online = 1; } elsif ($text =~ /Sorry, You are already authenticated as /) { - &SimBot::debug(2, "Channel Service reports already logged in.\n"); + &debug(2, "Channel Service reports already logged in.\n"); $logged_in = 1; $x_online = 1; } elsif ($text =~ /Sorry, You must be logged in to /) { - &SimBot::debug(2, "Channel Service reports not yet logged in.\n"); + &debug(2, "Channel Service reports not yet logged in.\n"); $logged_in = 0; $x_online = 1; &services_login($kernel); } else { - &SimBot::debug(4, "Channel Service message: $text\n"); + &debug(4, "Channel Service message: $text\n"); } } } @@ -83,10 +86,10 @@ sub check_response { # from X. sub request_invite { my ($kernel, undef, $channel) = @_; - if (&SimBot::option('services', 'pass')) { + if (&option('services', 'pass')) { $locked_out = 1; if($x_online && $logged_in) { - &SimBot::debug(3, "Asking Channel Service for invitation to $channel...\n"); + &debug(3, "Asking Channel Service for invitation to $channel...\n"); &SimBot::send_message("x", "invite $channel"); } elsif ($x_online) { &services_login($kernel); @@ -97,10 +100,10 @@ sub request_invite { # REQUEST_VOICE: If the bot was not able to speak, request a voice from X. sub request_voice { my ($kernel, undef, $channel) = @_; - if (&SimBot::option('services', 'pass')) { + if (&option('services', 'pass')) { $shut_up = 1; if($x_online && $logged_in) { - &SimBot::debug(2, "Could not speak. Asking for voice on $channel...\n"); + &debug(2, "Could not speak. Asking for voice on $channel...\n"); &SimBot::send_message("x", "voice $channel"); $shut_up = 0; } elsif ($x_online) { @@ -135,7 +138,7 @@ sub process_notify { # KICK_USER: Kicks a user through Channel Service. sub kick_user { my (undef, $channel, $user, $message) = @_; - &SimBot::debug(3, "Asking Channel Service to kick $user from $channel ($message)...\n"); + &debug(3, "Asking Channel Service to kick $user from $channel ($message)...\n"); &SimBot::send_message("x", "kick $channel $user $message"); } @@ -143,7 +146,7 @@ sub kick_user { sub ban_user { my (undef, $channel, $user, $time, $message) = @_; my $hours = int($time / 3600); - &SimBot::debug(3, "Asking Channel Service to ban $user (" . + &debug(3, "Asking Channel Service to ban $user (" . &SimBot::hostmask($user) . ") from $channel ($message)...\n"); &SimBot::send_message("x", "ban $channel " . &SimBot::hostmask($user) . " $hours 75 $message"); @@ -152,7 +155,7 @@ sub ban_user { # UNBAN_USER: Unbans a user through Channel Service. sub unban_user { my (undef, $channel, $user, $message) = @_; - &SimBot::debug(3, "Asking Channel Service to unban $user (" . + &debug(3, "Asking Channel Service to unban $user (" . &SimBot::hostmask($user) . ") from $channel...\n"); &SimBot::send_message("x", "unban $channel " . &SimBot::hostmask($user)); Index: sqlite-logger.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/sqlite-logger.pl,v retrieving revision 1.72 retrieving revision 1.73 diff -u -d -p -r1.72 -r1.73 --- sqlite-logger.pl 7 Sep 2005 04:20:50 -0000 1.72 +++ sqlite-logger.pl 10 Nov 2005 13:02:15 -0000 1.73 @@ -30,6 +30,10 @@ package SimBot::plugin::sqlite::logger; use warnings; use strict; + +# Use the SimBot Util perl module +use SimBot::Util; + use Data::Dumper; use Time::Local; @@ -71,7 +75,7 @@ sub messup_sqlite_logger { { RaiseError => 1, AutoCommit => 0 } ) or die; - &SimBot::debug( 3, + &debug( 3, 'sqlite: Using SQLite version ' . $dbh->{'sqlite_version'} . "\n" ); # let's create our table. If this fails, we don't care. @@ -185,7 +189,7 @@ sub get_nickchan_name { sub log_nick_change { my ( undef, undef, $nick, $newnick ) = @_; my $channel_id = - &get_nickchan_id( &SimBot::option( 'network', 'channel' ), 0 ); + &get_nickchan_id( &option( 'network', 'channel' ), 0 ); my $source_nick_id = &get_nickchan_id( $nick, 1 ); my $target_nick_id = &get_nickchan_id( $newnick, 1 ); @@ -212,7 +216,7 @@ sub set_seen { # First, we need to identify things my $channel_id = - &get_nickchan_id( &SimBot::option( 'network', 'channel' ), 1 ); + &get_nickchan_id( &option( 'network', 'channel' ), 1 ); my $source_nick_id = &get_nickchan_id( $nick, 1 ); my $target_nick_id; @@ -293,7 +297,7 @@ sub do_seen { } else { $seen_nick = shift(@args); - &SimBot::debug( 3, + &debug( 3, "sqlite-logger: Seen request by $nick for $seen_nick\n" ); if ( $seen_nick =~ m/^\*$/ ) { @@ -377,7 +381,7 @@ sub do_seen { return; } $seen_query->execute( - &get_nickchan_id( &SimBot::option( 'network', 'channel' ) ) ); + &get_nickchan_id( &option( 'network', 'channel' ) ) ); my $row; my $last_id; my @responses; @@ -446,7 +450,7 @@ sub do_recap { . ' AND id <= ?' ); my $channel_id = - &get_nickchan_id( &SimBot::option( 'network', 'channel' ) ); + &get_nickchan_id( &option( 'network', 'channel' ) ); $start_query->execute( $channel_id, $nick_id ); my $start_row; @@ -514,7 +518,7 @@ sub access_log { } elsif ( $query =~ m/^stats/ ) { my $statnick = $args[0]; my $chan_id = - &get_nickchan_id( &SimBot::option( 'network', 'channel' ) ); + &get_nickchan_id( &option( 'network', 'channel' ) ); $nick_id = &get_nickchan_id($nick); @@ -828,11 +832,11 @@ sub update_nick_context { sub score_word { my $word = $_[1]; if ( get_nickchan_id($word) ) { - &SimBot::debug( 4, "${word}:+1000(sqlite-logger) ", - SimBot::DEBUG_NO_PREFIX ); + &debug( 4, "${word}:+1000(sqlite-logger) ", + DEBUG_NO_PREFIX ); return 1000; } - &SimBot::debug( 5, "${word}:+0(sqlite-logger) ", SimBot::DEBUG_NO_PREFIX ); + &debug( 5, "${word}:+0(sqlite-logger) ", DEBUG_NO_PREFIX ); return 0; } @@ -895,7 +899,7 @@ sub web_log { my $channel_id = ( defined $query->{'channel_id'} ? $query->{'channel_id'} - : &get_nickchan_id( &SimBot::option( 'network', 'channel' ) ) + : &get_nickchan_id( &option( 'network', 'channel' ) ) ); if ( defined $query->{'smo'} ) { $start_month = $query->{'smo'}; } @@ -969,7 +973,7 @@ sub web_stats { my $channel_id = ( defined $query->{'channel_id'} ? $query->{'channel_id'} - : &get_nickchan_id( &SimBot::option( 'network', 'channel' ) ) + : &get_nickchan_id( &option( 'network', 'channel' ) ) ); @@ -1146,7 +1150,7 @@ sub web_stats { my $channel_id = ( defined $query->{'channel_id'} ? $query->{'channel_id'} - : &get_nickchan_id( &SimBot::option( 'network', 'channel' ) ) + : &get_nickchan_id( &option( 'network', 'channel' ) ) ); # Get the numbers for the graph at the top @@ -1305,7 +1309,7 @@ sub linkify { if ( $url =~ m{^(\S+)@(\S+)\.(\S+)$} ) { # probably an email address - $curWord = &SimBot::html_mask_email($url); + $curWord = &html_mask_email($url); next; } Index: time.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/time.pl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- time.pl 9 May 2005 02:02:36 -0000 1.1 +++ time.pl 10 Nov 2005 13:02:15 -0000 1.2 @@ -30,6 +30,9 @@ package SimBot::plugin::time; use warnings; use strict; +# Use the SimBot Util perl module +use SimBot::Util; + use DateTime; use DateTime::TimeZone; @@ -47,7 +50,7 @@ sub do_time { } if(!@zones) { - if(my $zonelist = &SimBot::option('plugin.time', 'default_zones')) { + if(my $zonelist = &option('plugin.time', 'default_zones')) { @zones = split(/,/, $zonelist); } else { @zones = ('UTC'); @@ -68,4 +71,4 @@ sub do_time { 'Gives you the current time in a selection of time zones. <zones>: Display these timezones. Use four digit offsets (+0400 for example) or <continent>/<city> (America/New_York) or US/<zone> (US/Eastern)', event_plugin_call => \&do_time, - ); \ No newline at end of file + ); Index: tinyurl.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/tinyurl.pl,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -p -r1.9 -r1.10 --- tinyurl.pl 18 Jul 2005 12:56:36 -0000 1.9 +++ tinyurl.pl 10 Nov 2005 13:02:15 -0000 1.10 @@ -37,6 +37,9 @@ package SimBot::plugin::tinyurl; use warnings; use strict; +# Use the SimBot Util perl module +use SimBot::Util; + use vars qw( @match_rules %urlcache ); use LWP::UserAgent; @@ -108,15 +111,15 @@ sub handle_chat { $db_query->execute($url); my $to_url; if(($to_url) = $db_query->fetchrow_array()) { - &SimBot::debug(3, "tinyurl: Looking up ${url} (cached)\n"); + &debug(3, "tinyurl: Looking up ${url} (cached)\n"); &SimBot::send_message($channel, 'TinyURL points to ' . &shorten_url($to_url)); } else { - &SimBot::debug(3, "tinyurl: Looking up ${url}\n"); + &debug(3, "tinyurl: Looking up ${url}\n"); my $useragent = LWP::UserAgent->new(requests_redirectable => undef); - $useragent->agent(SimBot::PROJECT . '/' . SimBot::VERSION); + $useragent->agent(PROJECT . '/' . VERSION); $useragent->timeout(5); my $request = HTTP::Request->new(GET => $url); my $response = $useragent->request($request); @@ -127,7 +130,7 @@ sub handle_chat { &SimBot::send_message($channel, 'TinyURL points to ' . &shorten_url($to_url)); } else { - &SimBot::debug(3, " failed! (no redirect)\n"); + &debug(3, " failed! (no redirect)\n"); } } else { # not a HTTP redirect, maybe a META? @@ -140,7 +143,7 @@ sub handle_chat { &SimBot::send_message($channel, 'TinyURL points to ' . &shorten_url($to_url)); } else { - &SimBot::debug(3, " failed!\n"); + &debug(3, " failed!\n"); warn $response->content; } } Index: todo.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/todo.pl,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -p -r1.28 -r1.29 --- todo.pl 4 May 2005 19:50:12 -0000 1.28 +++ todo.pl 10 Nov 2005 13:02:15 -0000 1.29 @@ -20,6 +20,9 @@ package SimBot::plugin::todo; use strict; use warnings; +# Use the SimBot Util perl module +use SimBot::Util; + our %vers = ( "1.0 Beta" => 1, "1.0 Final" => 1, @@ -29,7 +32,7 @@ our %vers = ( # PRINT_TODO: Prints todo list privately to the user. sub print_todo { my ($kernel, $nick) = @_; - &SimBot::debug(3, "todo: Received request from " . $nick . ".\n"); + &debug(3, "todo: Received request from " . $nick . ".\n"); if(open(TODO, "TODO")) { my $version = ""; Index: weather.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/weather.pl,v retrieving revision 1.108 retrieving revision 1.109 diff -u -d -p -r1.108 -r1.109 --- weather.pl 25 Oct 2005 22:54:50 -0000 1.108 +++ weather.pl 10 Nov 2005 13:02:15 -0000 1.109 @@ -38,6 +38,9 @@ package SimBot::plugin::weather; use strict; use warnings; +# Use the SimBot Util perl module +use SimBot::Util; + # the new fangled XML weather reports need to be parsed! use XML::Simple; @@ -207,16 +210,16 @@ sub do_wx { my ($kernel, $nick, $location, $flags) = @_[KERNEL, ARG0, ARG1, ARG2]; - &SimBot::debug(3, 'weather: Received request from ' . $nick + &debug(3, 'weather: Received request from ' . $nick . " for $location\n"); # So, what are we doing? unless($flags & DO_CONDITIONS || $flags & DO_ALERTS || $flags & DO_FORECAST) { - &SimBot::send_message(&SimBot::option('network', 'channel'), + &SimBot::send_message(&option('network', 'channel'), "$nick: Sorry, something unexpected happened. This has been logged; please try again later."); - &SimBot::debug(1, "weather: in do_wx with nothing to do!\n"); + &debug(1, "weather: in do_wx with nothing to do!\n"); return; } @@ -268,7 +271,7 @@ sub do_wx { } elsif(!($flags & USING_DEFAULTS)) { # If we don't have enough information to do the forecast or # alerts, only complain if we aren't using the default options. - &SimBot::send_message(&SimBot::option('network', 'channel'), + &SimBot::send_message(&option('network', 'channel'), "$nick: Sorry, but I have no forecast for that location."); } } @@ -276,7 +279,7 @@ sub do_wx { if($flags & DO_CONDITIONS) { if(!defined $station || length($station) != 4) { # Whine and bail - &SimBot::send_message(&SimBot::option('network', 'channel'), + &SimBot::send_message(&option('network', 'channel'), "$nick: " . ($station ? STATION_LOOKS_WRONG : STATION_UNSPECIFIED) @@ -315,15 +318,15 @@ sub got_metar { = (split(/!/, $request_packet->[1], 3)); my $response = $response_packet->[0]; - &SimBot::debug(4, 'weather: Got weather for ' . $nick + &debug(4, 'weather: Got weather for ' . $nick . " for $station\n"); if ($response->is_error) { if ($response->code eq '404') { - &SimBot::send_message(&SimBot::option('network', 'channel'), "$nick: Sorry, there is no METAR report available matching \"$station\". " . FIND_STATION_AT); + &SimBot::send_message(&option('network', 'channel'), "$nick: Sorry, there is no METAR report available matching \"$station\". " . FIND_STATION_AT); } else { &SimBot::send_message( - &SimBot::option('network', 'channel'), + &option('network', 'channel'), "$nick: " . CANNOT_ACCESS); } return; @@ -331,19 +334,19 @@ sub got_metar { # my ($datestamp, $raw_metar) = split(/\n/, $response->content); my $raw_metar; if($response->content =~ m|no data available|) { - &SimBot::send_message(&SimBot::option('network', 'channel'), + &SimB... [truncated message content] |
|
From: Kevin S. <ks...@us...> - 2005-11-10 13:02:23
|
Update of /cvsroot/simbot/simbot/lib/SimBot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23423/lib/SimBot Added Files: Util.pm Log Message: Added SimBot::Util module which is now used by literally everything. It's nice because it allows the plugins to use in their namespace several handy utility functions, while also allowing us to truly hide functions and variables that plugins shouldn't be accessing directly. This module can also be used by scripts in tools/ if they should want to use any utility functions we have created. It is a completely independent perl module. I will likely be adding SimBot::Plugin and attempting to migrate the plugin functions and data into that file if possible as my next step. The other thing I'd like to do fairly soon is get the main database into SQLite. We'll see... :) --- NEW FILE: Util.pm --- #!/usr/bin/perl # SimBot::Util # # Copyright (C) 2002-05, Kevin M Stange <ke...@si...> # # This program is free software; you can redistribute and/or modify it # under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # NOTE: You should not edit this file other than the path to perl at the top # unless you know what you are doing. Submit bugfixes back to: # http://sf.net/projects/simbot # Hi, my name(space) is: package SimBot::Util; # Exports use Exporter 'import'; @EXPORT = qw( VERSION PROJECT HOME_PAGE DEBUG_NO_PREFIX DEBUG_NONE DEBUG_ERR DEBUG_WARN DEBUG_STD DEBUG_INFO DEBUG_SPAM debug load_config pick option option_list options_in_section pick get_args parse_style htmlize html_mask_email numberize timeago char_sub ); # To make our own character substitutions easier to read, let's # be able to use character names use charnames ':full'; use strict; use warnings; # Support for Terminal Colors our $color = eval { use Term::ANSIColor; $Term::ANSIColor::AUTORESET = 1; }; use vars qw ( %args %conf ); # Software Name use constant PROJECT => "SimBot"; # Software Version use constant VERSION => "1.0 alpha"; # Software Home use constant HOME_PAGE => 'http://simbot.sf.net/'; # Debug Constants use constant DEBUG_PREFIX => ('', 'ERROR: ', 'ALERT: ', '', 'DEBUG: ', 'SPAM: '); use constant DEBUG_NONE => 0; use constant DEBUG_ERR => 1; use constant DEBUG_WARN => 2; use constant DEBUG_STD => 3; use constant DEBUG_INFO => 4; use constant DEBUG_SPAM => 5; use constant DEBUG_NO_PREFIX => 0x001; use constant DEBUG_COLORS => ("bold green", "bold red", "red", "", "bold blue", "blue"); # Default verbosity level # 0 is silent, 1 shows errors, 2 shows alert, 3 shows normal information, # 4 shows debug information, and 5 everything you never wanted to see. use constant VERBOSE => 3; # Number data for the numberize function our %numbers_groups = ( trillion => 1000000000000, billion => 1000000000, million => 1000000, thousand => 1000, hundred => 100, "hundred and" => 100, ); our %numbers_tens = ( twenty => 20, thirty => 30, forty => 40, fifty => 50, sixty => 60, seventy => 70, eighty => 80, ninety => 90, ); our %numbers_other = ( zero => 0, a => 1, ten => 10, eleven => 11, twelve => 12, thirteen => 13, fourteen => 14, fifteen => 15, sixteen => 16, seventeen => 17, eighteen => 18, nineteen => 19, ); our %numbers_digits = (one => 1, two => 2, three => 3, four => 4, five => 5, six => 6, seven => 7, eight => 8, nine => 9, ); our @named_colors = ("white", "black", "navy", "green", "red", "maroon", "purple", "orange", "yellow", "lightgreen", "teal", "cyan", "blue", "magenta", "gray", "silver"); ## debug ( level, message, flags ); returns ( ); # # Print out messages with the desired verbosity. # sub debug { if ((!defined $args{debug} && $_[0] <= VERBOSE) || (defined $args{debug} && $_[0] <= $args{debug})) { my $bitmask = (defined $_[2] ? $_[2] : 0x000); my $prefix = ($bitmask & DEBUG_NO_PREFIX ? "" : (DEBUG_PREFIX)[$_[0]]); if ($_[0] != 3 && $_[0] != 0) { if ($color) { print STDERR colored ($prefix . $_[1], (DEBUG_COLORS)[$_[0]]); } else { print STDERR ($prefix . $_[1]); } } else { if ($color) { print STDOUT colored ($prefix . $_[1], (DEBUG_COLORS)[$_[0]]); } else { print STDOUT ($prefix . $_[1]); } } } } ## pick ( array ); returns ( scalar ); # # Picks a random item from an array and returns it. # sub pick { return $_[int(rand()*@_)]; } ## parse_args ( ); returns ( ); # # Parses the arguments passed to the script. This is a private function. # sub parse_args { foreach (@ARGV) { if (m/^--/) { my ($flag, $value) = split(/=/); $flag =~ s/^--//; $value = 1 if (!defined $value); $args{$flag} = $value; } elsif (m/^-/) { my (@params) = split(//); foreach (@params) { $args{$_} = 1 unless $_ eq "-"; } } } } ## get_args ( ); returns ( hash table ); # # Returns the arguments that were passed to the script in the forum of a hash # table. # sub get_args { &parse_args if !defined %args; return %args; } ## load_config ( filename ); returns ( ); # # Loads in the specified configuration file. If any configuration data is # currently loaded, it will be deleted and replaced. # sub load_config { if (defined %conf) { debug(DEBUG_STD, "Reloading configuration file $_[0]...\n"); } else { debug(DEBUG_STD, "Loading configuration file $_[0]...\n"); } if (open(CONFIG, $_[0])) { undef %conf if defined %conf; my $section; foreach (<CONFIG>) { chomp; if (m/^#|^\s*$/) { } elsif (m/^\[(.*)\]$/) { &debug(DEBUG_SPAM, "Begin config section $1.\n"); $section = $1; } elsif (m/^(.*?)=(.*)$/) { if ($section eq "filters") { if ($1 eq "match") { push(@{$conf{'filters'}}, qr/$2/i); &debug(DEBUG_SPAM, "$section: loaded match filter for $2\n"); } elsif ($1 eq "word") { push(@{$conf{'filters'}}, qr/(^|\b)\Q$2\E(\b|$)/i); &debug(DEBUG_SPAM, "$section: loaded word filter for $2\n"); } else { &debug(DEBUG_SPAM, "$section: saw unknown filter type $1\n"); } } else { push(@{$conf{$section}{$1}}, "$2"); &debug(DEBUG_SPAM, "$section: loaded option $1 as $2\n"); } } } undef $section; close(CONFIG); # Set sane defaults for options that might have been omitted if (!option('global', 'command_prefix')) { $conf{'global'}{'command_prefix'}[0] = '%'; &debug(DEBUG_WARN, "global/command_prefix missing from config. Using '%'.\n"); } if (!defined option('chat', 'new_sentence_chance')) { $conf{'chat'}{'new_sentence_chance'}[0] = 0; &debug(DEBUG_WARN, "chat/new_sentence_chance missing from config. Using 0 (off).\n"); } if (!defined option('chat', 'delete_usage_max')) { $conf{'chat'}{'delete_usage_max'}[0] = -1; &debug(DEBUG_WARN, "chat/delete_usage_max missing from config. Using -1 (off).\n"); } if (!option('network', 'username')) { $conf{'network'}{'username'}[0] = 'nobody'; &debug(DEBUG_WARN, "network/username missing from config. Using 'nobody'.\n"); } &debug(DEBUG_STD, "Configuration file loaded successfully!\n"); } else { &debug(DEBUG_ERR, "Your configuration file ($_[0]) is missing or unreadable.\nMake sure you copied and customized the config.default.ini"); die "Unable to continue without a configuration file" if !defined %conf; } } ## option ( section, option ); returns ( value ); # # Returns the value (or a random value from a list) for a particular option. # sub option { if (!defined %conf) { debug(DEBUG_WARN, "Configuration is not loaded!\n"); } my ($sec, $val) = @_; return "" if (!defined $conf{$sec} || !defined $conf{$sec}{$val}); return pick(@{$conf{$sec}{$val}}); } ## option_list ( section, option); returns ( array ); # # Returns a list of the values set for a particular option. # sub option_list { if (!defined %conf) { debug(DEBUG_WARN, "Configuration is not loaded!\n"); } my ($sec, $val) = @_; return () if !defined $conf{$sec}; if ($sec eq "filters") { return @{$conf{$sec}}; } else { return () if (!defined $conf{$sec}{$val}); return @{$conf{$sec}{$val}}; } } ## options_in_section ( section ); returns ( array ); # # Returns a list of the options that are set in a particular section. # sub options_in_section { if (!defined %conf) { debug(DEBUG_WARN, "Configuration is not loaded!\n"); } my ($sec) = $_[0]; return () if !defined $conf{$sec}; return keys %{$conf{$sec}}; } ## parse_style ( string ); returns ( new string ); # # Parses a string for style codes and turns them into IRC style codes. # sub parse_style { $_ = $_[0]; # \003 begins a color. Avoid using black and white, as the window # will likely be either white or black, and you don't know which s/%white%/\0030/g; # white s/%black%/\0031/g; # black s/%navy%/\0032/g; # navy s/%green%/\0033/g; # green s/%red%/\0034/g; # red s/%maroon%/\0035/g; # maroon s/%purple%/\0036/g; # purple s/%orange%/\0037/g; # orange s/%yellow%/\0038/g; # yellow s/%l(igh)?tgreen%/\0039/g; # light green (ltgreen, lightgreen) s/%teal%/\00310/g; # teal s/%cyan%/\00311/g; # cyan s/%blue%/\00312/g; # blue s/%magenta%/\00313/g; # magenta s/%gray%/\00314/g; # gray s/%silver%/\00315/g; # silver s/%normal%/\017/g; # normal - remove color and style s/%bold%/\002/g; # bold s/%u(nder)?line%/\037/g; # underline (uline) return $_; } ## htmlize ( string ); returns ( new string ); # # Converts IRC color codes and links into HTML text. # sub htmlize { my @lines = split(/\n/, $_[0]); my $string = ""; foreach my $line (@lines) { my $bold = 0; my $reverse = 0; my $underline = 0; my $color = -1; my $bgcolor = -1; my $tag = ""; $line =~ s/&/&/; $line =~ s/>/>/; $line =~ s/</</; $line = "<div>" . $line; while($line =~ m/[\002\003\017\026\037]+/) { my $block = $&; my @codes = split(//, $block); debug (DEBUG_SPAM, "htmlize: codes: " . (@codes) . "\n"); foreach my $code (@codes) { if ($code eq "\002") { $bold = 1 - $bold; debug (DEBUG_SPAM, "htmlize: bold: $bold\n"); } elsif ($code eq "\037") { $underline = 1 - $underline; debug (DEBUG_SPAM, "htmlize: underline: $underline\n"); } elsif ($code eq "\026") { $reverse = 1 - $reverse; debug (DEBUG_SPAM, "htmlize: reverse: $reverse\n"); } elsif ($code eq "\003") { $line =~ m/\003(\d{1,2})?(,(\d{1,2}))?/; if ($2) { $color = $1 if $1; $bgcolor = $3; $line =~ s/\003$1$2/\003/; } elsif ($1) { $color = $1; $line =~ s/\003$1/\003/; } else { $color = -1; $bgcolor = -1; } debug (DEBUG_SPAM, "htmlize: c: $color; bgc: $bgcolor\n"); } else { $bold = 0; $underline = 0; $reverse = 0; $color = -1; $bgcolor = -1; debug (DEBUG_SPAM, "htmlize: b: $bold; u: $underline; r $reverse; c: $color; bgc: $bgcolor\n"); } } #end foreach code debug (DEBUG_SPAM, "htmlize: old tag: $tag\n"); if ($tag =~ /<span style=.*>/) { $tag = "</span>"; } else { $tag = ""; } my $css = ($bold ? "font-weight: bold; " : "") . ($underline ? "text-decoration: underline; " : "") . ($reverse ? "color: white; background: black; " : ($color != -1 ? "color: $named_colors[$color]; " : "") . ($bgcolor != -1 ? "background: $named_colors[$bgcolor]; " : "") ); debug (DEBUG_SPAM, "htmlize: css: $css\n"); $tag .= "<span style=\"$css\">" if ($css ne ""); debug (DEBUG_SPAM, "htmlize: new tag: $tag\n"); $line =~ s/$block/$tag/; } # end while blocks $line .= "</span>" if ($tag =~ /<span style=.*>/); $string .= $line . "</div>\n"; } # end foreach lines $string =~ s%(http|ftp)://[^\s\n<>]+%<a href="$&">$&</a>%g; while($string =~ m/\b(\S+@[a-z\-\.]+\.[a-z]+)/i) { my $email = $&; my $masked = &html_mask_email($email); $string =~ s/$email/$masked/g; } return $string; } ## html_mask_email ( email address ); returns ( masked html ); # # Returns the HTML for a masked email address. Currently, we break the # address apart into user and host, turn each character into its HTML # escaped ascii code, and return a simple javascript with the address # broken up and out of order. When run, the script outputs the address # properly (and properly linked). # # This doesn't make harvesting impossible, but it does make it more # difficult. Viewers without javascript see [email removed] instead. # sub html_mask_email { my ($user, $host) = $_[0] =~ m/^(\S+)@(\S+)$/; my ($nuser, $nhost); for(my $i = 0; $i < length $user; $i++) { $nuser .= '&#' . ord(substr($user, $i, 1)) . ';'; } for(my $i = 0; $i < length $host; $i++) { $nhost .= '&#' . ord(substr($host, $i, 1)) . ';'; } return <<EOT; <script type="text/javascript"> var p='$nhost'; var w='to:'; var l='$nuser'; var u='ma'; var s='@'; var d='il'; document.write('<a href="'); document.write(u+d); document.write(w+l); document.write(s+p); document.write('">'); document.write(l); document.write(s+p); document.write('</a>'); </script><noscript>[email removed]</noscript> EOT } ## numberize ( string ); returns ( new string ); # # Finds all the word-based numbers in a string and replaces them with # digit-based numbers. # sub numberize { my $string = $_[0]; debug(DEBUG_SPAM, "numberize: new string: $string\n"); my $tmatch = "(" . join("|", keys(%numbers_tens)) . ")"; my $omatch = "(" . join("|", keys(%numbers_other)) . ")"; my $dmatch = "(" . join("|", keys(%numbers_digits)) . ")"; while ($string =~ /\b($tmatch[-]$dmatch)\b/) { my $match = $1; my $value = ($numbers_tens{$2} + $numbers_digits{$3}); $string =~ s/$match/$value/g; debug(DEBUG_SPAM, "numberize: tens-ones: $string\n"); } while ($string =~ /\b($tmatch|$omatch|$dmatch)\b/) { my $match = $1; my $value = (defined $numbers_tens{$match} ? $numbers_tens{$match} : (defined $numbers_other{$match} ? $numbers_other{$match} : $numbers_digits{$match})); $string =~ s/$match/$value/g; debug(DEBUG_SPAM, "numberize: numbers: $string\n"); } foreach my $match ("hundred and", "hundred", "thousand", "million", "billion", "trillion") { while ($string =~ /\b$match\b/) { my $value = $numbers_groups{$match}; my $left = "$`"; my $right = "$'"; if ($left =~ s/([\s-]*)([0-9]+)\s*$/$1/) { $value *= $2 if $2; } if($right =~ s/^\s*([0-9]+)([\s-]*)/$2/) { $value += $1; } $string = "$left$value$right"; debug(DEBUG_SPAM, "numberize: groups: $string\n"); } } debug(DEBUG_SPAM, "numberize: final: $string\n"); return $string; } ## timeago ( unix time, specificity ); returns ( string ); # # Returns a string of how long ago something happened. # specificity: # 0 shows as needed (1 hour 15 minutes 36 seconds) # 1 hides seconds (1 hour 15 minutes) # except if there are only seconds # sub timeago { my ($seconds, $minutes, $hours, $days, $weeks, $years); my $now = time; $seconds = $now - $_[0]; my $hidemode = (defined $_[1] ? $_[1] : 0); if($_[0] > $now) { warn "Trying to use timeago on a time in the future! Now is ${now}, Then is $_[0]"; } if($seconds >= 60) { $minutes = int $seconds / 60; $seconds %= 60; if($minutes >= 60) { $hours = int $minutes / 60; $minutes %= 60; if($hours >= 24) { $days = int $hours / 24; $hours %= 24; if($days >= 365) { $years = int $days/365; $days %= 365; } } } } my @reply; push(@reply, "$years year" . (($years == 1) ? '' : 's')) if $years; push(@reply, "$days day" . (($days == 1) ? '' : 's')) if $days; push(@reply, "$hours hour" . (($hours == 1) ? '' : 's')) if $hours; push(@reply, "$minutes minute" . (($minutes == 1) ? '' : 's')) if $minutes; push(@reply, "$seconds second" . (($seconds == 1) ? '' : 's')) if $seconds && $hidemode != 1; if(@reply) { my $string = join(', ', @reply) . ' ago'; $string =~ s/(.*),/$1 and/; return $string; } else { return 'very recently'; } } ## char_sub ( string ); returns ( new string ); # # Returns the string with some odd unicode replaced with more ordinary # characters. # sub char_sub { my $text = $_[0]; $text =~ s/\N{HORIZONTAL ELLIPSIS}/.../g; $text =~ s/\N{TWO DOT LEADER}/../g; $text =~ s/\N{ONE DOT LEADER}/./g; $text =~ s/\N{DOUBLE QUESTION MARK}/??/g; $text =~ s/\N{QUESTION EXCLAMATION MARK}/?!/g; $text =~ s/\N{EXCLAMATION QUESTION MARK}/!?/g; return $text; } |
|
From: Kevin S. <ks...@us...> - 2005-11-10 12:54:30
|
Update of /cvsroot/simbot/simbot/lib/SimBot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21734/lib/SimBot Log Message: Directory /cvsroot/simbot/simbot/lib/SimBot added to the repository |
|
From: Kevin S. <ks...@us...> - 2005-11-10 12:54:16
|
Update of /cvsroot/simbot/simbot/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21677/lib Log Message: Directory /cvsroot/simbot/simbot/lib added to the repository |
|
From: Pete P. <fou...@us...> - 2005-10-25 22:55:00
|
Update of /cvsroot/simbot/simbot/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10210/plugins Modified Files: weather.pl Log Message: snow snow snow snow snow snow SNOW! er... yeah. Anyway, SimBot will no longer consider "sb, SNOW!" a request for weather at the non-existant station SNOW. Index: weather.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/weather.pl,v retrieving revision 1.107 retrieving revision 1.108 diff -u -d -p -r1.107 -r1.108 --- weather.pl 24 Oct 2005 20:16:52 -0000 1.107 +++ weather.pl 25 Oct 2005 22:54:50 -0000 1.108 @@ -824,7 +824,7 @@ sub nlp_match { } } - if (defined $station) { + if (defined $station && $station !~ m/RAIN|SNOW|HAIL|WARM|COLD/) { &handle_user_command($kernel, $nick, $channel, " weather", $station); return 1; } else { |
|
From: Pete P. <fou...@us...> - 2005-10-24 20:17:03
|
Update of /cvsroot/simbot/simbot/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1219/plugins Modified Files: weather.pl Log Message: Bad commands should not be silently ignored. Index: weather.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/weather.pl,v retrieving revision 1.106 retrieving revision 1.107 diff -u -d -p -r1.106 -r1.107 --- weather.pl 14 Oct 2005 01:33:31 -0000 1.106 +++ weather.pl 24 Oct 2005 20:16:52 -0000 1.107 @@ -273,8 +273,8 @@ sub do_wx { } } - if($flags & DO_CONDITIONS && defined $station) { - if(length($station) != 4) { + if($flags & DO_CONDITIONS) { + if(!defined $station || length($station) != 4) { # Whine and bail &SimBot::send_message(&SimBot::option('network', 'channel'), "$nick: " @@ -850,11 +850,15 @@ sub handle_user_command { if($command =~ /^.metar$/) { $flags |= RAW_METAR | DO_CONDITIONS; } foreach(@args) { - if(m/^m(etric)?$/) { $flags |= UNITS_METRIC; } - if(m/^f(ore)?cast$/) { $flags |= DO_FORECAST | DO_ALERTS; } - if(m/^(us|imp(erial)?)$/) { $flags |= UNITS_IMPERIAL; } - if(m/^raw$/) { $flags |= RAW_METAR | DO_CONDITIONS; } - if(m/^cond(itions)?/) { $flags |= DO_CONDITIONS; } + if (m/^m(etric)?$/) { $flags |= UNITS_METRIC; } + elsif(m/^f(ore)?cast$/) { $flags |= DO_FORECAST | DO_ALERTS; } + elsif(m/^(us|imp(erial)?)$/) { $flags |= UNITS_IMPERIAL; } + elsif(m/^raw$/) { $flags |= RAW_METAR | DO_CONDITIONS; } + elsif(m/^cond(itions)?/) { $flags |= DO_CONDITIONS; } + else { + &SimBot::send_message($channel, "$nick: I didn't understand your request."); + return; + } } if($flags == 0 || $flags == UNITS_METRIC |