hypixel-api-reborn 11.2.0 → 11.2.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.
Files changed (84) hide show
  1. package/README.md +1 -1
  2. package/eslint.config.mjs +71 -0
  3. package/package.json +11 -17
  4. package/src/API/getAchievements.js +1 -0
  5. package/src/API/getBoosters.js +1 -0
  6. package/src/API/getChallenges.js +1 -0
  7. package/src/API/getGameCounts.js +1 -0
  8. package/src/API/getGuild.js +4 -3
  9. package/src/API/getGuildAchievements.js +1 -0
  10. package/src/API/getLeaderboards.js +1 -1
  11. package/src/API/getPlayer.js +1 -0
  12. package/src/API/getQuests.js +1 -0
  13. package/src/API/getRecentGames.js +5 -9
  14. package/src/API/getServerInfo.js +40 -37
  15. package/src/API/getStatus.js +1 -0
  16. package/src/API/getWatchdogStats.js +1 -0
  17. package/src/API/skyblock/getAuction.js +8 -6
  18. package/src/API/skyblock/getAuctions.js +15 -12
  19. package/src/API/skyblock/getAuctionsByPlayer.js +1 -1
  20. package/src/API/skyblock/getBazaar.js +1 -3
  21. package/src/API/skyblock/getBingo.js +1 -2
  22. package/src/API/skyblock/getBingoByPlayer.js +3 -3
  23. package/src/API/skyblock/getEndedAuctions.js +1 -0
  24. package/src/API/skyblock/getFireSales.js +1 -1
  25. package/src/API/skyblock/getGovernment.js +1 -2
  26. package/src/API/skyblock/getMember.js +1 -0
  27. package/src/API/skyblock/getMuseum.js +1 -0
  28. package/src/API/skyblock/getNews.js +1 -0
  29. package/src/API/skyblock/getProfiles.js +1 -0
  30. package/src/Client.js +42 -14
  31. package/src/Private/rateLimit.js +7 -11
  32. package/src/Private/requests.js +11 -12
  33. package/src/Private/updater.js +2 -3
  34. package/src/Private/uuidCache.js +1 -2
  35. package/src/Private/validate.js +19 -19
  36. package/src/structures/APIIncident.js +1 -2
  37. package/src/structures/APIStatus.js +0 -1
  38. package/src/structures/Boosters/Booster.js +9 -8
  39. package/src/structures/Game.js +1 -1
  40. package/src/structures/Guild/Guild.js +19 -36
  41. package/src/structures/Guild/GuildMember.js +2 -2
  42. package/src/structures/MiniGames/Arcade.js +242 -240
  43. package/src/structures/MiniGames/ArenaBrawl.js +11 -11
  44. package/src/structures/MiniGames/BedWars.js +197 -194
  45. package/src/structures/MiniGames/BlitzSurvivalGames.js +24 -23
  46. package/src/structures/MiniGames/CopsAndCrims.js +1 -0
  47. package/src/structures/MiniGames/Duels.js +9 -11
  48. package/src/structures/MiniGames/Pit.js +4 -5
  49. package/src/structures/MiniGames/SkyWars.js +197 -186
  50. package/src/structures/MiniGames/SmashHeroes.js +36 -34
  51. package/src/structures/MiniGames/SpeedUHC.js +17 -4
  52. package/src/structures/MiniGames/UHC.js +26 -25
  53. package/src/structures/MiniGames/WoolWars.js +6 -5
  54. package/src/structures/Pet.js +1 -1
  55. package/src/structures/Player.js +13 -104
  56. package/src/structures/PlayerCosmetics.js +5 -4
  57. package/src/structures/SkyBlock/Auctions/AuctionInfo.js +2 -1
  58. package/src/structures/SkyBlock/Auctions/BaseAuction.js +1 -1
  59. package/src/structures/SkyBlock/News/SkyblockNews.js +15 -15
  60. package/src/structures/SkyBlock/PlayerBingo.js +7 -14
  61. package/src/structures/SkyBlock/SkyblockInventoryItem.js +4 -28
  62. package/src/structures/SkyBlock/SkyblockMember.js +78 -223
  63. package/src/structures/SkyBlock/SkyblockPet.js +3 -4
  64. package/src/structures/SkyBlock/Static/Bingo.js +10 -11
  65. package/src/structures/SkyBlock/Static/BingoData.js +1 -1
  66. package/src/structures/Static/Achievement.js +16 -15
  67. package/src/structures/Static/AchievementTier.js +2 -2
  68. package/src/structures/Static/Quest.js +2 -2
  69. package/src/utils/Constants.js +17 -517
  70. package/src/utils/{guildExp.js → Guild.js} +42 -12
  71. package/src/utils/Player.js +112 -0
  72. package/src/utils/SkyblockUtils.js +449 -192
  73. package/src/utils/arrayTools.js +1 -1
  74. package/src/utils/divide.js +1 -1
  75. package/src/utils/index.js +2 -1
  76. package/src/utils/isGuildID.js +1 -1
  77. package/src/utils/oscillation.js +4 -2
  78. package/src/utils/removeSnakeCase.js +11 -7
  79. package/src/utils/rgbToHexColor.js +1 -1
  80. package/src/utils/romanize.js +3 -3
  81. package/src/utils/toUuid.js +4 -4
  82. package/src/utils/varInt.js +2 -2
  83. package/typings/index.d.ts +272 -162
  84. package/src/utils/toIGN.js +0 -24
@@ -1,3 +1,10 @@
1
+ const {
2
+ playerLevelProgress,
3
+ parseClaimedRewards,
4
+ getSocialMedia,
5
+ getPlayerLevel,
6
+ getRank
7
+ } = require('../utils/Player');
1
8
  const SkyWars = require('./MiniGames/SkyWars');
2
9
  const BedWars = require('./MiniGames/BedWars');
3
10
  const UHC = require('./MiniGames/UHC');
@@ -24,6 +31,8 @@ const Walls = require('./MiniGames/Walls');
24
31
  const Warlords = require('./MiniGames/Warlords');
25
32
  const WoolWars = require('./MiniGames/WoolWars');
26
33
  const Pit = require('./MiniGames/Pit');
34
+ const Guild = require('./Guild/Guild');
35
+ const RecentGame = require('./RecentGame');
27
36
  /**
28
37
  * Player class
29
38
  */
@@ -93,7 +102,7 @@ class Player {
93
102
  * @type {Color|null}
94
103
  */
95
104
  this.plusColor =
96
- this.rank === 'MVP+' || this.rank === 'MVP++'
105
+ 'MVP+' === this.rank || 'MVP++' === this.rank
97
106
  ? data.rankPlusColor
98
107
  ? new Color(data.rankPlusColor)
99
108
  : new Color('RED')
@@ -103,7 +112,7 @@ class Player {
103
112
  * @type {Color|null}
104
113
  */
105
114
  this.prefixColor =
106
- this.rank === 'MVP++' ? (data.monthlyRankColor ? new Color(data.monthlyRankColor) : new Color('GOLD')) : null;
115
+ 'MVP++' === this.rank ? (data.monthlyRankColor ? new Color(data.monthlyRankColor) : new Color('GOLD')) : null;
107
116
  /**
108
117
  * Player karma
109
118
  * @type {number}
@@ -158,7 +167,7 @@ class Player {
158
167
  * Last time player claimed the daily reward
159
168
  * @type {Date | null}
160
169
  */
161
- this.lastDailyReward = new Date(data.lastAdsenseGenerateTime) || null;
170
+ this.lastDailyReward = data.lastAdsenseGenerateTime ? new Date(data.lastAdsenseGenerateTime) : null;
162
171
  /**
163
172
  * Last time player claimed the daily reward, as timestamp
164
173
  * @type {number | null}
@@ -249,7 +258,7 @@ class Player {
249
258
  * Global Cosmetics a player owns
250
259
  * @type {PlayerCosmetics}
251
260
  */
252
- this.globalCosmetics = new PlayerCosmetics(data) || null;
261
+ this.globalCosmetics = data ? new PlayerCosmetics(data) : null;
253
262
  /**
254
263
  * Time at which the ranks were purchased. Can be all null if bought a long time ago, and some values can be null if player bought directly a rank above that
255
264
  * @type {RanksPurchaseTime}
@@ -269,106 +278,6 @@ class Player {
269
278
  return this.nickname;
270
279
  }
271
280
  }
272
-
273
- // eslint-disable-next-line require-jsdoc
274
- function getRank(player) {
275
- let rank;
276
- if (player.prefix) {
277
- rank = player.prefix.replace(/§[0-9|a-z]|\[|\]/g, '');
278
- } else if (player.rank && player.rank !== 'NORMAL') {
279
- switch (player.rank) {
280
- case 'YOUTUBER':
281
- rank = 'YouTube';
282
- break;
283
- case 'GAME_MASTER':
284
- rank = 'Game Master';
285
- break;
286
- case 'ADMIN':
287
- rank = 'Admin';
288
- break;
289
- }
290
- } else {
291
- switch (player.newPackageRank) {
292
- case 'MVP_PLUS':
293
- rank = player.monthlyPackageRank && player.monthlyPackageRank === 'SUPERSTAR' ? 'MVP++' : 'MVP+';
294
- break;
295
- case 'MVP':
296
- rank = 'MVP';
297
- break;
298
- case 'VIP_PLUS':
299
- rank = 'VIP+';
300
- break;
301
- case 'VIP':
302
- rank = 'VIP';
303
- break;
304
- default:
305
- rank = player.monthlyPackageRank && player.monthlyPackageRank === 'SUPERSTAR' ? 'MVP++' : 'Default';
306
- }
307
- }
308
- return rank;
309
- }
310
- // eslint-disable-next-line require-jsdoc
311
- function getPlayerLevel(exp) {
312
- const base = 10000;
313
- const growth = 2500;
314
- const reversePqPrefix = -(base - 0.5 * growth) / growth;
315
- const reverseConst = reversePqPrefix * reversePqPrefix;
316
- const growthDivides2 = 2 / growth;
317
- const num = 1 + reversePqPrefix + Math.sqrt(reverseConst + growthDivides2 * exp);
318
- const level = Math.round(num * 100) / 100;
319
- return level;
320
- }
321
- // eslint-disable-next-line require-jsdoc
322
- function xpToNextLevel(player) {
323
- const lvl = getPlayerLevel(player.networkExp);
324
- const xpToNext = 2500 * Math.floor(lvl) + 5000;
325
- if (player.networkExp < 10000) return 10000;
326
- return xpToNext;
327
- }
328
- // eslint-disable-next-line require-jsdoc
329
- function levelToXP(player) {
330
- let level = Number(Math.floor(getPlayerLevel(player.networkExp)));
331
- level = level - 1;
332
- const xp = 1250 * level ** 2 + 8750 * level;
333
- return xp;
334
- }
335
- // eslint-disable-next-line require-jsdoc
336
- function playerLevelProgress(player) {
337
- const xpFromLevel = levelToXP(player);
338
- let currentXP = player.networkExp - xpFromLevel;
339
- const xpToNext = xpToNextLevel(player);
340
- const remainingXP = xpToNext - currentXP + 2500;
341
- currentXP = currentXP - 2500;
342
- const percent = Math.round((currentXP / xpToNext) * 100 * 100) / 100;
343
- const percentRemaining = Math.round((100 - percent) * 100) / 100;
344
- return {
345
- xpToNext,
346
- remainingXP,
347
- currentXP,
348
- percent,
349
- percentRemaining
350
- };
351
- }
352
- // eslint-disable-next-line require-jsdoc
353
- function getSocialMedia(data) {
354
- if (!data) return null;
355
- const links = data.links;
356
- const formattedNames = ['Twitter', 'YouTube', 'Instagram', 'Twitch', 'Hypixel', 'Discord'];
357
- const upperNames = ['TWITTER', 'YOUTUBE', 'INSTAGRAM', 'TWITCH', 'HYPIXEL', 'DISCORD'];
358
- if (!links) return null;
359
- return Object.keys(links)
360
- .map((x) => upperNames.indexOf(x))
361
- .filter((x) => x !== -1)
362
- .map((x) => ({ name: formattedNames[x], link: links[upperNames[x]], id: upperNames[x] }));
363
- }
364
- // eslint-disable-next-line require-jsdoc
365
- function parseClaimedRewards(data) {
366
- if (!data) return null;
367
- return Object.keys(data)
368
- .map((x) => x.match(/levelingReward_(\d+)/))
369
- .filter((x) => x)
370
- .map((x) => parseInt(x[1], 10));
371
- }
372
281
  /**
373
282
  * @typedef {string} PlayerRank
374
283
  * * `Default`
@@ -1,5 +1,6 @@
1
- const Pets = require('./Pets');
1
+ /* eslint-disable no-underscore-dangle */
2
2
  const { removeSnakeCaseString } = require('../utils/removeSnakeCase');
3
+ const Pets = require('./Pets');
3
4
  /**
4
5
  * Player Cosmetics class
5
6
  */
@@ -113,14 +114,14 @@ class PlayerCosmetics {
113
114
  * @type {string[]}
114
115
  */
115
116
  get rankColors() {
116
- if (!this._rankcolors) {
117
- this._rankcolors = this.allCosmetics
117
+ if (!this._rankColors) {
118
+ this._rankColors = this.allCosmetics
118
119
  ? this.allCosmetics
119
120
  .filter((x) => x.startsWith('rankcolor_'))
120
121
  .map((x) => removeSnakeCaseString(x.replace('rankcolor_', ''))) || []
121
122
  : [];
122
123
  }
123
- return this._rankcolors;
124
+ return this._rankColors;
124
125
  }
125
126
  /**
126
127
  * Particle Packs
@@ -1,4 +1,3 @@
1
- /* eslint-disable require-jsdoc */
2
1
  /**
3
2
  * Auction info class
4
3
  */
@@ -36,6 +35,8 @@ class AuctionInfo {
36
35
  * Age
37
36
  * @type {number}
38
37
  */
38
+
39
+ // eslint-disable-next-line no-underscore-dangle
39
40
  this.age = parseInt(data._headers.get('age'), 10) || 0;
40
41
  }
41
42
 
@@ -32,7 +32,7 @@ class BaseAuction {
32
32
  * Item bytes
33
33
  * @type {ItemBytes|null}
34
34
  */
35
- this.itemBytes = includeItemBytes ? new ItemBytes(data.item_bytes) || null : null;
35
+ this.itemBytes = includeItemBytes ? new ItemBytes(data.item_bytes) : null;
36
36
  }
37
37
  /**
38
38
  * Auction ID
@@ -1,5 +1,19 @@
1
- const dateRegExp = /(\d{1,2})(?:st|nd|rd|th|) ([A-z]+) (\d+)/;
1
+ const dateRegExp = /(\d{1,2})(?:st|nd|rd|th|) ([A-Za-z]+) (\d+)/;
2
2
  const versionRegExp = /v\d+(\.\d+){1,}/;
3
+
4
+ // eslint-disable-next-line jsdoc/require-jsdoc
5
+ function parseDate(stringDate) {
6
+ const matched = stringDate.match(dateRegExp);
7
+ if (!matched) return null;
8
+ return new Date(matched.slice(1).join(' '));
9
+ }
10
+
11
+ // eslint-disable-next-line jsdoc/require-jsdoc
12
+ function parseVer(stringVer) {
13
+ const matches = versionRegExp.exec(stringVer);
14
+ if (!matches?.length) return null;
15
+ return matches[0];
16
+ }
3
17
  /**
4
18
  * SkyblockNews
5
19
  */
@@ -32,7 +46,6 @@ class SkyblockNews {
32
46
  * The version from the title (Skyblock v0.12.57673856757.327.2 => v0.12.57673856757.327.2)
33
47
  * @author linearaccelerator
34
48
  * @type {string | null}
35
- * @version >6.0.1
36
49
  */
37
50
  this.version = parseVer(this.title);
38
51
  }
@@ -44,17 +57,4 @@ class SkyblockNews {
44
57
  return this.title;
45
58
  }
46
59
  }
47
- // eslint-disable-next-line require-jsdoc
48
- function parseDate(stringDate) {
49
- const matched = stringDate.match(dateRegExp);
50
- if (!matched) return null;
51
- return new Date(matched.slice(1).join(' ')); // Ok this is lazy, but should work
52
- }
53
-
54
- // eslint-disable-next-line require-jsdoc
55
- function parseVer(stringVer) {
56
- const matches = versionRegExp.exec(stringVer);
57
- if (!matches?.length) return null; // this shouldn't really happen
58
- return matches[0];
59
- }
60
60
  module.exports = SkyblockNews;
@@ -1,6 +1,11 @@
1
+ const { populateGoals } = require('../../utils/SkyblockUtils');
2
+ // eslint-disable-next-line no-unused-vars
3
+ const BingoDataType = require('./Static/BingoData.js');
4
+ // eslint-disable-next-line no-unused-vars
5
+ const BingoType = require('./Static/Bingo.js');
1
6
  /**
2
- * @typedef {require('./Static/BingoData.js')} BingoData
3
- * @typedef {require('./Static/Bingo.js')} Bingo
7
+ * @typedef {BingoDataType} BingoData
8
+ * @typedef {BingoType} Bingo
4
9
  */
5
10
 
6
11
  /**
@@ -33,18 +38,6 @@ class PlayerBingo {
33
38
  }
34
39
  }
35
40
 
36
- // eslint-disable-next-line require-jsdoc
37
- function populateGoals(achieved, all) {
38
- const populatedAchieved = [];
39
- const unachieved = [];
40
- for (const goal of all) {
41
- if (achieved.find((str) => str === goal.name)) populatedAchieved.push(goal);
42
- else unachieved.push(goal);
43
- }
44
- populatedAchieved.unachievedGoals = unachieved;
45
- return populatedAchieved;
46
- }
47
-
48
41
  /**
49
42
  * @typedef {Object} PlayerBingoDataPerEvent
50
43
  * @property {number} eventId ID of event
@@ -1,3 +1,4 @@
1
+ const { parseRarity, parseGearScore } = require('../../utils/SkyblockUtils');
1
2
  /**
2
3
  * Item class
3
4
  */
@@ -21,7 +22,7 @@ class SkyblockInventoryItem {
21
22
  * @type {string}
22
23
  */
23
24
  this.name =
24
- data.tag.display.Name !== null ? data.tag.display.Name.toString().replace(/§([1-9]|[a-f])|§/gm, '') : null;
25
+ null !== data.tag.display.Name ? data.tag.display.Name.toString().replace(/§([1-9]|[a-f])|§/gm, '') : null;
25
26
  /**
26
27
  * Item lore
27
28
  * @type {string}
@@ -58,7 +59,6 @@ class SkyblockInventoryItem {
58
59
  */
59
60
  this.gemstones = data.tag.ExtraAttributes.gems
60
61
  ? Object.entries(data.tag.ExtraAttributes.gems).map((gem) => {
61
- // eslint-disable-next-line no-new-object
62
62
  return new Object({ type: gem[0].split('_')[0], quality: gem[1] });
63
63
  })
64
64
  : null;
@@ -71,7 +71,6 @@ class SkyblockInventoryItem {
71
71
  * What rarity the item has, as an uppercase string
72
72
  * @author linearaccelerator
73
73
  * @type {string}
74
- * @version >6.0.1
75
74
  */
76
75
  this.rarity = parseRarity(this.loreArray[this.loreArray.length - 1]);
77
76
  /**
@@ -94,7 +93,7 @@ class SkyblockInventoryItem {
94
93
  * Is the item soulbound
95
94
  * @type {boolean}
96
95
  */
97
- this.soulbound = data.tag.ExtraAttributes.donated_museum === 1;
96
+ this.soulbound = 1 === data.tag.ExtraAttributes.donated_museum;
98
97
  /**
99
98
  * Amount of art of war books applied to the item
100
99
  * @type {number}
@@ -114,7 +113,7 @@ class SkyblockInventoryItem {
114
113
  * Is the item recombobulated
115
114
  * @type {boolean}
116
115
  */
117
- this.recombobulated = data.tag.ExtraAttributes.rarity_upgrades === 1;
116
+ this.recombobulated = 1 === data.tag.ExtraAttributes.rarity_upgrades;
118
117
  /**
119
118
  * Item attributes
120
119
  * @type {object}
@@ -159,29 +158,6 @@ class SkyblockInventoryItem {
159
158
  return this.name;
160
159
  }
161
160
  }
162
- // eslint-disable-next-line require-jsdoc
163
- function parseRarity(stringContainingRarity) {
164
- const rarityArray = [
165
- 'COMMON',
166
- 'UNCOMMON',
167
- 'RARE',
168
- 'EPIC',
169
- 'LEGENDARY',
170
- 'MYTHIC',
171
- 'DIVINE',
172
- 'SPECIAL',
173
- 'VERY SPECIAL'
174
- ];
175
- for (const rarity of rarityArray) {
176
- if (stringContainingRarity.includes(rarity)) return rarity;
177
- }
178
- }
179
- // eslint-disable-next-line require-jsdoc
180
- function parseGearScore(lore) {
181
- for (const line of lore) {
182
- if (line.match(/Gear Score: §[0-9a-f](\d+)/)) return Number(line.match(/Gear Score: §d(\d+)/)[1]);
183
- }
184
- }
185
161
 
186
162
  /**
187
163
  * @typedef {object} SkyblockItemGemstone