Skip to content

Commit c7d9c8d

Browse files
committed
feat(plugins/names): add 'multi-prefix' capability
1 parent ea8edf7 commit c7d9c8d

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

client_test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe("client", (test) => {
4343
user: { nick: "me", username: "user", realname: "real name" },
4444
supported: getDefaults(),
4545
nicklists: {},
46+
capabilities: ["multi-prefix"],
4647
});
4748

4849
// should connect to server
@@ -61,6 +62,8 @@ describe("client", (test) => {
6162
raw = server.receive();
6263

6364
assertEquals(raw, [
65+
"CAP REQ multi-prefix",
66+
"CAP END",
6467
"PASS password",
6568
"NICK me",
6669
"USER user 0 * :real name",

plugins/names.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type Plugin } from "../core/client.ts";
22
import { type Raw } from "../core/parsers.ts";
33
import { type IsupportParams } from "./isupport.ts";
4+
import { type RegistrationParams } from "./registration.ts";
45

56
export type Names = Record<string, string[]>;
67

@@ -22,7 +23,11 @@ export interface NamesParams {
2223
};
2324
}
2425

25-
export const namesPlugin: Plugin<IsupportParams & NamesParams> = (client) => {
26+
export const namesPlugin: Plugin<
27+
& RegistrationParams
28+
& IsupportParams
29+
& NamesParams
30+
> = (client) => {
2631
const sendNamesCommand = (channels: string[]): void => {
2732
if (!Array.isArray(channels)) channels = [channels];
2833
client.send("NAMES", channels.join(","));
@@ -79,6 +84,9 @@ export const namesPlugin: Plugin<IsupportParams & NamesParams> = (client) => {
7984

8085
const buffers: Record<string, Names> = {};
8186

87+
client.state.capabilities ??= []; // TODO depends of plugins loading order
88+
client.state.capabilities.push("multi-prefix");
89+
8290
client.names = sendNamesCommand;
8391
client.on("raw", emitNamesReplyEvent);
8492
};

plugins/names_test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import { assertEquals } from "../deps.ts";
22
import { describe } from "../testing/helpers.ts";
33
import { mock } from "../testing/mock.ts";
4+
import { nickPlugin } from "./nick.ts";
5+
import { registerPlugin } from "./register.ts";
6+
import { registrationPlugin } from "./registration.ts";
47
import { isupportPlugin } from "./isupport.ts";
58
import { namesPlugin } from "./names.ts";
69

710
describe("plugins/names", (test) => {
8-
const plugins = [isupportPlugin, namesPlugin];
11+
const plugins = [
12+
nickPlugin,
13+
registerPlugin,
14+
registrationPlugin,
15+
isupportPlugin,
16+
namesPlugin,
17+
];
18+
19+
const options = { nick: "me" };
920

1021
test("send NAMES", async () => {
11-
const { client, server } = await mock(plugins, {});
22+
const { client, server } = await mock(plugins, options);
1223

1324
client.names("#channel");
1425
client.names(["#channel1", "#channel2"]);
@@ -21,7 +32,7 @@ describe("plugins/names", (test) => {
2132
});
2233

2334
test("emit 'names_reply' on RPL_ENDOFNAMES", async () => {
24-
const { client, server } = await mock(plugins, {});
35+
const { client, server } = await mock(plugins, options);
2536

2637
server.send([
2738
":serverhost 353 me = #channel :%nick1 @+nick2 +nick3",
@@ -44,7 +55,7 @@ describe("plugins/names", (test) => {
4455
});
4556

4657
test("emit 'names_reply' on RPL_ISUPPORT + RPL_ENDOFNAMES", async () => {
47-
const { client, server } = await mock(plugins, {});
58+
const { client, server } = await mock(plugins, options);
4859

4960
server.send(
5061
":serverhost 005 nick PREFIX=(qaohv)~&@%+ :are supported by this server",

0 commit comments

Comments
 (0)