comparison bot.py @ 3:3f651f4fdb4f

Added IRC "part" event handling Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Sun, 16 Aug 2009 17:10:12 +0200
parents f2d0a8b448db
children cb0daec4b778
comparison
equal deleted inserted replaced
2:f2d0a8b448db 3:3f651f4fdb4f
104 pass 104 pass
105 else: 105 else:
106 # presence comes from a participant of the muc 106 # presence comes from a participant of the muc
107 try: 107 try:
108 p = bridge.getParticipant(resource) 108 p = bridge.getParticipant(resource)
109 if p.protocol == 'xmpp': 109 if p.protocol in ['xmpp', 'both']:
110 if presence.getType() == 'unavailable': 110 if presence.getType() == 'unavailable':
111 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user') 111 x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user')
112 if x and x.getTag('status', attrs={'code': '303'}): 112 if x and x.getTag('status', attrs={'code': '303'}):
113 # participant changed its nickname 113 # participant changed its nickname
114 item = x.getTag('item') 114 item = x.getTag('item')
122 p.changeNickname(new_nick, 'irc') 122 p.changeNickname(new_nick, 'irc')
123 return 123 return
124 # participant left 124 # participant left
125 bridge.removeParticipant('xmpp', resource, presence.getStatus()) 125 bridge.removeParticipant('xmpp', resource, presence.getStatus())
126 except NoSuchParticipantException: 126 except NoSuchParticipantException:
127 try: 127 if presence.getType() != 'unavailable':
128 bridge.addParticipant('xmpp', resource) 128 try:
129 except Exception: 129 bridge.addParticipant('xmpp', resource)
130 pass 130 except Exception:
131 pass
131 return 132 return
132 133
133 134
134 def _xmpp_iq_handler(self, xmpp_c, iq): 135 def _xmpp_iq_handler(self, xmpp_c, iq):
135 """[Internal] Manage XMPP IQs.""" 136 """[Internal] Manage XMPP IQs."""
261 connection.bridge.getParticipant(nickname) 262 connection.bridge.getParticipant(nickname)
262 except NoSuchParticipantException: 263 except NoSuchParticipantException:
263 connection.bridge.addParticipant('irc', nickname) 264 connection.bridge.addParticipant('irc', nickname)
264 try: 265 try:
265 from_ = connection.bridge.getParticipant(event.source().split('!')[0]) 266 from_ = connection.bridge.getParticipant(event.source().split('!')[0])
266 if event.eventtype() == 'quit': 267 if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target() == connection.bridge.irc_room:
267 if from_.protocol == 'irc': 268 if from_.protocol in ['irc', 'both']:
268 connection.bridge.removeParticipant('irc', from_.nickname, event.arguments()[0]) 269 connection.bridge.removeParticipant('irc', from_.nickname, event.arguments()[0])
269 return 270 return
270 except NoSuchParticipantException: 271 except NoSuchParticipantException:
271 return 272 return
272 except AttributeError: 273 except AttributeError: