/
HelixGame.ts
80 lines (71 loc) · 2.36 KB
/
HelixGame.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
import { Enumerable } from '@d-fischer/shared-utils';
import { DataObject, rawDataSymbol, rtfm } from '@twurple/common';
import { type BaseApiClient } from '../../client/BaseApiClient';
import { type HelixGameData } from '../../interfaces/endpoints/game.external';
import { type HelixStreamData } from '../../interfaces/endpoints/stream.external';
import type { HelixPaginatedRequest } from '../../utils/pagination/HelixPaginatedRequest';
import type { HelixPaginatedResult } from '../../utils/pagination/HelixPaginatedResult';
import type { HelixPagination } from '../../utils/pagination/HelixPagination';
import type { HelixStream } from '../stream/HelixStream';
/**
* A game as displayed on Twitch.
*/
@rtfm<HelixGame>('api', 'HelixGame', 'id')
export class HelixGame extends DataObject<HelixGameData> {
/** @internal */ @Enumerable(false) private readonly _client: BaseApiClient;
/** @internal */
constructor(data: HelixGameData, client: BaseApiClient) {
super(data);
this._client = client;
}
/**
* The ID of the game.
*/
get id(): string {
return this[rawDataSymbol].id;
}
/**
* The name of the game.
*/
get name(): string {
return this[rawDataSymbol].name;
}
/**
* The URL of the box art of the game.
*/
get boxArtUrl(): string {
return this[rawDataSymbol].box_art_url;
}
/**
* The IGDB ID of the game, or null if the game doesn't have an IGDB ID assigned at Twitch.
*/
get igdbId(): string | null {
return this[rawDataSymbol].igdb_id || null;
}
/**
* Builds the URL of the box art of the game using the given dimensions.
*
* @param width The width of the box art.
* @param height The height of the box art.
*/
getBoxArtUrl(width: number, height: number): string {
return this[rawDataSymbol].box_art_url
.replace('{width}', width.toString())
.replace('{height}', height.toString());
}
/**
* Gets streams that are currently playing the game.
*
* @param pagination
* @expandParams
*/
async getStreams(pagination?: HelixPagination): Promise<HelixPaginatedResult<HelixStream>> {
return await this._client.streams.getStreams({ ...pagination, game: this[rawDataSymbol].id });
}
/**
* Creates a paginator for streams that are currently playing the game.
*/
getStreamsPaginated(): HelixPaginatedRequest<HelixStreamData, HelixStream> {
return this._client.streams.getStreamsPaginated({ game: this[rawDataSymbol].id });
}
}