@twurple/eventsub-base
Version:
Base for the other Twurple EventSub packages
131 lines (130 loc) • 4.25 kB
JavaScript
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 a Hype Train starting in a channel.
*/
let EventSubChannelHypeTrainBeginV2Event = class EventSubChannelHypeTrainBeginV2Event 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 EventSubChannelHypeTrainBeginV2Event#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 EventSubChannelHypeTrainBeginV2Event#isSharedTrain} is `false`.
*/
get sharedTrainParticipants() {
return (mapNullable(this[rawDataSymbol].shared_train_participants, data => data.map(participant => new EventSubChannelHypeTrainSharedParticipant(participant, this._client))) ?? []);
}
/**
* The all-time high level this type of Hype Train has reached for this broadcaster.
*/
get allTimeHighLevel() {
return this[rawDataSymbol].all_time_high_level;
}
/**
* The all-time high total this type of Hype Train has reached for this broadcaster.
*/
get allTimeHighTotal() {
return this[rawDataSymbol].all_time_high_total;
}
/**
* 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)
], EventSubChannelHypeTrainBeginV2Event.prototype, "_client", void 0);
EventSubChannelHypeTrainBeginV2Event = __decorate([
rtfm('eventsub-base', 'EventSubChannelHypeTrainBeginV2Event', 'broadcasterId')
], EventSubChannelHypeTrainBeginV2Event);
export { EventSubChannelHypeTrainBeginV2Event };