# HG changeset patch # User Charly COSTE # Date 1268043280 -3600 # Node ID 71c23e30cd6c082a732dee01626815c195c71a5b # Parent 8acbfda313b9ab5c6aa27e2bb5538c628ec81b63 created Bridge.soft_restart Signed-off-by: Charly COSTE diff --git a/bridge.py b/bridge.py --- a/bridge.py +++ b/bridge.py @@ -397,9 +397,32 @@ class Bridge: self.say(say_levels.info, 'Participants on IRC: '+' '.join(irc_participants_nicknames), on_irc=False) + def soft_restart(self, message='Softly restarting bridge', log=True): + """Make the bot leave and rejoin, avoid presence flood but can leave ghosts""" + + if log: + self.bot.error(-1, message+' '+str(self), send_to_admins=True) + + # Leave + if isinstance(self.irc_connection, ServerConnection) and isinstance(self.xmpp_room, xmpp.muc): + self.irc_connection.part(self.irc_room, message=message) + self.xmpp_room.leave(message=message) + else: + self.stop() + self.init2() + return + + # Rejoin + self.irc_connection.join(self.irc_room, callback=self._irc_join_callback) + self.xmpp_room.rejoin(callback=self._xmpp_join_callback) + + def stop(self, message='Stopping bridge', log=True): """Stop the bridge""" + if log: + self.bot.error(-1, message+' '+str(self), send_to_admins=True) + # Close IRC connection if not used by an other bridge, just leave the room otherwise if isinstance(self.irc_connection, ServerConnection): self.irc_connection.used_by -= 1 @@ -419,9 +442,6 @@ class Bridge: for p in self.participants: p.leave(message) self.participants = [] - - if log: - self.bot.error(-1, message+' '+str(self), send_to_admins=True) def __str__(self):