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
package/.prettierrc CHANGED
@@ -5,9 +5,9 @@
5
5
  "bracketSpacing": true,
6
6
  "proseWrap": "always",
7
7
  "singleQuote": true,
8
- "printWidth": 210,
8
+ "printWidth": 120,
9
+ "endOfLine": "lf",
9
10
  "useTabs": false,
10
11
  "tabWidth": 2,
11
- "semi": true,
12
- "endOfLine": "lf"
12
+ "semi": true
13
13
  }
package/README.md CHANGED
@@ -15,12 +15,15 @@
15
15
 
16
16
  ### Links
17
17
 
18
- [Discord Support](https://discord.gg/NSEBNMM) | [Documentation](https://hypixel-api-reborn.github.io/) | [NPM](https://www.npmjs.com/package/hypixel-api-reborn) |
19
- [GitHub](https://github.com/Hypixel-API-Reborn/hypixel-api-reborn) | [ToDo](https://github.com/Hypixel-API-Reborn/hypixel-api-reborn/projects/1) | [CLI](https://github.com/Hypixel-API-Reborn/cli)
18
+ [Discord Support](https://discord.gg/NSEBNMM) | [Documentation](https://hypixel-api-reborn.github.io/) |
19
+ [NPM](https://www.npmjs.com/package/hypixel-api-reborn) |
20
+ [GitHub](https://github.com/Hypixel-API-Reborn/hypixel-api-reborn) |
21
+ [ToDo](https://github.com/Hypixel-API-Reborn/hypixel-api-reborn/projects/1) |
22
+ [CLI](https://github.com/Hypixel-API-Reborn/cli)
20
23
 
21
24
  #### Requirements
22
25
 
23
- **For Node.js users >= v14.x.x** <br> **For TypeScript users >= v3.5**
26
+ **For Node.js users >= v18.18.0** <br> **For TypeScript users >= v3.5**
24
27
 
25
28
  ### Installation & Usage
26
29
 
@@ -31,7 +34,6 @@ npm i hypixel-api-reborn
31
34
  ```js
32
35
  const Hypixel = require('hypixel-api-reborn');
33
36
  const hypixel = new Hypixel.Client('API-KEY');
34
- // https://stavzdev.is-inside.me/cCMiZdoy.gif
35
37
 
36
38
  // getPlayer
37
39
  hypixel
@@ -0,0 +1,71 @@
1
+ import jsdoc from 'eslint-plugin-jsdoc';
2
+ import globals from 'globals';
3
+ import js from '@eslint/js';
4
+
5
+ export default [
6
+ js.configs.recommended,
7
+ {
8
+ ignores: ['docs/**', 'tests/**', 'node_modules/*'],
9
+ plugins: { jsdoc: jsdoc },
10
+ languageOptions: {
11
+ ecmaVersion: 2021,
12
+ sourceType: 'commonjs',
13
+ globals: {
14
+ ...globals.commonjs,
15
+ ...globals.es2021,
16
+ ...globals.node
17
+ }
18
+ },
19
+ rules: {
20
+ 'max-len': ['error', { code: 120, ignoreUrls: true, ignoreComments: true }],
21
+ 'no-constant-condition': ['error', { checkLoops: false }],
22
+ 'prefer-const': ['warn', { destructuring: 'all' }],
23
+ 'no-unused-vars': ['error', { args: 'none' }],
24
+ curly: ['warn', 'multi-line', 'consistent'],
25
+ 'logical-assignment-operators': 'warn',
26
+ 'no-template-curly-in-string': 'error',
27
+ 'quote-props': ['error', 'as-needed'],
28
+ 'jsdoc/no-undefined-types': 'warn',
29
+ 'comma-dangle': ['error', 'never'],
30
+ 'no-useless-constructor': 'error',
31
+ 'no-useless-assignment': 'error',
32
+ 'no-inner-declarations': 'error',
33
+ 'no-implicit-coercion': 'error',
34
+ 'jsdoc/require-jsdoc': 'error',
35
+ 'no-use-before-define': 'warn',
36
+ 'no-underscore-dangle': 'warn',
37
+ 'no-unneeded-ternary': 'error',
38
+ 'jsdoc/check-values': 'error',
39
+ 'default-param-last': 'error',
40
+ 'one-var': ['warn', 'never'],
41
+ 'no-inline-comments': 'warn',
42
+ 'jsdoc/valid-types': 'error',
43
+ 'no-empty-function': 'error',
44
+ 'no-useless-return': 'error',
45
+ 'no-useless-rename': 'warn',
46
+ 'no-useless-concat': 'warn',
47
+ 'no-throw-literal': 'error',
48
+ 'no-extend-native': 'error',
49
+ 'default-case-last': 'warn',
50
+ 'no-self-compare': 'error',
51
+ 'no-new-wrappers': 'error',
52
+ 'no-lone-blocks': 'error',
53
+ 'no-undef-init': 'error',
54
+ 'no-else-return': 'warn',
55
+ 'no-extra-semi': 'error',
56
+ 'require-await': 'warn',
57
+ yoda: ['error', 'always'],
58
+ 'default-case': 'error',
59
+ 'dot-notation': 'error',
60
+ 'no-sequences': 'warn',
61
+ 'no-multi-str': 'warn',
62
+ 'no-lonely-if': 'warn',
63
+ 'no-new-func': 'error',
64
+ 'no-console': 'error',
65
+ camelcase: 'warn',
66
+ 'no-var': 'warn',
67
+ eqeqeq: 'warn',
68
+ semi: 'error'
69
+ }
70
+ }
71
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypixel-api-reborn",
3
- "version": "11.1.0",
3
+ "version": "11.2.1",
4
4
  "description": "Feature-rich Hypixel API wrapper for Node.js",
5
5
  "main": "./src/index.js",
6
6
  "types": "./typings/index.d.ts",
@@ -16,25 +16,23 @@
16
16
  "url": "https://github.com/Hypixel-API-Reborn/hypixel-api-reborn/issues"
17
17
  },
18
18
  "scripts": {
19
- "eslint": "npx eslint src/ typings/",
20
- "eslint:fix": "npx eslint src/ typings/ --fix",
21
- "lint:dev": "npm run eslint && npm run dtslint",
22
- "test": "npx mocha tests --exit",
23
- "docgen": "npx docgen -s src -o ../docs/master.json",
24
- "docgen:custom": "npx docgen -s src --custom docs/index.yml -o ../docs/master.json",
25
- "dtslint": "npx dtslint typings",
26
- "prettier": "npx prettier --write src/ typings/",
27
- "prettier:check": "npx prettier --check src/ typings/"
19
+ "lint": "npx eslint --cache src/",
20
+ "lint:fix": "npx eslint --cache src/ --fix",
21
+ "tests": "npx mocha tests --exit --recursive",
22
+ "docgen": " npx docgen -s src/ --custom docs/index.yml -o ./master.json",
23
+ "prettier": "npx prettier --cache --write src/ typings/",
24
+ "prettier:check": "npx prettier --cache --check src/ typings/"
28
25
  },
29
26
  "engines": {
30
- "node": ">=14.0.0"
27
+ "node": ">=18.18.0"
31
28
  },
32
29
  "author": "StavZ",
33
30
  "dependencies": {
34
- "node-fetch": "^2.6.1",
35
- "object-path": "^0.11.8",
36
- "prismarine-nbt": "^2.1.0",
37
- "rss-parser": "^3.13.0"
31
+ "node-cache": "^5.1.2",
32
+ "node-fetch": "^3.3.2",
33
+ "prismarine-nbt": "^2.5.0",
34
+ "rss-parser": "^3.13.0",
35
+ "skyhelper-networth": "latest"
38
36
  },
39
37
  "license": "MIT",
40
38
  "readme": "https://hypixel.stavzdev.me/",
@@ -43,18 +41,16 @@
43
41
  },
44
42
  "publisher": "StavZ",
45
43
  "devDependencies": {
46
- "@types/node": "^20.6.5",
47
- "@typescript-eslint/eslint-plugin": "^4.33.0",
48
- "@typescript-eslint/parser": "^4.33.0",
44
+ "@discordjs/docgen": "github:discordjs/docgen",
45
+ "@types/node": "^20.11.19",
49
46
  "chai": "^4.3.4",
50
- "dtslint": "^4.1.6",
51
- "eslint": "^7.32.0",
52
- "eslint-config-google": "^0.14.0",
53
- "eslint-config-prettier": "^9.0.0",
54
- "mocha": "^9.1.2",
47
+ "eslint": "^9.3.0",
48
+ "eslint-plugin-jsdoc": "^48.2.7",
49
+ "globals": "^15.3.0",
50
+ "mocha": "^10.4.0",
55
51
  "node-env-run": "^4.0.2",
56
52
  "path": "^0.12.7",
57
- "prettier": "^3.0.3",
58
- "typescript": "^4.3.3"
53
+ "prettier": "^3.2.5",
54
+ "typescript": "^5.3.3"
59
55
  }
60
56
  }
@@ -0,0 +1,7 @@
1
+ module.exports = async function () {
2
+ const Achievements = require('../structures/Static/Achievements');
3
+ // eslint-disable-next-line no-underscore-dangle
4
+ const res = await this._makeRequest('/resources/achievements');
5
+ if (res.raw) return res;
6
+ return new Achievements(res);
7
+ };
@@ -1,5 +1,6 @@
1
1
  module.exports = async function () {
2
2
  const Booster = require('../structures/Boosters/Booster');
3
+ // eslint-disable-next-line no-underscore-dangle
3
4
  const res = await this._makeRequest('/boosters');
4
5
  if (res.raw) return res;
5
6
  return res.boosters.length ? res.boosters.map((b) => new Booster(b)).reverse() : [];
@@ -0,0 +1,7 @@
1
+ module.exports = async function () {
2
+ const Challenges = require('../structures/Static/Challenges');
3
+ // eslint-disable-next-line no-underscore-dangle
4
+ const res = await this._makeRequest('/resources/challenges');
5
+ if (res.raw) return res;
6
+ return new Challenges(res);
7
+ };
@@ -1,5 +1,6 @@
1
1
  const GameCounts = require('../structures/GameCounts');
2
2
  module.exports = async function () {
3
+ // eslint-disable-next-line no-underscore-dangle
3
4
  const res = await this._makeRequest('/counts');
4
5
  if (res.raw) return res;
5
6
  return new GameCounts(res);
@@ -4,13 +4,14 @@ const isGuildID = require('../utils/isGuildID');
4
4
  module.exports = async function (searchParameter, query) {
5
5
  if (!query) throw new Error(Errors.NO_GUILD_QUERY);
6
6
  const Guild = require('../structures/Guild/Guild');
7
- if (searchParameter === 'id' && !isGuildID(query)) throw new Error(Errors.INVALID_GUILD_ID);
8
- const isPlayerQuery = searchParameter === 'player';
9
- if (isPlayerQuery) query = await toUuid(query);
7
+ if ('id' === searchParameter && !isGuildID(query)) throw new Error(Errors.INVALID_GUILD_ID);
8
+ const isPlayerQuery = 'player' === searchParameter;
9
+ if (isPlayerQuery) query = await toUuid(query, this.options.mojangCacheTime, this.options.useThirdPartyAPI);
10
10
  if (!['id', 'name', 'player'].includes(searchParameter)) throw new Error(Errors.INVALID_GUILD_SEARCH_PARAMETER);
11
+ // eslint-disable-next-line no-underscore-dangle
11
12
  const res = await this._makeRequest(`/guild?${searchParameter}=${encodeURI(query)}`);
12
13
  if (res.raw) return res;
13
- if (!res.guild && searchParameter !== 'player') {
14
+ if (!res.guild && 'player' !== searchParameter) {
14
15
  throw new Error(Errors.GUILD_DOES_NOT_EXIST);
15
16
  }
16
17
 
@@ -0,0 +1,7 @@
1
+ module.exports = async function () {
2
+ const GuildAchievements = require('../structures/Static/GuildAchievements');
3
+ // eslint-disable-next-line no-underscore-dangle
4
+ const res = await this._makeRequest('/resources/guilds/achievements');
5
+ if (res.raw) return res;
6
+ return new GuildAchievements(res);
7
+ };
@@ -1,13 +1,15 @@
1
1
  const Errors = require('../Errors');
2
2
  module.exports = async function () {
3
3
  const Leaderboard = require('../structures/Leaderboard');
4
+ // eslint-disable-next-line no-underscore-dangle
4
5
  const res = await this._makeRequest('/leaderboards');
5
6
  if (res.raw) return res;
6
7
  if (!res.leaderboards) throw new Error(Errors.SOMETHING_WENT_WRONG.replace(/{cause}/, 'Try again.'));
7
8
  const lbnames = Object.create(require('../utils/Constants').leaderboardNames);
8
- // eslint-disable-next-line guard-for-in
9
9
  for (const name in lbnames) {
10
- lbnames[name] = res.leaderboards[lbnames[name]].length ? res.leaderboards[lbnames[name]].map((lb) => new Leaderboard(lb)) : [];
10
+ lbnames[name] = res.leaderboards[lbnames[name]].length
11
+ ? res.leaderboards[lbnames[name]].map((lb) => new Leaderboard(lb))
12
+ : [];
11
13
  }
12
14
  return lbnames;
13
15
  };
@@ -5,7 +5,8 @@ const getRecentGames = require('./getRecentGames');
5
5
  module.exports = async function (query, options = { guild: false, recentGames: false }) {
6
6
  if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
7
7
  const Player = require('../structures/Player');
8
- query = await toUuid(query);
8
+ query = await toUuid(query, this.options.mojangCacheTime, this.options.useThirdPartyAPI);
9
+ // eslint-disable-next-line no-underscore-dangle
9
10
  const res = await this._makeRequest(`/player?uuid=${query}`);
10
11
  if (res.raw) return res;
11
12
  if (query && !res.player) throw new Error(Errors.PLAYER_HAS_NEVER_LOGGED);
@@ -0,0 +1,7 @@
1
+ module.exports = async function () {
2
+ const Quests = require('../structures/Static/Quests');
3
+ // eslint-disable-next-line no-underscore-dangle
4
+ const res = await this._makeRequest('/resources/quests');
5
+ if (res.raw) return res;
6
+ return new Quests(res);
7
+ };
@@ -1,18 +1,14 @@
1
- const Errors = require('../Errors');
2
1
  const toUuid = require('../utils/toUuid');
3
- const day3 = 1000 * 60 * 60 * 24 * 3;
4
- module.exports = async function (query, playerData) {
2
+ const Errors = require('../Errors');
3
+ module.exports = async function (query) {
5
4
  if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
6
5
  const RecentGame = require('../structures/RecentGame');
7
-
8
- query = await toUuid(query);
9
-
6
+ query = await toUuid(query, this.options.mojangCacheTime, this.options.useThirdPartyAPI);
7
+ // eslint-disable-next-line no-underscore-dangle
10
8
  const res = await this._makeRequest(`/recentgames?uuid=${query}`);
11
9
  if (res.raw) return res;
12
- if (res.games === []) {
13
- if (!playerData) throw new Error(Errors.PLAYER_IS_INACTIVE);
14
- if (Date.now() - playerData.lastLogoutTimestamp < day3) throw new Error(Errors.PLAYER_DISABLED_ENDPOINT);
15
- throw new Error(Errors.PLAYER_IS_INACTIVE);
10
+ if (0 === res.games.length) {
11
+ return [];
16
12
  }
17
13
  return res.games.map((x) => new RecentGame(x));
18
14
  };
@@ -1,11 +1,43 @@
1
- const net = require('net');
2
- const Errors = require('../Errors');
1
+ /* eslint-disable jsdoc/require-jsdoc */
3
2
  const ServerInfo = require('../structures/ServerInfo');
4
3
  const varInt = require('../utils/varInt');
5
- const packetsToSend = ['1500E0050E6D632E6879706978656C2E6E657463DD01', '0100', '09010000000000000000'].map((x) => Buffer.from(x, 'hex')); // To avoid dependency hell, these are precompiled as hex.
4
+ const Errors = require('../Errors');
5
+ const net = require('net');
6
+ const packetsToSend = ['1500E0050E6D632E6879706978656C2E6E657463DD01', '0100', '09010000000000000000'].map((x) =>
7
+ // To avoid dependency hell, these are precompiled as hex.
8
+ Buffer.from(x, 'hex')
9
+ );
10
+
11
+ async function ping(cli) {
12
+ await cli.write(packetsToSend[2]);
13
+ const time = Date.now();
14
+ return new Promise((resolve) => {
15
+ cli.once('data', () => {
16
+ resolve(Date.now() - time);
17
+ });
18
+ });
19
+ }
20
+
21
+ async function getPing(amount, cli) {
22
+ let pingSum = 0;
23
+ for (let i = 0; i < amount; i++) {
24
+ pingSum += await ping(cli);
25
+ }
26
+ cli.destroy();
27
+ return Math.round(pingSum / amount);
28
+ }
29
+
30
+ function parseData(stringJson, ping) {
31
+ try {
32
+ return new ServerInfo(JSON.parse(stringJson), ping);
33
+ } catch {
34
+ return undefined;
35
+ }
36
+ }
37
+
6
38
  module.exports = async function (repeats) {
7
- if (repeats < 0 || typeof repeats !== 'number') repeats = 3;
8
- if (repeats > 10) repeats = 10;
39
+ if (0 > repeats || 'number' !== typeof repeats) repeats = 3;
40
+ if (10 < repeats) repeats = 10;
9
41
  let aggregatedData = '';
10
42
  let dataLength = 0;
11
43
  return await new Promise((resolve, reject) => {
@@ -18,7 +50,7 @@ module.exports = async function (repeats) {
18
50
  });
19
51
  cli.on('data', async (data) => {
20
52
  if (!aggregatedData) {
21
- const varIntBorder = data.findIndex((x) => x === 0x00) + 1;
53
+ const varIntBorder = data.findIndex((x) => 0x00 === x) + 1;
22
54
  dataLength = varInt(
23
55
  data
24
56
  .toString('hex', 0, varIntBorder)
@@ -27,40 +59,13 @@ module.exports = async function (repeats) {
27
59
  );
28
60
  dataLength -= varIntBorder * 8;
29
61
  aggregatedData += data.toString('utf-8', 5);
30
- } else aggregatedData += data.toString('utf-8');
62
+ } else {
63
+ aggregatedData += data.toString('utf-8');
64
+ }
31
65
 
32
66
  if (dataLength >= aggregatedData.length) return;
33
- cli.removeAllListeners('data'); // Remove this listener
67
+ cli.removeAllListeners('data');
34
68
  resolve(parseData(aggregatedData, await getPing(repeats, cli)));
35
69
  });
36
70
  });
37
71
  };
38
- // eslint-disable-next-line require-jsdoc
39
- async function getPing(amount, cli) {
40
- let pingSum = 0;
41
- for (let i = 0; i < amount; i++) {
42
- pingSum += await ping(cli);
43
- }
44
- cli.destroy();
45
- return Math.round(pingSum / amount);
46
- }
47
-
48
- // eslint-disable-next-line require-jsdoc
49
- async function ping(cli) {
50
- await cli.write(packetsToSend[2]);
51
- const time = Date.now();
52
- return new Promise((resolve) => {
53
- cli.once('data', () => {
54
- resolve(Date.now() - time);
55
- });
56
- });
57
- }
58
-
59
- // eslint-disable-next-line require-jsdoc
60
- function parseData(stringJson, ping) {
61
- try {
62
- return new ServerInfo(JSON.parse(stringJson), ping);
63
- } catch (e) {
64
- return undefined;
65
- }
66
- }
@@ -1,7 +1,8 @@
1
1
  const toUuid = require('../utils/toUuid');
2
2
  module.exports = async function (query) {
3
3
  const Status = require('../structures/Status');
4
- query = await toUuid(query);
4
+ query = await toUuid(query, this.options.mojangCacheTime, this.options.useThirdPartyAPI);
5
+ // eslint-disable-next-line no-underscore-dangle
5
6
  const res = await this._makeRequest(`/status?uuid=${query}`);
6
7
  if (res.raw) return res;
7
8
  return new Status(res.session);
@@ -1,5 +1,6 @@
1
1
  module.exports = async function () {
2
2
  const WatchdogStats = require('../structures/Watchdog/Stats');
3
+ // eslint-disable-next-line no-underscore-dangle
3
4
  const res = await this._makeRequest('/punishmentstats');
4
5
  if (res.raw) return res;
5
6
  return new WatchdogStats(res);
package/src/API/index.js CHANGED
@@ -1,19 +1,30 @@
1
1
  module.exports = {
2
- getAPIStatus: require('./getAPIStatus'),
3
- getBoosters: require('./getBoosters'),
4
- getGameCounts: require('./getGameCounts'),
5
- getGuild: require('./getGuild'),
6
- getLeaderboards: require('./getLeaderboards'),
7
- getPlayer: require('./getPlayer'),
8
- getRecentGames: require('./getRecentGames'),
9
- getServerInfo: require('./getServerInfo'),
10
- getStatus: require('./getStatus'),
11
- getWatchdogStats: require('./getWatchdogStats'),
12
- getEndedSkyblockAuctions: require('./skyblock/getEndedSkyblockAuctions'),
13
- getSkyblockAuctions: require('./skyblock/getSkyblockAuctions'),
14
- getSkyblockAuctionsByPlayer: require('./skyblock/getSkyblockAuctionsByPlayer'),
15
- getSkyblockBazaar: require('./skyblock/getSkyblockBazaar'),
16
- getSkyblockMember: require('./skyblock/getSkyblockMember'),
17
- getSkyblockNews: require('./skyblock/getSkyblockNews'),
18
- getSkyblockProfiles: require('./skyblock/getSkyblockProfiles')
2
+ getAchievements: require('./getAchievements.js'),
3
+ getAPIStatus: require('./getAPIStatus.js'),
4
+ getBoosters: require('./getBoosters.js'),
5
+ getChallenges: require('./getChallenges.js'),
6
+ getGameCounts: require('./getGameCounts.js'),
7
+ getGuild: require('./getGuild.js'),
8
+ getGuildAchievements: require('./getGuildAchievements.js'),
9
+ getLeaderboards: require('./getLeaderboards.js'),
10
+ getPlayer: require('./getPlayer.js'),
11
+ getQuests: require('./getQuests.js'),
12
+ getRecentGames: require('./getRecentGames.js'),
13
+ getServerInfo: require('./getServerInfo.js'),
14
+ getStatus: require('./getStatus.js'),
15
+ getWatchdogStats: require('./getWatchdogStats.js'),
16
+
17
+ getSkyblockAuction: require('./skyblock/getAuction.js'),
18
+ getSkyblockAuctions: require('./skyblock/getAuctions.js'),
19
+ getSkyblockAuctionsByPlayer: require('./skyblock/getAuctionsByPlayer.js'),
20
+ getSkyblockBazaar: require('./skyblock/getBazaar.js'),
21
+ getSkyblockBingo: require('./skyblock/getBingo.js'),
22
+ getSkyblockBingoByPlayer: require('./skyblock/getBingoByPlayer.js'),
23
+ getSkyblockEndedAuctions: require('./skyblock/getEndedAuctions.js'),
24
+ getSkyblockFireSales: require('./skyblock/getFireSales.js'),
25
+ getSkyblockGovernment: require('./skyblock/getGovernment.js'),
26
+ getSkyblockMember: require('./skyblock/getMember.js'),
27
+ getSkyblockMuseum: require('./skyblock/getMuseum.js'),
28
+ getSkyblockNews: require('./skyblock/getNews.js'),
29
+ getSkyblockProfiles: require('./skyblock/getProfiles.js')
19
30
  };
@@ -0,0 +1,21 @@
1
+ const Errors = require('../../Errors');
2
+ const toUuid = require('../../utils/toUuid');
3
+ module.exports = async function (type, query, includeItemBytes = false) {
4
+ if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
5
+ const Auction = require('../../structures/SkyBlock/Auctions/Auction');
6
+ let filter;
7
+ if ('PROFILE' === type) {
8
+ filter = 'profile';
9
+ } else if ('PLAYER' === type) {
10
+ query = await toUuid(query, this.options.mojangCacheTime, this.options.useThirdPartyAPI);
11
+ filter = 'player';
12
+ } else if ('AUCTION' === type) {
13
+ filter = 'uuid';
14
+ } else {
15
+ throw new Error(Errors.BAD_AUCTION_FILTER);
16
+ }
17
+ // eslint-disable-next-line no-underscore-dangle
18
+ const res = await this._makeRequest(`/skyblock/auction?${filter}=${query}`);
19
+ if (res.raw) return res;
20
+ return res.auctions.length ? res.auctions.map((a) => new Auction(a, includeItemBytes)) : [];
21
+ };
@@ -1,10 +1,10 @@
1
- /* eslint-disable require-jsdoc */
1
+ /* eslint-disable jsdoc/require-jsdoc */
2
2
  const Auction = require('../../structures/SkyBlock/Auctions/Auction');
3
3
  const AuctionInfo = require('../../structures/SkyBlock/Auctions/AuctionInfo');
4
4
  const Errors = require('../../Errors');
5
- let _makeRequest;
6
5
  async function getPage(page = 0, options = {}) {
7
- const content = await _makeRequest(`/skyblock/auctions?page=${page}`, false);
6
+ // eslint-disable-next-line no-underscore-dangle
7
+ const content = await this._makeRequest(`/skyblock/auctions?page=${page}`, false);
8
8
  const result = {};
9
9
  if (!options.noInfo) result.info = new AuctionInfo(content);
10
10
  if (options.raw) result.auctions = content.auctions;
@@ -16,22 +16,26 @@ async function noReject(promise, args = [], retries = 3, cooldown = 100) {
16
16
  try {
17
17
  const result = await promise.call(null, ...args);
18
18
  return result;
19
- } catch (e) {
19
+ } catch {
20
20
  if (retries) {
21
21
  await new Promise((resolve) => setTimeout(resolve, cooldown));
22
22
  return await noReject(promise, args, retries - 1, cooldown);
23
- } else return null;
23
+ }
24
+ return null;
24
25
  }
25
26
  }
26
27
  module.exports = async function (range, options = {}) {
27
- _makeRequest = this._makeRequest;
28
- options.retries = options.retries || 3;
29
- options.cooldown = options.cooldown || 100;
30
- if (range == null || range === '*') range = [0, (await getPage(0, { noAuctions: true })).info.totalPages];
28
+ options.retries ||= 3;
29
+ options.cooldown ||= 100;
30
+ if (null === range || '*' === range) range = [0, (await getPage(0, { noAuctions: true })).info.totalPages];
31
31
  if (!Array.isArray(range)) range = [parseInt(range), parseInt(range)];
32
32
  if (isNaN(range[0])) throw new Error(Errors.PAGE_INDEX_ERROR);
33
- if (parseInt(options.retries) !== options.retries || options.retries > 10 || options.retries < 0) throw new Error(Errors.INVALID_OPTION_VALUE);
34
- if (parseInt(options.cooldown) !== options.cooldown || options.cooldown > 3000 || options.cooldown < 0) throw new Error(Errors.INVALID_OPTION_VALUE);
33
+ if (parseInt(options.retries) !== options.retries || 10 < options.retries || 0 > options.retries) {
34
+ throw new Error(Errors.INVALID_OPTION_VALUE);
35
+ }
36
+ if (parseInt(options.cooldown) !== options.cooldown || 3000 < options.cooldown || 0 > options.cooldown) {
37
+ throw new Error(Errors.INVALID_OPTION_VALUE);
38
+ }
35
39
  range = range.sort();
36
40
  const result = { auctions: [] };
37
41
  const fetches = [];
@@ -45,7 +49,9 @@ module.exports = async function (range, options = {}) {
45
49
  if (resp) {
46
50
  result.auctions = result.auctions.concat(resp.auctions);
47
51
  if (resp.info) result.info = resp.info;
48
- } else failedPages.push(i);
52
+ } else {
53
+ failedPages.push(i);
54
+ }
49
55
  }
50
56
  }
51
57
  if (fetches.length) {
@@ -59,6 +65,7 @@ module.exports = async function (range, options = {}) {
59
65
  return pV;
60
66
  }, []);
61
67
  }
68
+ // eslint-disable-next-line no-underscore-dangle
62
69
  result.info = result.info ? result.info._extend('failedPages', failedPages) : { failedPages };
63
70
  return result;
64
71
  };
@@ -3,9 +3,9 @@ const toUuid = require('../../utils/toUuid');
3
3
  module.exports = async function (query, includeItemBytes = false) {
4
4
  if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
5
5
  const Auction = require('../../structures/SkyBlock/Auctions/Auction');
6
- query = await toUuid(query);
6
+ query = await toUuid(query, this.options.mojangCacheTime, this.options.useThirdPartyAPI);
7
+ // eslint-disable-next-line no-underscore-dangle
7
8
  const res = await this._makeRequest(`/skyblock/auction?player=${query}`);
8
9
  if (res.raw) return res;
9
-
10
10
  return res.auctions.length ? res.auctions.map((a) => new Auction(a, includeItemBytes)) : [];
11
11
  };
@@ -1,10 +1,8 @@
1
1
  module.exports = async function () {
2
2
  const Product = require('../../structures/SkyBlock/Bazzar/Product');
3
-
3
+ // eslint-disable-next-line no-underscore-dangle
4
4
  const res = await this._makeRequest('/skyblock/bazaar');
5
5
  if (res.raw) return res;
6
-
7
6
  const productsKeys = Object.keys(res.products);
8
-
9
7
  return productsKeys.map((x) => new Product(res.products[x]));
10
8
  };
@@ -0,0 +1,7 @@
1
+ module.exports = async function () {
2
+ const BingoData = require('../../structures/SkyBlock/Static/BingoData');
3
+ // eslint-disable-next-line no-underscore-dangle
4
+ const res = await this._makeRequest('/resources/skyblock/bingo');
5
+ if (res.raw) return res;
6
+ return new BingoData(res);
7
+ };
@@ -0,0 +1,14 @@
1
+ const toUuid = require('../../utils/toUuid');
2
+ const getBingo = require('./getBingo');
3
+ const Errors = require('../../Errors');
4
+ module.exports = async function (query, { fetchBingoData = false }) {
5
+ if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
6
+ const PlayerBingo = require('../../structures/SkyBlock/PlayerBingo');
7
+ query = await toUuid(query, this.options.mojangCacheTime, this.options.useThirdPartyAPI);
8
+ // eslint-disable-next-line no-underscore-dangle
9
+ const res = await this._makeRequest(`/skyblock/uuid?player=${query}`);
10
+ if (res.raw) return res;
11
+ let bingoData = null;
12
+ if (fetchBingoData) bingoData = await getBingo.call(this);
13
+ return new PlayerBingo(res, bingoData);
14
+ };
@@ -1,6 +1,7 @@
1
1
  const PartialAuction = require('../../structures/SkyBlock/Auctions/PartialAuction');
2
2
  const AuctionInfo = require('../../structures/SkyBlock/Auctions/AuctionInfo');
3
3
  module.exports = async function (includeItemBytes = false) {
4
+ // eslint-disable-next-line no-underscore-dangle
4
5
  const res = await this._makeRequest('/skyblock/auctions_ended', false);
5
6
  if (res.raw) return res;
6
7
  return {
@@ -0,0 +1,7 @@
1
+ module.exports = async function () {
2
+ const FireSale = require('../../structures/SkyBlock/Static/FireSale');
3
+ // eslint-disable-next-line no-underscore-dangle
4
+ const res = await this._makeRequest('/skyblock/firesales');
5
+ if (res.raw) return res;
6
+ return res.sales.length ? res.sales.map((a) => new FireSale(a)) : [];
7
+ };