From 79d4af0a46794eafa2ce5832deb91b7423df58e6 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Sat, 24 Sep 2022 14:58:56 +0300 Subject: [PATCH] set nick function --- src/irc.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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