From 0136ac9e413e02a5827c1849cd94b95b8e3132b9 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 2 Sep 2017 21:35:03 -0700 Subject: [PATCH] relay: fix potential irc.channels KeyErrors in get_prefix_modes and handle_join --- plugins/relay.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/relay.py b/plugins/relay.py index a205a20..7dc4168 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -206,7 +206,7 @@ def get_prefix_modes(irc, remoteirc, channel, user, mlist=None): """ modes = '' - if user in irc.channels[channel].users: + if channel in irc.channels and user in irc.channels[channel].users: # Iterate over the the prefix modes for relay supported by the remote IRCd. # Note: reverse the order so prefix modes are bursted in their traditional order # (e.g. owner before op before halfop). TODO: SJOIN modes should probably be @@ -1072,7 +1072,7 @@ def handle_join(irc, numeric, command, args): users = set(args['users']) claim_passed = check_claim(irc, channel, numeric) - current_chandata = irc.channels[channel] + current_chandata = irc.channels.get(channel) chandata = args.get('channeldata') log.debug('(%s) relay.handle_join: claim for %s on %s: %s', irc.name, numeric, channel, claim_passed) log.debug('(%s) relay.handle_join: old channel data %s', irc.name, chandata) @@ -1092,7 +1092,11 @@ def handle_join(irc, numeric, command, args): except KeyError: # User was never in channel. Treat their mode list as empty. oldmodes = set() - newmodes = set(current_chandata.get_prefix_modes(user)) + + newmodes = set() + if current_chandata is not None: + newmodes = set(current_chandata.get_prefix_modes(user)) + modediff = newmodes - oldmodes log.debug('(%s) relay.handle_join: mode diff for %s on %s: %s oldmodes=%s newmodes=%s', irc.name, user, channel, modediff, oldmodes, newmodes)