11import { type Message , parseSource , type Source } from "../core/parsers.ts" ;
22import { 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
3729interface 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} ) ;
0 commit comments