Mercurial > xib
comparison bot.py @ 34:57d0e66378b0
Fixed XMPP message handling and removed disconnect handler.
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sat, 22 Aug 2009 20:16:01 +0200 |
parents | cb6771a8c3ca |
children | ebf516b2e5c9 |
comparison
equal
deleted
inserted
replaced
33:cb6771a8c3ca | 34:57d0e66378b0 |
---|---|
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(xmpp_c): | |
95 xmpp_c.reconnectAndReauth() | |
96 return | |
97 | |
98 | |
99 def _xmpp_presence_handler(self, dispatcher, presence): | 94 def _xmpp_presence_handler(self, dispatcher, presence): |
100 """[Internal] Manage XMPP presence.""" | 95 """[Internal] Manage XMPP presence.""" |
101 | 96 |
102 xmpp_c = dispatcher._owner | 97 xmpp_c = dispatcher._owner |
103 | 98 |
161 def _xmpp_message_handler(self, dispatcher, message): | 156 def _xmpp_message_handler(self, dispatcher, message): |
162 """[Internal] Manage XMPP messages.""" | 157 """[Internal] Manage XMPP messages.""" |
163 | 158 |
164 xmpp_c = dispatcher._owner | 159 xmpp_c = dispatcher._owner |
165 | 160 |
161 if message.getBody() == None: | |
162 return | |
163 | |
166 if message.getType() == 'chat': | 164 if message.getType() == 'chat': |
167 self.error('==> Debug: Received XMPP chat message.', debug=True) | 165 self.error('==> Debug: Received XMPP chat message.', debug=True) |
168 self.error(message.__str__(fancy=1), debug=True) | 166 self.error(message.__str__(fancy=1), debug=True) |
169 from_bare_jid = unicode(message.getFrom().getNode()+'@'+message.getFrom().getDomain()) | 167 from_bare_jid = unicode(message.getFrom().getNode()+'@'+message.getFrom().getDomain()) |
170 for bridge in self.bridges: | 168 for bridge in self.bridges: |
173 | 171 |
174 try: | 172 try: |
175 from_ = bridge.getParticipant(message.getFrom().getResource()) | 173 from_ = bridge.getParticipant(message.getFrom().getResource()) |
176 to_ = bridge.getParticipant(xmpp_c.nickname) | 174 to_ = bridge.getParticipant(xmpp_c.nickname) |
177 | 175 |
178 if from_.protocol == 'xmpp': | 176 from_.sayOnIRCTo(to_.nickname, message.getBody()) |
179 from_.sayOnIRCTo(to_.nickname, message.getBody()) | |
180 else: | |
181 self.error('=> Debug: received XMPP chat message from a non-XMPP participant, WTF ?', debug=True) | |
182 | 177 |
183 except NoSuchParticipantException: | 178 except NoSuchParticipantException: |
184 if xmpp_c.nickname == self.nickname: | 179 if xmpp_c.nickname == self.nickname: |
185 xmpp_c.send(xmpp.protocol.Message(to=message.getFrom(), body=self.respond(message.getBody(), participant=from_), typ='chat')) | 180 xmpp_c.send(xmpp.protocol.Message(to=message.getFrom(), body=self.respond(message.getBody(), participant=from_), typ='chat')) |
186 return | 181 return |
439 c.connect() | 434 c.connect() |
440 c.auth(self.bare_jid.getNode(), self.password) | 435 c.auth(self.bare_jid.getNode(), self.password) |
441 c.RegisterHandler('presence', self._xmpp_presence_handler) | 436 c.RegisterHandler('presence', self._xmpp_presence_handler) |
442 c.RegisterHandler('iq', self._xmpp_iq_handler) | 437 c.RegisterHandler('iq', self._xmpp_iq_handler) |
443 c.RegisterHandler('message', self._xmpp_message_handler) | 438 c.RegisterHandler('message', self._xmpp_message_handler) |
444 c.RegisterDisconnectHandler(self.__class__._xmpp_disconnect_handler) | |
445 c.sendInitPresence() | 439 c.sendInitPresence() |
446 c.lock.release() | 440 c.lock.release() |
447 return c | 441 return c |
448 | 442 |
449 | 443 |