Mercurial > xib
comparison bot.py @ 25:a9066c416533
Added an XMPP disconnect handler, fixed XMPP message handling.
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Fri, 21 Aug 2009 00:23:14 +0200 |
parents | 4e1f27ea527b |
children | 9b7a628ca612 |
comparison
equal
deleted
inserted
replaced
24:4e1f27ea527b | 25:a9066c416533 |
---|---|
89 except (xml.parsers.expat.ExpatError, xmpp.protocol.XMLNotWellFormed): | 89 except (xml.parsers.expat.ExpatError, xmpp.protocol.XMLNotWellFormed): |
90 self.error('=> Debug: received invalid stanza', debug=True) | 90 self.error('=> Debug: received invalid stanza', debug=True) |
91 continue | 91 continue |
92 | 92 |
93 | 93 |
94 def _xmpp_disconnect_handler(self, xmpp_c): | |
95 xmpp_c.reconnectAndReauth() | |
96 return | |
97 | |
98 | |
94 def _xmpp_presence_handler(self, dispatcher, presence): | 99 def _xmpp_presence_handler(self, dispatcher, presence): |
95 """[Internal] Manage XMPP presence.""" | 100 """[Internal] Manage XMPP presence.""" |
96 | 101 |
97 xmpp_c = dispatcher._owner | 102 xmpp_c = dispatcher._owner |
98 | 103 |
219 except NoSuchParticipantException: | 224 except NoSuchParticipantException: |
220 if resource != self.nickname: | 225 if resource != self.nickname: |
221 self.error('=> Debug: NoSuchParticipantException "'+resource+'", WTF ?', debug=True) | 226 self.error('=> Debug: NoSuchParticipantException "'+resource+'", WTF ?', debug=True) |
222 return | 227 return |
223 | 228 |
224 if participant_.protocol == 'xmpp': | 229 participant_.sayOnIRC(message.getBody()) |
225 participant_.sayOnIRC(message.getBody()) | |
226 | 230 |
227 else: | 231 else: |
228 self.error('==> Debug: Received XMPP message of unknown type "'+message.getType()+'".', debug=True) | 232 self.error('==> Debug: Received XMPP message of unknown type "'+message.getType()+'".', debug=True) |
229 self.error(message.__str__(fancy=1), debug=True) | 233 self.error(message.__str__(fancy=1), debug=True) |
230 | 234 |
326 | 330 |
327 | 331 |
328 # Chan message | 332 # Chan message |
329 if event.eventtype() == 'pubmsg': | 333 if event.eventtype() == 'pubmsg': |
330 if bridge.irc_room == event.target() and bridge.irc_server == connection.server: | 334 if bridge.irc_room == event.target() and bridge.irc_server == connection.server: |
331 if from_.protocol != 'xmpp': | 335 from_.sayOnXMPP(event.arguments()[0]) |
332 from_.sayOnXMPP(event.arguments()[0]) | |
333 return | 336 return |
334 else: | 337 else: |
335 continue | 338 continue |
336 | 339 |
337 return | 340 return |
428 c.connect() | 431 c.connect() |
429 c.auth(self.bare_jid.getNode(), self.password) | 432 c.auth(self.bare_jid.getNode(), self.password) |
430 c.RegisterHandler('presence', self._xmpp_presence_handler) | 433 c.RegisterHandler('presence', self._xmpp_presence_handler) |
431 c.RegisterHandler('iq', self._xmpp_iq_handler) | 434 c.RegisterHandler('iq', self._xmpp_iq_handler) |
432 c.RegisterHandler('message', self._xmpp_message_handler) | 435 c.RegisterHandler('message', self._xmpp_message_handler) |
436 c.DisconnectHandler = self._xmpp_disconnect_handler(c) | |
433 c.sendInitPresence() | 437 c.sendInitPresence() |
434 c.lock.release() | 438 c.lock.release() |
435 return c | 439 return c |
436 | 440 |
437 | 441 |