-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
271 lines (243 loc) · 8.52 KB
/
index.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import fetch from 'node-fetch';
import throttle from 'fetch-throttle';
const fetchMCC = throttle(fetch, 200, 60 * 1000);
export default class MCCAPI {
private static BASE_URL = "https://api.mcchampionship.com/v1";
private static async request(endpoint: string): Promise<unknown> {
const response = await fetchMCC(`${this.BASE_URL}/${endpoint}`)
return await response.json()
}
/**
* Returns event information about the current event cycle.
*/
public static async getEventInformation(): Promise<EventInformationResponse> {
return await this.request("event") as EventInformationResponse;
}
public static async getValidEvents(): Promise<AllEventInformationResponse> {
return await this.request("events") as AllEventInformationResponse;
}
/**
* @deprecated This endpoint will be removed in the future as the statistics API will be changed in the future.
* See https://github.com/Noxcrew/mcchampionship-api/releases/tag/v1.3.0 for more information
*
* Returns all statistics in the legacy Hall of Fame.
* Updates at the end of each event.
*/
public static async getHallOfFameStats(): Promise<HallOfFameResponse> {
return await this.request("halloffame") as HallOfFameResponse;
}
/**
* @deprecated This endpoint will be removed in the future as the statistics API will be changed in the future.
* See https://github.com/Noxcrew/mcchampionship-api/releases/tag/v1.3.0 for more information
*
* Returns all statistics in the legacy Hall of Fame for a given game.
* Updates at the end of each event.
*
* @param game The key of the game you want statistics for
*/
public static async getHallOfFameStatsForGame(game: Game): Promise<HallOfFameGameResponse> {
return await this.request(`halloffame/${game}`) as HallOfFameGameResponse;
}
/**
* Returns summary data for the last including event scores, participants and the order of games.
*
* NOTE: Any event from Season 3 (29 and beyond) gives a full rundown of each game,
* including its game and individual scores. Events before Season 3 (28 and below) will receive this data "soon".
*/
public static async getRundown(): Promise<RundownResponse> {
return await this.request("rundown") as RundownResponse
}
/**
* Returns summary data for the event you give including event scores, participants and the order of games.
*
* NOTE: Any event from Season 3 (29 and beyond) gives a full rundown of each game,
* including its game and individual scores. Events before Season 3 (28 and below) will receive this data "soon".
*
* @param event the abbreviation of an event
*/
public static async getRundownForEvent(event: string): Promise<RundownResponse> {
return await this.request(`rundown/${event}`) as RundownResponse
}
/**
* Returns a list of all participants in the current event cycle.
*/
public static async getParticipants(): Promise<ParticipantResponse> {
return await this.request("participants") as ParticipantResponse
}
/**
* Returns a list of all participants in the given team in the current event cycle.
*
* @param team The team you want all participants of
*/
public static async getParticipantsOnTeam(team: Team): Promise<ParticipantTeamResponse> {
return await this.request(`participants/${team}`) as ParticipantTeamResponse
}
/**
* Returns a single participant in the current event cycle
*
* @param uuid The UUID (dashed or un-dashed) of the participant
*/
public static async getParticipant(uuid: String): Promise<SingleParticipantResponse> {
return await this.request(`participant/${uuid}`) as SingleParticipantResponse;
}
}
export interface BaseResponse {
/** The HTTP response code (e.g. 200, 429) */
"code": number,
/** The reason for the response, if applicable. */
"reason": string
}
export interface EventInformationResponse extends BaseResponse {
"data": {
/** The date of the event in form of a JavaScript Date object. */
"date": string,
/** The name of the next MCC. */
"event": string,
/** URL to the YouTube embed of the update video published on the Noxcrew Channel. */
"updateVideo": string
}
}
export interface AllEventInformationResponse extends BaseResponse {
"data": String[]
}
export interface HallOfFameResponse extends BaseResponse {
"data": {
[key in Game]: HallOfFameGameData
}
}
export interface HallOfFameGameResponse extends BaseResponse {
"data": HallOfFameGameData
}
export interface HallOfFameGameData {
[k: string]: {
/** The player who currently holds this record. */
"player": string,
/** The value of this record (e.g. most eliminations). */
"value": string,
// Internal mcc.live value (?)
"placement": number,
/** Whether the record has changed hands in the last MCC. */
"changedHands": boolean
}
}
export interface RundownResponse extends BaseResponse {
"data": {
"dodgeboltData": {
[key in Team]: string
},
"eventPlacements": {
[key in Team]: number
},
"eventScores": {
[key in Team]: number
},
"individualScores": {
[k: string]: number
},
"history": LegacyGameHistory | GameHistory,
"creators": {
[key in Team]: Array<String>
}
}
}
export interface ParticipantResponse extends BaseResponse {
"data": {
[key in Team]: Array<PlayerData>
}
}
export interface SingleParticipantResponse extends BaseResponse {
"data": PlayerData
}
export interface PlayerData {
/** The players Minecraft username. */
"username": string,
/** The players Minecraft UUID. */
"uuid": string,
/** The link to the players stream. */
"stream": string,
/** A link to an icon for the player. */
"icon": string,
/** The team the player is on. */
"team": Team,
/** The platform the player is streaming on. */
"platform": string,
}
export interface ParticipantTeamResponse extends BaseResponse {
"data": Array<PlayerData>
}
/** Internal keys for every MCC game */
export type Game =
"MG_ROCKET_SPLEEF"
| "MG_SURVIVAL_GAMES"
/** This key does not hold any statistics. */
| "MG_PARKOUR_WARRIOR"
| "MG_ACE_RACE"
| "MG_BINGO_BUT_FAST"
| "MG_TGTTOSAWAF"
| "MG_SKYBLOCKLE"
| "MG_SKY_BATTLE"
| "MG_HOLE_IN_THE_WALL"
| "MG_BATTLE_BOX"
| "MG_BUILD_MART"
/** This key does not hold any statistics. */
| "MG_SANDS_OF_TIME"
| "MG_DODGEBOLT"
| "MG_PARKOUR_TAG"
/** This key does not hold any statistics. */
| "MG_GRID_RUNNERS"
/** This key does not hold any statistics. */
| "MG_MELTDOWN"
| "GLOBAL_STATISTICS"
| "LEGACY_STATISTICS"
/** This key does not hold any statistics. */
| "MG_LOCKOUT_BINGO"
/** This key does not hold any statistics. */
| "MG_FOOT_RACE"
/** This key does not hold any statistics. */
| "MG_ROCKET_SPLEEF_OLD"
/** This key does not hold any statistics. */
| "MG_RAILROAD_RUSH"
export type Team = "RED" | "ORANGE" | "YELLOW" | "LIME" | "GREEN" | "CYAN" | "AQUA" | "BLUE" | "PURPLE" | "PINK"
/** This should be used for events before Season 4 */
export type LegacyGameHistory = {
/** The first game played. */
"0": GameInformation,
/** The second game played. */
"1": GameInformation,
/** The third game played. */
"2": GameInformation,
/** The forth game played. */
"3": GameInformation,
/** The fifth game played. */
"4": GameInformation,
/** The sixth game played. */
"5": GameInformation,
/** The seventh game played. */
"6": GameInformation,
/** The eighth game played. */
"7": GameInformation
}
/** This should be used for events after the start of Season 4 */
export type GameHistory = {
[key in string]: GameInformation
}
export type GameInformation = {
/** The score multiplier of the game. Values can be 1, 1.5, 2, 2.5 and 3. */
"multiplier": number,
/** The key of the game played. */
"game": Game,
/** A zero based index of when the game was played in the event. */
"index": number,
"eventScores": {
[key in Team]: number
},
"gamePlacements": {
[key in Team]: number
},
"individualScores": {
[k: string]: number
},
"eventPlacements": {
[key in Team]: number
}
}