Mercurial > xib
comparison bot.py @ 96:dd7e1b935894
Code cleaning
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sun, 04 Oct 2009 13:42:50 +0200 |
parents | c95fe0b319d9 |
children | 5390e9abfa44 |
comparison
equal
deleted
inserted
replaced
95:f27de569f5db | 96:dd7e1b935894 |
---|---|
142 # TODO: handle room deletion and muc server reboot | 142 # TODO: handle room deletion and muc server reboot |
143 pass | 143 pass |
144 | 144 |
145 else: | 145 else: |
146 # presence comes from a participant of the muc | 146 # presence comes from a participant of the muc |
147 try: | |
148 p = None | |
149 p = bridge.getParticipant(resource) | |
150 | |
151 except NoSuchParticipantException: | |
152 if presence.getType() != 'unavailable' and resource != bridge.bot.nickname: | |
153 bridge.addParticipant('xmpp', resource) | |
154 return | |
155 elif resource == bridge.bot.nickname: | |
156 pass | |
157 else: | |
158 return | |
159 | |
160 | 147 |
161 if presence.getType() == 'unavailable': | 148 if presence.getType() == 'unavailable': |
149 try: | |
150 p = bridge.getParticipant(resource) | |
151 except NoSuchParticipantException: | |
152 p = None | |
153 | |
162 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user') | 154 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user') |
163 item = None | 155 item = None |
164 if x: | 156 if x: |
165 item = x.getTag('item') | 157 item = x.getTag('item') |
166 if x and x.getTag('status', attrs={'code': '303'}): | 158 if x and x.getTag('status', attrs={'code': '303'}): |
233 | 225 |
234 else: | 226 else: |
235 # participant left | 227 # participant left |
236 bridge.removeParticipant('xmpp', resource, presence.getStatus()) | 228 bridge.removeParticipant('xmpp', resource, presence.getStatus()) |
237 | 229 |
230 elif resource != bridge.bot.nickname: | |
231 bridge.addParticipant('xmpp', resource) | |
232 return | |
233 | |
238 return | 234 return |
239 | 235 |
240 | 236 |
241 def _xmpp_iq_handler(self, dispatcher, iq): | 237 def _xmpp_iq_handler(self, dispatcher, iq): |
242 """[Internal] Manage XMPP IQs.""" | 238 """[Internal] Manage XMPP IQs.""" |
525 if connection.get_nickname() != self.nickname: | 521 if connection.get_nickname() != self.nickname: |
526 self.error('=> Debug: ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) | 522 self.error('=> Debug: ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) |
527 return | 523 return |
528 | 524 |
529 if event.eventtype() == 'namreply': | 525 if event.eventtype() == 'namreply': |
530 # TODO: lock self.bridges for thread safety | |
531 for bridge in self.getBridges(irc_room=event.arguments()[1].lower(), irc_server=connection.server): | 526 for bridge in self.getBridges(irc_room=event.arguments()[1].lower(), irc_server=connection.server): |
532 for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): | 527 for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): |
533 if nickname == '' or nickname == self.nickname: | 528 if nickname == '' or nickname == self.nickname: |
534 continue | 529 continue |
535 bridge.addParticipant('irc', nickname) | 530 bridge.addParticipant('irc', nickname) |
605 self.bridges.append(b) | 600 self.bridges.append(b) |
606 return b | 601 return b |
607 | 602 |
608 | 603 |
609 def getBridges(self, irc_room=None, irc_server=None, xmpp_room_jid=None): | 604 def getBridges(self, irc_room=None, irc_server=None, xmpp_room_jid=None): |
605 # TODO: lock self.bridges for thread safety | |
610 bridges = [b for b in self.bridges] | 606 bridges = [b for b in self.bridges] |
611 for bridge in [b for b in bridges]: | 607 for bridge in [b for b in bridges]: |
612 if irc_room != None and bridge.irc_room != irc_room: | 608 if irc_room != None and bridge.irc_room != irc_room: |
613 bridges.remove(bridge) | 609 bridges.remove(bridge) |
614 continue | 610 continue |