From 2b027d57ad93a54c1f0d237c9d20d961e969d774 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Sat, 24 Sep 2022 11:16:16 +0300 Subject: [PATCH] sasl and bot stuff --- src/examples/connection-test.ts | 1 + src/irc.ts | 26 ++++++++++++++++++++++---- src/spec/command-replies.ts | 16 ++++++++++++++++ src/spec/error-replies.ts | 13 +++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/examples/connection-test.ts b/src/examples/connection-test.ts index 9115190..7603263 100644 --- a/src/examples/connection-test.ts +++ b/src/examples/connection-test.ts @@ -5,6 +5,7 @@ const bot = new IRCBot({ host: 'icynet.eu', nick: 'MyTestBot', channels: ['#squeebot'], + bot: true, nickserv: { enabled: true, command: 'STATUS', diff --git a/src/irc.ts b/src/irc.ts index cc81bfe..b53dfc1 100644 --- a/src/irc.ts +++ b/src/irc.ts @@ -34,8 +34,17 @@ export class IRCConnectionWrapper public queue: IQueue[] = []; public authenticated = false; public serverData: { [key: string]: any } = { + /** + * (true host)Name of this server. + */ name: '', + /** + * Supported channel user modes from the server (e.g. `ohv: @%+`) + */ supportedModes: {}, + /** + * Everything this server supports. See IRC documentation for command `005` or `RPL_ISUPPORT` for more info. + */ serverSupports: {}, }; @@ -153,12 +162,20 @@ export class IRCConnectionWrapper this._supportsDone = true; this.emit('supported-modes', this.serverData.supportedModes); this.emit('server-supports', this.serverData.serverSupports); + + if ( + this.options.bot && + this.serverData.serverSupports.USERMODES && + this.serverData.serverSupports.USERMODES.includes('B') + ) { + this.write('MODE %s +B', this.options.nick); + } } switch (line.command.toLowerCase()) { case 'cap': if ( - line.trailing === 'sasl' && + line.trailing.includes('sasl') && line.arguments?.[1] === 'ACK' && !this.authenticated ) { @@ -226,13 +243,14 @@ export class IRCConnectionWrapper this.write('NICK %s', newNick); this.options.nick = newNick; break; - case '904': // SASL fail + case '902': // ERR_NICKLOCKED + case '904': // ERR_SASLFAIL + case '905': // ERR_SASLTOOLONG this.emit('error', { error: new Error(line.trailing), fatal: true, }); - break; - case '903': // SASL success + case '903': // RPL_SASLSUCCESS this.write('CAP END'); break; case 'notice': diff --git a/src/spec/command-replies.ts b/src/spec/command-replies.ts index 55ea1f8..a8f4633 100644 --- a/src/spec/command-replies.ts +++ b/src/spec/command-replies.ts @@ -107,4 +107,20 @@ export const RPL_COMMAND = [ ['258', 'RPL_ADMINLOC2', ':'], ['259', 'RPL_ADMINEMAIL', ':'], ['671', 'RPL_WHOISSECURE', ' [] :is using a secure connection'], + [ + '900', + 'RPL_LOGGEDIN', + ' :You are now logged in as', + ], + [ + '901', + 'RPL_LOGGEDOUT', + ' :You are now logged out', + ], + ['903', 'RPL_SASLSUCCESS', ' :SASL authentication successful'], + [ + '908', + 'RPL_SASLMECHS', + ' :are available SASL mechanisms', + ], ]; diff --git a/src/spec/error-replies.ts b/src/spec/error-replies.ts index 35bbc6f..7e0fcdc 100644 --- a/src/spec/error-replies.ts +++ b/src/spec/error-replies.ts @@ -56,4 +56,17 @@ export const RPL_ERROR = [ ['491', 'ERR_NOOPERHOST', ':No O-lines for your host'], ['501', 'ERR_UMODEUNKNOWNFLAG', ':Unknown MODE flag'], ['502', 'ERR_USERSDONTMATCH', ':Cant change mode for other users'], + [ + '902', + 'ERR_NICKLOCKED', + ' :You must use a nick assigned to you', + ], + ['904', 'ERR_SASLFAIL', ' :SASL authentication failed'], + ['905', 'ERR_SASLTOOLONG', ' :SASL message too long'], + ['906', 'ERR_SASLABORTED', ' :SASL authentication aborted'], + [ + '907', + 'ERR_SASLALREADY', + ' :You have already authenticated using SASL', + ], ];