# HG changeset patch # User Charly COSTE # Date 1267119715 -3600 # Node ID dcabe54deeba8023f91213333f7b3a53dc3bb27e # Parent 66ed2dcdc4d1354b2a1e973d1bf585c173eadb0b improved an XMPP error handling, created Participant.say_on_XMPP_through_bridge() Signed-off-by: Charly COSTE diff --git a/bot.py b/bot.py --- a/bot.py +++ b/bot.py @@ -408,11 +408,19 @@ class Bot(threading.Thread): for cc in c.getChildren(): if cc.getNamespace() == 'urn:ietf:params:xml:ns:xmpp-stanzas' and cc.getName() != 'text': err = cc.getName() - if err == 'not-acceptable': + if err in ['not-acceptable', 'not-allowed']: # we sent a message to a room we are not in - # probable cause is a MUC server restart - # let's restart the bot - self.restart() + # can be due to a MUC server restart + # can be a concurrency bug + if xmpp_c.nickname == self.nickname: + b.restart(message='Automatic restart of bridge') + else: + try: + p = b.getParticipant(xmpp_c.nickname) + p.say_on_XMPP_through_bridge(message.getBody()) + except Bridge.NoSuchParticipantException: + b.restart(message='Automatic restart of bridge') + elif err == 'forbidden': # we don't have the permission to speak # let's remove the bridge and tell admins diff --git a/participant.py b/participant.py --- a/participant.py +++ b/participant.py @@ -313,10 +313,14 @@ class Participant: if isinstance(self.xmpp_c, xmpp.client.Client): self.muc.say(message) elif not isinstance(self.irc_connection, ServerConnection): - if message[:4] == '/me ': - self.bridge.say(-1, '* '+self.nickname+' '+message[4:], on_irc=False) - else: - self.bridge.say(-1, '<'+self.nickname+'> '+message, on_irc=False) + self.say_on_XMPP_through_bridge(message) + + + def say_on_XMPP_through_bridge(message): + if message[:4] == '/me ': + self.bridge.say(-1, '* '+self.nickname+' '+message[4:], on_irc=False) + else: + self.bridge.say(-1, '<'+self.nickname+'> '+message, on_irc=False) def sayOnXMPPTo(self, to, message):