sasl and bot stuff

This commit is contained in:
Evert Prants 2022-09-24 11:16:16 +03:00
parent 146c7ba900
commit 2b027d57ad
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
4 changed files with 52 additions and 4 deletions

View File

@ -5,6 +5,7 @@ const bot = new IRCBot({
host: 'icynet.eu', host: 'icynet.eu',
nick: 'MyTestBot', nick: 'MyTestBot',
channels: ['#squeebot'], channels: ['#squeebot'],
bot: true,
nickserv: { nickserv: {
enabled: true, enabled: true,
command: 'STATUS', command: 'STATUS',

View File

@ -34,8 +34,17 @@ export class IRCConnectionWrapper
public queue: IQueue[] = []; public queue: IQueue[] = [];
public authenticated = false; public authenticated = false;
public serverData: { [key: string]: any } = { public serverData: { [key: string]: any } = {
/**
* (true host)Name of this server.
*/
name: '', name: '',
/**
* Supported channel user modes from the server (e.g. `ohv: @%+`)
*/
supportedModes: {}, supportedModes: {},
/**
* Everything this server supports. See IRC documentation for command `005` or `RPL_ISUPPORT` for more info.
*/
serverSupports: {}, serverSupports: {},
}; };
@ -153,12 +162,20 @@ export class IRCConnectionWrapper
this._supportsDone = true; this._supportsDone = true;
this.emit('supported-modes', this.serverData.supportedModes); this.emit('supported-modes', this.serverData.supportedModes);
this.emit('server-supports', this.serverData.serverSupports); 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()) { switch (line.command.toLowerCase()) {
case 'cap': case 'cap':
if ( if (
line.trailing === 'sasl' && line.trailing.includes('sasl') &&
line.arguments?.[1] === 'ACK' && line.arguments?.[1] === 'ACK' &&
!this.authenticated !this.authenticated
) { ) {
@ -226,13 +243,14 @@ export class IRCConnectionWrapper
this.write('NICK %s', newNick); this.write('NICK %s', newNick);
this.options.nick = newNick; this.options.nick = newNick;
break; break;
case '904': // SASL fail case '902': // ERR_NICKLOCKED
case '904': // ERR_SASLFAIL
case '905': // ERR_SASLTOOLONG
this.emit('error', { this.emit('error', {
error: new Error(line.trailing), error: new Error(line.trailing),
fatal: true, fatal: true,
}); });
break; case '903': // RPL_SASLSUCCESS
case '903': // SASL success
this.write('CAP END'); this.write('CAP END');
break; break;
case 'notice': case 'notice':

View File

@ -107,4 +107,20 @@ export const RPL_COMMAND = [
['258', 'RPL_ADMINLOC2', ':<admin info>'], ['258', 'RPL_ADMINLOC2', ':<admin info>'],
['259', 'RPL_ADMINEMAIL', ':<admin info>'], ['259', 'RPL_ADMINEMAIL', ':<admin info>'],
['671', 'RPL_WHOISSECURE', '<nick> [<type>] :is using a secure connection'], ['671', 'RPL_WHOISSECURE', '<nick> [<type>] :is using a secure connection'],
[
'900',
'RPL_LOGGEDIN',
'<nick> <nick> <ident> <host> <account> :You are now logged in as',
],
[
'901',
'RPL_LOGGEDOUT',
'<nick> <nick> <ident> <host> <account> :You are now logged out',
],
['903', 'RPL_SASLSUCCESS', '<nick> :SASL authentication successful'],
[
'908',
'RPL_SASLMECHS',
'<nick> <mechanisms> :are available SASL mechanisms',
],
]; ];

View File

@ -56,4 +56,17 @@ export const RPL_ERROR = [
['491', 'ERR_NOOPERHOST', ':No O-lines for your host'], ['491', 'ERR_NOOPERHOST', ':No O-lines for your host'],
['501', 'ERR_UMODEUNKNOWNFLAG', ':Unknown MODE flag'], ['501', 'ERR_UMODEUNKNOWNFLAG', ':Unknown MODE flag'],
['502', 'ERR_USERSDONTMATCH', ':Cant change mode for other users'], ['502', 'ERR_USERSDONTMATCH', ':Cant change mode for other users'],
[
'902',
'ERR_NICKLOCKED',
'<nick> <nick> :You must use a nick assigned to you',
],
['904', 'ERR_SASLFAIL', '<nick> :SASL authentication failed'],
['905', 'ERR_SASLTOOLONG', '<nick> :SASL message too long'],
['906', 'ERR_SASLABORTED', '<nick> :SASL authentication aborted'],
[
'907',
'ERR_SASLALREADY',
'<nick> :You have already authenticated using SASL',
],
]; ];