/
EventSubChannelPredictionBeginEvent.ts
82 lines (71 loc) · 2.2 KB
/
EventSubChannelPredictionBeginEvent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { Enumerable } from '@d-fischer/shared-utils';
import type { ApiClient, HelixUser } from '@twurple/api';
import { checkRelationAssertion, DataObject, rawDataSymbol, rtfm } from '@twurple/common';
import { EventSubChannelPredictionBeginOutcome } from './common/EventSubChannelPredictionBeginOutcome';
import { type EventSubChannelPredictionBeginEventData } from './EventSubChannelPredictionBeginEvent.external';
/**
* An EventSub event representing a prediction starting in a channel.
*/
@rtfm<EventSubChannelPredictionBeginEvent>('eventsub-base', 'EventSubChannelPredictionBeginEvent', 'broadcasterId')
export class EventSubChannelPredictionBeginEvent extends DataObject<EventSubChannelPredictionBeginEventData> {
/** @internal */ @Enumerable(false) private readonly _client: ApiClient;
/** @internal */
constructor(data: EventSubChannelPredictionBeginEventData, client: ApiClient) {
super(data);
this._client = client;
}
/**
* The ID of the prediction.
*/
get id(): string {
return this[rawDataSymbol].id;
}
/**
* The ID of the broadcaster.
*/
get broadcasterId(): string {
return this[rawDataSymbol].broadcaster_user_id;
}
/**
* The name of the broadcaster.
*/
get broadcasterName(): string {
return this[rawDataSymbol].broadcaster_user_login;
}
/**
* The display name of the broadcaster.
*/
get broadcasterDisplayName(): string {
return this[rawDataSymbol].broadcaster_user_name;
}
/**
* Gets more information about the broadcaster.
*/
async getBroadcaster(): Promise<HelixUser> {
return checkRelationAssertion(await this._client.users.getUserById(this[rawDataSymbol].broadcaster_user_id));
}
/**
* The title of the prediction.
*/
get title(): string {
return this[rawDataSymbol].title;
}
/**
* The possible outcomes of the prediction.
*/
get outcomes(): EventSubChannelPredictionBeginOutcome[] {
return this[rawDataSymbol].outcomes.map(data => new EventSubChannelPredictionBeginOutcome(data));
}
/**
* The time when the prediction started.
*/
get startDate(): Date {
return new Date(this[rawDataSymbol].started_at);
}
/**
* The time when the prediction is locked.
*/
get lockDate(): Date {
return new Date(this[rawDataSymbol].locks_at);
}
}