@twurple/eventsub-base
Version:
Base for the other Twurple EventSub packages
113 lines (112 loc) • 3.61 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 the end of a Hype train event.
*/
let EventSubChannelHypeTrainEndV2Event = class EventSubChannelHypeTrainEndV2Event 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 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 EventSubChannelHypeTrainEndV2Event#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 EventSubChannelHypeTrainEndV2Event#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 ended.
*/
get endDate() {
return new Date(this[rawDataSymbol].ended_at);
}
/**
* The time when the Hype Train cooldown ends.
*/
get cooldownEndDate() {
return new Date(this[rawDataSymbol].cooldown_ends_at);
}
};
__decorate([
Enumerable(false)
], EventSubChannelHypeTrainEndV2Event.prototype, "_client", void 0);
EventSubChannelHypeTrainEndV2Event = __decorate([
rtfm('eventsub-base', 'EventSubChannelHypeTrainEndV2Event', 'broadcasterId')
], EventSubChannelHypeTrainEndV2Event);
export { EventSubChannelHypeTrainEndV2Event };