UNPKG

@twurple/eventsub-base

Version:

Base for the other Twurple EventSub packages

126 lines (125 loc) 3.87 kB
import { __decorate } from "tslib"; import { Enumerable, groupBy } from '@d-fischer/shared-utils'; import { checkRelationAssertion, DataObject, rawDataSymbol, rtfm } from '@twurple/common'; /** * An EventSub event representing an automatic reward being redeemed by a user in a channel. */ let EventSubChannelAutomaticRewardRedemptionAddEvent = class EventSubChannelAutomaticRewardRedemptionAddEvent extends DataObject { /** @internal */ _client; /** @internal */ constructor(data, client) { super(data); this._client = client; } /** * The ID of the redemption. */ get id() { return this[rawDataSymbol].id; } /** * The ID of the broadcaster in whose channel the reward was redeemed. */ get broadcasterId() { return this[rawDataSymbol].broadcaster_user_id; } /** * The name of the broadcaster in whose channel the reward was redeemed. */ get broadcasterName() { return this[rawDataSymbol].broadcaster_user_login; } /** * The display name of the broadcaster in whose channel the reward was redeemed. */ 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)); } /** * The ID of the redeeming user. */ get userId() { return this[rawDataSymbol].user_id; } /** * The name of the redeeming user. */ get userName() { return this[rawDataSymbol].user_login; } /** * The display name of the redeeming user. */ get userDisplayName() { return this[rawDataSymbol].user_name; } /** * Gets more information about the redeeming user. */ async getUser() { return checkRelationAssertion(await this._client.users.getUserById(this[rawDataSymbol].user_id)); } /** * The type of the reward. */ get rewardType() { return this[rawDataSymbol].reward.type; } /** * The cost of the reward. */ get rewardCost() { return this[rawDataSymbol].reward.cost; } /** * The emote that was unlocked by the corresponding rewards, or `null` if this field is not relevant. */ get unlockedEmote() { return this[rawDataSymbol].reward.unlocked_emote; } /** * The input text given by the user. * * If there is no input to be given, this is an empty string. */ get input() { return this[rawDataSymbol].user_input || null; } /** * The text of the message, or `null` if there is no message. */ get messageText() { return this[rawDataSymbol].message?.text ?? null; } /** * The offsets of emote usages in the message, or `null` if there is no message. */ get emoteOffsets() { if (this[rawDataSymbol].message) { return new Map(Object.entries(groupBy(this[rawDataSymbol].message.emotes, 'id')).map(([id, ranges]) => [ id, ranges.map(({ begin, end }) => `${begin}-${end}`), ])); } return null; } /** * The date when the user redeemed the reward. */ get redemptionDate() { return new Date(this[rawDataSymbol].redeemed_at); } }; __decorate([ Enumerable(false) ], EventSubChannelAutomaticRewardRedemptionAddEvent.prototype, "_client", void 0); EventSubChannelAutomaticRewardRedemptionAddEvent = __decorate([ rtfm('eventsub-base', 'EventSubChannelAutomaticRewardRedemptionAddEvent', 'id') ], EventSubChannelAutomaticRewardRedemptionAddEvent); export { EventSubChannelAutomaticRewardRedemptionAddEvent };