nick validator standalone stuff

This commit is contained in:
Evert Prants 2022-09-23 21:20:50 +03:00
parent ea7f81d9fe
commit 7f28f41ca9
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 25 additions and 21 deletions

View File

@ -3,12 +3,7 @@ import {
IRCConnector, IRCConnector,
IRCConnectorConstructor, IRCConnectorConstructor,
} from './types/impl.interface'; } from './types/impl.interface';
import { import { IIRCLine, IIRCOptions, IQueue } from './types/irc.interfaces';
IIRCLine,
IIRCOptions,
INickStore,
IQueue,
} from './types/irc.interfaces';
import { Collector, WhoisCollector } from './utility/collector'; import { Collector, WhoisCollector } from './utility/collector';
import { parse } from './utility/parser'; import { parse } from './utility/parser';
import { SimpleEventEmitter } from './utility/simple-event-emitter'; import { SimpleEventEmitter } from './utility/simple-event-emitter';
@ -29,7 +24,6 @@ export class IRCConnectionWrapper
{ {
public channels: string[] = []; public channels: string[] = [];
public queue: IQueue[] = []; public queue: IQueue[] = [];
public nickservStore: { [key: string]: INickStore } = {};
public authenticated = false; public authenticated = false;
public serverData: { [key: string]: any } = { public serverData: { [key: string]: any } = {
name: '', name: '',
@ -37,7 +31,7 @@ export class IRCConnectionWrapper
serverSupports: {}, serverSupports: {},
}; };
public connection?: IRCConnector; private connection?: IRCConnector;
private _supportsDone = false; private _supportsDone = false;
private _lastLineWasSupports = false; private _lastLineWasSupports = false;
@ -316,10 +310,6 @@ export class IRCConnectionWrapper
break; break;
case 'quit': case 'quit':
if (line.user.nickname !== this.options.nick) { if (line.user.nickname !== this.options.nick) {
if (this.nickservStore[line.user.nickname]) {
delete this.nickservStore[line.user.nickname];
}
this.emit('leave', { this.emit('leave', {
nickname: line.user.nickname, nickname: line.user.nickname,
}); });
@ -328,8 +318,6 @@ export class IRCConnectionWrapper
case 'nick': case 'nick':
if (line.user.nickname === this.options.nick) { if (line.user.nickname === this.options.nick) {
this.options.nick = line.arguments?.[0] || 'unknown'; this.options.nick = line.arguments?.[0] || 'unknown';
} else if (this.nickservStore[line.user.nickname]) {
delete this.nickservStore[line.user.nickname];
} }
this.emit('nick', { this.emit('nick', {
oldNick: line.user.nickname, oldNick: line.user.nickname,

View File

@ -48,8 +48,3 @@ export interface IIRCOptions {
channels?: string[]; channels?: string[];
nickserv?: INickServOptions; nickserv?: INickServOptions;
} }
export interface INickStore {
checked: number;
result: boolean;
}

View File

@ -1,7 +1,12 @@
import { IRCConnectionWrapper } from '../irc'; import { IRCConnectionWrapper } from '../irc';
import { INickServOptions, INickStore } from '../types/irc.interfaces'; import { INickServOptions } from '../types/irc.interfaces';
import { Collector } from './collector'; import { Collector } from './collector';
export interface INickStore {
checked: number;
result: boolean;
}
export class NickServCollector extends Collector { export class NickServCollector extends Collector {
constructor( constructor(
nickservOptions: INickServOptions, nickservOptions: INickServOptions,
@ -30,7 +35,23 @@ export class NickServCollector extends Collector {
export class NickServValidator { export class NickServValidator {
public nickservStore: { [key: string]: INickStore } = {}; public nickservStore: { [key: string]: INickStore } = {};
constructor(public irc: IRCConnectionWrapper) {} constructor(public irc: IRCConnectionWrapper) {
this.irc.on('leave', ({ nickname }) => {
if (this.nickservStore[nickname]) {
delete this.nickservStore[nickname];
}
});
this.irc.on('nick', ({ oldNick }) => {
if (this.nickservStore[oldNick]) {
delete this.nickservStore[oldNick];
}
});
this.irc.on('disconnect', () => {
this.nickservStore = {};
});
}
async getNickStatus(nickname: string): Promise<boolean> { async getNickStatus(nickname: string): Promise<boolean> {
return new Promise<boolean>((resolve) => { return new Promise<boolean>((resolve) => {