From 7f28f41ca9f47785642006c86291e301cb503e2d Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Fri, 23 Sep 2022 21:20:50 +0300 Subject: [PATCH] nick validator standalone stuff --- src/irc.ts | 16 ++-------------- src/types/irc.interfaces.ts | 5 ----- src/utility/nickserv-validator.ts | 25 +++++++++++++++++++++++-- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/irc.ts b/src/irc.ts index fc73d2e..084d502 100644 --- a/src/irc.ts +++ b/src/irc.ts @@ -3,12 +3,7 @@ import { IRCConnector, IRCConnectorConstructor, } from './types/impl.interface'; -import { - IIRCLine, - IIRCOptions, - INickStore, - IQueue, -} from './types/irc.interfaces'; +import { IIRCLine, IIRCOptions, IQueue } from './types/irc.interfaces'; import { Collector, WhoisCollector } from './utility/collector'; import { parse } from './utility/parser'; import { SimpleEventEmitter } from './utility/simple-event-emitter'; @@ -29,7 +24,6 @@ export class IRCConnectionWrapper { public channels: string[] = []; public queue: IQueue[] = []; - public nickservStore: { [key: string]: INickStore } = {}; public authenticated = false; public serverData: { [key: string]: any } = { name: '', @@ -37,7 +31,7 @@ export class IRCConnectionWrapper serverSupports: {}, }; - public connection?: IRCConnector; + private connection?: IRCConnector; private _supportsDone = false; private _lastLineWasSupports = false; @@ -316,10 +310,6 @@ export class IRCConnectionWrapper break; case 'quit': if (line.user.nickname !== this.options.nick) { - if (this.nickservStore[line.user.nickname]) { - delete this.nickservStore[line.user.nickname]; - } - this.emit('leave', { nickname: line.user.nickname, }); @@ -328,8 +318,6 @@ export class IRCConnectionWrapper case 'nick': if (line.user.nickname === this.options.nick) { this.options.nick = line.arguments?.[0] || 'unknown'; - } else if (this.nickservStore[line.user.nickname]) { - delete this.nickservStore[line.user.nickname]; } this.emit('nick', { oldNick: line.user.nickname, diff --git a/src/types/irc.interfaces.ts b/src/types/irc.interfaces.ts index 1706958..2a2c3b4 100644 --- a/src/types/irc.interfaces.ts +++ b/src/types/irc.interfaces.ts @@ -48,8 +48,3 @@ export interface IIRCOptions { channels?: string[]; nickserv?: INickServOptions; } - -export interface INickStore { - checked: number; - result: boolean; -} diff --git a/src/utility/nickserv-validator.ts b/src/utility/nickserv-validator.ts index 23e5393..2a95326 100644 --- a/src/utility/nickserv-validator.ts +++ b/src/utility/nickserv-validator.ts @@ -1,7 +1,12 @@ import { IRCConnectionWrapper } from '../irc'; -import { INickServOptions, INickStore } from '../types/irc.interfaces'; +import { INickServOptions } from '../types/irc.interfaces'; import { Collector } from './collector'; +export interface INickStore { + checked: number; + result: boolean; +} + export class NickServCollector extends Collector { constructor( nickservOptions: INickServOptions, @@ -30,7 +35,23 @@ export class NickServCollector extends Collector { export class NickServValidator { 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 { return new Promise((resolve) => {