From 54422fc5eba1b4815b0e5c9a21f065f640e37cb3 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Tue, 19 Aug 2025 01:48:39 +0200 Subject: [PATCH] Tighten NOTICE, PRIVMSG recognition. --- ircplom/client.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ircplom/client.py b/ircplom/client.py index 5d9ea89..21fe0f6 100644 --- a/ircplom/client.py +++ b/ircplom/client.py @@ -556,8 +556,7 @@ class Client(ABC, ClientQueueMixin): self._log('nickname already in use, trying increment', alert=True) self.set_nick(self._db.nick_incremented) elif msg.match('900', 4): # RPL_LOGGEDIN - nick, remainder = msg.params[1].split('!', maxsplit=1) - assert nick == self._db.nickname + self._db.nickname, remainder = msg.params[1].split('!', maxsplit=1) self._db.username, self._db.client_host = remainder.split('@') self._db.sasl_account = msg.params[2] elif msg.match('903', 2) or msg.match('904', 2): # RPL_SASLSUCCESS, … @@ -584,11 +583,18 @@ class Client(ABC, ClientQueueMixin): self._db.user_modes = msg.params[1] elif msg.match('NICK') and msg.nick_from_source == self._db.nickname: self.set_nick(msg.params[0], confirmed=True) - elif msg.match('NOTICE', 2) or msg.match('PRIVMSG', 2): - scope = LogScope.CHAT if '!' in msg.source else LogScope.SERVER - self._log(msg.params[-1], scope=scope, target=msg.params[0], - out=False, as_notice=msg.verb == 'NOTICE', - sender=msg.nick_from_source) + elif msg.match('NOTICE', 2) and (msg.params[0] != '*' + or not self._db.nickname): + kw: dict[str, str | LogScope] = {} + if '!' in msg.source: + kw |= {'sender': msg.nick_from_source, 'scope': LogScope.CHAT} + self._log(msg.params[-1], out=False, target=msg.params[0], + as_notice=True, **kw) + elif msg.match('PRIVMSG', 2) and msg.params[0] != '*': + kw = {} + if '!' in msg.source: + kw |= {'sender': msg.nick_from_source, 'scope': LogScope.CHAT} + self._log(msg.params[-1], out=False, target=msg.params[0], **kw) elif msg.match('PART', len_is_min=True) or msg.match('JOIN'): channel = msg.params[0] log_msg = f'{msg.nick_from_source} {msg.verb.lower()}s {channel}' -- 2.30.2