UNPKG

@twurple/eventsub-base

Version:

Base for the other Twurple EventSub packages

119 lines (118 loc) 3.89 kB
import { __decorate } from "tslib"; import { Enumerable, mapNullable } from '@d-fischer/shared-utils'; import { checkRelationAssertion, DataObject, rawDataSymbol, rtfm } from '@twurple/common'; import { EventSubChannelHypeTrainContribution } from './common/EventSubChannelHypeTrainContribution.js'; import { EventSubChannelHypeTrainSharedParticipant } from './common/EventSubChannelHypeTrainSharedParticipant.js'; /** * An EventSub event representing progress towards the Hype Train goal. */ let EventSubChannelHypeTrainProgressV2Event = class EventSubChannelHypeTrainProgressV2Event extends DataObject { /** @internal */ _client; /** @internal */ constructor(data, client) { super(data); this._client = client; } /** * The ID of the Hype Train. */ get id() { return this[rawDataSymbol].id; } /** * 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)); } /** * The type of the Hype Train. */ get type() { return this[rawDataSymbol].type; } /** * The level the Hype Train started on. */ get level() { return this[rawDataSymbol].level; } /** * The total points already contributed to the Hype Train. */ get total() { return this[rawDataSymbol].total; } /** * The number of points contributed to the Hype Train at the current level. */ get progress() { return this[rawDataSymbol].progress; } /** * The number of points required to reach the next level. */ get goal() { return this[rawDataSymbol].goal; } /** * The contributors with the most points contributed. */ get topContributors() { return this[rawDataSymbol].top_contributions.map(data => new EventSubChannelHypeTrainContribution(data, this._client)); } /** * Indicates if the Hype Train is shared. * * When `true`, {@link EventSubChannelHypeTrainProgressV2Event#sharedTrainParticipants} will contain the list of * broadcasters the train is shared with. */ get isSharedTrain() { return this[rawDataSymbol].is_shared_train; } /** * The list of broadcasters in the shared Hype Train. * * Empty if {@link EventSubChannelHypeTrainProgressV2Event#isSharedTrain} is `false`. */ get sharedTrainParticipants() { return (mapNullable(this[rawDataSymbol].shared_train_participants, data => data.map(participant => new EventSubChannelHypeTrainSharedParticipant(participant, this._client))) ?? []); } /** * The time when the Hype Train started. */ get startDate() { return new Date(this[rawDataSymbol].started_at); } /** * The time when the Hype Train is expected to expire, unless a change of level occurs to extend the expiration. */ get expiryDate() { return new Date(this[rawDataSymbol].expires_at); } }; __decorate([ Enumerable(false) ], EventSubChannelHypeTrainProgressV2Event.prototype, "_client", void 0); EventSubChannelHypeTrainProgressV2Event = __decorate([ rtfm('eventsub-base', 'EventSubChannelHypeTrainProgressV2Event', 'broadcasterId') ], EventSubChannelHypeTrainProgressV2Event); export { EventSubChannelHypeTrainProgressV2Event };