comparison participant.py @ 94:810a6bed6c9c

Tried to fix participant.changeNickname Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sat, 26 Sep 2009 23:02:55 +0200
parents bfa32b017fc9
children f27de569f5db
comparison
equal deleted inserted replaced
93:c95fe0b319d9 94:810a6bed6c9c
119 119
120 oldnick = self.nickname 120 oldnick = self.nickname
121 121
122 if self.protocol == 'xmpp': 122 if self.protocol == 'xmpp':
123 if on_protocol == 'xmpp': 123 if on_protocol == 'xmpp':
124 self.bridge.removeParticipant('irc', self.nickname, '') 124 self._close_irc_connection('unwanted nick change')
125 self.bridge.addParticipant('irc', newnick) 125 self.irc_connection = 'unwanted nick change'
126 126
127 else: 127 else:
128 self.nickname = newnick 128 self.nickname = newnick
129 if isinstance(self.irc_connection, ServerConnection): 129 if isinstance(self.irc_connection, ServerConnection):
130 self.irc_connection.nick(newnick, callback=self._irc_nick_callback) 130 self.irc_connection.nick(newnick, callback=self._irc_nick_callback)
131 else: 131 else:
132 self.createDuplicateOnIRC() 132 self.createDuplicateOnIRC()
133 133
134 elif self.protocol == 'irc': 134 elif self.protocol == 'irc':
135 if on_protocol == 'irc': 135 if on_protocol == 'irc':
136 self.bridge.removeParticipant('xmpp', self.nickname, '') 136 self._close_xmpp_connection('unwanted nick change')
137 self.bridge.addParticipant('xmpp', newnick) 137 self.xmpp_c = 'unwanted nick change'
138 138
139 else: 139 else:
140 self.nickname = newnick 140 self.nickname = newnick
141 if self.muc != None: 141 if self.muc != None:
142 for b in self.bridge.bot.bridges: 142 for b in self.bridge.bot.bridges:
210 210
211 211
212 def leave(self, message): 212 def leave(self, message):
213 if message == None: 213 if message == None:
214 message = '' 214 message = ''
215 self._close_xmpp_connection(message)
216 self._close_irc_connection(message)
217 self.nickname = None
218
219
220 def _close_xmpp_connection(self, message):
215 if isinstance(self.xmpp_c, xmpp.client.Client): 221 if isinstance(self.xmpp_c, xmpp.client.Client):
216 self.muc.leave(auto_decode(message)) 222 self.muc.leave(auto_decode(message))
217 self.bridge.bot.close_xmpp_connection(self.nickname) 223 self.bridge.bot.close_xmpp_connection(self.nickname)
224
225
226 def _close_irc_connection(self, message):
218 if isinstance(self.irc_connection, ServerConnection): 227 if isinstance(self.irc_connection, ServerConnection):
219 if self.irc_connection.really_connected == True: 228 if self.irc_connection.really_connected == True:
220 self.irc_connection.part(self.bridge.irc_room, message=message) 229 self.irc_connection.part(self.bridge.irc_room, message=message)
221 self.irc_connection.used_by -= 1 230 self.irc_connection.used_by -= 1
222 if self.irc_connection.used_by < 1: 231 if self.irc_connection.used_by < 1:
223 self.irc_connection.close(message) 232 self.irc_connection.close(message)
224 self.irc_connection = None 233 self.irc_connection = None
225 self.nickname = None
226 234
227 235
228 def __del__(self): 236 def __del__(self):
229 if self.nickname != None: 237 if self.nickname != None:
230 self.leave('') 238 self.leave('')