From b8f86ae4fbfb76f3aa78bd98401f578ded108fea Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 18 Aug 2025 17:49:02 +0200 Subject: [PATCH] Handle 433 with automatic new nickname. --- ircplom/client.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ircplom/client.py b/ircplom/client.py index 9f166be..05ea0dd 100644 --- a/ircplom/client.py +++ b/ircplom/client.py @@ -412,6 +412,16 @@ class _ClientDb(_Db, IrcConnSetup): else: self.isupports[toks[0]] = toks[1] if len(toks) > 1 else '' + @property + def nick_incremented(self) -> str: + 'Return .nickname with number suffix incremented, or "0" if none yet.' + name, digits = ([(self.nickname, '')] + + [(self.nickname[:i], self.nickname[i:]) + for i in range(len(self.nickname), 0, -1) + if self.nickname[i:].isdigit()] + )[-1] + return name + str(0 if not digits else (int(digits) + 1)) + class Client(ABC, ClientQueueMixin): 'Abstracts socket connection, loop over it, and handling messages from it.' @@ -520,6 +530,10 @@ class Client(ABC, ClientQueueMixin): # '@'-split because # claims: " can also be in the form " self._db.client_host = msg.params[1].split('@')[-1] + elif msg.match('433', 3): # ERR_NICKNAMEINUSE + new_nick = self._db.nick_incremented + self._log('nickname already in use, trying {new_nick}', alert=True) + self.send(IrcMessage(verb='NICK', params=(new_nick,))) elif msg.match('903', 2) or msg.match('904', 2): # RPL_SUCESS, or … self._db.sasl_auth_state = 'WIN' if msg.verb == '903' else 'FAIL' self._caps.end_negotiation() # … ERR_SASLFAIL -- 2.30.2