# HG changeset patch # User Charly COSTE # Date 1266687323 -3600 # Node ID 594f570f4657cb0027cd58b892868049cb8f5d59 # Parent 70a54da14e6356448f246c76ef642e8abcc5cde0 handle IRC mode event Signed-off-by: Charly COSTE diff --git a/bot.py b/bot.py --- a/bot.py +++ b/bot.py @@ -488,7 +488,7 @@ class Bot(threading.Thread): printed_event = True if event.eventtype() == 'kick' and len(event.arguments()) < 1: - self.error(1, 'length of arguments should be greater than 0 for a '+event.eventtype()+' event') + self.error(1, 'at least 1 argument is needed for a '+event.eventtype()+' event', debug=True) return if event.eventtype() in ['pubmsg', 'action']: @@ -619,30 +619,6 @@ class Bot(threading.Thread): return - # Joining events - if event.eventtype() in ['namreply', 'join']: - if connection.get_nickname() != self.nickname: - self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) - return - - if event.eventtype() == 'namreply': - for bridge in self.getBridges(irc_room=event.arguments()[1].lower(), irc_server=connection.server): - for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): - if nickname == '' or nickname == self.nickname: - continue - bridge.addParticipant('irc', nickname) - return - elif event.eventtype() == 'join': - bridges = self.getBridges(irc_room=event.target().lower(), irc_server=connection.server) - if len(bridges) == 0: - self.error(2, debug_str, debug=True) - self.error(3, 'no bridge found for "'+event.target().lower()+' at '+connection.server+'"', debug=True) - return - for bridge in bridges: - bridge.addParticipant('irc', nickname, irc_id=event.source()) - return - - if event.eventtype() in ['disconnect', 'kill', 'error']: if len(event.arguments()) > 0 and event.arguments()[0] == 'Connection reset by peer': self.error(2, debug_str, debug=True) @@ -666,6 +642,58 @@ class Bot(threading.Thread): return + # Ignore events not received on bot connection + if connection.get_nickname() != self.nickname: + self.error(1, 'ignoring IRC '+event.eventtype()+' not received on bridge connection', debug=True) + return + + + # Joining events + if event.eventtype() in ['namreply', 'join']: + if event.eventtype() == 'namreply': + for bridge in self.getBridges(irc_room=event.arguments()[1].lower(), irc_server=connection.server): + for nickname in re.split('(?:^[&@\+%]?|(?: [&@\+%]?)*)', event.arguments()[2].strip()): + if nickname == '' or nickname == self.nickname: + continue + bridge.addParticipant('irc', nickname) + return + elif event.eventtype() == 'join': + bridges = self.getBridges(irc_room=event.target().lower(), irc_server=connection.server) + if len(bridges) == 0: + self.error(2, debug_str, debug=True) + self.error(3, 'no bridge found for "'+event.target().lower()+' at '+connection.server+'"', debug=True) + return + for bridge in bridges: + bridge.addParticipant('irc', nickname, irc_id=event.source()) + return + + + # Mode event + if event.eventtype() == 'mode': + if len(event.arguments()) < 2: + self.error(2, debug_str, debug=True) + self.error(1, '2 arguments are needed for a '+event.eventtype()+' event', debug=True) + return + if event.arguments()[1] != self.nickname or not 'o' in event.arguments()[0]: + self.error(1, 'ignoring IRC mode "'+event.arguments()[0]+'" for "'+event.arguments()[1]+'"', debug=True) + return + self.error(2, debug_str, debug=True) + bridges = self.getBridges(irc_room=event.target(), irc_server=connection.server) + if len(bridges) > 1: + raise Exception, 'more than one bridge for one irc chan, WTF ?' + bridge = bridges[0] + if re.search('\+[^\-]*o', event.arguments()[0]): + # bot is channel operator + bridge.irc_op = True + self.error(say_levels.notice, 'bot has IRC operator privileges in '+event.target()) + elif re.search('\-[^\+]*o', event.arguments()[0]): + # bot lost channel operator privileges + if bridge.irc_op: + self.error(say_levels.notice, 'bot lost IRC operator privileges in '+event.target(), send_to_admins=True) + bridge.irc_op = False + return + + # Unhandled events if not printed_event: self.error(say_levels.debug, 'The following IRC event was not handled:\n'+event_str+'\n', send_to_admins=True) diff --git a/bridge.py b/bridge.py --- a/bridge.py +++ b/bridge.py @@ -43,6 +43,7 @@ class Bridge: self.irc_room = irc_room.lower() self.irc_connection_interval = irc_connection_interval self.irc_charsets = irc_charsets + self.irc_op = False self.xmpp_room_jid = xmpp_room_jid self.say_level = say_level self.participants = []