comparison irclib.py @ 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 c5e4bf95f52a
comparison
equal deleted inserted replaced
68:7aa1f59800b0 69:0a2b9e84bbde
68 import string 68 import string
69 import sys 69 import sys
70 import time 70 import time
71 import types 71 import types
72 import threading 72 import threading
73 import traceback
73 74
74 VERSION = 0, 4, 8 75 VERSION = 0, 4, 8
75 DEBUG = 0 76 DEBUG = 0
76 77
77 # TODO 78 # TODO
86 # NOTES 87 # NOTES
87 # ----- 88 # -----
88 # connection.quit() only sends QUIT to the server. 89 # connection.quit() only sends QUIT to the server.
89 # ERROR from the server triggers the error event and the disconnect event. 90 # ERROR from the server triggers the error event and the disconnect event.
90 # dropping of the connection triggers the disconnect event. 91 # dropping of the connection triggers the disconnect event.
92
93 strip_colors_re = re.compile('\x03[0-9]+')
91 94
92 class IRCError(Exception): 95 class IRCError(Exception):
93 """Represents an IRC exception.""" 96 """Represents an IRC exception."""
94 pass 97 pass
95 98
622 625
623 m = list(m) 626 m = list(m)
624 if DEBUG: 627 if DEBUG:
625 print "command: %s, source: %s, target: %s, arguments: %s" % ( 628 print "command: %s, source: %s, target: %s, arguments: %s" % (
626 command, prefix, target, m) 629 command, prefix, target, m)
630
631 # Remove colors
632 for i in range(len(m)):
633 m[i] = strip_colors_re.sub('', m[i])
634
627 self._handle_event(Event(command, prefix, target, m)) 635 self._handle_event(Event(command, prefix, target, m))
628 if command == "ctcp" and m[0] == "ACTION": 636 if command == "ctcp" and m[0] == "ACTION":
629 self._handle_event(Event("action", prefix, target, m[1:])) 637 self._handle_event(Event("action", prefix, target, m[1:]))
630 else: 638 else:
631 if DEBUG: 639 if DEBUG:
632 print "command: %s, source: %s, target: %s, arguments: %s" % ( 640 print "command: %s, source: %s, target: %s, arguments: %s" % (
633 command, prefix, target, [m]) 641 command, prefix, target, [m])
634 self._handle_event(Event(command, prefix, target, [m])) 642 self._handle_event(Event(command, prefix, target, [strip_colors_re.sub('', m)]))
635 else: 643 else:
636 target = None 644 target = None
637 645
638 if command == "quit": 646 if command == "quit":
639 arguments = [arguments[0]] 647 arguments = [arguments[0]]
648 command = "umode" 656 command = "umode"
649 657
650 if DEBUG: 658 if DEBUG:
651 print "command: %s, source: %s, target: %s, arguments: %s" % ( 659 print "command: %s, source: %s, target: %s, arguments: %s" % (
652 command, prefix, target, arguments) 660 command, prefix, target, arguments)
661
662 # Remove colors
663 for i in range(len(arguments)):
664 arguments[i] = strip_colors_re.sub('', arguments[i])
665
653 self._handle_event(Event(command, prefix, target, arguments)) 666 self._handle_event(Event(command, prefix, target, arguments))
654 667
655 def _handle_event(self, event): 668 def _handle_event(self, event):
656 """[Internal]""" 669 """[Internal]"""
657 self.irclibobj._handle_event(self, event) 670 self.irclibobj._handle_event(self, event)