changeset 226:0d85049ac68d

switch to IRC join callbacks in bridge.py and participant.py Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sun, 07 Mar 2010 18:52:48 +0100
parents da8fbaf69242
children 87fa6bc893de
files bridge.py participant.py
diffstat 2 files changed, 30 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/bridge.py
+++ b/bridge.py
@@ -76,14 +76,11 @@ class Bridge:
 	
 	
 	def _irc_nick_callback(self, error):
-		if error == None:
-			if self.mode == None:
+		if not error:
+			if not self.mode:
 				return
-			self.irc_connection.join(self.irc_room)
-			self.bot.error(3, 'successfully connected on IRC side of bridge "'+str(self)+'"', debug=True)
-			self.say(say_levels.notice, 'bridge "'+str(self)+'" is running in '+self.mode+' mode', on_xmpp=False)
-			if self.mode not in ['normal', 'bypass']:
-				self.show_participants_list_on(protocols=['irc'])
+			self.irc_connection.join(self.irc_room, callback=self._irc_join_callback)
+		
 		else:
 			self.mode = None
 			self.say(say_levels.error, 'failed to connect to the IRC chan, leaving ...', on_irc=False)
@@ -98,6 +95,17 @@ class Bridge:
 			self._join_irc_failed(reason)
 	
 	
+	def _irc_join_callback(self, channel, error):
+		if not error:
+			self.bot.error(3, 'successfully joined IRC side of bridge "'+str(self)+'"', debug=True)
+			self.say(say_levels.notice, 'bridge "'+str(self)+'" is running in '+self.mode+' mode', on_xmpp=False)
+			if self.mode not in ['normal', 'bypass']:
+				self.show_participants_list_on(protocols=['irc'])
+		
+		else:
+			self._join_irc_failed(error)
+	
+	
 	def _RemoteServerNotFound_handler(self):
 		server = xmpp.protocol.JID(self.xmpp_room_jid).getDomain()
 		bridges = self.bot.iter_bridges(patterns=[server])
@@ -130,7 +138,6 @@ class Bridge:
 	def add_participant(self, from_protocol, nickname, real_jid=None):
 		"""Add a participant to the bridge."""
 		if (from_protocol == 'irc' and nickname == self.bot.nickname) or (from_protocol == 'xmpp' and nickname == self.bot.nickname):
-			self.bot.error(3, 'not adding self ('+self.bot.nickname+') to bridge "'+str(self)+'"', debug=True)
 			return
 		try:
 			p = self.get_participant(nickname)
--- a/participant.py
+++ b/participant.py
@@ -115,13 +115,8 @@ class Participant:
 	
 	
 	def _irc_nick_callback(self, error):
-		if error == None:
-			self.irc_connection.join(self.bridge.irc_room)
-			m = '"'+self.nickname+'" duplicate succesfully created on IRC side of bridge "'+str(self.bridge)+'"'
-			if self.nickname != self.duplicate_nickname:
-				m += ' using nickname "'+self.duplicate_nickname+'"'
-				self.bridge.say(say_levels.info, '"'+self.nickname+'" will appear as "'+self.duplicate_nickname+'" on IRC because its real nickname is reserved or contains unauthorized characters')
-			self.bridge.bot.error(3, m, debug=True)
+		if not error:
+			self.irc_connection.join(self.bridge.irc_room, callback=self._irc_join_callback)
 		
 		elif self.irc_connection != 'both':
 			
@@ -167,6 +162,19 @@ class Participant:
 				self.irc_connection = error
 	
 	
+	def _irc_join_callback(self, channel, error):
+		if not error:
+			m = '"'+self.nickname+'" duplicate succesfully joined IRC side of bridge "'+str(self.bridge)+'"'
+			if self.nickname != self.duplicate_nickname:
+				m += ' using nickname "'+self.duplicate_nickname+'"'
+				self.bridge.say(say_levels.info, '"'+self.nickname+'" will appear as "'+self.duplicate_nickname+'" on IRC because its real nickname is reserved or contains unauthorized characters')
+			self.bridge.bot.error(3, m, debug=True)
+		
+		elif self.irc_connection != 'both':
+			self._close_irc_connection('')
+			self.irc_connection = error
+	
+	
 	def set_both_sides(self):
 		self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used on both sides of the bridge', log=True)
 		if isinstance(self.irc_connection, ServerConnection):