116 lines
2.4 KiB
TypeScript
116 lines
2.4 KiB
TypeScript
import { IIRCLine, IQueue } from '../types/irc.interfaces';
|
|
|
|
/**
|
|
* Collect a single line from the server.
|
|
*/
|
|
export class Collector implements IQueue<IIRCLine> {
|
|
constructor(
|
|
public await: string,
|
|
private resolve: (lines: IIRCLine) => void,
|
|
public from?: string,
|
|
public match?: (line: IIRCLine) => boolean,
|
|
) {}
|
|
|
|
do(line: IIRCLine): void {
|
|
this.resolve(line);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Collect lines from the server.
|
|
*/
|
|
export class MultiLineCollector implements IQueue<IIRCLine[]> {
|
|
public buffer: IIRCLine[] = [];
|
|
|
|
constructor(
|
|
public await: string,
|
|
public additional: string[],
|
|
private resolve: (lines: IIRCLine[]) => void,
|
|
public match?: (line: IIRCLine) => boolean,
|
|
) {}
|
|
|
|
do(line: IIRCLine, data: IIRCLine[]): void {
|
|
this.resolve([...data, line]);
|
|
}
|
|
|
|
digest(line: IIRCLine): void {
|
|
this.buffer.push(line);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get a full WHOIS response from the server
|
|
*
|
|
* `311` - Start of WHOIS, Nickname, hostmask, realname
|
|
*
|
|
* `319` - Channels
|
|
*
|
|
* `378` - Connecting from
|
|
*
|
|
* `379` - User modes
|
|
*
|
|
* `312` - Server and server name
|
|
*
|
|
* `313` - User title
|
|
*
|
|
* `330` - Login time
|
|
*
|
|
* `335` - Is a bot
|
|
*
|
|
* `307` - Registered
|
|
*
|
|
* `671` - Secure connection
|
|
*
|
|
* `317` - Sign on time and idle time
|
|
*
|
|
* `318` - End of WHOIS
|
|
*/
|
|
export class WhoisCollector extends MultiLineCollector {
|
|
constructor(
|
|
resolve: (lines: IIRCLine[]) => void,
|
|
match?: (line: IIRCLine) => boolean,
|
|
) {
|
|
super(
|
|
'318', // End of WHOIS
|
|
[
|
|
'311', // Start of WHOIS, Nickname, hostmask, realname
|
|
'319', // Channels
|
|
'378', // Connecting from
|
|
'379', // User modes
|
|
'312', // Server and server name
|
|
'313', // User title
|
|
'330', // Login time
|
|
'335', // Is a bot
|
|
'307', // Registered
|
|
'671', // Secure connection
|
|
'317', // Sign on time and idle time
|
|
],
|
|
resolve,
|
|
match,
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get a full WHO response from the server
|
|
*
|
|
* `352` - WHO line: `<channel> <user> <host> <server> <nick> <H|G>[*][@|+] :<hopcount> <real_name>`
|
|
*
|
|
* `315` - end of WHO
|
|
*/
|
|
export class WhoCollector extends MultiLineCollector {
|
|
constructor(
|
|
resolve: (lines: IIRCLine[]) => void,
|
|
match?: (line: IIRCLine) => boolean,
|
|
) {
|
|
super(
|
|
'315', // End of WHO
|
|
[
|
|
'352', // WHO line: <channel> <user> <host> <server> <nick> <H|G>[*][@|+] :<hopcount> <real_name>
|
|
],
|
|
resolve,
|
|
match,
|
|
);
|
|
}
|
|
}
|