comparison bridge.py @ 237:71c23e30cd6c

created Bridge.soft_restart Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Mon, 08 Mar 2010 11:14:40 +0100
parents 4ad8e985c7d3
children ebd67e3e4866
comparison
equal deleted inserted replaced
236:8acbfda313b9 237:71c23e30cd6c
395 if 'xmpp' in protocols: 395 if 'xmpp' in protocols:
396 irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc']) 396 irc_participants_nicknames = self.get_participants_nicknames_list(protocols=['irc'])
397 self.say(say_levels.info, 'Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False) 397 self.say(say_levels.info, 'Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False)
398 398
399 399
400 def soft_restart(self, message='Softly restarting bridge', log=True):
401 """Make the bot leave and rejoin, avoid presence flood but can leave ghosts"""
402
403 if log:
404 self.bot.error(-1, message+' '+str(self), send_to_admins=True)
405
406 # Leave
407 if isinstance(self.irc_connection, ServerConnection) and isinstance(self.xmpp_room, xmpp.muc):
408 self.irc_connection.part(self.irc_room, message=message)
409 self.xmpp_room.leave(message=message)
410 else:
411 self.stop()
412 self.init2()
413 return
414
415 # Rejoin
416 self.irc_connection.join(self.irc_room, callback=self._irc_join_callback)
417 self.xmpp_room.rejoin(callback=self._xmpp_join_callback)
418
419
400 def stop(self, message='Stopping bridge', log=True): 420 def stop(self, message='Stopping bridge', log=True):
401 """Stop the bridge""" 421 """Stop the bridge"""
422
423 if log:
424 self.bot.error(-1, message+' '+str(self), send_to_admins=True)
402 425
403 # Close IRC connection if not used by an other bridge, just leave the room otherwise 426 # Close IRC connection if not used by an other bridge, just leave the room otherwise
404 if isinstance(self.irc_connection, ServerConnection): 427 if isinstance(self.irc_connection, ServerConnection):
405 self.irc_connection.used_by -= 1 428 self.irc_connection.used_by -= 1
406 if self.irc_connection.used_by < 1: 429 if self.irc_connection.used_by < 1:
417 440
418 # Delete participants objects 441 # Delete participants objects
419 for p in self.participants: 442 for p in self.participants:
420 p.leave(message) 443 p.leave(message)
421 self.participants = [] 444 self.participants = []
422
423 if log:
424 self.bot.error(-1, message+' '+str(self), send_to_admins=True)
425 445
426 446
427 def __str__(self): 447 def __str__(self):
428 return self.irc_room+'@'+self.irc_server+' <-> '+self.xmpp_room_jid 448 return self.irc_room+'@'+self.irc_server+' <-> '+self.xmpp_room_jid
429 449