# HG changeset patch # User Charly COSTE # Date 1250435412 -7200 # Node ID 3f651f4fdb4fd5498bf343bc26d59b6f19ae6e56 # Parent f2d0a8b448db6b5bf16585a602595345b9058459 Added IRC "part" event handling Signed-off-by: Charly COSTE diff --git a/bot.py b/bot.py --- a/bot.py +++ b/bot.py @@ -106,7 +106,7 @@ class bot(Thread): # presence comes from a participant of the muc try: p = bridge.getParticipant(resource) - if p.protocol == 'xmpp': + if p.protocol in ['xmpp', 'both']: if presence.getType() == 'unavailable': x = presence.getTag('x', namespace='http://jabber.org/protocol/muc#user') if x and x.getTag('status', attrs={'code': '303'}): @@ -124,10 +124,11 @@ class bot(Thread): # participant left bridge.removeParticipant('xmpp', resource, presence.getStatus()) except NoSuchParticipantException: - try: - bridge.addParticipant('xmpp', resource) - except Exception: - pass + if presence.getType() != 'unavailable': + try: + bridge.addParticipant('xmpp', resource) + except Exception: + pass return @@ -263,8 +264,8 @@ class bot(Thread): connection.bridge.addParticipant('irc', nickname) try: from_ = connection.bridge.getParticipant(event.source().split('!')[0]) - if event.eventtype() == 'quit': - if from_.protocol == 'irc': + if event.eventtype() == 'quit' or event.eventtype() == 'part' and event.target() == connection.bridge.irc_room: + if from_.protocol in ['irc', 'both']: connection.bridge.removeParticipant('irc', from_.nickname, event.arguments()[0]) return except NoSuchParticipantException: diff --git a/bridge.py b/bridge.py --- a/bridge.py +++ b/bridge.py @@ -103,9 +103,11 @@ class bridge: if p.protocol == 'both': self.bot.error('===> Debug: "'+nickname+'" was on both sides of bridge "'+str(self)+'" but left '+protocol, debug=True) if protocol == 'xmpp': - p.createDuplicateOnIRC() + p.protocol = 'irc' + p.createDuplicateOnXMPP() elif protocol == 'irc': - p.createDuplicateOnXMPP() + p.protocol = 'xmpp' + p.createDuplicateOnIRC() else: raise Exception('Internal Error: bad protocol') else: diff --git a/participant.py b/participant.py --- a/participant.py +++ b/participant.py @@ -74,7 +74,7 @@ class participant: elif self.protocol != 'both': if error == 'nicknameinuse': self.bridge.bot.error('===> Debug: "'+self.nickname+'" is already used in the IRC chan of bridge "'+str(self.bridge)+'"', debug=True) - self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms, please avoid that if possible') + self.bridge.say('[Warning] The nickname "'+self.nickname+'" is used on both rooms or reserved on the IRC server, please avoid that if possible') self.protocol = 'both' self.irc_connection.close() self.irc_connection = None