home · contact · privacy
Add further parameter number expectations.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 14 Aug 2025 18:32:37 +0000 (20:32 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 14 Aug 2025 18:32:37 +0000 (20:32 +0200)
ircplom/client.py

index 6f46b33d2d7a8b910a827dbe836fbebe62bbae51..0eff7a46491daac33ab992af4cdffdb5f8fdb375 100644 (file)
@@ -411,14 +411,14 @@ class Client(ABC, ClientQueueMixin):
             channel = msg.params[0]
             log_msg = f'{msg.nick_from_source} {msg.verb.lower()}s {channel}'
         match msg.verb:
-            case '005':
+            case '005' if len(msg.params) > 2:
                 for param in msg.params[1:-1]:
                     self._db.append('isupports', param)
-            case '372':  # RPL_MOTD
+            case '372' if len(msg.params) == 2:  # RPL_MOTD
                 self._db.append('motd', msg.params[-1])
-            case '376':  # RPL_ENDOFMOTD
+            case '376' if len(msg.params) == 2:  # RPL_ENDOFMOTD
                 self._update_db('motd', None, True)
-            case '396':  # RPL_VISIBLEHOST/RPL_YOURDISPLAYEDHOST/RPL_HOSTHIDDEN
+            case '396' if len(msg.params) == 3:  # RPL_VISIBLEHOST
                 # '@'-split because <https://defs.ircdocs.horse/defs/numerics>
                 # claims: "<hostname> can also be in the form <user@hostname>"
                 self._update_db('client_host', confirm=True,
@@ -439,7 +439,7 @@ class Client(ABC, ClientQueueMixin):
                             self.send(IrcMessage('AUTHENTICATE', ('PLAIN',)))
                         else:
                             self._caps.end_negotiation()
-            case 'ERROR':
+            case 'ERROR' if len(msg.params) == 1:
                 self.close()
             case 'JOIN' if len(msg.params) == 1:
                 self._log(log_msg, scope=scope, channel=channel)
@@ -449,7 +449,7 @@ class Client(ABC, ClientQueueMixin):
             case 'NICK' if (len(msg.params) == 1
                             and msg.nick_from_source == self._db.nickname):
                 self._update_db('nickname', msg.params[0], confirm=True)
-            case 'NOTICE' | 'PRIVMSG' if len(msg.params) > 1:
+            case 'NOTICE' | 'PRIVMSG' if len(msg.params) == 2:
                 scope = LogScope.CHAT if '!' in msg.source else LogScope.SERVER
                 self._log(msg.params[-1], scope=scope, channel=msg.params[0],
                           out=False, as_notice=msg.verb == 'NOTICE',
@@ -460,7 +460,7 @@ class Client(ABC, ClientQueueMixin):
                 self._log(log_msg, scope=scope, channel=channel)
             case 'PING' if len(msg.params) == 1:
                 self.send(IrcMessage(verb='PONG', params=(msg.params[0],)))
-            case '903' | '904':
+            case '903' | '904' if len(msg.params) == 1:
                 alert = msg.verb == '904'
                 self._log(f'SASL auth {"failed" if alert else "succeeded"}',
                           alert=alert)