hypixel-api-reborn 11.1.0 → 11.2.0

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 (93) hide show
  1. package/.prettierrc +3 -3
  2. package/README.md +5 -3
  3. package/package.json +20 -18
  4. package/src/API/getAchievements.js +6 -0
  5. package/src/API/getChallenges.js +6 -0
  6. package/src/API/getGuild.js +1 -1
  7. package/src/API/getGuildAchievements.js +6 -0
  8. package/src/API/getLeaderboards.js +3 -1
  9. package/src/API/getPlayer.js +1 -1
  10. package/src/API/getQuests.js +6 -0
  11. package/src/API/getRecentGames.js +1 -1
  12. package/src/API/getServerInfo.js +3 -1
  13. package/src/API/getStatus.js +1 -1
  14. package/src/API/index.js +28 -17
  15. package/src/API/skyblock/getAuction.js +19 -0
  16. package/src/API/skyblock/{getSkyblockAuctions.js → getAuctions.js} +6 -2
  17. package/src/API/skyblock/{getSkyblockAuctionsByPlayer.js → getAuctionsByPlayer.js} +1 -1
  18. package/src/API/skyblock/getBingo.js +8 -0
  19. package/src/API/skyblock/getBingoByPlayer.js +14 -0
  20. package/src/API/skyblock/getFireSales.js +7 -0
  21. package/src/API/skyblock/getGovernment.js +8 -0
  22. package/src/API/skyblock/{getSkyblockMember.js → getMember.js} +9 -3
  23. package/src/API/skyblock/getMuseum.js +14 -0
  24. package/src/API/skyblock/{getSkyblockProfiles.js → getProfiles.js} +13 -7
  25. package/src/Client.js +88 -14
  26. package/src/Errors.js +38 -17
  27. package/src/Private/rateLimit.js +10 -2
  28. package/src/Private/requests.js +19 -7
  29. package/src/Private/updater.js +9 -5
  30. package/src/Private/uuidCache.js +23 -29
  31. package/src/Private/validate.js +20 -9
  32. package/src/index.js +9 -0
  33. package/src/structures/APIIncident.js +3 -9
  34. package/src/structures/Boosters/Booster.js +5 -5
  35. package/src/structures/Color.js +93 -48
  36. package/src/structures/Game.js +3 -1
  37. package/src/structures/Guild/Guild.js +21 -17
  38. package/src/structures/Guild/GuildMember.js +6 -6
  39. package/src/structures/Guild/GuildRank.js +2 -2
  40. package/src/structures/MiniGames/Arcade.js +22 -17
  41. package/src/structures/MiniGames/BedWars.js +152 -24
  42. package/src/structures/MiniGames/Duels.js +84 -23
  43. package/src/structures/MiniGames/MegaWalls.js +3 -1
  44. package/src/structures/MiniGames/MurderMystery.js +2 -2
  45. package/src/structures/MiniGames/Pit.js +231 -2
  46. package/src/structures/MiniGames/PitInventoryItem.js +43 -0
  47. package/src/structures/MiniGames/SkyWars.js +19 -14
  48. package/src/structures/MiniGames/SmashHeroes.js +1 -1
  49. package/src/structures/MiniGames/TNTGames.js +1 -1
  50. package/src/structures/MiniGames/UHC.js +21 -3
  51. package/src/structures/Player.js +16 -20
  52. package/src/structures/PlayerCosmetics.js +64 -10
  53. package/src/structures/ServerInfo.js +1 -1
  54. package/src/structures/SkyBlock/Auctions/Auction.js +3 -1
  55. package/src/structures/SkyBlock/Auctions/AuctionInfo.js +1 -0
  56. package/src/structures/SkyBlock/Auctions/BaseAuction.js +1 -0
  57. package/src/structures/SkyBlock/Auctions/Bid.js +1 -0
  58. package/src/structures/SkyBlock/Auctions/PartialAuction.js +1 -0
  59. package/src/structures/SkyBlock/PlayerBingo.js +56 -0
  60. package/src/structures/SkyBlock/SkyblockInventoryItem.js +86 -18
  61. package/src/structures/SkyBlock/SkyblockMember.js +252 -144
  62. package/src/structures/SkyBlock/SkyblockMuseum.js +60 -0
  63. package/src/structures/SkyBlock/SkyblockMuseumItem.js +54 -0
  64. package/src/structures/SkyBlock/SkyblockPet.js +1 -0
  65. package/src/structures/SkyBlock/SkyblockProfile.js +37 -23
  66. package/src/structures/SkyBlock/Static/Bingo.js +102 -0
  67. package/src/structures/SkyBlock/Static/BingoData.js +45 -0
  68. package/src/structures/SkyBlock/Static/Candidate.js +40 -0
  69. package/src/structures/SkyBlock/Static/FireSale.js +55 -0
  70. package/src/structures/SkyBlock/Static/Government.js +74 -0
  71. package/src/structures/SkyBlock/Static/Perk.js +24 -0
  72. package/src/structures/Static/Achievement.js +86 -0
  73. package/src/structures/Static/AchievementTier.js +33 -0
  74. package/src/structures/Static/Achievements.js +30 -0
  75. package/src/structures/Static/Challenges.js +29 -0
  76. package/src/structures/Static/GameAchievements.js +36 -0
  77. package/src/structures/Static/GameChallenges.js +40 -0
  78. package/src/structures/Static/GameQuests.js +24 -0
  79. package/src/structures/Static/GuildAchievements.js +34 -0
  80. package/src/structures/Static/Quest.js +66 -0
  81. package/src/structures/Static/Quests.js +31 -0
  82. package/src/structures/Status.js +2 -2
  83. package/src/utils/Constants.js +382 -41
  84. package/src/utils/SkyblockUtils.js +12 -7
  85. package/src/utils/guildExp.js +4 -1
  86. package/src/utils/removeSnakeCase.js +9 -2
  87. package/src/utils/romanize.js +32 -1
  88. package/src/utils/toIGN.js +6 -2
  89. package/src/utils/toUuid.js +10 -5
  90. package/typings/index.d.ts +985 -295
  91. /package/src/API/skyblock/{getSkyblockBazaar.js → getBazaar.js} +0 -0
  92. /package/src/API/skyblock/{getEndedSkyblockAuctions.js → getEndedAuctions.js} +0 -0
  93. /package/src/API/skyblock/{getSkyblockNews.js → getNews.js} +0 -0
package/src/Errors.js CHANGED
@@ -2,44 +2,65 @@
2
2
  module.exports = {
3
3
  INVALID_API_KEY: '[hypixel-api-reborn] Invalid API Key! For help join our Discord Server https://discord.gg/NSEBNMM',
4
4
  NO_API_KEY: '[hypixel-api-reborn] No API Key specified! For help join our Discord Server https://discord.gg/NSEBNMM',
5
- ERROR_CODE_CAUSE: '[hypixel-api-reborn] Code: {code} - {cause}! For help join our Discord Server https://discord.gg/NSEBNMM',
5
+ ERROR_CODE_CAUSE:
6
+ '[hypixel-api-reborn] Code: {code} - {cause}! For help join our Discord Server https://discord.gg/NSEBNMM',
6
7
  ERROR_STATUSTEXT: '[hypixel-api-reborn] {statustext}! For help join our Discord Server https://discord.gg/NSEBNMM',
7
- KEY_MUST_BE_A_STRING: '[hypixel-api-reborn] Specified API Key must be a string! For help join our Discord Server https://discord.gg/NSEBNMM',
8
- OPTIONS_MUST_BE_AN_OBJECT: '[hypixel-api-reborn] Options must be an object! For help join our Discord Server https://discord.gg/NSEBNMM',
9
- CACHE_TIME_MUST_BE_A_NUMBER: '[hypixel-api-reborn] Cache Time must be a number! For help join our Discord Server https://discord.gg/NSEBNMM',
10
- CACHE_LIMIT_MUST_BE_A_NUMBER: '[hypixel-api-reborn] Cache Limit must be a number! For help join our Discord Server https://discord.gg/NSEBNMM',
11
- CACHE_FILTER_INVALID: '[hypixel-api-reborn] Cache Filter must be a function returning a boolean, an object, an array, or a string!',
8
+ KEY_MUST_BE_A_STRING:
9
+ '[hypixel-api-reborn] Specified API Key must be a string! For help join our Discord Server https://discord.gg/NSEBNMM',
10
+ OPTIONS_MUST_BE_AN_OBJECT:
11
+ '[hypixel-api-reborn] Options must be an object! For help join our Discord Server https://discord.gg/NSEBNMM',
12
+ CACHE_TIME_MUST_BE_A_NUMBER:
13
+ '[hypixel-api-reborn] Cache Time must be a number! For help join our Discord Server https://discord.gg/NSEBNMM',
14
+ CACHE_LIMIT_MUST_BE_A_NUMBER:
15
+ '[hypixel-api-reborn] Cache Limit must be a number! For help join our Discord Server https://discord.gg/NSEBNMM',
16
+ CACHE_FILTER_INVALID:
17
+ '[hypixel-api-reborn] Cache Filter must be a function returning a boolean, an object, an array, or a string!',
12
18
  NO_NICKNAME_UUID: '[hypixel-api-reborn] No nickname or uuid specified.',
13
19
  NO_UUID: '[hypixel-api-reborn] No uuid specified.',
14
20
  UUID_NICKNAME_MUST_BE_A_STRING: '[hypixel-api-reborn] Nickname or uuid must be a string.',
15
21
  MALFORMED_UUID: '[hypixel-api-reborn] Malformed UUID!',
16
22
  PLAYER_DOES_NOT_EXIST: '[hypixel-api-reborn] Player does not exist.',
17
23
  PLAYER_HAS_NEVER_LOGGED: '[hypixel-api-reborn] Player has never logged into Hypixel.',
18
- PLAYER_IS_INACTIVE: "[hypixel-api-reborn] No records of recent games because player hasn't been online for more than 3 days or is lacking data to determine the cause of an empty response",
24
+ PLAYER_IS_INACTIVE:
25
+ "[hypixel-api-reborn] No records of recent games because player hasn't been online for more than 3 days or is lacking data to determine the cause of an empty response",
19
26
  PLAYER_DISABLED_ENDPOINT: '[hypixel-api-reborn] Player has disabled this endpoint.',
20
27
  NO_GUILD_QUERY: '[hypixel-api-reborn] No guild search query specified.',
21
28
  INVALID_GUILD_ID: '[hypixel-api-reborn] Specified Guild ID is invalid.',
22
29
  INVALID_GUILD_SEARCH_PARAMETER: "[hypixel-api-reborn] getGuild() searchParameter must be 'id', 'guild' or 'player'.",
23
30
  SOMETHING_WENT_WRONG: '[hypixel-api-reborn] Something went wrong. {cause}',
24
31
  GUILD_DOES_NOT_EXIST: '[hypixel-api-reborn] Guild does not exist.',
25
- PAGE_INDEX_ERROR: '[hypixel-api-reborn] Invalid page index. Must be an integer, an array of 2 integers, or a keyword. For help join our Discord Server https://discord.gg/NSEBNMM',
26
- INVALID_OPTION_VALUE: '[hypixel-api-reborn] Invalid option value! For help join our Discord Server https://discord.gg/NSEBNMM',
27
- INVALID_RESPONSE_BODY: '[hypixel-api-reborn] An error occurred while converting to JSON. Perhaps this is due to an update or maintenance. For help join our Discord Server https://discord.gg/NSEBNMM',
28
- INVALID_RATE_LIMIT_OPTION: "[hypixel-api-reborn] Rate Limit provided in Client options must be 'HARD', 'AUTO', or 'NONE'. For help join our Discord Server https://discord.gg/NSEBNMM",
29
- INVALID_KEY_LIMIT_OPTION: '[hypixel-api-reborn] Key Limit provided in Client options must be an integer representing the amount of requests possible in one minute with your key.',
32
+ PAGE_INDEX_ERROR:
33
+ '[hypixel-api-reborn] Invalid page index. Must be an integer, an array of 2 integers, or a keyword. For help join our Discord Server https://discord.gg/NSEBNMM',
34
+ INVALID_OPTION_VALUE:
35
+ '[hypixel-api-reborn] Invalid option value! For help join our Discord Server https://discord.gg/NSEBNMM',
36
+ INVALID_RESPONSE_BODY:
37
+ '[hypixel-api-reborn] An error occurred while converting to JSON. Perhaps this is due to an update or maintenance. For help join our Discord Server https://discord.gg/NSEBNMM',
38
+ INVALID_RATE_LIMIT_OPTION:
39
+ "[hypixel-api-reborn] Rate Limit provided in Client options must be 'HARD', 'AUTO', or 'NONE'. For help join our Discord Server https://discord.gg/NSEBNMM",
40
+ INVALID_KEY_LIMIT_OPTION:
41
+ '[hypixel-api-reborn] Key Limit provided in Client options must be an integer representing the amount of requests possible in one minute with your key.',
30
42
  INVALID_HEADER_SYNC_OPTION: '[hypixel-api-reborn] Invalid Value for maxSyncHeaders : must be a boolean',
31
43
  INVALID_BURST_OPTION: '[hypixel-api-reborn] maxBurstRequests provided in Client options must be a number',
32
- NODE_VERSION_ERR: "[hypixel-api-reborn] You are using a version of Nodejs that doesn't support certain features we use. Please upgrade to version 14 or above.",
44
+ NODE_VERSION_ERR:
45
+ "[hypixel-api-reborn] You are using a version of Nodejs that doesn't support certain features we use. Please upgrade to version 14 or above.",
33
46
  UPDATER_REQUEST_NOT_OK: '[hypixel-api-reborn] An error occurred checking for updates.',
34
47
  CONNECTION_ERROR: '[hypixel-api-reborn] Failed to connect.',
35
- RATE_LIMIT_INIT_ERROR: '[hypixel-api-reborn] An error happened whilst initializing rate limit. We strongly recommend restarting the code as this can lead to desynchronization.',
48
+ RATE_LIMIT_INIT_ERROR:
49
+ '[hypixel-api-reborn] An error happened whilst initializing rate limit. We strongly recommend restarting the code as this can lead to desynchronization.',
36
50
  MULTIPLE_INSTANCES:
37
51
  '[hypixel-api-reborn] Multiple instances of hypixel-api-reborn are found so we merged them for you. Please refrain from spawning multiple instances in the future. For more information, join our Discord Server https://discord.gg/NSEBNMM.',
38
- INVALID_HEADERS: '[hypixel-api-reborn] Invalid Headers are provided in ClientOptions. For help join our Discord Server https://discord.gg/NSEBNMM',
39
- INVALID_CACHE_HANDLER: '[hypixel-api-reborn] An invalid cache handler is provideed. For help join our Discord Server https://discord.gg/NSEBNMM',
52
+ INVALID_HEADERS:
53
+ '[hypixel-api-reborn] Invalid Headers are provided in ClientOptions. For help join our Discord Server https://discord.gg/NSEBNMM',
54
+ INVALID_CACHE_HANDLER:
55
+ '[hypixel-api-reborn] An invalid cache handler is provideed. For help join our Discord Server https://discord.gg/NSEBNMM',
40
56
  UNEXPECTED_ERROR:
41
57
  "[hypixel-api-reborn] The data provided to hypixel API is malformed and thus not recognized by hypixel, but this shouldn't be your fault. Please report this error in our Discord Server https://discord.gg/NSEBNMM or GitHub. ",
42
58
  RATE_LIMIT_EXCEEDED:
43
59
  "[hypixel-api-reborn] The rate limitations on your API Key has been exceeded. There might be an outage (Check Hypixel's status page), or you simply did too many requests in a short time. Hint: Enable rate limit options! They can help you avoid this error! For help join our Discord Server https://discord.gg/NSEBNMM",
44
- NO_SKYBLOCK_PROFILES: '[hypixel-api-reborn] The player has no skyblock profiles.'
60
+ NO_SKYBLOCK_PROFILES: '[hypixel-api-reborn] The player has no skyblock profiles.',
61
+ INVALID_SILENT_OPTION: '[hypixel-api-reborn] Invalid Value for silent : must be a boolean',
62
+ INVALID_UPDATE_OPTION: '[hypixel-api-reborn] Invalid Value for update : must be a boolean',
63
+ INVALID_THIRD_PARTY_API_OPTION: '[hypixel-api-reborn] Invalid Third Party API option : must be a boolean or string',
64
+ BAD_AUCTION_FILTER:
65
+ '[hypixel-api-reborn] Unexpected filter for Client#getSkyblockAuction. Expected one of "PLAYER", "AUCTION", "PROFILE", but got something else.'
45
66
  };
@@ -23,7 +23,11 @@ class RateLimit {
23
23
  sync(data) {
24
24
  this.options.keyLimit = parseInt(data.get('ratelimit-limit'), 10) || this.options.keyLimit;
25
25
  this.requests = parseInt(data.get('ratelimit-remaining'), 10) || this.requests;
26
- if (data.get('ratelimit-reset') && Math.round(Date.now() / 1000) - (300 - parseInt(data.get('ratelimit-reset'), 10)) !== Math.round(this.lastResetHappenedAt / 1000)) {
26
+ if (
27
+ data.get('ratelimit-reset') &&
28
+ Math.round(Date.now() / 1000) - (300 - parseInt(data.get('ratelimit-reset'), 10)) !==
29
+ Math.round(this.lastResetHappenedAt / 1000)
30
+ ) {
27
31
  clearTimeout(this.resetTimer);
28
32
  this.resetTimer = setTimeout(this.reset.bind(this), parseInt(data.get('ratelimit-reset'), 10) * 1000);
29
33
  }
@@ -32,7 +36,11 @@ class RateLimit {
32
36
  computeCooldownTime() {
33
37
  const overhead = this.requestQueue[1] <= Date.now() ? 0 : this.requestQueue[1] - Date.now();
34
38
  const multiplier = Math.floor(this.requests / this.options.keyLimit) + 1;
35
- return overhead + (-overhead - Date.now() + 300000 * multiplier + this.lastResetHappenedAt) / (this.options.keyLimit * multiplier - this.requests);
39
+ return (
40
+ overhead +
41
+ (-overhead - Date.now() + 300000 * multiplier + this.lastResetHappenedAt) /
42
+ (this.options.keyLimit * multiplier - this.requests)
43
+ );
36
44
  }
37
45
 
38
46
  reset() {
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable require-jsdoc */
2
2
  const requireFetch = !globalThis.fetch;
3
- const externalFetch = require('node-fetch');
3
+ const externalFetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
4
+ const fetch = requireFetch ? externalFetch : globalThis.fetch;
4
5
  const BASE_URL = 'https://api.hypixel.net/v2';
5
6
  const Errors = require('../Errors');
6
7
  const Cache = require('./defaultCache');
@@ -14,16 +15,23 @@ class Requests {
14
15
  }
15
16
  async request(endpoint, options = {}) {
16
17
  options.headers = { 'API-Key': this.client.key, ...options.headers };
17
- const fetchMethod = requireFetch ? externalFetch : fetch;
18
18
  /**
19
19
  * @type {externalFetch.Response|Response}
20
20
  */
21
- const res = await fetchMethod(BASE_URL + endpoint, options);
22
- if (res.status >= 500 && res.status < 528) throw new Error(Errors.ERROR_STATUSTEXT.replace(/{statustext}/, `Server Error : ${res.status} ${res.statusText}`));
21
+ const res = await fetch(BASE_URL + endpoint, options);
22
+ if (res.status >= 500 && res.status < 528) {
23
+ throw new Error(
24
+ Errors.ERROR_STATUSTEXT.replace(/{statustext}/, `Server Error : ${res.status} ${res.statusText}`)
25
+ );
26
+ }
23
27
  const parsedRes = await res.json().catch(() => {
24
28
  throw new Error(Errors.INVALID_RESPONSE_BODY);
25
29
  });
26
- if (res.status === 400) throw new Error(Errors.ERROR_CODE_CAUSE.replace(/{code}/, '400 Bad Request').replace(/{cause}/, parsedRes.cause || ''));
30
+ if (res.status === 400) {
31
+ throw new Error(
32
+ Errors.ERROR_CODE_CAUSE.replace(/{code}/, '400 Bad Request').replace(/{cause}/, parsedRes.cause || '')
33
+ );
34
+ }
27
35
  if (res.status === 403) throw new Error(Errors.INVALID_API_KEY);
28
36
  if (res.status === 422) throw new Error(Errors.UNEXPECTED_ERROR);
29
37
  if (res.status === 429) throw new Error(Errors.RATE_LIMIT_EXCEEDED);
@@ -36,10 +44,14 @@ class Requests {
36
44
  if (options.noCaching) return parsedRes;
37
45
  // split by question mark : first part is /path, remove /
38
46
  if (this.client.options.cache && this.client.options.cacheFilter(endpoint.split('?')[0].slice(1))) {
39
- if (this.client.options.cacheSize < (await this.cached.size())) await this.cached.delete(Array.from(await this.cached.keys())[0]);
47
+ if (this.client.options.cacheSize < (await this.cached.size())) {
48
+ await this.cached.delete(Array.from(await this.cached.keys())[0]);
49
+ }
40
50
  await this.cached.delete(endpoint);
41
51
  await this.cached.set(endpoint, parsedRes);
42
- if (this.client.options.cacheTime >= 0) setTimeout(() => this.cached.delete(endpoint), 1000 * this.client.options.cacheTime);
52
+ if (this.client.options.hypixelCacheTime >= 0) {
53
+ setTimeout(() => this.cached.delete(endpoint), 1000 * this.client.options.hypixelCacheTime);
54
+ }
43
55
  }
44
56
  return parsedRes;
45
57
  }
@@ -1,17 +1,21 @@
1
1
  /* eslint-disable require-jsdoc */
2
2
  /* eslint-disable no-console */
3
- const fetch = require('node-fetch');
3
+ const requireFetch = !globalThis.fetch;
4
+ const externalFetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
5
+ const fetch = requireFetch ? externalFetch : globalThis.fetch;
4
6
  const Errors = require('../Errors');
5
7
  class Updater {
6
8
  async checkForUpdates() {
7
- const currentVersion = require('../../package.json').version;
9
+ const version = require('../../package.json').version;
8
10
  const request = await fetch('https://registry.npmjs.org/hypixel-api-reborn');
9
11
  if (!request.ok) return console.log(Errors.UPDATER_REQUEST_NOT_OK);
10
12
  const metadata = await request.json();
11
- const latestVersion = metadata['dist-tags'].latest;
12
- const compare = this.compare(currentVersion, latestVersion);
13
+ const latest = metadata['dist-tags'].latest;
14
+ const compare = this.compare(version, latest);
13
15
  if (compare === -1) {
14
- console.log(`New version of hypixel-api-reborn is available! Current version: ${currentVersion}, Latest version: ${latestVersion}`);
16
+ console.log(
17
+ `New version of hypixel-api-reborn is available! Current version: ${version}, Latest version: ${latest}`
18
+ );
15
19
  }
16
20
  }
17
21
  compare(a, b) {
@@ -1,37 +1,31 @@
1
1
  /* eslint-disable require-jsdoc */
2
2
  const requireFetch = !globalThis.fetch;
3
- const externalFetch = require('node-fetch');
3
+ const externalFetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
4
4
  const fetch = requireFetch ? externalFetch : globalThis.fetch;
5
- const cachedUuids = new Map();
5
+ const NodeCache = require('node-cache');
6
+ const cache = new NodeCache();
6
7
 
7
8
  // TODO - use this for all cache models
8
9
 
9
- async function putCache(response) {
10
- try {
11
- response = await response.json();
12
- cachedUuids.set(response.id, response.name);
13
- setTimeout(deleteCache, 1000 * 60 * 10, response.id);
14
- } catch (e) {
15
- // F
16
- }
17
- }
18
- function deleteCache(id) {
19
- return cachedUuids.delete(id);
20
- }
21
- function response(obj) {
22
- return new fetch.Response(JSON.stringify(obj));
23
- }
24
- function checkHit(query) {
25
- if (cachedUuids.has(query)) return response({ id: query, name: cachedUuids.get(query) });
26
- const reverseSearch = Array.from(cachedUuids.entries()).find((pair) => pair[1].toLowerCase() === query.toLowerCase());
27
- if (reverseSearch) return response({ id: reverseSearch[0], name: query });
28
- return null;
29
- }
30
- module.exports = async (url, query) => {
31
- if (checkHit(query || url)) return checkHit(query || url);
10
+ module.exports = async (url, query, cacheTime) => {
11
+ if (cache.has(query.toLowerCase())) return cache.get(query.toLowerCase());
32
12
  const res = await fetch(url);
33
- const response = await res.clone().json();
34
- // Don't cache 5xx
35
- if (response.error !== 'Internal Server Error' && response.status < 500) setTimeout(putCache, 0, res.clone());
36
- return res;
13
+ const data = await res.json();
14
+ // Don't cache 4xx
15
+ if (res.status >= 400) {
16
+ return {
17
+ status: res.status,
18
+ id: null,
19
+ name: null
20
+ };
21
+ }
22
+
23
+ cache.set(query.toLowerCase(), { status: res.status, id: data.id, name: data.name }, cacheTime);
24
+ cache.set(data.id.toLowerCase(), { status: res.status, id: data.id, name: data.name }, cacheTime);
25
+
26
+ return {
27
+ status: res.status,
28
+ id: data.id,
29
+ name: data.name
30
+ };
37
31
  };
@@ -12,12 +12,20 @@ class Validation {
12
12
  * @private
13
13
  */
14
14
  validateOptions(options) {
15
- if (typeof options.cacheTime !== 'number') throw new Error(Errors.CACHE_TIME_MUST_BE_A_NUMBER);
15
+ if (typeof options.hypixelCacheTime !== 'number') throw new Error(Errors.CACHE_TIME_MUST_BE_A_NUMBER);
16
+ if (typeof options.mojangCacheTime !== 'number') throw new Error(Errors.CACHE_TIME_MUST_BE_A_NUMBER);
16
17
  if (typeof options.cacheSize !== 'number') throw new Error(Errors.CACHE_LIMIT_MUST_BE_A_NUMBER);
17
- if (typeof options.rateLimit !== 'string' || !['AUTO', 'HARD', 'NONE'].includes(options.rateLimit)) throw new Error(Errors.INVALID_RATE_LIMIT_OPTION);
18
+ if (typeof options.rateLimit !== 'string' || !['AUTO', 'HARD', 'NONE'].includes(options.rateLimit)) {
19
+ throw new Error(Errors.INVALID_RATE_LIMIT_OPTION);
20
+ }
18
21
  if (typeof options.keyLimit !== 'number') throw new Error(Errors.INVALID_KEY_LIMIT_OPTION);
19
22
  if (typeof options.syncWithHeaders !== 'boolean') throw new Error(Errors.INVALID_HEADER_SYNC_OPTION);
20
23
  if (typeof options.headers !== 'object') throw new Error(Errors.INVALID_HEADERS);
24
+ if (typeof options.silent !== 'boolean') throw new Error(Errors.INVALID_SILENT_OPTION);
25
+ if (typeof options.checkForUpdates !== 'boolean') throw new Error(Errors.INVALID_UPDATE_OPTION);
26
+ if (!['boolean', 'string'].includes(typeof options.useThirdPartyAPI)) {
27
+ throw new Error(Errors.INVALID_THIRD_PARTY_API_OPTION);
28
+ }
21
29
  }
22
30
 
23
31
  /**
@@ -29,16 +37,19 @@ class Validation {
29
37
  parseOptions(options) {
30
38
  if (typeof options !== 'object' || options === null) throw new Error(Errors.OPTIONS_MUST_BE_AN_OBJECT);
31
39
  return {
32
- cache: options.cache || false,
33
- cacheTime: options.cacheTime || 60,
40
+ cache: options.cache ?? true,
41
+ hypixelCacheTime: options.hypixelCacheTime ?? 60,
42
+ mojangCacheTime: options.mojangCacheTime ?? 600,
34
43
  cacheSize: (options.cacheSize === -1 ? Infinity : options.cacheSize) || Infinity,
35
- cacheFilter: typeof options.cacheFilter === 'function' ? options.cacheFilter : this._handleFilter(options.cacheFilter),
36
- rateLimit: options.rateLimit || 'AUTO',
37
- keyLimit: options.keyLimit || 120,
44
+ cacheFilter:
45
+ typeof options.cacheFilter === 'function' ? options.cacheFilter : this._handleFilter(options.cacheFilter),
46
+ rateLimit: options.rateLimit ?? 'AUTO',
47
+ keyLimit: options.keyLimit ?? 60,
38
48
  syncWithHeaders: !!options.syncWithHeaders,
39
- headers: options.headers || {},
49
+ headers: options.headers ?? {},
40
50
  silent: !!options.silent,
41
- checkForUpdates: options.checkForUpdates || true
51
+ checkForUpdates: options.checkForUpdates ?? true,
52
+ useThirdPartyAPI: options.useThirdPartyAPI ?? false
42
53
  };
43
54
  }
44
55
 
package/src/index.js CHANGED
@@ -14,6 +14,10 @@ module.exports = {
14
14
  Pets: require('./structures/Pets'),
15
15
  PlayerCosmetics: require('./structures/PlayerCosmetics'),
16
16
 
17
+ /* Challenges */
18
+ Challenges: require('./structures/Static/Challenges.js'),
19
+ GameChallenges: require('./structures/Static/GameChallenges.js'),
20
+
17
21
  /* Watchdog */
18
22
  WatchdogStats: require('./structures/Watchdog/Stats.js'),
19
23
 
@@ -27,6 +31,10 @@ module.exports = {
27
31
  SkyblockMember: require('./structures/SkyBlock/SkyblockMember.js'),
28
32
  SkyblockInventoryItem: require('./structures/SkyBlock/SkyblockInventoryItem.js'),
29
33
  SkyblockPet: require('./structures/SkyBlock/SkyblockPet'),
34
+ GovernmentData: require('./structures/SkyBlock/Static/Government.js'),
35
+ Candidate: require('./structures/SkyBlock/Static/Candidate.js'),
36
+ BingoData: require('./structures/SkyBlock/Static/BingoData.js'),
37
+ Bingo: require('./structures/SkyBlock/Static/Bingo.js'),
30
38
 
31
39
  /* Skyblock Auctions */
32
40
  BaseAuction: require('./structures/SkyBlock/Auctions/BaseAuction.js'),
@@ -34,6 +42,7 @@ module.exports = {
34
42
  Auction: require('./structures/SkyBlock/Auctions/Auction.js'),
35
43
  AuctionInfo: require('./structures/SkyBlock/Auctions/AuctionInfo.js'),
36
44
  Bid: require('./structures/SkyBlock/Auctions/Bid.js'),
45
+ FireSale: require('./structures/SkyBlock/Static/FireSale.js'),
37
46
 
38
47
  /* Skyblock Bazaar */
39
48
  Product: require('./structures/SkyBlock/Bazzar/Product.js'),
@@ -42,12 +42,6 @@ class APIIncident {
42
42
  * @type {string|null}
43
43
  */
44
44
  this.snippet = data.contentSnippet || null;
45
- /**
46
- * Content as plain text
47
- * The parsing might be faulty!
48
- * @type {string|null}
49
- */
50
- this.TextContent = (data.content || '').replace(/<[^>]+>/g, '') || null;
51
45
  /**
52
46
  * GUID
53
47
  * @type {string|null}
@@ -64,14 +58,14 @@ class APIIncident {
64
58
  * @type {boolean}
65
59
  * @version >6.0.1
66
60
  */
67
- this.isResolved = this.TextContent.includes('Resolved -') || this.TextContent.includes('Completed -');
61
+ this.isResolved = this.HTMLContent.includes('Resolved -') || this.HTMLContent.includes('Completed -');
68
62
  }
69
63
  /**
70
- * Text Content
64
+ * HTML Content
71
65
  * @return {string}
72
66
  */
73
67
  toString() {
74
- return this.TextContent;
68
+ return this.HTMLContent;
75
69
  }
76
70
  }
77
71
 
@@ -9,27 +9,27 @@ class Booster {
9
9
  constructor(data) {
10
10
  /**
11
11
  * Booster's purchaser's UUID
12
- * @type {String}
12
+ * @type {string}
13
13
  */
14
14
  this.purchaser = data.purchaserUuid;
15
15
  /**
16
16
  * Booster's multiplier
17
- * @type {Number}
17
+ * @type {number}
18
18
  */
19
19
  this.amount = data.amount;
20
20
  /**
21
21
  * Booster's length in seconds
22
- * @type {Number}
22
+ * @type {number}
23
23
  */
24
24
  this.originalLength = data.originalLength;
25
25
  /**
26
26
  * Length remaining in seconds
27
- * @type {Number}
27
+ * @type {number}
28
28
  */
29
29
  this.remaining = data.length;
30
30
  /**
31
31
  * Date activated timestamp
32
- * @type {Number}
32
+ * @type {number}
33
33
  */
34
34
  this.activatedTimestamp = data.dateActivated;
35
35
  /**
@@ -68,62 +68,107 @@ class Color {
68
68
  toCode() {
69
69
  return this.color;
70
70
  }
71
+
72
+ /**
73
+ * Returns color code
74
+ * @return {InGameCode}
75
+ */
76
+ toInGameCode() {
77
+ const InGameCodes = {
78
+ BLACK: '§0',
79
+ DARK_BLUE: '§1',
80
+ DARK_GREEN: '§2',
81
+ DARK_AQUA: '§3',
82
+ DARK_RED: '§4',
83
+ DARK_PURPLE: '§5',
84
+ GOLD: '§6',
85
+ GRAY: '§7',
86
+ DARK_GRAY: '§8',
87
+ BLUE: '§9',
88
+ GREEN: '§a',
89
+ AQUA: '§b',
90
+ RED: '§c',
91
+ LIGHT_PURPLE: '§d',
92
+ YELLOW: '§e',
93
+ WHITE: '§f'
94
+ };
95
+ return InGameCodes[this.color];
96
+ }
71
97
  }
72
98
  /**
73
99
  * @typedef {string} ColorCode
74
- * * `BLACK`
75
- * * `DARK_BLUE`
76
- * * `DARK_GREEN`
77
- * * `DARK_AQUA`
78
- * * `DARK_RED`
79
- * * `DARK_PURPLE`
80
- * * `GOLD`
81
- * * `GRAY`
82
- * * `DARK_GRAY`
83
- * * `BLUE`
84
- * * `GREEN`
85
- * * `AQUA`
86
- * * `RED`
87
- * * `LIGHT_PURPLE`
88
- * * `YELLOW`
89
- * * `WHITE`
100
+ * * 'BLACK'
101
+ * * 'DARK_BLUE'
102
+ * * 'DARK_GREEN'
103
+ * * 'DARK_AQUA'
104
+ * * 'DARK_RED'
105
+ * * 'DARK_PURPLE'
106
+ * * 'GOLD'
107
+ * * 'GRAY'
108
+ * * 'DARK_GRAY'
109
+ * * 'BLUE'
110
+ * * 'GREEN'
111
+ * * 'AQUA'
112
+ * * 'RED'
113
+ * * 'LIGHT_PURPLE'
114
+ * * 'YELLOW'
115
+ * * 'WHITE'
90
116
  */
91
117
  /**
92
118
  * @typedef {string} ColorString
93
- * * BLACK: `Black`
94
- * * DARK_BLUE: `Dark Blue`
95
- * * DARK_GREEN: `Dark Green`
96
- * * DARK_AQUA: `Dark Aqua`
97
- * * DARK_RED: `Dark Red`
98
- * * DARK_PURPLE: `Dark Purple`
99
- * * GOLD: `Gold`
100
- * * GRAY: `Gray`
101
- * * DARK_GRAY: `Dark Gray`
102
- * * BLUE: `Blue`,
103
- * * GREEN: `Green`
104
- * * AQUA: `Aqua`
105
- * * RED: `Red`
106
- * * LIGHT_PURPLE: `Light Purple`
107
- * * YELLOW: `Yellow`
108
- * * WHITE: `White`
119
+ * * BLACK: 'Black'
120
+ * * DARK_BLUE: 'Dark Blue'
121
+ * * DARK_GREEN: 'Dark Green'
122
+ * * DARK_AQUA: 'Dark Aqua'
123
+ * * DARK_RED: 'Dark Red'
124
+ * * DARK_PURPLE: 'Dark Purple'
125
+ * * GOLD: 'Gold'
126
+ * * GRAY: 'Gray'
127
+ * * DARK_GRAY: 'Dark Gray'
128
+ * * BLUE: 'Blue`'
129
+ * * GREEN: 'Green'
130
+ * * AQUA: 'Aqua'
131
+ * * RED: 'Red'
132
+ * * LIGHT_PURPLE: 'Light Purple'
133
+ * * YELLOW: 'Yellow'
134
+ * * WHITE: 'White'
109
135
  */
110
136
  /**
111
137
  * @typedef {string} ColorHex
112
- * * BLACK: `#000000`
113
- * * DARK_BLUE: `#0000AA`
114
- * * DARK_GREEN: `#008000`
115
- * * DARK_AQUA: `#00AAAA`
116
- * * DARK_RED: `#AA0000`
117
- * * DARK_PURPLE: `#AA00AA`
118
- * * GOLD: `#FFAA00`
119
- * * GRAY: `#AAAAAA`
120
- * * DARK_GRAY: `#555555`
121
- * * BLUE: `#5555FF`
122
- * * GREEN: `#3CE63C`
123
- * * AQUA: `#3CE6E6`
124
- * * RED: `#FF5555`
125
- * * LIGHT_PURPLE: `#FF55FF`
126
- * * YELLOW: `#FFFF55`
127
- * * WHITE: `#FFFFFF`
138
+ * * BLACK: '#000000'
139
+ * * DARK_BLUE: '#0000AA'
140
+ * * DARK_GREEN: '#008000'
141
+ * * DARK_AQUA: '#00AAAA'
142
+ * * DARK_RED: '#AA0000'
143
+ * * DARK_PURPLE: '#AA00AA'
144
+ * * GOLD: '#FFAA00'
145
+ * * GRAY: '#AAAAAA'
146
+ * * DARK_GRAY: '#555555'
147
+ * * BLUE: '#5555FF'
148
+ * * GREEN: '#3CE63C'
149
+ * * AQUA: '#3CE6E6'
150
+ * * RED: '#FF5555'
151
+ * * LIGHT_PURPLE: '#FF55FF'
152
+ * * YELLOW: '#FFFF55'
153
+ * * WHITE: '#FFFFFF'
154
+ */
155
+ /**
156
+ * @typedef {string} InGameCode
157
+ * * BLACK: '§0'
158
+ * * DARK_BLUE: '§1'
159
+ * * DARK_GREEN: '§2'
160
+ * * DARK_AQUA: '§3'
161
+ * * DARK_RED: '§4'
162
+ * * DARK_PURPLE: '§5'
163
+ * * GOLD: '§6'
164
+ * * GRAY: '§7'
165
+ * * DARK_GRAY: '§8'
166
+ * * BLUE: '§9'
167
+ * * GREEN: '§a'
168
+ * * AQUA: '§b'
169
+ * * RED: '§c'
170
+ * * LIGHT_PURPLE: '§d'
171
+ * * YELLOW: '§e'
172
+ * * WHITE: '§f'
128
173
  */
129
174
  module.exports = Color;
@@ -12,7 +12,9 @@ class Game {
12
12
  * @type {GameId|GameCode}
13
13
  */
14
14
  this.game = game.toString().toLowerCase();
15
- const result = games.find((g) => g.code.toLowerCase() === this.game || g.id.toString() === this.game || g.name.toLowerCase() === this.game);
15
+ const result = games.find(
16
+ (g) => g.code.toLowerCase() === this.game || g.id.toString() === this.game || g.name.toLowerCase() === this.game
17
+ );
16
18
  /**
17
19
  * ID of game
18
20
  * @type {GameId}