Mercurial > xib
changeset 199:dcabe54deeba
improved an XMPP error handling, created Participant.say_on_XMPP_through_bridge()
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Thu, 25 Feb 2010 18:41:55 +0100 |
parents | 66ed2dcdc4d1 |
children | 740effa74c18 |
files | bot.py participant.py |
diffstat | 2 files changed, 20 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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):