Skip to content

Commit 22e70bb

Browse files
committed
feat(plugins): allow to provide a ctcp version string
1 parent fdfea68 commit 22e70bb

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

client_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Deno.test("client options", async () => {
2222
clientinfo: true,
2323
ping: true,
2424
time: true,
25-
version: true,
25+
version: "deno-irc",
2626
},
2727
debug: false,
2828
resolveInvalidNames: false,

plugins/version.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import { createCtcp } from "./ctcp.ts";
66
export interface VersionParams {
77
options: {
88
ctcpReplies?: {
9-
/** Replies to CTCP VERSION. */
10-
version?: boolean;
9+
/**
10+
* Replies to CTCP VERSION with the given string.
11+
*
12+
* Default to `"deno-irc"`. `false` to disable.
13+
*/
14+
version?: string | false;
1115
};
1216
};
1317
commands: {
@@ -38,7 +42,7 @@ export interface CtcpVersionReply {
3842

3943
function options(client: ExtendedClient<VersionParams>) {
4044
client.options.ctcpReplies ??= {};
41-
client.options.ctcpReplies.version ??= true;
45+
client.options.ctcpReplies.version ??= "deno-irc";
4246
}
4347

4448
function commands(
@@ -81,12 +85,14 @@ function events(
8185
}
8286

8387
function replies(client: ExtendedClient<VersionParams>) {
84-
if (!client.options.ctcpReplies?.version) {
88+
const version = client.options.ctcpReplies?.version;
89+
90+
if (!version) {
8591
return;
8692
}
8793

8894
client.on("ctcp_version", (msg) => {
89-
client.send("NOTICE", msg.origin.nick, createCtcp("VERSION", "deno-irc"));
95+
client.send("NOTICE", msg.origin.nick, createCtcp("VERSION", version));
9096
});
9197
}
9298

plugins/version_test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Deno.test("version events", async () => {
5151
Deno.test("version replies", async () => {
5252
const { server, client, sanitize } = arrange(
5353
[ctcp, version],
54-
{ ctcpReplies: { version: true } },
54+
{ ctcpReplies: { version: "custom version" } },
5555
);
5656

5757
server.listen();
@@ -60,7 +60,24 @@ Deno.test("version replies", async () => {
6060

6161
server.send(":nick2!user@host PRIVMSG nick :\u0001VERSION\u0001");
6262
const raw = await server.once("NOTICE");
63-
assertEquals(raw, "NOTICE nick2 :\u0001VERSION deno-irc\u0001");
63+
assertEquals(raw, "NOTICE nick2 :\u0001VERSION custom version\u0001");
64+
65+
await sanitize();
66+
});
67+
68+
Deno.test("version replies (disabled)", async () => {
69+
const { server, client, sanitize } = arrange(
70+
[ctcp, version],
71+
{ ctcpReplies: { version: false } },
72+
);
73+
74+
server.listen();
75+
client.connect(server.host, server.port);
76+
await server.waitClient();
77+
78+
server.send(":nick2!user@host PRIVMSG nick :\u0001VERSION\u0001");
79+
const raw = await server.wait("NOTICE", 10);
80+
assertEquals(raw, null);
6481

6582
await sanitize();
6683
});

0 commit comments

Comments
 (0)