more tweaks

This commit is contained in:
Evert Prants 2022-09-25 09:39:47 +03:00
parent d32ae78c56
commit bd82c52fcd
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
6 changed files with 20 additions and 11 deletions

View File

@ -31,7 +31,7 @@ This module provides two connectors: `IRCSocketConnector` for Node.js usage (`ne
The main classes use a special custom [TypedEventEmitter](https://lunasqu.ee/irclib/classes/TypedEventEmitter.html) to send events. The main classes use a special custom [TypedEventEmitter](https://lunasqu.ee/irclib/classes/TypedEventEmitter.html) to send events.
- [Connection wrapper events](https://lunasqu.ee/irclib/types/IRCCommunicatorEvents.html) - [Connection wrapper events](https://lunasqu.ee/irclib/types/IRCConnectionEvents.html)
- [Nick list events](https://lunasqu.ee/irclib/types/NickListEvents.html) - [Nick list events](https://lunasqu.ee/irclib/types/NickListEvents.html)
Basically, you're mostly just going to need the `message` event for IRC. Basically, you're mostly just going to need the `message` event for IRC.

View File

@ -1,12 +1,12 @@
import net, { Socket } from 'net'; import net, { Socket } from 'net';
import tls, { TLSSocket } from 'tls'; import tls, { TLSSocket } from 'tls';
import { ConnectorEvents } from '../types/events'; import { IRCConnectorEvents } from '../types/events';
import { IIRCConnector } from '../types/impl.interface'; import { IIRCConnector } from '../types/impl.interface';
import { formatstr } from '../utility/formatstr'; import { formatstr } from '../utility/formatstr';
import { TypedEventEmitter } from '../utility/typed-event-emitter'; import { TypedEventEmitter } from '../utility/typed-event-emitter';
export class IRCSocketConnector export class IRCSocketConnector
extends TypedEventEmitter<ConnectorEvents> extends TypedEventEmitter<IRCConnectorEvents>
implements IIRCConnector implements IIRCConnector
{ {
connected = false; connected = false;

View File

@ -1,10 +1,10 @@
import { ConnectorEvents } from '../types/events'; import { IRCConnectorEvents } from '../types/events';
import { IIRCConnector } from '../types/impl.interface'; import { IIRCConnector } from '../types/impl.interface';
import { formatstr } from '../utility/formatstr'; import { formatstr } from '../utility/formatstr';
import { TypedEventEmitter } from '../utility/typed-event-emitter'; import { TypedEventEmitter } from '../utility/typed-event-emitter';
export class IRCWebSocketConnector export class IRCWebSocketConnector
extends TypedEventEmitter<ConnectorEvents> extends TypedEventEmitter<IRCConnectorEvents>
implements IIRCConnector implements IIRCConnector
{ {
connected = false; connected = false;

View File

@ -1,4 +1,4 @@
import { IRCCommunicatorEvents } from './types/events'; import { IRCConnectionEvents } from './types/events';
import { import {
IWritableEventEmitter, IWritableEventEmitter,
IIRCConnector, IIRCConnector,
@ -24,7 +24,7 @@ import { parseWho, WhoResponse } from './utility/who-parser';
import { parseWhois, WhoisResponse } from './utility/whois-parser'; import { parseWhois, WhoisResponse } from './utility/whois-parser';
export class IRCConnection export class IRCConnection
extends TypedEventEmitter<IRCCommunicatorEvents> extends TypedEventEmitter<IRCConnectionEvents>
implements IIRCWrapper implements IIRCWrapper
{ {
public channels: string[] = []; public channels: string[] = [];
@ -138,6 +138,7 @@ export class IRCConnection
private handleServerLine(line: IIRCLine): void { private handleServerLine(line: IIRCLine): void {
if (this.pumpQueue(line)) { if (this.pumpQueue(line)) {
this.emit('line', line, true);
return; return;
} }
@ -160,6 +161,8 @@ export class IRCConnection
} }
} }
this.emit('line', line, false);
switch (line.command.toLowerCase()) { switch (line.command.toLowerCase()) {
case 'cap': case 'cap':
if ( if (
@ -495,7 +498,6 @@ export class IRCConnection
this.connection.on('data', (line: string) => { this.connection.on('data', (line: string) => {
const parsedLine = parse(line); const parsedLine = parse(line);
this.emit('line', parsedLine);
this.handleServerLine(parsedLine); this.handleServerLine(parsedLine);
}); });

View File

@ -1,16 +1,16 @@
import { IIRCLine } from './irc.interfaces'; import { IIRCLine } from './irc.interfaces';
export type ConnectorEvents = { export type IRCConnectorEvents = {
error: (error: any) => void; error: (error: any) => void;
data: (data: string) => void; data: (data: string) => void;
close: (reason: string) => void; close: (reason: string) => void;
}; };
export type IRCCommunicatorEvents = { export type IRCConnectionEvents = {
/** /**
* Parsed line from the IRC server. * Parsed line from the IRC server.
*/ */
line: (line: IIRCLine) => void; line: (line: IIRCLine, processed: boolean) => void;
/** /**
* Supported channel user modes from the server (e.g. `ohv: @%+`) * Supported channel user modes from the server (e.g. `ohv: @%+`)
*/ */

View File

@ -71,6 +71,13 @@ export interface IIRCWrapper extends IWritableEventEmitter {
* @param reason Reason for disconnection * @param reason Reason for disconnection
*/ */
disconnect(reason?: string): Promise<void>; disconnect(reason?: string): Promise<void>;
/**
* Set a new nickname. A `nick` event will be fired for self.
* When setting the new nick fails, the connection will reset it
* and emit your previous nickname back in the `nick` event.
* @param newNick New nickname
*/
setNick(newNick: string): void;
/** /**
* Asynchronously ping the server. * Asynchronously ping the server.
* @returns Ping in milliseconds * @returns Ping in milliseconds