/
HelixSchedule.ts
73 lines (62 loc) · 2.05 KB
/
HelixSchedule.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
import { Enumerable } from '@d-fischer/shared-utils';
import { checkRelationAssertion, DataObject, rawDataSymbol, rtfm } from '@twurple/common';
import { type BaseApiClient } from '../../client/BaseApiClient';
import { type HelixScheduleData } from '../../interfaces/endpoints/schedule.external';
import type { HelixUser } from '../user/HelixUser';
import { HelixScheduleSegment } from './HelixScheduleSegment';
/**
* A schedule of a channel.
*/
@rtfm<HelixSchedule>('api', 'HelixSchedule', 'broadcasterId')
export class HelixSchedule extends DataObject<HelixScheduleData> {
/** @internal */ @Enumerable(false) private readonly _client: BaseApiClient;
/** @internal */
constructor(data: HelixScheduleData, client: BaseApiClient) {
super(data);
this._client = client;
}
/**
* The segments of the schedule.
*/
get segments(): HelixScheduleSegment[] {
return this[rawDataSymbol].segments?.map(data => new HelixScheduleSegment(data, this._client)) ?? [];
}
/**
* The ID of the broadcaster.
*/
get broadcasterId(): string {
return this[rawDataSymbol].broadcaster_id;
}
/**
* The name of the broadcaster.
*/
get broadcasterName(): string {
return this[rawDataSymbol].broadcaster_login;
}
/**
* The display name of the broadcaster.
*/
get broadcasterDisplayName(): string {
return this[rawDataSymbol].broadcaster_name;
}
/**
* Gets more information about the broadcaster.
*/
async getBroadcaster(): Promise<HelixUser> {
return checkRelationAssertion(await this._client.users.getUserById(this[rawDataSymbol].broadcaster_id));
}
/**
* The date when the current vacation started, or null if the schedule is not in vacation mode.
*/
get vacationStartDate(): Date | null {
const timestamp = this[rawDataSymbol].vacation?.start_time;
return timestamp ? new Date(timestamp) : null;
}
/**
* The date when the current vacation ends, or null if the schedule is not in vacation mode.
*/
get vacationEndDate(): Date | null {
const timestamp = this[rawDataSymbol].vacation?.end_time;
return timestamp ? new Date(timestamp) : null;
}
}