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,
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,

View File

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

View File

@ -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<boolean> {
return new Promise<boolean>((resolve) => {