Skip to content

Commit d869558

Browse files
committed
feat(plugins/topic): rename some events for better consistency
1 parent 8a25f0b commit d869558

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

plugins/topic.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
import { type Message, parseSource, type Source } from "../core/parsers.ts";
22
import { createPlugin } from "../core/plugins.ts";
33

4-
export interface TopicChangeEventParams {
4+
export interface TopicEventParams {
55
/** Channel where the topic is set. */
66
channel: string;
77

88
/** New topic of the channel. */
9-
topic: string;
9+
topic?: string;
1010
}
1111

12-
export type TopicChangeEvent = Message<TopicChangeEventParams>;
12+
export type TopicEvent = Message<TopicEventParams>;
1313

14-
export interface TopicSetEventParams {
15-
/** Channel where the topic is set. */
16-
channel: string;
17-
18-
/** New topic of the channel. */
19-
topic: string | undefined;
20-
}
21-
22-
export type TopicSetEvent = Message<TopicSetEventParams>;
14+
export type TopicReplyEvent = Message<TopicEventParams>;
2315

24-
export interface TopicSetByEventParams {
16+
export interface TopicWhoTimeReplyEventParams {
2517
/** Channel where the topic is set. */
2618
channel: string;
2719

@@ -32,7 +24,7 @@ export interface TopicSetByEventParams {
3224
time: Date;
3325
}
3426

35-
export type TopicSetByEvent = Message<TopicSetByEventParams>;
27+
export type TopicWhoTimeReplyEvent = Message<TopicWhoTimeReplyEventParams>;
3628

3729
interface TopicFeatures {
3830
commands: {
@@ -43,9 +35,9 @@ interface TopicFeatures {
4335
topic(channel: string, topic: string): void;
4436
};
4537
events: {
46-
"topic_change": TopicChangeEvent;
47-
"topic_set": TopicSetEvent;
48-
"topic_set_by": TopicSetByEvent;
38+
"topic": TopicEvent;
39+
"topic_reply": TopicReplyEvent;
40+
"topic_who_time_reply": TopicWhoTimeReplyEvent;
4941
};
5042
}
5143

@@ -56,32 +48,35 @@ export default createPlugin("topic")<TopicFeatures>((client) => {
5648
client.send("TOPIC", ...params);
5749
};
5850

59-
// Emits 'topic_change' event.
51+
// Emits 'topic' event.
6052

6153
client.on("raw:topic", (msg) => {
6254
const { source, params: [channel, topic] } = msg;
63-
client.emit("topic_change", { source, params: { channel, topic } });
55+
client.emit("topic", { source, params: { channel, topic } });
6456
});
6557

66-
// Emits 'topic_set' event.
58+
// Emits 'topic_reply' event.
6759

6860
client.on("raw:rpl_topic", (msg) => {
6961
const { source, params: [, channel, topic] } = msg;
70-
client.emit("topic_set", { source, params: { channel, topic } });
62+
client.emit("topic_reply", { source, params: { channel, topic } });
7163
});
7264

7365
client.on("raw:rpl_notopic", (msg) => {
7466
const { source, params: [, channel] } = msg;
7567
const topic = undefined;
76-
client.emit("topic_set", { source, params: { channel, topic } });
68+
client.emit("topic_reply", { source, params: { channel, topic } });
7769
});
7870

79-
// Emits 'topic_set_by' event.
71+
// Emits 'topic_reply_by' event.
8072

8173
client.on("raw:rpl_topicwhotime", (msg) => {
8274
const { source, params: [, channel, mask, timestamp] } = msg;
8375
const time = new Date(parseInt(timestamp, 10) * 1000);
8476
const who = parseSource(mask);
85-
client.emit("topic_set_by", { source, params: { channel, who, time } });
77+
client.emit("topic_who_time_reply", {
78+
source,
79+
params: { channel, who, time },
80+
});
8681
});
8782
});

plugins/topic_test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("plugins/topic", (test) => {
2020
const { client, server } = await mock();
2121

2222
server.send(":someone!user@host TOPIC #channel :Welcome to #channel");
23-
const msg = await client.once("topic_change");
23+
const msg = await client.once("topic");
2424

2525
assertEquals(msg, {
2626
source: { name: "someone", mask: { user: "user", host: "host" } },
@@ -32,7 +32,7 @@ describe("plugins/topic", (test) => {
3232
const { client, server } = await mock();
3333

3434
server.send(":serverhost 332 me #channel :Welcome to #channel");
35-
const msg = await client.once("topic_set");
35+
const msg = await client.once("topic_reply");
3636

3737
assertEquals(msg, {
3838
source: { name: "serverhost" },
@@ -44,7 +44,7 @@ describe("plugins/topic", (test) => {
4444
const { client, server } = await mock();
4545

4646
server.send(":serverhost 331 me #channel :No topic is set");
47-
const msg = await client.once("topic_set");
47+
const msg = await client.once("topic_reply");
4848

4949
assertEquals(msg, {
5050
source: { name: "serverhost" },
@@ -56,7 +56,7 @@ describe("plugins/topic", (test) => {
5656
const { client, server } = await mock();
5757

5858
server.send(":serverhost 333 me #channel someone!user@host :1596564019");
59-
const msg = await client.once("topic_set_by");
59+
const msg = await client.once("topic_who_time_reply");
6060

6161
assertEquals(msg, {
6262
source: { name: "serverhost" },

0 commit comments

Comments
 (0)