UNPKG

@twurple/eventsub-base

Version:

Base for the other Twurple EventSub packages

199 lines (198 loc) 7.17 kB
import { __decorate } from "tslib"; import { Enumerable } from '@d-fischer/shared-utils'; import { checkRelationAssertion, DataObject, rawDataSymbol, rtfm } from '@twurple/common'; /** * An EventSub event representing a notification being sent to a channel's chat. */ let EventSubChannelChatBaseNotificationEvent = class EventSubChannelChatBaseNotificationEvent extends DataObject { /** @internal */ _client; /** @internal */ constructor(data, client) { super(data); this._client = client; } /** * The ID of the broadcaster. */ get broadcasterId() { return this[rawDataSymbol].broadcaster_user_id; } /** * The name of the broadcaster. */ get broadcasterName() { return this[rawDataSymbol].broadcaster_user_login; } /** * The display name of the broadcaster. */ get broadcasterDisplayName() { return this[rawDataSymbol].broadcaster_user_name; } /** * Gets more information about the broadcaster. */ async getBroadcaster() { return checkRelationAssertion(await this._client.users.getUserById(this[rawDataSymbol].broadcaster_user_id)); } /** * Whether the chatter is anonymous. * * Only applies to some event types like sub gifts. */ get chatterIsAnonymous() { return this[rawDataSymbol].chatter_is_anonymous; } /** * The ID of the chatter. */ get chatterId() { return this[rawDataSymbol].chatter_user_id; } /** * The name of the chatter. */ get chatterName() { return this[rawDataSymbol].chatter_user_login; } /** * The display name of the chatter. */ get chatterDisplayName() { return this[rawDataSymbol].chatter_user_name; } /** * Gets more information about the chatter. */ async getChatter() { return checkRelationAssertion(await this._client.users.getUserById(this[rawDataSymbol].chatter_user_id)); } /** * The color of the chatter, or null if they didn't choose a color. */ get color() { return this[rawDataSymbol].color || null; } /** * The badges the chatter has. * * The returned object contains the badge names as keys and the badge versions as the respective values. */ get badges() { return Object.fromEntries(this[rawDataSymbol].badges.map(badge => [badge.set_id, badge.id])); } /** * Checks whether the chatter has the specified badge. * * @param name The name of the badge to check. */ hasBadge(name) { return this[rawDataSymbol].badges.some(badge => badge.set_id === name); } /** * Gets the badge info for a specified badge, or null if the badge does not exist. * * @param name The name of the badge to get info for. */ getBadgeInfo(name) { return this[rawDataSymbol].badges.find(badge => badge.set_id === name)?.info ?? null; } /** * The ID of the notification message. */ get messageId() { return this[rawDataSymbol].message_id; } /** * The text that was sent with the notification, e.g. the resub message or announcement text. */ get messageText() { return this[rawDataSymbol].message.text; } /** * The text that was sent with the notification, structured into pre-parsed parts. */ get messageParts() { return this[rawDataSymbol].message.fragments; } /** * The ID of the broadcaster from whose channel the message was sent. * * This only applies if a chatter sends a chat message in another channel's chat during a shared chat session. * Is `null` when the message notification happens in the same channel as the broadcaster. */ get sourceBroadcasterId() { return this[rawDataSymbol].source_broadcaster_user_id; } /** * The name of the broadcaster from whose channel the message was sent. * * This only applies if a chatter sends a chat message in another channel's chat during a shared chat session. * Is `null` when the message notification happens in the same channel as the broadcaster. */ get sourceBroadcasterName() { return this[rawDataSymbol].source_broadcaster_user_login; } /** * The display name of the broadcaster from whose channel the message was sent. * * This only applies if a chatter sends a chat message in another channel's chat during a shared chat session. * Is `null` when the message notification happens in the same channel as the broadcaster. */ get sourceBroadcasterDisplayName() { return this[rawDataSymbol].source_broadcaster_user_name; } /** * The UUID that identifies the source message from the channel the message was sent. * * This only applies if a chatter sends a chat message in another channel's chat during a shared chat session. * Is `null` when the message happens in the same channel as the broadcaster. */ get sourceMessageId() { return this[rawDataSymbol].source_message_id; } /** * The chat badges for the chatter in the channel the message was sent from. * * The returned object contains the badge names as keys and the badge versions as the respective values. * * This only applies if a chatter sends a chat message in another channel's chat during a shared chat session. * Is `null` when the message happens in the same channel as the broadcaster. */ get sourceBadges() { return this[rawDataSymbol].source_badges ? Object.fromEntries(this[rawDataSymbol].source_badges.map(badge => [badge.set_id, badge.id])) : null; } /** * Checks whether the chatter has the specified badge. * * This only applies if a chatter sends a chat message to another chat during a shared chat session. * Is `null` when the message happens in the same channel as the broadcaster. * * @param name The name of the badge to check. */ hasSourceBadge(name) { return this[rawDataSymbol].source_badges ? this[rawDataSymbol].source_badges.some(badge => badge.set_id === name) : null; } /** * Gets the badge info for a specified badge. * * This only applies if a chatter sends a chat message in another channel's chat during a shared chat session. * Is `null` when the message happens in the same channel as the broadcaster, or if the badge does not exist. * * @param name The name of the badge to get info for. */ getSourceBadgeInfo(name) { return this[rawDataSymbol].source_badges?.find(badge => badge.set_id === name)?.info ?? null; } }; __decorate([ Enumerable(false) ], EventSubChannelChatBaseNotificationEvent.prototype, "_client", void 0); EventSubChannelChatBaseNotificationEvent = __decorate([ rtfm('eventsub-base', 'EventSubChannelChatBaseNotificationEvent', 'broadcasterId') ], EventSubChannelChatBaseNotificationEvent); export { EventSubChannelChatBaseNotificationEvent };