set nick function

This commit is contained in:
Evert Prants 2022-09-24 14:58:56 +03:00
parent ad68321e8b
commit 79d4af0a46
Signed by: evert
GPG Key ID: 1688DA83D222D0B5

View File

@ -251,6 +251,12 @@ export class IRCConnectionWrapper
case '433': // ERR_NICKNAMEINUSE case '433': // ERR_NICKNAMEINUSE
const newNick = this.options.nick + '_'; const newNick = this.options.nick + '_';
this.write('NICK %s', newNick); this.write('NICK %s', newNick);
this.emit('nick', {
oldNick: this.options.nick,
newNick,
});
this.options.nick = newNick; this.options.nick = newNick;
break; break;
case '902': // ERR_NICKLOCKED case '902': // ERR_NICKLOCKED
@ -534,6 +540,19 @@ export class IRCConnectionWrapper
return this.connection?.connected ?? false; 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. * Asynchronously ping the server.
* @returns Ping in milliseconds * @returns Ping in milliseconds