From ef910a6147d3f6aae581349bedc846c2c3e234c5 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Tue, 30 Sep 2025 20:14:39 +0200 Subject: [PATCH] Move part of 433 handling into MSG_EXPECTATIONS, improve messaging. --- src/ircplom/client.py | 8 +++----- src/ircplom/msg_parse_expectations.py | 3 ++- src/tests/test.txt | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ircplom/client.py b/src/ircplom/client.py index 3ebbc11..d8e59b7 100644 --- a/src/ircplom/client.py +++ b/src/ircplom/client.py @@ -951,11 +951,9 @@ class Client(ABC, ClientQueueMixin): elif ret['_verb'] == '401': # ERR_NOSUCHNICK raise TargetUserOffline(ret['missing']) elif ret['_verb'] == '432': # ERR_ERRONEOUSNICKNAME - alert = 'nickname refused for bad format' - if 'nick' not in ret: - alert += ', giving up' - self.close() - self._alert(alert) + self._alert('nickname refused for bad format, ' + + ('keeping current one' if 'nick' in ret + else 'giving up')) elif ret['_verb'] == '433': # ERR_NICKNAMEINUSE self._alert('nickname already in use, trying increment') self.send('NICK', _NickUserHost(nick=ret['used']).incremented) diff --git a/src/ircplom/msg_parse_expectations.py b/src/ircplom/msg_parse_expectations.py index 95fbc5f..158154f 100644 --- a/src/ircplom/msg_parse_expectations.py +++ b/src/ircplom/msg_parse_expectations.py @@ -401,7 +401,8 @@ MSG_EXPECTATIONS: list[_MsgParseExpectation] = [ _MsgTok.SERVER, ('*', _MsgTok.ANY, # bad one probably fails our NICKNAME tests - _MsgTok.ANY)), # comment + _MsgTok.ANY), # comment + bonus_tasks=('do_close:',)), _MsgParseExpectation( '432', # ERR_ERRONEOUSNICKNAME _MsgTok.SERVER, diff --git a/src/tests/test.txt b/src/tests/test.txt index 10ae008..1010942 100644 --- a/src/tests/test.txt +++ b/src/tests/test.txt @@ -170,7 +170,7 @@ > /nick @foo 1 .> NICK :@foo 0:1 .< :*.?.net 432 foo1 @foo :Erroneous nickname -1 .!$ nickname refused for bad format +1 .!$ nickname refused for bad format, keeping current one # join channel, collect topic, residents; update me:user from JOIN message; ensure topic.who not affecting users DB > /join #test -- 2.30.2