comparison irclib.py @ 74:676c2d2bf240

Strip bold character from IRC messages Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Wed, 02 Sep 2009 17:48:41 +0200
parents c5e4bf95f52a
children 6034087b1d10
comparison
equal deleted inserted replaced
73:fa291fd20480 74:676c2d2bf240
88 # ----- 88 # -----
89 # connection.quit() only sends QUIT to the server. 89 # connection.quit() only sends QUIT to the server.
90 # 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.
91 # dropping of the connection triggers the disconnect event. 91 # dropping of the connection triggers the disconnect event.
92 92
93 strip_colors_re = re.compile('\x03[0-9]+') 93 strip_formatting_re = re.compile('(?:\x03[0-9]+|\x02)')
94 94
95 class IRCError(Exception): 95 class IRCError(Exception):
96 """Represents an IRC exception.""" 96 """Represents an IRC exception."""
97 pass 97 pass
98 98
626 m = list(m) 626 m = list(m)
627 if DEBUG: 627 if DEBUG:
628 print "command: %s, source: %s, target: %s, arguments: %s" % ( 628 print "command: %s, source: %s, target: %s, arguments: %s" % (
629 command, prefix, target, m) 629 command, prefix, target, m)
630 630
631 # Remove colors 631 # Remove formatting
632 for i in range(len(m)): 632 for i in range(len(m)):
633 m[i] = strip_colors_re.sub('', m[i]) 633 m[i] = strip_formatting_re.sub('', m[i])
634 634
635 self._handle_event(Event(command, prefix, target, m)) 635 self._handle_event(Event(command, prefix, target, m))
636 if command == "ctcp" and m[0] == "ACTION": 636 if command == "ctcp" and m[0] == "ACTION":
637 self._handle_event(Event("action", prefix, target, m[1:])) 637 self._handle_event(Event("action", prefix, target, m[1:]))
638 else: 638 else:
639 if DEBUG: 639 if DEBUG:
640 print "command: %s, source: %s, target: %s, arguments: %s" % ( 640 print "command: %s, source: %s, target: %s, arguments: %s" % (
641 command, prefix, target, [m]) 641 command, prefix, target, [m])
642 self._handle_event(Event(command, prefix, target, [strip_colors_re.sub('', m)])) 642 self._handle_event(Event(command, prefix, target, [strip_formatting_re.sub('', m)]))
643 else: 643 else:
644 target = None 644 target = None
645 645
646 if command == "quit": 646 if command == "quit":
647 arguments = [arguments[0]] 647 arguments = [arguments[0]]
657 657
658 if DEBUG: 658 if DEBUG:
659 print "command: %s, source: %s, target: %s, arguments: %s" % ( 659 print "command: %s, source: %s, target: %s, arguments: %s" % (
660 command, prefix, target, arguments) 660 command, prefix, target, arguments)
661 661
662 # Remove colors 662 # Remove formatting
663 for i in range(len(arguments)): 663 for i in range(len(arguments)):
664 arguments[i] = strip_colors_re.sub('', arguments[i]) 664 arguments[i] = strip_formatting_re.sub('', arguments[i])
665 665
666 self._handle_event(Event(command, prefix, target, arguments)) 666 self._handle_event(Event(command, prefix, target, arguments))
667 667
668 def _handle_event(self, event): 668 def _handle_event(self, event):
669 """[Internal]""" 669 """[Internal]"""