hypixel-api-reborn 11.1.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 (113) hide show
  1. package/.prettierrc +3 -3
  2. package/README.md +6 -4
  3. package/eslint.config.mjs +71 -0
  4. package/package.json +21 -25
  5. package/src/API/getAchievements.js +7 -0
  6. package/src/API/getBoosters.js +1 -0
  7. package/src/API/getChallenges.js +7 -0
  8. package/src/API/getGameCounts.js +1 -0
  9. package/src/API/getGuild.js +5 -4
  10. package/src/API/getGuildAchievements.js +7 -0
  11. package/src/API/getLeaderboards.js +4 -2
  12. package/src/API/getPlayer.js +2 -1
  13. package/src/API/getQuests.js +7 -0
  14. package/src/API/getRecentGames.js +6 -10
  15. package/src/API/getServerInfo.js +42 -37
  16. package/src/API/getStatus.js +2 -1
  17. package/src/API/getWatchdogStats.js +1 -0
  18. package/src/API/index.js +28 -17
  19. package/src/API/skyblock/getAuction.js +21 -0
  20. package/src/API/skyblock/{getSkyblockAuctions.js → getAuctions.js} +19 -12
  21. package/src/API/skyblock/{getSkyblockAuctionsByPlayer.js → getAuctionsByPlayer.js} +2 -2
  22. package/src/API/skyblock/{getSkyblockBazaar.js → getBazaar.js} +1 -3
  23. package/src/API/skyblock/getBingo.js +7 -0
  24. package/src/API/skyblock/getBingoByPlayer.js +14 -0
  25. package/src/API/skyblock/{getEndedSkyblockAuctions.js → getEndedAuctions.js} +1 -0
  26. package/src/API/skyblock/getFireSales.js +7 -0
  27. package/src/API/skyblock/getGovernment.js +7 -0
  28. package/src/API/skyblock/{getSkyblockMember.js → getMember.js} +10 -3
  29. package/src/API/skyblock/getMuseum.js +15 -0
  30. package/src/API/skyblock/{getSkyblockNews.js → getNews.js} +1 -0
  31. package/src/API/skyblock/{getSkyblockProfiles.js → getProfiles.js} +14 -7
  32. package/src/Client.js +127 -25
  33. package/src/Errors.js +38 -17
  34. package/src/Private/rateLimit.js +17 -13
  35. package/src/Private/requests.js +27 -16
  36. package/src/Private/updater.js +11 -8
  37. package/src/Private/uuidCache.js +23 -30
  38. package/src/Private/validate.js +33 -22
  39. package/src/index.js +9 -0
  40. package/src/structures/APIIncident.js +4 -11
  41. package/src/structures/APIStatus.js +0 -1
  42. package/src/structures/Boosters/Booster.js +14 -13
  43. package/src/structures/Color.js +93 -48
  44. package/src/structures/Game.js +4 -2
  45. package/src/structures/Guild/Guild.js +35 -48
  46. package/src/structures/Guild/GuildMember.js +8 -8
  47. package/src/structures/Guild/GuildRank.js +2 -2
  48. package/src/structures/MiniGames/Arcade.js +242 -235
  49. package/src/structures/MiniGames/ArenaBrawl.js +11 -11
  50. package/src/structures/MiniGames/BedWars.js +262 -131
  51. package/src/structures/MiniGames/BlitzSurvivalGames.js +24 -23
  52. package/src/structures/MiniGames/CopsAndCrims.js +1 -0
  53. package/src/structures/MiniGames/Duels.js +92 -33
  54. package/src/structures/MiniGames/MegaWalls.js +3 -1
  55. package/src/structures/MiniGames/MurderMystery.js +2 -2
  56. package/src/structures/MiniGames/Pit.js +230 -2
  57. package/src/structures/MiniGames/PitInventoryItem.js +43 -0
  58. package/src/structures/MiniGames/SkyWars.js +211 -195
  59. package/src/structures/MiniGames/SmashHeroes.js +37 -35
  60. package/src/structures/MiniGames/SpeedUHC.js +17 -4
  61. package/src/structures/MiniGames/TNTGames.js +1 -1
  62. package/src/structures/MiniGames/UHC.js +33 -14
  63. package/src/structures/MiniGames/WoolWars.js +6 -5
  64. package/src/structures/Pet.js +1 -1
  65. package/src/structures/Player.js +26 -121
  66. package/src/structures/PlayerCosmetics.js +67 -12
  67. package/src/structures/ServerInfo.js +1 -1
  68. package/src/structures/SkyBlock/Auctions/Auction.js +3 -1
  69. package/src/structures/SkyBlock/Auctions/AuctionInfo.js +3 -1
  70. package/src/structures/SkyBlock/Auctions/BaseAuction.js +2 -1
  71. package/src/structures/SkyBlock/Auctions/Bid.js +1 -0
  72. package/src/structures/SkyBlock/Auctions/PartialAuction.js +1 -0
  73. package/src/structures/SkyBlock/News/SkyblockNews.js +15 -15
  74. package/src/structures/SkyBlock/PlayerBingo.js +49 -0
  75. package/src/structures/SkyBlock/SkyblockInventoryItem.js +76 -32
  76. package/src/structures/SkyBlock/SkyblockMember.js +252 -289
  77. package/src/structures/SkyBlock/SkyblockMuseum.js +60 -0
  78. package/src/structures/SkyBlock/SkyblockMuseumItem.js +54 -0
  79. package/src/structures/SkyBlock/SkyblockPet.js +3 -3
  80. package/src/structures/SkyBlock/SkyblockProfile.js +37 -23
  81. package/src/structures/SkyBlock/Static/Bingo.js +101 -0
  82. package/src/structures/SkyBlock/Static/BingoData.js +45 -0
  83. package/src/structures/SkyBlock/Static/Candidate.js +40 -0
  84. package/src/structures/SkyBlock/Static/FireSale.js +55 -0
  85. package/src/structures/SkyBlock/Static/Government.js +74 -0
  86. package/src/structures/SkyBlock/Static/Perk.js +24 -0
  87. package/src/structures/Static/Achievement.js +87 -0
  88. package/src/structures/Static/AchievementTier.js +33 -0
  89. package/src/structures/Static/Achievements.js +30 -0
  90. package/src/structures/Static/Challenges.js +29 -0
  91. package/src/structures/Static/GameAchievements.js +36 -0
  92. package/src/structures/Static/GameChallenges.js +40 -0
  93. package/src/structures/Static/GameQuests.js +24 -0
  94. package/src/structures/Static/GuildAchievements.js +34 -0
  95. package/src/structures/Static/Quest.js +66 -0
  96. package/src/structures/Static/Quests.js +31 -0
  97. package/src/structures/Status.js +2 -2
  98. package/src/utils/Constants.js +384 -543
  99. package/src/utils/{guildExp.js → Guild.js} +46 -13
  100. package/src/utils/Player.js +112 -0
  101. package/src/utils/SkyblockUtils.js +448 -186
  102. package/src/utils/arrayTools.js +1 -1
  103. package/src/utils/divide.js +1 -1
  104. package/src/utils/index.js +2 -1
  105. package/src/utils/isGuildID.js +1 -1
  106. package/src/utils/oscillation.js +4 -2
  107. package/src/utils/removeSnakeCase.js +19 -8
  108. package/src/utils/rgbToHexColor.js +1 -1
  109. package/src/utils/romanize.js +35 -4
  110. package/src/utils/toUuid.js +12 -7
  111. package/src/utils/varInt.js +2 -2
  112. package/typings/index.d.ts +1246 -446
  113. package/src/utils/toIGN.js +0 -20
@@ -1,5 +1,12 @@
1
+ /* eslint-disable jsdoc/require-jsdoc */
2
+ const GuildRank = require('../structures/Guild/GuildRank');
1
3
  const dateRegExp = /(\d{4})-(\d{2})-(\d{2})/;
2
- // eslint-disable-next-line require-jsdoc
4
+
5
+ function parseDate(date) {
6
+ date[1] -= 1;
7
+ return new Date(Math.round(new Date(new Date().setUTCFullYear(...date)).setUTCHours(5, 0, 0) / 1000) * 1000);
8
+ }
9
+
3
10
  function parseHistory(historyData) {
4
11
  return Object.entries(historyData).map((x, index) => ({
5
12
  day: x[0],
@@ -17,27 +24,23 @@ function parseHistory(historyData) {
17
24
  }));
18
25
  }
19
26
 
20
- // eslint-disable-next-line require-jsdoc
21
- function parseDate(date) {
22
- date[1] -= 1;
23
- return new Date(Math.round(new Date(new Date().setUTCFullYear(...date)).setUTCHours(5, 0, 0) / 1000) * 1000);
24
- }
25
-
26
- // eslint-disable-next-line require-jsdoc
27
27
  function getGuildLevel(exp) {
28
- const EXP_NEEDED = [100000, 150000, 250000, 500000, 750000, 1000000, 1250000, 1500000, 2000000, 2500000, 2500000, 2500000, 2500000, 2500000, 3000000];
28
+ const EXP_NEEDED = [
29
+ 100000, 150000, 250000, 500000, 750000, 1000000, 1250000, 1500000, 2000000, 2500000, 2500000, 2500000, 2500000,
30
+ 2500000, 3000000
31
+ ];
29
32
 
30
33
  let level = 0;
31
34
 
32
- for (let i = 0; i <= 1000; i += 1) {
33
- let need = 0;
35
+ for (let i = 0; 1000 >= i; i += 1) {
36
+ let need;
34
37
  if (i >= EXP_NEEDED.length) {
35
38
  need = EXP_NEEDED[EXP_NEEDED.length - 1];
36
39
  } else {
37
40
  need = EXP_NEEDED[i];
38
41
  }
39
42
 
40
- if (exp - need < 0) {
43
+ if (0 > exp - need) {
41
44
  return Math.round((level + exp / need) * 100) / 100;
42
45
  }
43
46
  level += 1;
@@ -47,6 +50,28 @@ function getGuildLevel(exp) {
47
50
  return 1000;
48
51
  }
49
52
 
53
+ function ranks(data) {
54
+ return data.ranks && data.ranks.length
55
+ ? data.ranks.map((r) => new GuildRank(r)).sort((a, b) => a.priority - b.priority)
56
+ : [];
57
+ }
58
+
59
+ function expLimit(exp) {
60
+ return 2e5 < exp ? (7e5 < exp ? 2.5e5 + Math.round(exp * 0.03) : 2e5 + Math.round((exp - 2e5) / 10)) : exp;
61
+ }
62
+
63
+ function calculateExpHistory(data) {
64
+ const finalObj = {};
65
+ for (const day of Object.keys(data.members[0].expHistory)) {
66
+ let gexp = 0;
67
+ for (const member of data.members) {
68
+ gexp += member.expHistory[day] || 0;
69
+ }
70
+ finalObj[day] = expLimit(gexp);
71
+ }
72
+ return parseHistory(finalObj);
73
+ }
74
+
50
75
  /**
51
76
  * @typedef {object} ExpHistory
52
77
  * @property {string} day String Date ( unparsed )
@@ -54,4 +79,12 @@ function getGuildLevel(exp) {
54
79
  * @property {number} exp Experience of the day
55
80
  * @property {number} totalExp Experience earned from day 0 to this day
56
81
  */
57
- module.exports = { parseHistory, getGuildLevel };
82
+
83
+ module.exports = {
84
+ parseDate,
85
+ parseHistory,
86
+ getGuildLevel,
87
+ ranks,
88
+ expLimit,
89
+ calculateExpHistory
90
+ };
@@ -0,0 +1,112 @@
1
+ /* eslint-disable jsdoc/require-jsdoc */
2
+ function getRank(player) {
3
+ let rank;
4
+ if (player.prefix) {
5
+ rank = player.prefix.replace(/§[0-9|a-z]|\[|\]/g, '');
6
+ } else if (player.rank && 'NORMAL' !== player.rank) {
7
+ switch (player.rank) {
8
+ case 'YOUTUBER':
9
+ rank = 'YouTube';
10
+ break;
11
+ case 'GAME_MASTER':
12
+ rank = 'Game Master';
13
+ break;
14
+ case 'ADMIN':
15
+ rank = 'Admin';
16
+ break;
17
+ default:
18
+ rank = '';
19
+ break;
20
+ }
21
+ } else {
22
+ switch (player.newPackageRank) {
23
+ case 'MVP_PLUS':
24
+ rank = player.monthlyPackageRank && 'SUPERSTAR' === player.monthlyPackageRank ? 'MVP++' : 'MVP+';
25
+ break;
26
+ case 'MVP':
27
+ rank = 'MVP';
28
+ break;
29
+ case 'VIP_PLUS':
30
+ rank = 'VIP+';
31
+ break;
32
+ case 'VIP':
33
+ rank = 'VIP';
34
+ break;
35
+ default:
36
+ rank = player.monthlyPackageRank && 'SUPERSTAR' === player.monthlyPackageRank ? 'MVP++' : 'Default';
37
+ }
38
+ }
39
+ return rank;
40
+ }
41
+
42
+ function getPlayerLevel(exp) {
43
+ const base = 10000;
44
+ const growth = 2500;
45
+ const reversePqPrefix = -(base - 0.5 * growth) / growth;
46
+ const reverseConst = reversePqPrefix * reversePqPrefix;
47
+ const growthDivides2 = 2 / growth;
48
+ const num = 1 + reversePqPrefix + Math.sqrt(reverseConst + growthDivides2 * exp);
49
+ const level = Math.round(num * 100) / 100;
50
+ return level;
51
+ }
52
+
53
+ function xpToNextLevel(player) {
54
+ const lvl = getPlayerLevel(player.networkExp);
55
+ const xpToNext = 2500 * Math.floor(lvl) + 5000;
56
+ if (10000 > player.networkExp) return 10000;
57
+ return xpToNext;
58
+ }
59
+
60
+ function levelToXP(player) {
61
+ let level = Number(Math.floor(getPlayerLevel(player.networkExp)));
62
+ level = level - 1;
63
+ const xp = 1250 * level ** 2 + 8750 * level;
64
+ return xp;
65
+ }
66
+
67
+ function playerLevelProgress(player) {
68
+ const xpFromLevel = levelToXP(player);
69
+ let currentXP = player.networkExp - xpFromLevel;
70
+ const xpToNext = xpToNextLevel(player);
71
+ const remainingXP = xpToNext - currentXP + 2500;
72
+ currentXP = currentXP - 2500;
73
+ const percent = Math.round((currentXP / xpToNext) * 100 * 100) / 100;
74
+ const percentRemaining = Math.round((100 - percent) * 100) / 100;
75
+ return {
76
+ xpToNext,
77
+ remainingXP,
78
+ currentXP,
79
+ percent,
80
+ percentRemaining
81
+ };
82
+ }
83
+
84
+ function getSocialMedia(data) {
85
+ if (!data) return null;
86
+ const links = data.links;
87
+ const formattedNames = ['Twitter', 'YouTube', 'Instagram', 'Twitch', 'Hypixel', 'Discord'];
88
+ const upperNames = ['TWITTER', 'YOUTUBE', 'INSTAGRAM', 'TWITCH', 'HYPIXEL', 'DISCORD'];
89
+ if (!links) return null;
90
+ return Object.keys(links)
91
+ .map((x) => upperNames.indexOf(x))
92
+ .filter((x) => -1 !== x)
93
+ .map((x) => ({ name: formattedNames[x], link: links[upperNames[x]], id: upperNames[x] }));
94
+ }
95
+
96
+ function parseClaimedRewards(data) {
97
+ if (!data) return null;
98
+ return Object.keys(data)
99
+ .map((x) => x.match(/levelingReward_(\d+)/))
100
+ .filter((x) => x)
101
+ .map((x) => parseInt(x[1], 10));
102
+ }
103
+
104
+ module.exports = {
105
+ getRank,
106
+ getPlayerLevel,
107
+ xpToNextLevel,
108
+ levelToXP,
109
+ playerLevelProgress,
110
+ getSocialMedia,
111
+ parseClaimedRewards
112
+ };