From 31a0d369900f7f8e72e757429d81b8de83aef821 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 8 Jun 2018 18:45:20 -0700 Subject: [PATCH] clientbot: ignore missing args in 324 / RPL_CHANNELMODEIS Fixes #537. --- classes.py | 14 ++++++++------ protocols/clientbot.py | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/classes.py b/classes.py index d05a3cf..83b74ac 100644 --- a/classes.py +++ b/classes.py @@ -768,7 +768,8 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore): # Band-aid patch here to prevent bad bans set by Janus forwarding people into invalid channels. return bool(cls._HOSTMASK_RE.match(text) and '#' not in text) - def _parse_modes(self, args, existing, supported_modes, is_channel=False, prefixmodes=None): + def _parse_modes(self, args, existing, supported_modes, is_channel=False, prefixmodes=None, + ignore_missing_args=False): """ parse_modes() core. @@ -839,9 +840,10 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore): log.debug('Mode %s: Only has parameter when setting.', mode) arg = args.pop(0) except IndexError: - log.warning('(%s) Error while parsing mode %r: mode requires an ' - 'argument but none was found. (modestring: %r)', - self.name, mode, modestring) + logfunc = log.debug if ignore_missing_args else log.warning + logfunc('(%s) Error while parsing mode %r: mode requires an ' + 'argument but none was found. (modestring: %r)', + self.name, mode, modestring) continue # Skip this mode; don't error out completely. newmode = (prefix + mode, arg) res.append(newmode) @@ -851,7 +853,7 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore): return res - def parse_modes(self, target, args): + def parse_modes(self, target, args, ignore_missing_args=False): """Parses a modestring list into a list of (mode, argument) tuples. ['+mitl-o', '3', 'person'] => [('+m', None), ('+i', None), ('+t', None), ('+l', '3'), ('-o', 'person')] """ @@ -880,7 +882,7 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore): prefixmodes = self._channels[target].prefixmodes return self._parse_modes(args, oldmodes, supported_modes, is_channel=is_channel, - prefixmodes=prefixmodes) + prefixmodes=prefixmodes, ignore_missing_args=ignore_missing_args) def _apply_modes(self, old_modelist, changedmodes, is_channel=False, prefixmodes=None): diff --git a/protocols/clientbot.py b/protocols/clientbot.py index e74ebc9..e5176e4 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -972,7 +972,10 @@ class ClientbotWrapperProtocol(IRCCommonProtocol): channel = args[1] modes = args[2:] log.debug('(%s) Got RPL_CHANNELMODEIS (324) modes %s for %s', self.name, modes, channel) - changedmodes = self.parse_modes(channel, modes) + + # Sometimes IRCds suppress arguments to +lk, so ignore missing args + changedmodes = self.parse_modes(channel, modes, ignore_missing_args=True) + self.apply_modes(channel, changedmodes) def handle_329(self, source, command, args):