handle ERR_NICKNAMEINUSE pre-registration (add alt-nicknames param)
This commit is contained in:
parent
4d9dcf0652
commit
bfdae87b36
2 changed files with 21 additions and 2 deletions
|
@ -46,6 +46,7 @@ class ConnectionParams(object):
|
||||||
sts: Optional[STSPolicy] = None
|
sts: Optional[STSPolicy] = None
|
||||||
resume: Optional[ResumePolicy] = None
|
resume: Optional[ResumePolicy] = None
|
||||||
|
|
||||||
reconnect: int = 10 # seconds
|
reconnect: int = 10 # seconds
|
||||||
|
alt_nicknames: List[str] = field(default_factory=list)
|
||||||
|
|
||||||
autojoin: List[str] = field(default_factory=list)
|
autojoin: List[str] = field(default_factory=list)
|
||||||
|
|
|
@ -69,7 +69,8 @@ class Server(IServer):
|
||||||
self._wait_for: Optional[Tuple[Awaitable, WaitFor]] = None
|
self._wait_for: Optional[Tuple[Awaitable, WaitFor]] = None
|
||||||
self._wait_for_fut: Optional[Future[WaitFor]] = None
|
self._wait_for_fut: Optional[Future[WaitFor]] = None
|
||||||
|
|
||||||
self._pending_who: Deque[str] = deque()
|
self._pending_who: Deque[str] = deque()
|
||||||
|
self._initial_nick: Optional[str] = None
|
||||||
|
|
||||||
def hostmask(self) -> str:
|
def hostmask(self) -> str:
|
||||||
hostmask = self.nickname
|
hostmask = self.nickname
|
||||||
|
@ -139,6 +140,8 @@ class Server(IServer):
|
||||||
username = self.params.username or nickname
|
username = self.params.username or nickname
|
||||||
realname = self.params.realname or nickname
|
realname = self.params.realname or nickname
|
||||||
|
|
||||||
|
self._initial_nick = nickname
|
||||||
|
|
||||||
# these must remain non-awaited; reading hasn't started yet
|
# these must remain non-awaited; reading hasn't started yet
|
||||||
if not self.params.password is None:
|
if not self.params.password is None:
|
||||||
self.send(build("PASS", [self.params.password]))
|
self.send(build("PASS", [self.params.password]))
|
||||||
|
@ -172,6 +175,21 @@ class Server(IServer):
|
||||||
self._pending_who.pop()
|
self._pending_who.pop()
|
||||||
await self._next_who()
|
await self._next_who()
|
||||||
|
|
||||||
|
elif (line.command == ERR_NICKNAMEINUSE and
|
||||||
|
self._initial_nick is not None):
|
||||||
|
nick = self._initial_nick
|
||||||
|
|
||||||
|
alt_nicks = self.params.alt_nicknames
|
||||||
|
if not alt_nicks:
|
||||||
|
alt_nicks = [nick+"_"*i for i in range(3)]
|
||||||
|
|
||||||
|
for alt_nick in alt_nicks:
|
||||||
|
if await self.send_nick(alt_nick):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self._initial_nick = None
|
||||||
|
await self.send(build("QUIT"))
|
||||||
|
|
||||||
elif emit is not None:
|
elif emit is not None:
|
||||||
if emit.command == "001":
|
if emit.command == "001":
|
||||||
await self.send(build("WHO", [self.nickname]))
|
await self.send(build("WHO", [self.nickname]))
|
||||||
|
|
Loading…
Reference in a new issue