From 621ba2ca3aa9b65a6ef137be4f3b383b38bef700 Mon Sep 17 00:00:00 2001 From: Romybron <66818801+Romybron@users.noreply.github.com> Date: Tue, 9 Nov 2021 19:05:34 +0100 Subject: [PATCH] Add missing tags for `ClearChat` and `UserNotice` (#309) * Add missing tags for `ClearChat` and `UserNotice` * Update following d-fischer's feedback Co-authored-by: Romybron <> --- packages/chat/src/ChatClient.ts | 22 +++++++++++++------ .../twitchCommands/messageTypes/ClearChat.ts | 8 +++++++ .../twitchCommands/messageTypes/UserNotice.ts | 4 ++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/chat/src/ChatClient.ts b/packages/chat/src/ChatClient.ts index 35ec12e57..c060be0a6 100644 --- a/packages/chat/src/ChatClient.ts +++ b/packages/chat/src/ChatClient.ts @@ -183,8 +183,10 @@ export class ChatClient extends IrcClient { * @param channel The channel the user is timed out from. * @param user The timed out user. * @param duration The duration of the timeout, in seconds. + * @param msg The full message object containing all message and user information. */ - readonly onTimeout: EventBinder<[channel: string, user: string, duration: number]> = this.registerEvent(); + readonly onTimeout: EventBinder<[channel: string, user: string, duration: number, msg: ClearChat]> = + this.registerEvent(); /** * Fires when a user is permanently banned from a channel. @@ -192,8 +194,9 @@ export class ChatClient extends IrcClient { * @eventListener * @param channel The channel the user is banned from. * @param user The banned user. + * @param msg The full message object containing all message and user information. */ - readonly onBan: EventBinder<[channel: string, user: string]> = this.registerEvent(); + readonly onBan: EventBinder<[channel: string, user: string, msg: ClearChat]> = this.registerEvent(); /** * Fires when a user upgrades their bits badge in a channel. @@ -213,8 +216,9 @@ export class ChatClient extends IrcClient { * * @eventListener * @param channel The channel whose chat is cleared. + * @param msg The full message object containing all message and user information. */ - readonly onChatClear: EventBinder<[channel: string]> = this.registerEvent(); + readonly onChatClear: EventBinder<[channel: string, msg: ClearChat]> = this.registerEvent(); /** * Fires when emote-only mode is toggled in a channel. @@ -831,20 +835,24 @@ export class ChatClient extends IrcClient { } }); - this.onTypedMessage(ClearChat, ({ params: { channel, user }, tags }) => { + this.onTypedMessage(ClearChat, msg => { + const { + params: { channel, user }, + tags + } = msg; if (user) { const duration = tags.get('ban-duration'); if (duration === undefined) { // ban - this.emit(this.onBan, channel, user); + this.emit(this.onBan, channel, user, msg); } else { // timeout - this.emit(this.onTimeout, channel, user, Number(duration)); + this.emit(this.onTimeout, channel, user, Number(duration), msg); this.emit(this._onTimeoutResult, channel, user, Number(duration)); } } else { // full chat clear - this.emit(this.onChatClear, channel); + this.emit(this.onChatClear, channel, msg); } }); diff --git a/packages/chat/src/caps/twitchCommands/messageTypes/ClearChat.ts b/packages/chat/src/caps/twitchCommands/messageTypes/ClearChat.ts index f99e7d773..726dda0eb 100644 --- a/packages/chat/src/caps/twitchCommands/messageTypes/ClearChat.ts +++ b/packages/chat/src/caps/twitchCommands/messageTypes/ClearChat.ts @@ -14,4 +14,12 @@ export class ClearChat extends Message { optional: true }) user!: MessageParam; + + get channelId(): string { + return this._tags.get('room-id')!; + } + + get targetUserId(): string | null { + return this._tags.get('target-user-id') ?? null; + } } diff --git a/packages/chat/src/caps/twitchCommands/messageTypes/UserNotice.ts b/packages/chat/src/caps/twitchCommands/messageTypes/UserNotice.ts index 2226d2c7c..9a1e72091 100644 --- a/packages/chat/src/caps/twitchCommands/messageTypes/UserNotice.ts +++ b/packages/chat/src/caps/twitchCommands/messageTypes/UserNotice.ts @@ -18,6 +18,10 @@ export class UserNotice extends Message { }) message!: MessageParam; + get id(): string { + return this._tags.get('id')!; + } + get userInfo(): ChatUser { return new ChatUser(this._tags.get('login')!, this._tags); }