comparison participant.py @ 248:234e8ca6a10c

in Participant, test isinstance(self.muc, xmpp.muc) before using self.muc Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Mon, 08 Mar 2010 19:17:19 +0100
parents 303e571bc104
children 93990ebdbbaf
comparison
equal deleted inserted replaced
247:303e571bc104 248:234e8ca6a10c
93 self.create_duplicate_on_xmpp() 93 self.create_duplicate_on_xmpp()
94 return 94 return
95 95
96 else: 96 else:
97 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server', log=True) 97 self.bridge.say(say_levels.warning, 'The nickname "'+self.nickname+'" is used on both rooms or reserved on the XMPP server', log=True)
98 if self.muc.connected == True: 98 if isinstance(self.muc, xmpp.muc) and self.muc.connected:
99 self.muc.leave('Changed nickname to "'+self.nickname+'"') 99 self.muc.leave('Changed nickname to "'+self.nickname+'"')
100 except xmpp.muc.RoomIsFull: 100 except xmpp.muc.RoomIsFull:
101 self.bridge.say(say_levels.warning, 'XMPP room is full', log=True) 101 self.bridge.say(say_levels.warning, 'XMPP room is full', log=True)
102 except xmpp.muc.RemoteServerNotFound: 102 except xmpp.muc.RemoteServerNotFound:
103 self.bridge._RemoteServerNotFound_handler() 103 self.bridge._RemoteServerNotFound_handler()
227 try: 227 try:
228 p = self.bridge.get_participant(newnick) 228 p = self.bridge.get_participant(newnick)
229 except self.bridge.NoSuchParticipantException: 229 except self.bridge.NoSuchParticipantException:
230 self.nickname = newnick 230 self.nickname = newnick
231 self.duplicate_nickname = newnick 231 self.duplicate_nickname = newnick
232 if isinstance(self.xmpp_c, xmpp.client.Client): 232 if isinstance(self.muc, xmpp.muc):
233 for b in self.bridge.bot.bridges: 233 for b in self.bridge.bot.bridges:
234 if b.has_participant(oldnick) and b.irc_server != self.bridge.irc_server: 234 if b.has_participant(oldnick) and b.irc_server != self.bridge.irc_server:
235 self.muc.leave(message='Changed nickname to "'+self.nickname+'"') 235 self.muc.leave(message='Changed nickname to "'+self.nickname+'"')
236 self.xmpp_c = None 236 self.xmpp_c = None
237 self.bridge.bot.close_xmpp_connection(oldnick) 237 self.bridge.bot.close_xmpp_connection(oldnick)
321 else: 321 else:
322 self.bridge.get_participant(to).say_on_xmpp_to(self.nickname, 'XIB error: Sorry but you cannot send cross-protocol private messages because I don\'t have an IRC duplicate with your nickname.') 322 self.bridge.get_participant(to).say_on_xmpp_to(self.nickname, 'XIB error: Sorry but you cannot send cross-protocol private messages because I don\'t have an IRC duplicate with your nickname.')
323 323
324 324
325 def say_on_xmpp(self, message, action=False): 325 def say_on_xmpp(self, message, action=False):
326 if self.muc.connected: 326 if isinstance(self.muc, xmpp.muc) and self.muc.connected:
327 self.muc.say(message, action=action) 327 self.muc.say(message, action=action)
328 elif not isinstance(self.irc_connection, ServerConnection): 328 elif not isinstance(self.irc_connection, ServerConnection):
329 self.bridge.say_on_behalf(self.nickname, message, 'xmpp', action=action) 329 self.bridge.say_on_behalf(self.nickname, message, 'xmpp', action=action)
330 330
331 331
332 def say_on_xmpp_to(self, to, message, action=False): 332 def say_on_xmpp_to(self, to, message, action=False):
333 if self.muc.connected: 333 if isinstance(self.muc, xmpp.muc) and self.muc.connected:
334 self.muc.say_to(to, message, action=action) 334 self.muc.say_to(to, message, action=action)
335 elif not isinstance(self.irc_connection, ServerConnection): 335 elif not isinstance(self.irc_connection, ServerConnection):
336 if self.bridge.mode not in ['normal', 'bypass']: 336 if self.bridge.mode not in ['normal', 'bypass']:
337 self.bridge.get_participant(to).say_on_xmpp_to(self.nickname, 'XIB error: Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.') 337 self.bridge.get_participant(to).say_on_xmpp_to(self.nickname, 'XIB error: Sorry but cross-protocol private messages are disabled in '+self.bridge.mode+' mode.')
338 else: 338 else:
346 self._close_xmpp_connection(message) 346 self._close_xmpp_connection(message)
347 self._close_irc_connection(message) 347 self._close_irc_connection(message)
348 348
349 349
350 def _close_xmpp_connection(self, message): 350 def _close_xmpp_connection(self, message):
351 if isinstance(self.xmpp_c, xmpp.client.Client): 351 if isinstance(self.muc, xmpp.muc):
352 self.muc.leave(message) 352 self.muc.leave(message)
353 self.xmpp_c = None 353 self.xmpp_c = None
354 self.bridge.bot.close_xmpp_connection(self.nickname) 354 self.bridge.bot.close_xmpp_connection(self.nickname)
355 355
356 356
366 366
367 def __str__(self): 367 def __str__(self):
368 r = 'self.protocol='+str(self.protocol)+'\n'+'self.nickname='+str(self.nickname) 368 r = 'self.protocol='+str(self.protocol)+'\n'+'self.nickname='+str(self.nickname)
369 if isinstance(self.irc_connection, ServerConnection): 369 if isinstance(self.irc_connection, ServerConnection):
370 r += '\nself.irc_connection='+str(self.irc_connection)+'\n'+'self.irc_connection.logged_in='+str(self.irc_connection.logged_in) 370 r += '\nself.irc_connection='+str(self.irc_connection)+'\n'+'self.irc_connection.logged_in='+str(self.irc_connection.logged_in)
371 if isinstance(self.xmpp_c, xmpp.client.Client): 371 if isinstance(self.muc, xmpp.muc):
372 r += '\nself.muc.connected='+str(self.muc.connected) 372 r += '\nself.muc.connected='+str(self.muc.connected)
373 return r 373 return r
374 374
375 375
376 def __del__(self): 376 def __del__(self):