diff --git a/src/irc.ts b/src/irc.ts index 4ebf4fa..560fb9b 100644 --- a/src/irc.ts +++ b/src/irc.ts @@ -251,6 +251,12 @@ export class IRCConnectionWrapper case '433': // ERR_NICKNAMEINUSE const newNick = this.options.nick + '_'; this.write('NICK %s', newNick); + + this.emit('nick', { + oldNick: this.options.nick, + newNick, + }); + this.options.nick = newNick; break; case '902': // ERR_NICKLOCKED @@ -534,6 +540,19 @@ export class IRCConnectionWrapper return this.connection?.connected ?? false; } + /** + * Set a new nickname for self. + * @param newNick New nickname + */ + public setNick(newNick: string): void { + this.write('NICK %s', newNick); + this.emit('nick', { + oldNick: this.options.nick, + newNick, + }); + this.options.nick = newNick; + } + /** * Asynchronously ping the server. * @returns Ping in milliseconds