From 0284ed9ebd628aeb1f6485585b75451512d7d1c3 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 5 Jul 2020 19:45:08 +0200 Subject: [PATCH] irclib: Don't error when 004 is missing umodes and chanmodes. --- src/irclib.py | 11 ++++++++--- test/test_irclib.py | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/irclib.py b/src/irclib.py index 3ffb1de1c..f994d4de9 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -624,9 +624,14 @@ class IrcState(IrcCommandDispatcher, log.Firewalled): Supported user and channel modes are cached""" # msg.args = [nick, server, ircd-version, umodes, modes, # modes that require arguments? (non-standard)] - self.ircd = msg.args[2] if len(msg.args) >= 3 else msg.args[1] - self.supported['umodes'] = frozenset(msg.args[3]) - self.supported['chanmodes'] = frozenset(msg.args[4]) + self.ircd = msg.args[2] if len(msg.args) > 2 else msg.args[1] + + # The conditionals are for Twitch, which doesn't send umodes or + # chanmodes. + if len(msg.args) > 3: + self.supported['umodes'] = frozenset(msg.args[3]) + if len(msg.args) > 4: + self.supported['chanmodes'] = frozenset(msg.args[4]) _005converters = utils.InsensitivePreservingDict({ 'modes': lambda s: int(s) if s else None, # it's optional diff --git a/test/test_irclib.py b/test/test_irclib.py index da216c210..a3c328e5e 100644 --- a/test/test_irclib.py +++ b/test/test_irclib.py @@ -387,6 +387,12 @@ class IrcStateTestCase(SupyTestCase): self.assertEqual(state.supported['chanmodes'], frozenset('biklmnopstveI')) + def testShort004(self): + state = irclib.IrcState() + state.addMsg(self.irc, ircmsgs.IrcMsg(':coulomb.oftc.net 004 testnick coulomb.oftc.net hybrid-7.2.2+oftc1.6.8')) + self.assertNotIn('umodes', state.supported) + self.assertNotIn('chanmodes', state.supported) + def testEmptyTopic(self): state = irclib.IrcState() state.addMsg(self.irc, ircmsgs.topic('#foo'))