[pastebot-cvs] pastebot/Client IRC.pm,1.17,1.18
Status: Beta
Brought to you by:
rcaputo
From: <rc...@us...> - 2004-06-09 02:31:27
|
Update of /cvsroot/pastebot/pastebot/Client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30379/Client Modified Files: IRC.pm Log Message: Indigoid runs Memephage in a channel with a lot of color codes flying around. He discovered that Memephage was collecting broken URLs because of colorization attached to them, so he wrote a few regular expressions to remove them. This commit adds his color filtering code. Index: IRC.pm =================================================================== RCS file: /cvsroot/pastebot/pastebot/Client/IRC.pm,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** IRC.pm 22 Dec 2003 06:38:41 -0000 1.17 --- IRC.pm 9 Jun 2004 02:31:10 -0000 1.18 *************** *** 148,151 **** --- 148,154 ---- my ($nick) = $sender =~ /^([^!]+)/; print "Message $msg from $nick\n"; + + $msg = remove_colors($msg); + if ($msg =~ /^\s*help(?:\s+(\w+))?\s*$/) { my $what = $1 || 'help'; *************** *** 488,491 **** --- 491,495 ---- # Do something with input here? + # If so, remove colors from it first. }, }, *************** *** 536,539 **** --- 540,556 ---- } + # Helper functions. Remove color codes from a message. + + sub remove_colors { + my $msg = shift; + + # Indigoid supplied these regexps to extract colors. + $msg =~ s/[\x02\x0F\x11\x12\x16\x1d\x1f]//g; # Regular attributes. + $msg =~ s/\x03[0-9,]*//g; # mIRC colors. + $msg =~ s/\x04[0-9a-f]+//ig; # Other colors. + + return $msg; + } + #------------------------------------------------------------------------------ 1; |