changeset 69:0a2b9e84bbde

Strip colors from IRC messages Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sun, 30 Aug 2009 21:08:53 +0200
parents 7aa1f59800b0
children 01f1c6cb7447
files irclib.py
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/irclib.py
+++ b/irclib.py
@@ -70,6 +70,7 @@ import sys
 import time
 import types
 import threading
+import traceback
 
 VERSION = 0, 4, 8
 DEBUG = 0
@@ -89,6 +90,8 @@ DEBUG = 0
 # ERROR from the server triggers the error event and the disconnect event.
 # dropping of the connection triggers the disconnect event.
 
+strip_colors_re = re.compile('\x03[0-9]+')
+
 class IRCError(Exception):
     """Represents an IRC exception."""
     pass
@@ -624,6 +627,11 @@ class ServerConnection(Connection):
                         if DEBUG:
                             print "command: %s, source: %s, target: %s, arguments: %s" % (
                                 command, prefix, target, m)
+
+                        # Remove colors
+                        for i in range(len(m)):
+                            m[i] = strip_colors_re.sub('', m[i])
+
                         self._handle_event(Event(command, prefix, target, m))
                         if command == "ctcp" and m[0] == "ACTION":
                             self._handle_event(Event("action", prefix, target, m[1:]))
@@ -631,7 +639,7 @@ class ServerConnection(Connection):
                         if DEBUG:
                             print "command: %s, source: %s, target: %s, arguments: %s" % (
                                 command, prefix, target, [m])
-                        self._handle_event(Event(command, prefix, target, [m]))
+                        self._handle_event(Event(command, prefix, target, [strip_colors_re.sub('', m)]))
             else:
                 target = None
 
@@ -650,6 +658,11 @@ class ServerConnection(Connection):
                 if DEBUG:
                     print "command: %s, source: %s, target: %s, arguments: %s" % (
                         command, prefix, target, arguments)
+
+                # Remove colors
+                for i in range(len(arguments)):
+                    arguments[i] = strip_colors_re.sub('', arguments[i])
+
                 self._handle_event(Event(command, prefix, target, arguments))
 
     def _handle_event(self, event):