From db43b83dbee96f491262a279dba2304fbb54dc34 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 22 Sep 2025 09:15:25 +0200 Subject: [PATCH] Use space rather than colon as "impossible" meta character for server query, move ChatMessage.sender processing into class code proper. --- ircplom/client.py | 9 +++++---- ircplom/msg_parse_expectations.py | 4 ++-- test.txt | 14 +++++++------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ircplom/client.py b/ircplom/client.py index fe8479c..eeb1708 100644 --- a/ircplom/client.py +++ b/ircplom/client.py @@ -436,9 +436,11 @@ class _Channel(Channel): class _ChatMessage(ChatMessage): - def __init__(self, sender: str = '', db: Optional['_ClientDb'] = None + def __init__(self, + sender: str | NickUserHost = '', + db: Optional['_ClientDb'] = None ) -> None: - self.sender = sender + self.sender = sender if isinstance(sender, str) else sender.nick self._db = db def to(self, target: str) -> Self: @@ -671,8 +673,7 @@ class _ClientDb(_Clearable, _UpdatingAttrsMixin, SharedClientDbFields): def messaging(self, src: str | NickUserHost) -> ChatMessage: 'Start input chain for chat message data.' - return _ChatMessage(sender=f':{src}' if isinstance(src, str) - else src.nick, db=self) + return _ChatMessage(sender=src, db=self) def into_endnode_updates(self, path: tuple[str, ...] ) -> list[tuple[tuple[str, ...], Any]]: diff --git a/ircplom/msg_parse_expectations.py b/ircplom/msg_parse_expectations.py index 71755a9..84478b4 100644 --- a/ircplom/msg_parse_expectations.py +++ b/ircplom/msg_parse_expectations.py @@ -492,12 +492,12 @@ MSG_EXPECTATIONS: list[_MsgParseExpectation] = [ 'NOTICE', _MsgTok.SERVER, ('*', - (_MsgTok.ANY, 'setattr_db.messaging.server.to.:notice'))), + (_MsgTok.ANY, 'setattr_db.messaging. server.to.:notice'))), _MsgParseExpectation( 'NOTICE', _MsgTok.SERVER, ((_MsgTok.NICKNAME, 'setattr_db.users.me:nick'), - (_MsgTok.ANY, 'setattr_db.messaging.server.to.:notice'))), + (_MsgTok.ANY, 'setattr_db.messaging. server.to.:notice'))), _MsgParseExpectation( 'NOTICE', diff --git a/test.txt b/test.txt index 0ab00d3..352fac7 100644 --- a/test.txt +++ b/test.txt @@ -70,16 +70,16 @@ # expect some NOTICE and PING to process/reply during initiation 0:2 < :*.?.net NOTICE * :*** Looking up your ident... -1,2 $ message set to: [N :server :*** Looking up your ident...] -3 <<< [:server] *** Looking up your ident... +1,2 $ message set to: [N server :*** Looking up your ident...] +3 <<< [ server] *** Looking up your ident... 1,2 $ message set to: [P :] 0:2 < :*.?.net NOTICE * :*** Looking up your hostname... -1,2 $ message set to: [N :server :*** Looking up your hostname...] -3 <<< [:server] *** Looking up your hostname... +1,2 $ message set to: [N server :*** Looking up your hostname...] +3 <<< [ server] *** Looking up your hostname... 1,2 $ message set to: [P :] 0:2 < :*.?.net NOTICE * :*** Found your hostname (baz.bar.foo) -1,2 $ message set to: [N :server :*** Found your hostname (baz.bar.foo)] -3 <<< [:server] *** Found your hostname (baz.bar.foo) +1,2 $ message set to: [N server :*** Found your hostname (baz.bar.foo)] +3 <<< [ server] *** Found your hostname (baz.bar.foo) 1,2 $ message set to: [P :] 0:2 < PING :? 2 > PONG :? @@ -172,7 +172,7 @@ 0 # 0) :start 0 # 1) foo.bar.baz :DEBUG 0 # 2) foo.bar.baz :RAW -0 # 3) foo.bar.baz :server +0 # 3) foo.bar.baz server 0 # 4) foo.bar.baz SaslServ > /window 1 > /help -- 2.30.2