diff --git a/src/irc.ts b/src/irc.ts index 560fb9b..2e4cda0 100644 --- a/src/irc.ts +++ b/src/irc.ts @@ -248,7 +248,28 @@ export class IRCConnectionWrapper } break; } - case '433': // ERR_NICKNAMEINUSE + case '432': { + // ERR_ERRONEUSNICKNAME + // No backing away from this, we don't know what is wrong exactly. + if (!this.authenticated) { + this.emit('error', { + error: new Error('Invalid nickname'), + fatal: true, + }); + this.connection?.destroy(); + return; + } + + const resetNick = line.arguments[0]; + this.emit('nick', { + oldNick: this.options.nick, + newNick: resetNick, + }); + this.options.nick = resetNick; + break; + } + case '433': { + // ERR_NICKNAMEINUSE const newNick = this.options.nick + '_'; this.write('NICK %s', newNick); @@ -259,6 +280,7 @@ export class IRCConnectionWrapper this.options.nick = newNick; break; + } case '902': // ERR_NICKLOCKED case '904': // ERR_SASLFAIL case '905': // ERR_SASLTOOLONG