changeset 62:61491895c607

Added bridge.hasParticipant() and fixed participant.changeNickname() Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sat, 29 Aug 2009 14:52:11 +0200
parents 624c086b0a02
children 71508f22edb4
files bridge.py participant.py
diffstat 2 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/bridge.py
+++ b/bridge.py
@@ -161,6 +161,14 @@ class bridge:
 		return participants_nicknames
 	
 	
+	def hasParticipant(self, nickname):
+		try:
+			self.getParticipant(nickname)
+			return True
+		except NoSuchParticipantException:
+			return False
+	
+	
 	def removeParticipant(self, left_protocol, nickname, leave_message):
 		"""Remove the participant using nickname from the bridge. Raises a NoSuchParticipantException if nickname is not used in the bridge."""
 		
--- a/participant.py
+++ b/participant.py
@@ -123,8 +123,18 @@ class participant:
 			else:
 				self.nickname = newnick
 				if self.muc != None:
-					self.bridge.bot.xmpp_connections[newnick] = self.xmpp_c
-					self.bridge.bot.xmpp_connections.pop(oldnick)
+					for b in self.bridge.bot.bridges:
+						if b.hasParticipant(oldnick) and b.irc_server != self.bridge.irc_server:
+							self.muc.leave(message='Nickname change')
+							self.xmpp_c = None
+							self.bridge.bot.close_xmpp_connection(oldnick)
+							self.createDuplicateOnXMPP()
+							return
+					
+					if not self.bridge.bot.xmpp_connections.has_key(newnick):
+						self.bridge.bot.xmpp_connections.pop(oldnick)
+						self.bridge.bot.xmpp_connections[newnick] = self.xmpp_c
+					
 					self.muc.change_nick(newnick, status='From IRC', callback=self._xmpp_join_callback)
 				else:
 					self.createDuplicateOnXMPP()