hypixel-api-reborn 10.0.0 → 11.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +13 -0
- package/README.md +28 -16
- package/package.json +60 -58
- package/src/API/getAPIStatus.js +8 -8
- package/src/API/getBoosters.js +6 -6
- package/src/API/getGameCounts.js +6 -6
- package/src/API/getGuild.js +18 -18
- package/src/API/getLeaderboards.js +13 -13
- package/src/API/getPlayer.js +22 -27
- package/src/API/getRecentGames.js +18 -18
- package/src/API/getServerInfo.js +66 -77
- package/src/API/getStatus.js +8 -8
- package/src/API/getWatchdogStats.js +6 -6
- package/src/API/index.js +19 -23
- package/src/API/skyblock/getEndedSkyblockAuctions.js +10 -10
- package/src/API/skyblock/getSkyblockAuctions.js +64 -64
- package/src/API/skyblock/getSkyblockAuctionsByPlayer.js +11 -11
- package/src/API/skyblock/getSkyblockBazaar.js +10 -10
- package/src/API/skyblock/getSkyblockMember.js +28 -25
- package/src/API/skyblock/getSkyblockNews.js +6 -6
- package/src/API/skyblock/getSkyblockProfiles.js +44 -41
- package/src/Client.js +406 -450
- package/src/Errors.js +44 -39
- package/src/Private/defaultCache.js +77 -78
- package/src/Private/rateLimit.js +79 -98
- package/src/Private/requests.js +65 -54
- package/src/Private/updater.js +45 -45
- package/src/Private/uuidCache.js +37 -33
- package/src/Private/validate.js +97 -97
- package/src/index.js +82 -83
- package/src/structures/APIIncident.js +78 -78
- package/src/structures/APIStatus.js +47 -47
- package/src/structures/Boosters/Booster.js +83 -87
- package/src/structures/Color.js +129 -129
- package/src/structures/Game.js +164 -160
- package/src/structures/GameCounts.js +151 -151
- package/src/structures/Guild/Guild.js +204 -218
- package/src/structures/Guild/GuildMember.js +66 -66
- package/src/structures/Guild/GuildRank.js +48 -48
- package/src/structures/ItemBytes.js +33 -36
- package/src/structures/Leaderboard.js +31 -31
- package/src/structures/MiniGames/Arcade.js +567 -569
- package/src/structures/MiniGames/ArenaBrawl.js +52 -56
- package/src/structures/MiniGames/BedWars.js +423 -351
- package/src/structures/MiniGames/BlitzSurvivalGames.js +172 -148
- package/src/structures/MiniGames/BuildBattle.js +53 -53
- package/src/structures/MiniGames/CopsAndCrims.js +90 -90
- package/src/structures/MiniGames/Duels.js +694 -630
- package/src/structures/MiniGames/MegaWalls.js +137 -137
- package/src/structures/MiniGames/MurderMystery.js +93 -93
- package/src/structures/MiniGames/Paintball.js +67 -67
- package/src/structures/MiniGames/Pit.js +19 -19
- package/src/structures/MiniGames/Quakecraft.js +101 -101
- package/src/structures/MiniGames/SkyWars.js +508 -559
- package/src/structures/MiniGames/SmashHeroes.js +144 -151
- package/src/structures/MiniGames/SpeedUHC.js +115 -57
- package/src/structures/MiniGames/TNTGames.js +116 -116
- package/src/structures/MiniGames/TurboKartRacers.js +201 -176
- package/src/structures/MiniGames/UHC.js +164 -143
- package/src/structures/MiniGames/VampireZ.js +60 -60
- package/src/structures/MiniGames/Walls.js +52 -52
- package/src/structures/MiniGames/Warlords.js +62 -62
- package/src/structures/MiniGames/WoolWars.js +123 -0
- package/src/structures/Pet.js +96 -97
- package/src/structures/Pets.js +64 -64
- package/src/structures/Player.js +433 -449
- package/src/structures/PlayerCosmetics.js +100 -95
- package/src/structures/RecentGame.js +57 -57
- package/src/structures/ServerInfo.js +78 -78
- package/src/structures/SkyBlock/Auctions/Auction.js +104 -104
- package/src/structures/SkyBlock/Auctions/AuctionInfo.js +54 -54
- package/src/structures/SkyBlock/Auctions/BaseAuction.js +45 -45
- package/src/structures/SkyBlock/Auctions/Bid.js +48 -48
- package/src/structures/SkyBlock/Auctions/PartialAuction.js +25 -25
- package/src/structures/SkyBlock/Bazzar/Order.js +38 -38
- package/src/structures/SkyBlock/Bazzar/Product.js +53 -53
- package/src/structures/SkyBlock/News/SkyblockNews.js +60 -68
- package/src/structures/SkyBlock/SkyblockInventoryItem.js +124 -130
- package/src/structures/SkyBlock/SkyblockMember.js +820 -687
- package/src/structures/SkyBlock/SkyblockPet.js +71 -71
- package/src/structures/SkyBlock/SkyblockProfile.js +60 -60
- package/src/structures/Status.js +41 -41
- package/src/structures/Watchdog/Stats.js +36 -36
- package/src/utils/Constants.js +2789 -809
- package/src/utils/SkyblockUtils.js +208 -164
- package/src/utils/arrayTools.js +4 -4
- package/src/utils/divide.js +5 -5
- package/src/utils/guildExp.js +57 -67
- package/src/utils/index.js +13 -13
- package/src/utils/isGuildID.js +3 -3
- package/src/utils/isUUID.js +5 -5
- package/src/utils/oscillation.js +15 -23
- package/src/utils/removeSnakeCase.js +22 -35
- package/src/utils/rgbToHexColor.js +8 -8
- package/src/utils/romanize.js +11 -13
- package/src/utils/toIGN.js +20 -20
- package/src/utils/toUuid.js +19 -19
- package/src/utils/varInt.js +17 -21
- package/typings/index.d.ts +3532 -2644
- package/src/API/getFriends.js +0 -14
- package/src/API/getKeyInfo.js +0 -10
- package/src/API/getRankedSkyWars.js +0 -11
- package/src/structures/Friend.js +0 -38
- package/src/structures/KeyInfo.js +0 -42
- package/src/structures/MiniGames/SkyWarsRanked.js +0 -45
package/src/Client.js
CHANGED
|
@@ -1,450 +1,406 @@
|
|
|
1
|
-
/* eslint-disable require-jsdoc */
|
|
2
|
-
/* eslint-disable max-len */
|
|
3
|
-
const validate = new (require('./Private/validate'))();
|
|
4
|
-
const rateLimit = new (require('./Private/rateLimit'))();
|
|
5
|
-
const Requests = require('./Private/requests');
|
|
6
|
-
const updater = new (require('./Private/updater'))();
|
|
7
|
-
const Errors = require('./Errors');
|
|
8
|
-
const API = require('./API/index');
|
|
9
|
-
const EventEmitter = require('events');
|
|
10
|
-
const clients = [];
|
|
11
|
-
/**
|
|
12
|
-
* Client class
|
|
13
|
-
*/
|
|
14
|
-
class Client extends EventEmitter {
|
|
15
|
-
/**
|
|
16
|
-
* @param {string} key API key [(?)](https://stavzdev.is-inside.me/cCMiZdoy.gif)
|
|
17
|
-
* @param {ClientOptions} [options={}] Client options
|
|
18
|
-
*/
|
|
19
|
-
constructor
|
|
20
|
-
super();
|
|
21
|
-
this.requests = new Requests(this, options.cacheHandler);
|
|
22
|
-
// eslint-disable-next-line no-console
|
|
23
|
-
if (options && !options.silent) this.on('warn', console.warn);
|
|
24
|
-
// Test to check for multiple instances of client
|
|
25
|
-
if (clients.find((x) => x.key === key)) {
|
|
26
|
-
this.emit('warn', Errors.MULTIPLE_INSTANCES);
|
|
27
|
-
return clients.find((x) => x.key === key);
|
|
28
|
-
}
|
|
29
|
-
validate.validateNodeVersion();
|
|
30
|
-
this.key = validate.validateKey(key);
|
|
31
|
-
this.options = validate.parseOptions(options);
|
|
32
|
-
validate.validateOptions(this.options);
|
|
33
|
-
// eslint-disable-next-line guard-for-in
|
|
34
|
-
for (const func in API) {
|
|
35
|
-
Client.prototype[func] = function (...args) {
|
|
36
|
-
const lastArg = args[args.length - 1];
|
|
37
|
-
return API[func].apply(
|
|
38
|
-
{
|
|
39
|
-
_makeRequest: this._makeRequest.bind(this, { ...(validate.cacheSuboptions(lastArg) ? lastArg : {}) }),
|
|
40
|
-
...this
|
|
41
|
-
},
|
|
42
|
-
args
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
*
|
|
60
|
-
* @param {
|
|
61
|
-
* @param {
|
|
62
|
-
* @
|
|
63
|
-
* @
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
if (
|
|
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
|
-
* @param {
|
|
105
|
-
* @
|
|
106
|
-
* @
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* console.log(player.
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* console.log(player.guild
|
|
118
|
-
* console.log(player.guild.
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* //
|
|
128
|
-
* if
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
*
|
|
133
|
-
* @
|
|
134
|
-
* @
|
|
135
|
-
* @param {
|
|
136
|
-
* @param {
|
|
137
|
-
* @
|
|
138
|
-
* @
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* console.log(guild.
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
*
|
|
149
|
-
* @
|
|
150
|
-
* @
|
|
151
|
-
* @param {MethodOptions} [options={}] Method options
|
|
152
|
-
* @return {Promise<
|
|
153
|
-
* @example
|
|
154
|
-
* hypixel.
|
|
155
|
-
* console.log(
|
|
156
|
-
* }).catch(e => {
|
|
157
|
-
* console.log(e);
|
|
158
|
-
* })
|
|
159
|
-
*/
|
|
160
|
-
/**
|
|
161
|
-
* Allows you to get
|
|
162
|
-
* @method
|
|
163
|
-
* @name Client#
|
|
164
|
-
* @param {MethodOptions} [options={}] Method options
|
|
165
|
-
* @return {Promise<
|
|
166
|
-
* @example
|
|
167
|
-
* hypixel.
|
|
168
|
-
* console.log(
|
|
169
|
-
* }).catch(e => {
|
|
170
|
-
* console.log(e);
|
|
171
|
-
* })
|
|
172
|
-
*/
|
|
173
|
-
/**
|
|
174
|
-
* Allows you to get all
|
|
175
|
-
* @method
|
|
176
|
-
* @name Client#
|
|
177
|
-
* @param {
|
|
178
|
-
* @
|
|
179
|
-
* @
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
*
|
|
189
|
-
* @
|
|
190
|
-
* @
|
|
191
|
-
* @param {
|
|
192
|
-
* @
|
|
193
|
-
* @
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* console.log(
|
|
198
|
-
* })
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
*
|
|
204
|
-
* @
|
|
205
|
-
* @
|
|
206
|
-
* @return {Promise<
|
|
207
|
-
* @example
|
|
208
|
-
* hypixel.
|
|
209
|
-
* // '
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
*
|
|
217
|
-
* @
|
|
218
|
-
* @
|
|
219
|
-
* @return {Promise<
|
|
220
|
-
* @example
|
|
221
|
-
* hypixel.
|
|
222
|
-
* console.log(
|
|
223
|
-
* }).catch(e => {
|
|
224
|
-
* console.log(e);
|
|
225
|
-
* })
|
|
226
|
-
*/
|
|
227
|
-
/**
|
|
228
|
-
*
|
|
229
|
-
* @method
|
|
230
|
-
* @name Client#
|
|
231
|
-
* @param {
|
|
232
|
-
* @return {Promise<
|
|
233
|
-
* @example
|
|
234
|
-
* hypixel.
|
|
235
|
-
* console.log(
|
|
236
|
-
* }).catch(
|
|
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
|
-
* Allows you to get
|
|
266
|
-
* @method
|
|
267
|
-
* @name Client#
|
|
268
|
-
* @param {string}
|
|
269
|
-
* @param {
|
|
270
|
-
* @return {Promise<
|
|
271
|
-
* @example
|
|
272
|
-
* hypixel.
|
|
273
|
-
* console.log(
|
|
274
|
-
* })
|
|
275
|
-
* .catch(console.log);
|
|
276
|
-
*/
|
|
277
|
-
/**
|
|
278
|
-
* Allows you to get
|
|
279
|
-
* @method
|
|
280
|
-
* @name Client#
|
|
281
|
-
* @param {string} query
|
|
282
|
-
* @param {
|
|
283
|
-
* @
|
|
284
|
-
* @
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
*
|
|
293
|
-
* @
|
|
294
|
-
* @
|
|
295
|
-
* @param {
|
|
296
|
-
* @
|
|
297
|
-
* @
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
*
|
|
306
|
-
* @
|
|
307
|
-
* @
|
|
308
|
-
* @param {
|
|
309
|
-
* @
|
|
310
|
-
* @
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
*
|
|
319
|
-
* @
|
|
320
|
-
* @
|
|
321
|
-
* @
|
|
322
|
-
* @
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
*
|
|
332
|
-
* @
|
|
333
|
-
* @
|
|
334
|
-
* @
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
*
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
* @
|
|
395
|
-
* @
|
|
396
|
-
* @
|
|
397
|
-
* @
|
|
398
|
-
* @
|
|
399
|
-
* @
|
|
400
|
-
* @
|
|
401
|
-
* @
|
|
402
|
-
* @
|
|
403
|
-
* @
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
* @typedef {defaultCache} Cache
|
|
408
|
-
*/
|
|
409
|
-
/**
|
|
410
|
-
* @typedef {Cache} CacheHandler
|
|
411
|
-
*/
|
|
412
|
-
/**
|
|
413
|
-
* @typedef {object} MethodOptions
|
|
414
|
-
* @property {boolean} [raw=false] Raw data
|
|
415
|
-
* @property {boolean} [noCacheCheck=false] Disable/Enable cache checking
|
|
416
|
-
* @property {boolean} [noCaching=false] Disable/Enable writing to cache
|
|
417
|
-
* @prop {object} [headers={}] Extra Headers ( like User-Agent ) to add to request. Overrides the headers globally provided.
|
|
418
|
-
*/
|
|
419
|
-
/**
|
|
420
|
-
* @typedef {object} PlayerMethodOptions
|
|
421
|
-
* @property {boolean} [raw=false] Raw data
|
|
422
|
-
* @property {boolean} [noCacheCheck=false] Disable/Enable cache checking
|
|
423
|
-
* @property {boolean} [noCaching=false] Disable/Enable writing to cache
|
|
424
|
-
* @property {boolean} [guild=false] Disable/Enable request for player's guild
|
|
425
|
-
* @property {boolean} [recentGames=false] Disable/Enable request for player's recent game
|
|
426
|
-
* @property {boolean} [currentRankedSW=false] Disable/Enable request for player's current ranked SkyWars rating. Previous ratings will always show mindless of this option.
|
|
427
|
-
* @prop {object} [headers={}] Extra Headers ( like User-Agent ) to add to request. Overrides the headers globally provided.
|
|
428
|
-
*/
|
|
429
|
-
/**
|
|
430
|
-
* @typedef {object} SkyblockMethodOptions
|
|
431
|
-
* @property {boolean} [raw=false] Raw data
|
|
432
|
-
* @property {?boolean} [noCacheCheck=false] Disable/Enable cache checking
|
|
433
|
-
* @property {?boolean} [noCaching=false] Disable/Enable writing to cache
|
|
434
|
-
* @property {?boolean} [fetchPlayer=false] Disable/Enable player profile request for each member
|
|
435
|
-
* @prop {object} [headers={}] Extra Headers ( like User-Agent ) to add to request. Overrides the headers globally provided.
|
|
436
|
-
*/
|
|
437
|
-
/**
|
|
438
|
-
* @typedef {object} auctionsOptions
|
|
439
|
-
* @property {boolean} [noCacheCheck=false] Disable/Enable cache checking
|
|
440
|
-
* @property {boolean} [noCaching=false] Disable/Enable writing to cache
|
|
441
|
-
* @property {boolean} [noInfo=false] If true, result doesn't show Auction Info
|
|
442
|
-
* @property {boolean} [noAuctions=false] If true, result doesn't show auctions
|
|
443
|
-
* @property {boolean} [raw=false] If true, result will not contain parsed auctions, but will present them as it is received. This can speed up performance in some cases.
|
|
444
|
-
* @property {number} [retries=3] Number of times to retry fetching a page before abandoning
|
|
445
|
-
* @property {number} [cooldown=100] Cooldown between each fetch, only works if race is unset or false;
|
|
446
|
-
* @property {boolean} [race=false] Issues simultaneous requests to the API, instead of requesting then parsing one by one. Can largely increase speed at the cost of hogging bandwidth and memory
|
|
447
|
-
* @property {boolean} [includeItemBytes=false] Whether to include item bytes in the result
|
|
448
|
-
* @prop {object} [headers={}] Extra Headers ( like User-Agent ) to add to request. Overrides the headers globally provided.
|
|
449
|
-
*/
|
|
450
|
-
module.exports = Client;
|
|
1
|
+
/* eslint-disable require-jsdoc */
|
|
2
|
+
/* eslint-disable max-len */
|
|
3
|
+
const validate = new (require('./Private/validate'))();
|
|
4
|
+
const rateLimit = new (require('./Private/rateLimit'))();
|
|
5
|
+
const Requests = require('./Private/requests');
|
|
6
|
+
const updater = new (require('./Private/updater'))();
|
|
7
|
+
const Errors = require('./Errors');
|
|
8
|
+
const API = require('./API/index');
|
|
9
|
+
const EventEmitter = require('events');
|
|
10
|
+
const clients = [];
|
|
11
|
+
/**
|
|
12
|
+
* Client class
|
|
13
|
+
*/
|
|
14
|
+
class Client extends EventEmitter {
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} key API key [(?)](https://stavzdev.is-inside.me/cCMiZdoy.gif)
|
|
17
|
+
* @param {ClientOptions} [options={}] Client options
|
|
18
|
+
*/
|
|
19
|
+
constructor(key, options = {}) {
|
|
20
|
+
super();
|
|
21
|
+
this.requests = new Requests(this, options.cacheHandler);
|
|
22
|
+
// eslint-disable-next-line no-console
|
|
23
|
+
if (options && !options.silent) this.on('warn', console.warn);
|
|
24
|
+
// Test to check for multiple instances of client
|
|
25
|
+
if (clients.find((x) => x.key === key)) {
|
|
26
|
+
this.emit('warn', Errors.MULTIPLE_INSTANCES);
|
|
27
|
+
return clients.find((x) => x.key === key);
|
|
28
|
+
}
|
|
29
|
+
validate.validateNodeVersion();
|
|
30
|
+
this.key = validate.validateKey(key);
|
|
31
|
+
this.options = validate.parseOptions(options);
|
|
32
|
+
validate.validateOptions(this.options);
|
|
33
|
+
// eslint-disable-next-line guard-for-in
|
|
34
|
+
for (const func in API) {
|
|
35
|
+
Client.prototype[func] = function (...args) {
|
|
36
|
+
const lastArg = args[args.length - 1];
|
|
37
|
+
return API[func].apply(
|
|
38
|
+
{
|
|
39
|
+
_makeRequest: this._makeRequest.bind(this, { ...(validate.cacheSuboptions(lastArg) ? lastArg : {}) }),
|
|
40
|
+
...this
|
|
41
|
+
},
|
|
42
|
+
args
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if (this.options.checkForUpdates) {
|
|
47
|
+
updater.checkForUpdates();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* All cache entries
|
|
52
|
+
* @type {Map<string,object>}
|
|
53
|
+
*/
|
|
54
|
+
this.cache = this.requests.cache;
|
|
55
|
+
clients.push(this);
|
|
56
|
+
rateLimit.init(this.getPlayer('52d9a36f66ce4cdf9a56ad9724ae9fb4'), this.options, this).then(() => this.emit('ready'));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Private function - make request
|
|
60
|
+
* @param {MethodOptions} options Options for request
|
|
61
|
+
* @param {string} url Endpoint URL to request
|
|
62
|
+
* @param {boolean} [useRateLimitManager=true] Use rate limit
|
|
63
|
+
* @returns {Promise<Object>} Response
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
async _makeRequest(options, url, useRateLimitManager = true) {
|
|
67
|
+
if (!url) return;
|
|
68
|
+
if (url !== '/key' && !options.noCacheCheck && (await this.requests.cache.has(url))) return Object.assign(await this.requests.cache.get(url), { raw: !!options.raw });
|
|
69
|
+
if (useRateLimitManager) await rateLimit.rateLimitManager();
|
|
70
|
+
this.emit('outgoingRequest', url, { ...options, headers: { ...options.headers, ...this.options.headers } });
|
|
71
|
+
const result = await this.requests.request.call(this.requests, url, { ...options, headers: { ...options.headers, ...this.options.headers } });
|
|
72
|
+
if (this.options.syncWithHeaders) rateLimit.sync(result._headers);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Emitted when rate limiter is ready. ( You don't have to wait for this event to emit UNLESS you are planning to do data scraping which means spamming requests )
|
|
77
|
+
* @event
|
|
78
|
+
* @name Client#ready
|
|
79
|
+
* @example
|
|
80
|
+
* // This example gets player's uuid.
|
|
81
|
+
* hypixel.once('ready',()=>{
|
|
82
|
+
* hypixel.getPlayer('stavzdev')
|
|
83
|
+
* .then(player => player.uuid)
|
|
84
|
+
* .catch(console.log);
|
|
85
|
+
* })
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* Emitted when a request is going to be sent
|
|
89
|
+
* @event
|
|
90
|
+
* @name Client#outgoingRequest
|
|
91
|
+
* @param {string} url URL
|
|
92
|
+
* @param {object} [options] Options, if any
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* Emitted when there is a warning.
|
|
96
|
+
* @event
|
|
97
|
+
* @name Client#warn
|
|
98
|
+
* @param {string} error Warning Message
|
|
99
|
+
*/
|
|
100
|
+
/**
|
|
101
|
+
* Allows you to get statistics of player
|
|
102
|
+
* @method
|
|
103
|
+
* @name Client#getPlayer
|
|
104
|
+
* @param {string} query Player nickname or UUID
|
|
105
|
+
* @param {PlayerMethodOptions} [options={}] Method options
|
|
106
|
+
* @return {Promise<Player>}
|
|
107
|
+
* @example
|
|
108
|
+
* hypixel.getPlayer('StavZDev').then(player => {
|
|
109
|
+
* console.log(player.level); // 141
|
|
110
|
+
* console.log(player.rank); // 'MVP+'
|
|
111
|
+
* }).catch(e => {
|
|
112
|
+
* console.log(e);
|
|
113
|
+
* })
|
|
114
|
+
* @example
|
|
115
|
+
* // Get player's guild along with player stats
|
|
116
|
+
* hypixel.getPlayer('Minikloon', { guild: true }).then(player => {
|
|
117
|
+
* console.log(player.guild) // null if player isn't is guild
|
|
118
|
+
* console.log(player.guild.name) // Mini Squid
|
|
119
|
+
* console.log(player.guild.level) // 110
|
|
120
|
+
* }).catch(e => {
|
|
121
|
+
* console.log(e);
|
|
122
|
+
* });
|
|
123
|
+
* @example
|
|
124
|
+
* // async/await
|
|
125
|
+
* const player = await hypixel.getPlayer('Minikloon').catch(console.log);
|
|
126
|
+
* // If player doesn't exist, or if an error occurred ( check console )
|
|
127
|
+
* console.log(player); // null
|
|
128
|
+
* // Check if player exists
|
|
129
|
+
* if(player) console.log(player.uuid); // 20934ef9488c465180a78f861586b4cf
|
|
130
|
+
*/
|
|
131
|
+
/**
|
|
132
|
+
* Allows you to get statistics of hypixel guild
|
|
133
|
+
* @method
|
|
134
|
+
* @name Client#getGuild
|
|
135
|
+
* @param {id|name|player} searchParameter Search for guild by id, name or player (if player is in guild)
|
|
136
|
+
* @param {string} query Guild ID, Guild name or player uuid/nickname
|
|
137
|
+
* @param {MethodOptions} [options={}] Method options
|
|
138
|
+
* @return {Promise<Guild>}
|
|
139
|
+
* @example
|
|
140
|
+
* hypixel.getGuild('name', 'The Foundation').then(guild => {
|
|
141
|
+
* console.log(guild.level); // 111
|
|
142
|
+
* console.log(guild.id); // '52e5719284ae51ed0c716c69'
|
|
143
|
+
* }).catch(e => {
|
|
144
|
+
* console.log(e);
|
|
145
|
+
* })
|
|
146
|
+
*/
|
|
147
|
+
/**
|
|
148
|
+
* Allows you to get statistics of watchdog, the server anticheat
|
|
149
|
+
* @method
|
|
150
|
+
* @name Client#getWatchdogStats
|
|
151
|
+
* @param {MethodOptions} [options={}] Method options
|
|
152
|
+
* @return {Promise<WatchdogStats>}
|
|
153
|
+
* @example
|
|
154
|
+
* hypixel.getWatchdogStats().then(watchdog => {
|
|
155
|
+
* console.log(watchdog.byWatchdogTotal); // 5931897
|
|
156
|
+
* }).catch(e => {
|
|
157
|
+
* console.log(e);
|
|
158
|
+
* })
|
|
159
|
+
*/
|
|
160
|
+
/**
|
|
161
|
+
* Allows you to get all active boosters
|
|
162
|
+
* @method
|
|
163
|
+
* @name Client#getBoosters
|
|
164
|
+
* @param {MethodOptions} [options={}] Method options
|
|
165
|
+
* @return {Promise<Array<Booster>>}
|
|
166
|
+
* @example
|
|
167
|
+
* hypixel.getBoosters().then(boosters => {
|
|
168
|
+
* console.log(boosters[0].purchaser); // '978ddb705a8e43618e41749178c020b0'
|
|
169
|
+
* }).catch(e => {
|
|
170
|
+
* console.log(e);
|
|
171
|
+
* })
|
|
172
|
+
*/
|
|
173
|
+
/**
|
|
174
|
+
* Allows you to get all skyblock profiles of player
|
|
175
|
+
* @method
|
|
176
|
+
* @name Client#getSkyblockProfiles
|
|
177
|
+
* @param {string} query Player nickname or UUID
|
|
178
|
+
* @param {SkyblockMethodOptions} [options={}] Method options
|
|
179
|
+
* @return {Promise<Array<SkyblockProfile>>}
|
|
180
|
+
* @example
|
|
181
|
+
* hypixel.getSkyblockProfiles('StavZDev').then(profiles => {
|
|
182
|
+
* console.log(profiles[0].members[0].uuid); // '52d9a36f66ce4cdf9a56ad9724ae9fb4'
|
|
183
|
+
* }).catch(e => {
|
|
184
|
+
* console.log(e);
|
|
185
|
+
* })
|
|
186
|
+
*/
|
|
187
|
+
/**
|
|
188
|
+
* Allows you to get a player's skyblock member data from all their profiles
|
|
189
|
+
* @method
|
|
190
|
+
* @name Client#getSkyblockMember
|
|
191
|
+
* @param {string} query Player nickname or UUID
|
|
192
|
+
* @param {MethodOptions} [options={}] Method options
|
|
193
|
+
* @return {Promise<Map<string,SkyblockMember>>}
|
|
194
|
+
* @example
|
|
195
|
+
* hypixel.getSkyblockMember('StavZDev').then(member => {
|
|
196
|
+
* // 'Cucumber' - profile name
|
|
197
|
+
* console.log(member.get('Cucumber').uuid); // '52d9a36f66ce4cdf9a56ad9724ae9fb4'
|
|
198
|
+
* }).catch(e => {
|
|
199
|
+
* console.log(e);
|
|
200
|
+
* })
|
|
201
|
+
*/
|
|
202
|
+
/**
|
|
203
|
+
* Allows you to get the Hypixel API's Status and past Incidents, no key needed.
|
|
204
|
+
* @method
|
|
205
|
+
* @name Client#getAPIStatus
|
|
206
|
+
* @return {Promise<APIStatus>}
|
|
207
|
+
* @example
|
|
208
|
+
* hypixel.getAPIStatus().then(status => {
|
|
209
|
+
* console.log(status.incidents[0].link); // 'https://status.hypixel.net/incidents/zdd5gppdtcc3'
|
|
210
|
+
* }).catch(e => {
|
|
211
|
+
* console.log(e);
|
|
212
|
+
* })
|
|
213
|
+
*/
|
|
214
|
+
/**
|
|
215
|
+
* Gets all leaderboards
|
|
216
|
+
* @method
|
|
217
|
+
* @name Client#getLeaderboards
|
|
218
|
+
* @param {MethodOptions} [options={}] Method options
|
|
219
|
+
* @return {Promise<{ ARENA: Leaderboard[], COPS_AND_CRIMS: Leaderboard[], WARLORDS: Leaderboard[], BLITZ_SURVIVAL_GAMES: Leaderboard[], UHC: Leaderboard[], WALLS: Leaderboard[], PROTOTYPE: Leaderboard[], PAINTBALL: Leaderboard[], SKYWARS: Leaderboard[], MURDER_MYSTERY: Leaderboard[], SMASH_HEROES: Leaderboard[], DUELS: Leaderboard[], SPEED_UHC: Leaderboard[], TNTGAMES: Leaderboard[], BEDWARS: Leaderboard[], TURBO_KART_RACERS: Leaderboard[], BUILD_BATTLE: Leaderboard[], ARCADE: Leaderboard[], SKYCLASH: Leaderboard[], QUAKECRAFT: Leaderboard[], CRAZY_WALLS: Leaderboard[], MEGA_WALLS: Leaderboard[], VAMPIREZ: Leaderboard[] }>}
|
|
220
|
+
* @example
|
|
221
|
+
* hypixel.getLeaderboards().then(leaderboards => {
|
|
222
|
+
* console.log(leaderboards.ARENA[0].name); // 'Wins'
|
|
223
|
+
* }).catch(e => {
|
|
224
|
+
* console.log(e);
|
|
225
|
+
* })
|
|
226
|
+
*/
|
|
227
|
+
/**
|
|
228
|
+
* Sends a STATUS packet to hypixel and parses the return info (a 0x00 and 0x01 packet)
|
|
229
|
+
* @method
|
|
230
|
+
* @name Client#getServerInfo
|
|
231
|
+
* @param {number} [repeats=3] Sends x amount of ping requests and gets the average. Should be between 1 and 10
|
|
232
|
+
* @return {Promise<ServerInfo>}
|
|
233
|
+
* @example
|
|
234
|
+
* hypixel.getServerInfo(3).then(serverInfo =>{
|
|
235
|
+
* console.log(serverInfo.ping); // 69
|
|
236
|
+
* }).catch(console.log)
|
|
237
|
+
*/
|
|
238
|
+
/**
|
|
239
|
+
* Allows you to get recent games of a player
|
|
240
|
+
* @method
|
|
241
|
+
* @name Client#getRecentGames
|
|
242
|
+
* @param {string} query Player nickname or UUID
|
|
243
|
+
* @param {MethodOptions} [options={}] Method options
|
|
244
|
+
* @return {Promise<RecentGame[]>}
|
|
245
|
+
* @example
|
|
246
|
+
* hypixel.getRecentGames().then(recentGames =>{
|
|
247
|
+
* console.log(recentGames[0].endedTimestamp); // 1609670588789
|
|
248
|
+
* })
|
|
249
|
+
* .catch(console.log);
|
|
250
|
+
*/
|
|
251
|
+
/**
|
|
252
|
+
* Allows you to get the status of a player
|
|
253
|
+
* @method
|
|
254
|
+
* @name Client#getStatus
|
|
255
|
+
* @param {string} query Player nickname or UUID
|
|
256
|
+
* @param {MethodOptions} [options={}] Method options
|
|
257
|
+
* @return {Promise<Status>}
|
|
258
|
+
* @example
|
|
259
|
+
* hypixel.getStatus('Stavzdev').then(status =>{
|
|
260
|
+
* console.log(status.online); // true
|
|
261
|
+
* })
|
|
262
|
+
* .catch(console.log);
|
|
263
|
+
*/
|
|
264
|
+
/**
|
|
265
|
+
* Allows you to get skyblock auctions
|
|
266
|
+
* @method
|
|
267
|
+
* @name Client#getSkyblockAuctions
|
|
268
|
+
* @param {string|number|number[]} page - "*", a page number, or an array with the start and the end page number ( automatically sorted )
|
|
269
|
+
* @param {auctionsOptions} [options={}] Options
|
|
270
|
+
* @return {Promise<{info:AuctionInfo,auctions:Auction[]}>}
|
|
271
|
+
* @example
|
|
272
|
+
* hypixel.getSkyblockAuctions(0).then(auctions =>{
|
|
273
|
+
* console.log(auctions[0].item); // Mythic Farmer Boots
|
|
274
|
+
* })
|
|
275
|
+
* .catch(console.log);
|
|
276
|
+
*/
|
|
277
|
+
/**
|
|
278
|
+
* Allows you to get player's skyblock auctions
|
|
279
|
+
* @method
|
|
280
|
+
* @name Client#getSkyblockAuctionsByPlayer
|
|
281
|
+
* @param {string} query - player nickname or uuid
|
|
282
|
+
* @param {boolean} [includeItemBytes=false] - include item bytes (optional)
|
|
283
|
+
* @param {MethodOptions} [options={}] Options
|
|
284
|
+
* @return {Promise<Auction[]>}
|
|
285
|
+
* @example
|
|
286
|
+
* hypixel.getSkyblockAuctionsByPlayer('hypixel').then(auctions =>{
|
|
287
|
+
* console.log(auctions[0].auctionId); // b0491da3e81c43c88fd287ea3b3eacc0
|
|
288
|
+
* })
|
|
289
|
+
* .catch(console.log);
|
|
290
|
+
*/
|
|
291
|
+
/**
|
|
292
|
+
* Allows you to get all ended auctions in around the last 60 seconds
|
|
293
|
+
* @method
|
|
294
|
+
* @name Client#getEndedSkyblockAuctions
|
|
295
|
+
* @param {boolean} [includeItemBytes=false] - include item bytes (optional)
|
|
296
|
+
* @param {MethodOptions} [options={}] Options
|
|
297
|
+
* @return {Promise<{info:AuctionInfo,auctions:PartialAuction[]}>}
|
|
298
|
+
* @example
|
|
299
|
+
* hypixel.getEndedSkyblockAuctions().then(ended =>{
|
|
300
|
+
* console.log(ended.auctions[0].auctionId); // 0fe7fd132367474e86ff3022b4a84a13
|
|
301
|
+
* })
|
|
302
|
+
* .catch(console.log);
|
|
303
|
+
*/
|
|
304
|
+
/**
|
|
305
|
+
* Allows you to get list of products
|
|
306
|
+
* @method
|
|
307
|
+
* @name Client#getSkyblockBazaar
|
|
308
|
+
* @param {MethodOptions} [options={}] Options
|
|
309
|
+
* @return {Promise<Product[]>}
|
|
310
|
+
* @example
|
|
311
|
+
* hypixel.getSkyblockBazaar().then(products =>{
|
|
312
|
+
* console.log(products[0].productId); // INK_SACK:3
|
|
313
|
+
* })
|
|
314
|
+
* .catch(console.log);
|
|
315
|
+
*/
|
|
316
|
+
/**
|
|
317
|
+
* Allows you to get skyblock news
|
|
318
|
+
* @method
|
|
319
|
+
* @name Client#getSkyblockNews
|
|
320
|
+
* @param {MethodOptions} [options={}] Options
|
|
321
|
+
* @return {Promise<SkyblockNews[]>}
|
|
322
|
+
* @example
|
|
323
|
+
* hypixel.getSkyblockNews().then((news) => {
|
|
324
|
+
* console.log(news[0].link); // https://hypixel.net/threads/3749492/
|
|
325
|
+
* })
|
|
326
|
+
* .catch(console.log)
|
|
327
|
+
*/
|
|
328
|
+
/**
|
|
329
|
+
* Allows you to get player count along with the player count of each public game
|
|
330
|
+
* @method
|
|
331
|
+
* @name Client#getGameCounts
|
|
332
|
+
* @param {MethodOptions} [options={}] Options
|
|
333
|
+
* @return {Promise<GameCounts>}
|
|
334
|
+
* @example
|
|
335
|
+
* hypixel.getGameCounts().then((gameCounts) => {
|
|
336
|
+
* console.log(gameCounts.mainLobby.players);
|
|
337
|
+
* })
|
|
338
|
+
* .catch(console.log)
|
|
339
|
+
*/
|
|
340
|
+
/**
|
|
341
|
+
* Delete x (by default all) cache entries
|
|
342
|
+
* @param {?number} amount Amount of cache to delete
|
|
343
|
+
* @return {Promise<void|boolean[]>}
|
|
344
|
+
*/
|
|
345
|
+
sweepCache(amount) {
|
|
346
|
+
return this.requests.sweepCache(amount);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* @typedef {object} ClientOptions
|
|
351
|
+
* @prop {boolean} [cache=false] Enable/Disable request caching.
|
|
352
|
+
* @prop {number} [cacheTime=60] Amount of time in seconds to cache the requests.
|
|
353
|
+
* @prop {CacheHandler} [cacheHandler] Custom Cache Handler
|
|
354
|
+
* @prop {AUTO|HARD|NONE} [rateLimit='AUTO'] Rate limit mode.
|
|
355
|
+
* @prop {boolean} [syncWithHeaders=false] Sync with headers rate limit information. Usually not necessary nor recommended ( because of latency )
|
|
356
|
+
* @prop {number} [keyLimit=120] Key limit of your key.
|
|
357
|
+
* @prop {number} [cacheSize=-1] The amount how many results will be cached. (`-1` for infinity)
|
|
358
|
+
* @prop {boolean} [silent=false] Don't automatically put warnings into console.
|
|
359
|
+
* @prop {object} [headers={}] Extra Headers ( like User-Agent ) to add to request.
|
|
360
|
+
* @prop {boolean} [checkForUpdates=false] Enable/Disable check for new version of hypixel-api-reborn.
|
|
361
|
+
*/
|
|
362
|
+
const defaultCache = require('./Private/defaultCache.js');
|
|
363
|
+
/**
|
|
364
|
+
* @typedef {defaultCache} Cache
|
|
365
|
+
*/
|
|
366
|
+
/**
|
|
367
|
+
* @typedef {Cache} CacheHandler
|
|
368
|
+
*/
|
|
369
|
+
/**
|
|
370
|
+
* @typedef {object} MethodOptions
|
|
371
|
+
* @property {boolean} [raw=false] Raw data
|
|
372
|
+
* @property {boolean} [noCacheCheck=false] Disable/Enable cache checking
|
|
373
|
+
* @property {boolean} [noCaching=false] Disable/Enable writing to cache
|
|
374
|
+
* @prop {object} [headers={}] Extra Headers ( like User-Agent ) to add to request. Overrides the headers globally provided.
|
|
375
|
+
*/
|
|
376
|
+
/**
|
|
377
|
+
* @typedef {object} PlayerMethodOptions
|
|
378
|
+
* @property {boolean} [raw=false] Raw data
|
|
379
|
+
* @property {boolean} [noCacheCheck=false] Disable/Enable cache checking
|
|
380
|
+
* @property {boolean} [noCaching=false] Disable/Enable writing to cache
|
|
381
|
+
* @property {boolean} [guild=false] Disable/Enable request for player's guild
|
|
382
|
+
* @property {boolean} [recentGames=false] Disable/Enable request for player's recent game
|
|
383
|
+
* @prop {object} [headers={}] Extra Headers ( like User-Agent ) to add to request. Overrides the headers globally provided.
|
|
384
|
+
*/
|
|
385
|
+
/**
|
|
386
|
+
* @typedef {object} SkyblockMethodOptions
|
|
387
|
+
* @property {boolean} [raw=false] Raw data
|
|
388
|
+
* @property {?boolean} [noCacheCheck=false] Disable/Enable cache checking
|
|
389
|
+
* @property {?boolean} [noCaching=false] Disable/Enable writing to cache
|
|
390
|
+
* @property {?boolean} [fetchPlayer=false] Disable/Enable player profile request for each member
|
|
391
|
+
* @prop {object} [headers={}] Extra Headers ( like User-Agent ) to add to request. Overrides the headers globally provided.
|
|
392
|
+
*/
|
|
393
|
+
/**
|
|
394
|
+
* @typedef {object} auctionsOptions
|
|
395
|
+
* @property {boolean} [noCacheCheck=false] Disable/Enable cache checking
|
|
396
|
+
* @property {boolean} [noCaching=false] Disable/Enable writing to cache
|
|
397
|
+
* @property {boolean} [noInfo=false] If true, result doesn't show Auction Info
|
|
398
|
+
* @property {boolean} [noAuctions=false] If true, result doesn't show auctions
|
|
399
|
+
* @property {boolean} [raw=false] If true, result will not contain parsed auctions, but will present them as it is received. This can speed up performance in some cases.
|
|
400
|
+
* @property {number} [retries=3] Number of times to retry fetching a page before abandoning
|
|
401
|
+
* @property {number} [cooldown=100] Cooldown between each fetch, only works if race is unset or false;
|
|
402
|
+
* @property {boolean} [race=false] Issues simultaneous requests to the API, instead of requesting then parsing one by one. Can largely increase speed at the cost of hogging bandwidth and memory
|
|
403
|
+
* @property {boolean} [includeItemBytes=false] Whether to include item bytes in the result
|
|
404
|
+
* @prop {object} [headers={}] Extra Headers ( like User-Agent ) to add to request. Overrides the headers globally provided.
|
|
405
|
+
*/
|
|
406
|
+
module.exports = Client;
|