[SimBot-commits] CVS: simbot simbot.pl,1.128,1.129
Status: Abandoned
Brought to you by:
kstange
|
From: Kevin S. <ks...@us...> - 2005-07-27 17:37:27
|
Update of /cvsroot/simbot/simbot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15100 Modified Files: simbot.pl Log Message: What exactly did I do? I stole some old code from a perl script I had written, then I totally rewrote it anyway. This adds htmlize, which converts IRC control codes into HTML for use with the httpd plugin. I made recap use it and output in HTML, and I don't know why CVS says httpd.pl has been changed. Index: simbot.pl =================================================================== RCS file: /cvsroot/simbot/simbot/simbot.pl,v retrieving revision 1.128 retrieving revision 1.129 diff -u -d -p -r1.128 -r1.129 --- simbot.pl 26 Jul 2005 01:52:20 -0000 1.128 +++ simbot.pl 27 Jul 2005 17:37:17 -0000 1.129 @@ -107,6 +107,11 @@ 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 *********** # **************************************** @@ -490,6 +495,82 @@ 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 { @@ -710,7 +791,7 @@ sub load { $chat_words{$rule[1]}{$rule[0]}[0] = $rule[2]; } close(RULES); - &debug(DEBUG_STD, "Rules loaded successfully!\n"); + &debug(DEBUG_STD, "Rules loaded successfully!\n", DEBUG_NO_PREFIX); $loaded = 1; &debug(DEBUG_STD, "Checking for lost words... "); @@ -1708,10 +1789,6 @@ 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 . "|" . @@ -1723,6 +1800,14 @@ 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]; |