From 1e370988b2af22f0645030a7a81bbdf800bda4fd Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 10 Aug 2023 14:31:46 +0100 Subject: [PATCH 1/6] Add code for whoiscertfp --- src/codes.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/codes.ts b/src/codes.ts index cadc560e..3fada45b 100644 --- a/src/codes.ts +++ b/src/codes.ts @@ -157,6 +157,10 @@ export const replyCodes = { name: 'rpl_globalusers', type: 'reply' }, + 276: { + name: 'rpl_whoiscertfp', + type: 'reply', + }, 300: { name: 'rpl_none', type: 'reply' From ed44b9fd0272f0c72c242921c67a538e24b4e82c Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 10 Aug 2023 14:36:39 +0100 Subject: [PATCH 2/6] Add whoiscertfp parsing --- changelog.d/110.misc | 1 + src/irc.ts | 11 ++++++----- src/state.ts | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 changelog.d/110.misc diff --git a/changelog.d/110.misc b/changelog.d/110.misc new file mode 100644 index 00000000..4d9109a0 --- /dev/null +++ b/changelog.d/110.misc @@ -0,0 +1 @@ +Include any certfp lines in a whois response. diff --git a/src/irc.ts b/src/irc.ts index 40c85898..cd9b2970 100644 --- a/src/irc.ts +++ b/src/irc.ts @@ -1052,6 +1052,8 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter TypedEmitter { @@ -1692,11 +1695,9 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter Date: Thu, 10 Aug 2023 17:53:29 +0100 Subject: [PATCH 3/6] Allow extending the config of the test IrcServer --- src/testing/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/testing/index.ts b/src/testing/index.ts index e69c03d7..a8638c55 100644 --- a/src/testing/index.ts +++ b/src/testing/index.ts @@ -1,5 +1,5 @@ import { randomUUID } from 'crypto'; -import { Client, ClientEvents, Message } from '..'; +import { Client, ClientEvents, IrcClientOpts, Message } from '..'; const DEFAULT_PORT = parseInt(process.env.IRC_TEST_PORT ?? '6667', 10); const DEFAULT_ADDRESS = process.env.IRC_TEST_ADDRESS ?? "127.0.0.1"; @@ -75,7 +75,10 @@ export class TestIrcServer { } public readonly clients: Record = {}; - constructor(public readonly address = DEFAULT_ADDRESS, public readonly port = DEFAULT_PORT) { } + constructor( + public readonly address = DEFAULT_ADDRESS, public readonly port = DEFAULT_PORT, + public readonly customConfig: Partial = {} + ) { } async setUp(clients = ['speaker', 'listener']) { const connections: Promise[] = []; @@ -86,6 +89,7 @@ export class TestIrcServer { autoConnect: false, connectionTimeout: 4000, debug: true, + ...this.customConfig, }); this.clients[clientName] = client; // Make sure we load isupport before reporting readyness. From f787c8c2c68b7c392fcc3ed7b38598924eda1b5d Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 10 Aug 2023 17:54:35 +0100 Subject: [PATCH 4/6] Ignore type safety problem --- src/irc.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/irc.ts b/src/irc.ts index cd9b2970..e5d8ff49 100644 --- a/src/irc.ts +++ b/src/irc.ts @@ -1697,6 +1697,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter Date: Fri, 11 Aug 2023 15:38:58 +0100 Subject: [PATCH 5/6] Never fear, generics are here --- src/irc.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/irc.ts b/src/irc.ts index e5d8ff49..0350f7c2 100644 --- a/src/irc.ts +++ b/src/irc.ts @@ -1693,12 +1693,12 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter(nick: string, key: K, value: V, onlyIfExists = false) { if (onlyIfExists && !this.state.whoisData.has(nick)) {return;} const data: WhoisResponse = this.state.whoisData.get(nick) || { nick }; - // Note: Type unsafety, it's possible we might be trying to insert a string into a string[] or vice versa. - // eslint-disable-next-line @typescript-eslint/no-explicit-any - data[key] = value as any; + data[key] = value; this.state.whoisData.set(nick, data); } From c0701d8a9f1aa25b7cf043fb1beb4f874b4f6be0 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Fri, 11 Aug 2023 15:42:35 +0100 Subject: [PATCH 6/6] Slight optimisations --- src/irc.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/irc.ts b/src/irc.ts index 0350f7c2..80eb972f 100644 --- a/src/irc.ts +++ b/src/irc.ts @@ -1696,10 +1696,15 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter(nick: string, key: K, value: V, onlyIfExists = false) { - if (onlyIfExists && !this.state.whoisData.has(nick)) {return;} - const data: WhoisResponse = this.state.whoisData.get(nick) || { nick }; + let data: WhoisResponse|undefined = this.state.whoisData.get(nick); + if (onlyIfExists && !data) { + return; + } + else if (!data) { + data = { nick }; + this.state.whoisData.set(nick, data); + } data[key] = value; - this.state.whoisData.set(nick, data); } private _clearWhoisData(nick: string) {