From: Christian Heller Date: Tue, 19 Aug 2025 00:54:50 +0000 (+0200) Subject: Further tighten msg parsing. X-Git-Url: https://plomlompom.com/repos/blog?a=commitdiff_plain;h=2a01cc1a1d1309dfd7f9c7187111396ad1c56660;p=ircplom Further tighten msg parsing. --- diff --git a/ircplom/client.py b/ircplom/client.py index 8bce64a..27931bd 100644 --- a/ircplom/client.py +++ b/ircplom/client.py @@ -42,6 +42,7 @@ class _MsgParseExpectation(NamedTuple): len_min_params: int = 0 len_max_params: int = 0 params: tuple[str, ...] = tuple() + source: Optional[str] = None _EXPECTATIONS: dict[str, _MsgParseExpectation] = { @@ -56,15 +57,15 @@ _EXPECTATIONS: dict[str, _MsgParseExpectation] = { '900': _MsgParseExpectation(4), '903': _MsgParseExpectation(2), '904': _MsgParseExpectation(2), - 'AUTHENTICATE': _MsgParseExpectation(params=('+',)), + 'AUTHENTICATE': _MsgParseExpectation(params=('+',), source=''), 'CAP': _MsgParseExpectation(3, 15), - 'ERROR': _MsgParseExpectation(1), + 'ERROR': _MsgParseExpectation(1, source=''), 'JOIN': _MsgParseExpectation(1), 'MODE': _MsgParseExpectation(2), 'NICK': _MsgParseExpectation(1), 'NOTICE': _MsgParseExpectation(2), 'PART': _MsgParseExpectation(1, 2), - 'PING': _MsgParseExpectation(1), + 'PING': _MsgParseExpectation(1, source=''), 'PRIVMSG': _MsgParseExpectation(2), } @@ -77,6 +78,8 @@ class _IrcMsg(IrcMessage): if not verb == self.verb: return False expect = _EXPECTATIONS[verb] + if expect.source is not None and self.source != expect.source: + return False if expect.params: return self.params == expect.params n_msg_params = len(self.params)