changeset 166:0fc24e232997

some fixes related to IRC nicknames Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Wed, 20 Jan 2010 14:48:52 +0100
parents 12d564cd0203
children f4997d50e93b
files bot.py irclib.py
diffstat 2 files changed, 5 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/bot.py
+++ b/bot.py
@@ -451,7 +451,7 @@ class Bot(threading.Thread):
 		
 		
 		# Events we always want to ignore
-		if 'all' in event.eventtype() or 'motd' in event.eventtype():
+		if 'all' in event.eventtype() or 'motd' in event.eventtype() or event.eventtype() in ['nicknameinuse', 'nickcollision', 'erroneusnickname']:
 			return
 		if event.eventtype() in ['pong', 'privnotice', 'ctcp', 'nochanmodes', 'notexttosend', 'currenttopic', 'topicinfo', '328']:
 			self.error('=> Debug: ignoring IRC '+event.eventtype(), debug=True)
@@ -663,25 +663,8 @@ class Bot(threading.Thread):
 			return
 		
 		
-		# From here the event is shown
-		self.error(event_str, debug=True)
-		
-		
-		# Nickname callbacks
-		# TODO: move this into irclib.py
-		if event.eventtype() == 'nicknameinuse':
-			connection._call_nick_callbacks('nicknameinuse', arguments=[event])
-			return
-		if event.eventtype() == 'nickcollision':
-			connection._call_nick_callbacks('nickcollision', arguments=[event])
-			return
-		if event.eventtype() == 'erroneusnickname':
-			connection._call_nick_callbacks('erroneusnickname', arguments=[event])
-			return
-		
-		
 		# Unhandled events
-		self.error('=> Debug: event not handled', debug=True)
+		self.error(event_str+'\n=> Debug: event not handled', debug=True)
 	
 	
 	def _send_message_to_admins(self, message):
--- a/irclib.py
+++ b/irclib.py
@@ -700,6 +700,8 @@ class ServerConnection(Connection):
     def _handle_event(self, event):
         """[Internal]"""
         self.irclibobj._handle_event(self, event)
+        if event.eventtype() in ['disconnect', 'nicknameinuse', 'nickcollision', 'erroneusnickname']:
+            self._call_nick_callbacks(event.eventtype(), arguments=[event])
         if event.eventtype() in self.handlers:
             for fn in self.handlers[event.eventtype()]:
                 fn(self, event)
@@ -840,7 +842,7 @@ class ServerConnection(Connection):
         """Send a NICK command."""
         if callback != None:
             self.add_nick_callback(callback)
-        if re.search('[ \.]', newnick) != None:
+        if re.search('[ \.\']', newnick) != None:
             self._call_nick_callbacks('erroneusnickname')
             return False
         try: