[SimBot-commits] CVS: simbot simbot.pl,1.129,1.130
Status: Abandoned
Brought to you by:
kstange
|
From: Pete P. <fou...@us...> - 2005-07-28 00:09:59
|
Update of /cvsroot/simbot/simbot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21267 Modified Files: simbot.pl Log Message: Closer to getting restart in the admin page working. Index: simbot.pl =================================================================== RCS file: /cvsroot/simbot/simbot/simbot.pl,v retrieving revision 1.129 retrieving revision 1.130 diff -u -d -p -r1.129 -r1.130 --- simbot.pl 27 Jul 2005 17:37:17 -0000 1.129 +++ simbot.pl 28 Jul 2005 00:09:49 -0000 1.130 @@ -107,11 +107,6 @@ our %numbers_digits = (one => 1, two => 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 *********** # **************************************** @@ -287,6 +282,11 @@ if(option('chat', 'delete_usage_max') != ); } +# We'll need this perl module to be able to do anything meaningful. +use POE; +use POE::Component::IRC; +our $kernel = new POE::Kernel; + # Now that we've initialized the callback tables, let's load # all the plugins that we can from the plugins directory. opendir(DIR, "./plugins"); @@ -327,12 +327,6 @@ our $snooze = (option('chat','snooze') = # Load the massive table of rules simbot will need. &load; -# Now that everything is loaded, let's prepare to connect to IRC. -# We'll need this perl module to be able to do anything meaningful. -our $kernel = new POE::Kernel; -use POE; -use POE::Component::IRC; - # Create a new IRC connection. POE::Component::IRC->new('bot'); @@ -495,82 +489,6 @@ sub parse_style { 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 = 16; - my $bgcolor = 16; - 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 = 16; - $bgcolor = 16; - } - debug (DEBUG_SPAM, "htmlize: c: $color; bgc: $bgcolor\n"); - } else { - $bold = 0; - $underline = 0; - $reverse = 0; - $color = 16; - $bgcolor = 16; - 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 != 16 ? "color: $named_colors[$color]; " : "") - . ($bgcolor != 16 ? "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; - return $string; -} - # NUMBERIZE: Find all the word-based numbers in a string and replace them # with digit-based numbers. sub numberize { @@ -791,7 +709,7 @@ sub load { $chat_words{$rule[1]}{$rule[0]}[0] = $rule[2]; } close(RULES); - &debug(DEBUG_STD, "Rules loaded successfully!\n", DEBUG_NO_PREFIX); + &debug(DEBUG_STD, "Rules loaded successfully!\n"); $loaded = 1; &debug(DEBUG_STD, "Checking for lost words... "); @@ -963,6 +881,9 @@ sub plugin_register { # PLUGIN_CALLBACK: Calls the given plugin function with paramters. sub plugin_callback { + if(!defined $kernel) { + warn 'In plugin_callback before $kernel is defined'; + } my ($plugin, $function, @params) = @_; debug(DEBUG_SPAM, "Running callback to $function in $plugin.\n"); return &$function($kernel, @params); @@ -1789,6 +1710,10 @@ sub private_message { sub channel_message { my ($nick) = split(/!/, $_[ ARG0 ]); my ($channel, $text) = @_[ ARG1, ARG2 ]; + $text =~ s/\003\d{0,2},?\d{0,2}//g; + $text =~ s/[\002\017\026\037]//g; + + &debug(DEBUG_STD, "[@{$channel}:$nick] $text\n"); my $prefix = option('global', 'command_prefix'); my $nickmatch = "(" . $chosen_nick . "|" . @@ -1800,14 +1725,6 @@ sub channel_message { &plugin_callback($_, $event_channel_message{$_}, ($nick, $channel, 'SAY', $text)); } - # We pass the original string to plugins. Then, we strip out formatting - # codes. Who knows? Someone might want to log things exactly as they - # were. - $text =~ s/\003\d{0,2},?\d{0,2}//g; - $text =~ s/[\002\017\026\037]//g; - - &debug(DEBUG_STD, "[@{$channel}:$nick] $text\n"); - if ($text =~ /^\Q$prefix\E/) { my @command = split(/\s/, $text); my $cmd = $command[0]; @@ -1982,6 +1899,8 @@ sub initialize { $kernel->sig( USR1 => 'restart' ); $kernel->sig( USR2 => 'rehash' ); + $kernel->alias_set('simbot'); # so plugins can talk back to us + $kernel->post(bot => register => "all"); &irc_connect; @@ -2172,6 +2091,9 @@ sub quit_session { # remove any alarms. This stops any verbose output simbot was giving $kernel->alarm_remove_all( ); + + # remove our alias + $kernel->alias_remove('simbot'); $kernel->sig_handled(); } |