Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing tags for ClearChat and UserNotice #309

Merged
merged 3 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 15 additions & 7 deletions packages/chat/src/ChatClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,20 @@ 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.
*
* @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.
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ export class ClearChat extends Message<ClearChat> {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export class UserNotice extends Message<UserNotice> {
})
message!: MessageParam;

get id(): string {
return this._tags.get('id')!;
}

get userInfo(): ChatUser {
return new ChatUser(this._tags.get('login')!, this._tags);
}
Expand Down