hypixel-api-reborn 10.0.0 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/.prettierrc +13 -0
  2. package/README.md +28 -16
  3. package/package.json +60 -58
  4. package/src/API/getAPIStatus.js +8 -8
  5. package/src/API/getBoosters.js +6 -6
  6. package/src/API/getGameCounts.js +6 -6
  7. package/src/API/getGuild.js +18 -18
  8. package/src/API/getLeaderboards.js +13 -13
  9. package/src/API/getPlayer.js +22 -27
  10. package/src/API/getRecentGames.js +18 -18
  11. package/src/API/getServerInfo.js +66 -77
  12. package/src/API/getStatus.js +8 -8
  13. package/src/API/getWatchdogStats.js +6 -6
  14. package/src/API/index.js +19 -23
  15. package/src/API/skyblock/getEndedSkyblockAuctions.js +10 -10
  16. package/src/API/skyblock/getSkyblockAuctions.js +64 -64
  17. package/src/API/skyblock/getSkyblockAuctionsByPlayer.js +11 -11
  18. package/src/API/skyblock/getSkyblockBazaar.js +10 -10
  19. package/src/API/skyblock/getSkyblockMember.js +28 -25
  20. package/src/API/skyblock/getSkyblockNews.js +6 -6
  21. package/src/API/skyblock/getSkyblockProfiles.js +44 -41
  22. package/src/Client.js +406 -450
  23. package/src/Errors.js +44 -39
  24. package/src/Private/defaultCache.js +77 -78
  25. package/src/Private/rateLimit.js +79 -98
  26. package/src/Private/requests.js +65 -54
  27. package/src/Private/updater.js +45 -45
  28. package/src/Private/uuidCache.js +37 -33
  29. package/src/Private/validate.js +97 -97
  30. package/src/index.js +82 -83
  31. package/src/structures/APIIncident.js +78 -78
  32. package/src/structures/APIStatus.js +47 -47
  33. package/src/structures/Boosters/Booster.js +83 -87
  34. package/src/structures/Color.js +129 -129
  35. package/src/structures/Game.js +164 -160
  36. package/src/structures/GameCounts.js +151 -151
  37. package/src/structures/Guild/Guild.js +204 -218
  38. package/src/structures/Guild/GuildMember.js +66 -66
  39. package/src/structures/Guild/GuildRank.js +48 -48
  40. package/src/structures/ItemBytes.js +33 -36
  41. package/src/structures/Leaderboard.js +31 -31
  42. package/src/structures/MiniGames/Arcade.js +567 -569
  43. package/src/structures/MiniGames/ArenaBrawl.js +52 -56
  44. package/src/structures/MiniGames/BedWars.js +423 -351
  45. package/src/structures/MiniGames/BlitzSurvivalGames.js +172 -148
  46. package/src/structures/MiniGames/BuildBattle.js +53 -53
  47. package/src/structures/MiniGames/CopsAndCrims.js +90 -90
  48. package/src/structures/MiniGames/Duels.js +694 -630
  49. package/src/structures/MiniGames/MegaWalls.js +137 -137
  50. package/src/structures/MiniGames/MurderMystery.js +93 -93
  51. package/src/structures/MiniGames/Paintball.js +67 -67
  52. package/src/structures/MiniGames/Pit.js +19 -19
  53. package/src/structures/MiniGames/Quakecraft.js +101 -101
  54. package/src/structures/MiniGames/SkyWars.js +508 -559
  55. package/src/structures/MiniGames/SmashHeroes.js +144 -151
  56. package/src/structures/MiniGames/SpeedUHC.js +115 -57
  57. package/src/structures/MiniGames/TNTGames.js +116 -116
  58. package/src/structures/MiniGames/TurboKartRacers.js +201 -176
  59. package/src/structures/MiniGames/UHC.js +164 -143
  60. package/src/structures/MiniGames/VampireZ.js +60 -60
  61. package/src/structures/MiniGames/Walls.js +52 -52
  62. package/src/structures/MiniGames/Warlords.js +62 -62
  63. package/src/structures/MiniGames/WoolWars.js +123 -0
  64. package/src/structures/Pet.js +96 -97
  65. package/src/structures/Pets.js +64 -64
  66. package/src/structures/Player.js +433 -449
  67. package/src/structures/PlayerCosmetics.js +100 -95
  68. package/src/structures/RecentGame.js +57 -57
  69. package/src/structures/ServerInfo.js +78 -78
  70. package/src/structures/SkyBlock/Auctions/Auction.js +104 -104
  71. package/src/structures/SkyBlock/Auctions/AuctionInfo.js +54 -54
  72. package/src/structures/SkyBlock/Auctions/BaseAuction.js +45 -45
  73. package/src/structures/SkyBlock/Auctions/Bid.js +48 -48
  74. package/src/structures/SkyBlock/Auctions/PartialAuction.js +25 -25
  75. package/src/structures/SkyBlock/Bazzar/Order.js +38 -38
  76. package/src/structures/SkyBlock/Bazzar/Product.js +53 -53
  77. package/src/structures/SkyBlock/News/SkyblockNews.js +60 -68
  78. package/src/structures/SkyBlock/SkyblockInventoryItem.js +124 -130
  79. package/src/structures/SkyBlock/SkyblockMember.js +820 -687
  80. package/src/structures/SkyBlock/SkyblockPet.js +71 -71
  81. package/src/structures/SkyBlock/SkyblockProfile.js +60 -60
  82. package/src/structures/Status.js +41 -41
  83. package/src/structures/Watchdog/Stats.js +36 -36
  84. package/src/utils/Constants.js +2789 -809
  85. package/src/utils/SkyblockUtils.js +208 -164
  86. package/src/utils/arrayTools.js +4 -4
  87. package/src/utils/divide.js +5 -5
  88. package/src/utils/guildExp.js +57 -67
  89. package/src/utils/index.js +13 -13
  90. package/src/utils/isGuildID.js +3 -3
  91. package/src/utils/isUUID.js +5 -5
  92. package/src/utils/oscillation.js +15 -23
  93. package/src/utils/removeSnakeCase.js +22 -35
  94. package/src/utils/rgbToHexColor.js +8 -8
  95. package/src/utils/romanize.js +11 -13
  96. package/src/utils/toIGN.js +20 -20
  97. package/src/utils/toUuid.js +19 -19
  98. package/src/utils/varInt.js +17 -21
  99. package/typings/index.d.ts +3532 -2644
  100. package/src/API/getFriends.js +0 -14
  101. package/src/API/getKeyInfo.js +0 -10
  102. package/src/API/getRankedSkyWars.js +0 -11
  103. package/src/structures/Friend.js +0 -38
  104. package/src/structures/KeyInfo.js +0 -42
  105. package/src/structures/MiniGames/SkyWarsRanked.js +0 -45
package/.prettierrc ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "bracketSameLine": true,
3
+ "trailingComma": "none",
4
+ "arrowParens": "always",
5
+ "bracketSpacing": true,
6
+ "proseWrap": "always",
7
+ "singleQuote": true,
8
+ "printWidth": 210,
9
+ "useTabs": false,
10
+ "tabWidth": 2,
11
+ "semi": true,
12
+ "endOfLine": "lf"
13
+ }
package/README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  <div align="center">
3
2
  <img src="https://i.imgur.com/cDFoQZU.png?1">
4
3
  <h1>Hypixel API • Reborn</h1>
@@ -15,39 +14,52 @@
15
14
  </div>
16
15
 
17
16
  ### Links
18
- [Discord Support](https://discord.gg/NSEBNMM) | [Documentation](https://hypixel.stavzdev.me) | [NPM](https://www.npmjs.com/package/hypixel-api-reborn) | [GitHub](https://github.com/Hypixel-API-Reborn/hypixel-api-reborn) | [PreMiD Presence](https://premid.app/store/presences/Hypixel%20API%20Reborn) | [ToDo](https://github.com/Hypixel-API-Reborn/hypixel-api-reborn/projects/1) | [CLI](https://github.com/Hypixel-API-Reborn/cli)
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)
19
20
 
20
21
  #### Requirements
21
22
 
22
- **For Node.js users >= v14.x.x** <br>
23
- **For TypeScript users >= v3.5**
23
+ **For Node.js users >= v14.x.x** <br> **For TypeScript users >= v3.5**
24
24
 
25
25
  ### Installation & Usage
26
+
26
27
  ```shell
27
28
  npm i hypixel-api-reborn
28
29
  ```
30
+
29
31
  ```js
30
32
  const Hypixel = require('hypixel-api-reborn');
31
33
  const hypixel = new Hypixel.Client('API-KEY');
32
34
  // https://stavzdev.is-inside.me/cCMiZdoy.gif
33
35
 
34
36
  // getPlayer
35
- hypixel.getPlayer('StavZDev').then(player => {
36
- console.log(player.level); // 141
37
- }).catch(e => {
38
- console.error(e);
39
- })
37
+ hypixel
38
+ .getPlayer('StavZDev')
39
+ .then((player) => {
40
+ console.log(player.level); // 141
41
+ })
42
+ .catch((e) => {
43
+ console.error(e);
44
+ });
40
45
 
41
46
  // getGuild
42
- hypixel.getGuild('name', 'The Foundation').then(guild => {
43
- console.log(guild.level); // 111
44
- }).catch(e => {
45
- console.error(e);
46
- })
47
+ hypixel
48
+ .getGuild('name', 'The Foundation')
49
+ .then((guild) => {
50
+ console.log(guild.level); // 111
51
+ })
52
+ .catch((e) => {
53
+ console.error(e);
54
+ });
47
55
  ```
48
- For more examples go to our [documentation](https://hypixel.stavzdev.me/).
56
+
57
+ For more examples go to our [documentation](https://hypixel-api-reborn.github.io/).
58
+
49
59
  ## Changelog
50
- [v10.0.0](https://github.com/Hypixel-API-Reborn/hypixel-api-reborn/releases/tag/10.0.0)
60
+
61
+ [v11.0.0](https://github.com/Hypixel-API-Reborn/hypixel-api-reborn/releases/tag/11.0.0)
51
62
 
52
63
  ### Try it now
64
+
53
65
  **[Code Sandbox](https://codesandbox.io/s/clever-babbage-xqmfw?file=/src/index.js)**
package/package.json CHANGED
@@ -1,58 +1,60 @@
1
- {
2
- "name": "hypixel-api-reborn",
3
- "version": "10.0.0",
4
- "description": "Feature-rich Hypixel API wrapper for Node.js",
5
- "main": "./src/index.js",
6
- "types": "./typings/index.d.ts",
7
- "keywords": [
8
- "minecraft",
9
- "client",
10
- "hypixel",
11
- "api",
12
- "hypixel-api",
13
- "intellisense"
14
- ],
15
- "bugs": {
16
- "url": "https://github.com/Hypixel-API-Reborn/hypixel-api-reborn/issues"
17
- },
18
- "scripts": {
19
- "eslint": "eslint src",
20
- "eslint:fix": "eslint src --fix",
21
- "lint:dev": "npm run eslint && npm run dtslint",
22
- "test": "mocha tests --exit",
23
- "test:dev": "nodenv --exec mocha tests -- --exit",
24
- "docgen": "docgen -s src -o ../docs/master.json",
25
- "docgen:custom": "docgen -s src --custom docs/index.yml -o ../docs/master.json",
26
- "prepublishOnly": "npm run test:dev && npm run docgen:custom",
27
- "dtslint": "dtslint typings"
28
- },
29
- "engines": {
30
- "node": ">=14.0.0"
31
- },
32
- "author": "StavZ",
33
- "dependencies": {
34
- "node-fetch": "^2.6.1",
35
- "object-path": "^0.11.8",
36
- "prismarine-nbt": "^1.6.0",
37
- "rss-parser": "^3.12.0"
38
- },
39
- "license": "MIT",
40
- "readme": "https://hypixel.stavzdev.me/",
41
- "repository": {
42
- "url": "https://github.com/Hypixel-API-Reborn/hypixel-api-reborn"
43
- },
44
- "publisher": "StavZ",
45
- "devDependencies": {
46
- "@types/node": "^16.10.2",
47
- "@typescript-eslint/eslint-plugin": "^4.32.0",
48
- "@typescript-eslint/parser": "^4.32.0",
49
- "chai": "^4.3.4",
50
- "dtslint": "^4.1.6",
51
- "eslint": "^7.32.0",
52
- "eslint-config-google": "^0.14.0",
53
- "mocha": "^9.1.2",
54
- "node-env-run": "^4.0.2",
55
- "path": "^0.12.7",
56
- "typescript": "^4.4.3"
57
- }
58
- }
1
+ {
2
+ "name": "hypixel-api-reborn",
3
+ "version": "11.0.1",
4
+ "description": "Feature-rich Hypixel API wrapper for Node.js",
5
+ "main": "./src/index.js",
6
+ "types": "./typings/index.d.ts",
7
+ "keywords": [
8
+ "minecraft",
9
+ "client",
10
+ "hypixel",
11
+ "api",
12
+ "hypixel-api",
13
+ "intellisense"
14
+ ],
15
+ "bugs": {
16
+ "url": "https://github.com/Hypixel-API-Reborn/hypixel-api-reborn/issues"
17
+ },
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/"
28
+ },
29
+ "engines": {
30
+ "node": ">=14.0.0"
31
+ },
32
+ "author": "StavZ",
33
+ "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"
38
+ },
39
+ "license": "MIT",
40
+ "readme": "https://hypixel.stavzdev.me/",
41
+ "repository": {
42
+ "url": "https://github.com/Hypixel-API-Reborn/hypixel-api-reborn"
43
+ },
44
+ "publisher": "StavZ",
45
+ "devDependencies": {
46
+ "@types/node": "^20.6.5",
47
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
48
+ "@typescript-eslint/parser": "^4.33.0",
49
+ "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",
55
+ "node-env-run": "^4.0.2",
56
+ "path": "^0.12.7",
57
+ "prettier": "^3.0.3",
58
+ "typescript": "^4.3.3"
59
+ }
60
+ }
@@ -1,8 +1,8 @@
1
- const Rss = require('rss-parser');
2
- const Parser = new Rss();
3
- module.exports = async function (options) {
4
- const Status = require('../structures/APIStatus.js');
5
- const parsed = await Parser.parseURL('https://status.hypixel.net/history.rss');
6
- if (options.raw) return parsed;
7
- return new Status(parsed);
8
- };
1
+ const Rss = require('rss-parser');
2
+ const Parser = new Rss();
3
+ module.exports = async function (options) {
4
+ const Status = require('../structures/APIStatus.js');
5
+ const parsed = await Parser.parseURL('https://status.hypixel.net/history.rss');
6
+ if (options.raw) return parsed;
7
+ return new Status(parsed);
8
+ };
@@ -1,6 +1,6 @@
1
- module.exports = async function () {
2
- const Booster = require('../structures/Boosters/Booster');
3
- const res = await this._makeRequest('/boosters');
4
- if (res.raw) return res;
5
- return res.boosters.length ? res.boosters.map((b) => new Booster(b)).reverse() : [];
6
- };
1
+ module.exports = async function () {
2
+ const Booster = require('../structures/Boosters/Booster');
3
+ const res = await this._makeRequest('/boosters');
4
+ if (res.raw) return res;
5
+ return res.boosters.length ? res.boosters.map((b) => new Booster(b)).reverse() : [];
6
+ };
@@ -1,6 +1,6 @@
1
- const GameCounts = require('../structures/GameCounts');
2
- module.exports = async function () {
3
- const res = await this._makeRequest('/counts');
4
- if (res.raw) return res;
5
- return new GameCounts(res);
6
- };
1
+ const GameCounts = require('../structures/GameCounts');
2
+ module.exports = async function () {
3
+ const res = await this._makeRequest('/counts');
4
+ if (res.raw) return res;
5
+ return new GameCounts(res);
6
+ };
@@ -1,18 +1,18 @@
1
- const Errors = require('../Errors');
2
- const toUuid = require('../utils/toUuid');
3
- const isGuildID = require('../utils/isGuildID');
4
- module.exports = async function (searchParameter, query) {
5
- if (!query) throw new Error(Errors.NO_GUILD_QUERY);
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);
10
- if (!['id', 'name', 'player'].includes(searchParameter)) throw new Error(Errors.INVALID_GUILD_SEARCH_PARAMETER);
11
- const res = await this._makeRequest(`/guild?${searchParameter}=${encodeURI(query)}`);
12
- if (res.raw) return res;
13
- if (!res.guild && searchParameter !== 'player') {
14
- throw new Error(Errors.GUILD_DOES_NOT_EXIST);
15
- }
16
-
17
- return res.guild ? new Guild(res.guild, isPlayerQuery ? query : null) : null;
18
- };
1
+ const Errors = require('../Errors');
2
+ const toUuid = require('../utils/toUuid');
3
+ const isGuildID = require('../utils/isGuildID');
4
+ module.exports = async function (searchParameter, query) {
5
+ if (!query) throw new Error(Errors.NO_GUILD_QUERY);
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);
10
+ if (!['id', 'name', 'player'].includes(searchParameter)) throw new Error(Errors.INVALID_GUILD_SEARCH_PARAMETER);
11
+ const res = await this._makeRequest(`/guild?${searchParameter}=${encodeURI(query)}`);
12
+ if (res.raw) return res;
13
+ if (!res.guild && searchParameter !== 'player') {
14
+ throw new Error(Errors.GUILD_DOES_NOT_EXIST);
15
+ }
16
+
17
+ return res.guild ? new Guild(res.guild, isPlayerQuery ? query : null) : null;
18
+ };
@@ -1,13 +1,13 @@
1
- const Errors = require('../Errors');
2
- module.exports = async function () {
3
- const Leaderboard = require('../structures/Leaderboard');
4
- const res = await this._makeRequest('/leaderboards');
5
- if (res.raw) return res;
6
- if (!res.leaderboards) throw new Error(Errors.SOMETHING_WENT_WRONG.replace(/{cause}/, 'Try again.'));
7
- const lbnames = Object.create(require('../utils/Constants').leaderboardNames);
8
- // eslint-disable-next-line guard-for-in
9
- for (const name in lbnames) {
10
- lbnames[name] = res.leaderboards[lbnames[name]].length ? res.leaderboards[lbnames[name]].map((lb) => new Leaderboard(lb)) : [];
11
- }
12
- return lbnames;
13
- };
1
+ const Errors = require('../Errors');
2
+ module.exports = async function () {
3
+ const Leaderboard = require('../structures/Leaderboard');
4
+ const res = await this._makeRequest('/leaderboards');
5
+ if (res.raw) return res;
6
+ if (!res.leaderboards) throw new Error(Errors.SOMETHING_WENT_WRONG.replace(/{cause}/, 'Try again.'));
7
+ const lbnames = Object.create(require('../utils/Constants').leaderboardNames);
8
+ // eslint-disable-next-line guard-for-in
9
+ for (const name in lbnames) {
10
+ lbnames[name] = res.leaderboards[lbnames[name]].length ? res.leaderboards[lbnames[name]].map((lb) => new Leaderboard(lb)) : [];
11
+ }
12
+ return lbnames;
13
+ };
@@ -1,27 +1,22 @@
1
- const Errors = require('../Errors');
2
- const toUuid = require('../utils/toUuid');
3
- const getGuild = require('./getGuild');
4
- const getRecentGames = require('./getRecentGames');
5
- const getRankedSkyWars = require('./getRankedSkyWars');
6
- module.exports = async function (query, options = { guild: false, recentGames: false, currentRankedSW: false }) {
7
- if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
8
- const Player = require('../structures/Player');
9
- query = await toUuid(query);
10
- const res = await this._makeRequest(`/player?uuid=${query}`);
11
- if (res.raw) return res;
12
- if (query && !res.player) throw new Error(Errors.PLAYER_HAS_NEVER_LOGGED);
13
- let guild = null;
14
- let recentGames = null;
15
- let rankedSW = null;
16
- if (options.guild) {
17
- guild = getGuild.call(this, 'player', query);
18
- }
19
- if (options.recentGames) {
20
- recentGames = getRecentGames.call(this, query);
21
- }
22
- if (options.currentRankedSW) {
23
- rankedSW = getRankedSkyWars.call(this, query);
24
- }
25
- [guild, recentGames, rankedSW] = await Promise.all([guild, recentGames, rankedSW]);
26
- return new Player(res.player, { guild, recentGames, rankedSW });
27
- };
1
+ const Errors = require('../Errors');
2
+ const toUuid = require('../utils/toUuid');
3
+ const getGuild = require('./getGuild');
4
+ const getRecentGames = require('./getRecentGames');
5
+ module.exports = async function (query, options = { guild: false, recentGames: false }) {
6
+ if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
7
+ const Player = require('../structures/Player');
8
+ query = await toUuid(query);
9
+ const res = await this._makeRequest(`/player?uuid=${query}`);
10
+ if (res.raw) return res;
11
+ if (query && !res.player) throw new Error(Errors.PLAYER_HAS_NEVER_LOGGED);
12
+ let guild = null;
13
+ let recentGames = null;
14
+ if (options.guild) {
15
+ guild = getGuild.call(this, 'player', query);
16
+ }
17
+ if (options.recentGames) {
18
+ recentGames = getRecentGames.call(this, query);
19
+ }
20
+ [guild, recentGames] = await Promise.all([guild, recentGames]);
21
+ return new Player(res.player, { guild, recentGames });
22
+ };
@@ -1,18 +1,18 @@
1
- const Errors = require('../Errors');
2
- const toUuid = require('../utils/toUuid');
3
- const day3 = 1000 * 60 * 60 * 24 * 3;
4
- module.exports = async function (query, playerData) {
5
- if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
6
- const RecentGame = require('../structures/RecentGame');
7
-
8
- query = await toUuid(query);
9
-
10
- const res = await this._makeRequest(`/recentgames?uuid=${query}`);
11
- 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);
16
- }
17
- return res.games.map((x) => new RecentGame(x));
18
- };
1
+ const Errors = require('../Errors');
2
+ const toUuid = require('../utils/toUuid');
3
+ const day3 = 1000 * 60 * 60 * 24 * 3;
4
+ module.exports = async function (query, playerData) {
5
+ if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
6
+ const RecentGame = require('../structures/RecentGame');
7
+
8
+ query = await toUuid(query);
9
+
10
+ const res = await this._makeRequest(`/recentgames?uuid=${query}`);
11
+ 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);
16
+ }
17
+ return res.games.map((x) => new RecentGame(x));
18
+ };
@@ -1,77 +1,66 @@
1
- const net = require('net');
2
- const Errors = require('../Errors');
3
- const ServerInfo = require('../structures/ServerInfo');
4
- const varInt = require('../utils/varInt');
5
- const packetsToSend = [
6
- '1500E0050E6D632E6879706978656C2E6E657463DD01',
7
- '0100',
8
- '09010000000000000000'
9
- ].map((x) => Buffer.from(x, 'hex')); // To avoid dependency hell, these are precompiled as hex.
10
- module.exports = async function (repeats) {
11
- if (repeats < 0 || typeof repeats !== 'number') repeats = 3;
12
- if (repeats > 10) repeats = 10;
13
- let aggregatedData = '';
14
- let dataLength = 0;
15
- return await new Promise((resolve, reject) => {
16
- const cli = net.createConnection(25565, 'mc.hypixel.net', () => {
17
- cli.write(packetsToSend[0]);
18
- cli.write(packetsToSend[1]);
19
- });
20
- cli.on('error', () => {
21
- reject(Errors.CONNECTION_ERROR);
22
- });
23
- cli.on('data', async (data) => {
24
- if (!aggregatedData) {
25
- const varIntBorder = data.findIndex((x) => x === 0x00) + 1;
26
- dataLength = varInt(data.toString('hex', 0, varIntBorder).match(/(..)/g).map((x) => parseInt(x, 16)));
27
- dataLength -= varIntBorder * 8;
28
- aggregatedData += data.toString('utf-8', 5);
29
- } else aggregatedData += data.toString('utf-8');
30
-
31
- if (dataLength >= aggregatedData.length) return;
32
- cli.removeAllListeners('data'); // Remove this listener
33
- resolve(parseData(aggregatedData, await getPing(repeats, cli)));
34
- });
35
- });
36
- };
37
- /**
38
- * Gets hypixel's ping
39
- * @param {number} amount Amount of times to ping
40
- * @param {net.Socket} cli Socket connected to hypixel
41
- * @returns {number}
42
- */
43
- async function getPing (amount, cli) {
44
- let pingSum = 0;
45
- for (let i = 0; i < amount; i++) {
46
- pingSum += await ping(cli);
47
- }
48
- cli.destroy();
49
- return Math.round(pingSum / amount);
50
- }
51
- /**
52
- * Pings hypixel
53
- * @param {net.Socket} cli Client socket, connected to hypixel.
54
- * @returns {number} Ping
55
- */
56
- async function ping (cli) {
57
- await cli.write(packetsToSend[2]);
58
- const time = Date.now();
59
- return new Promise((resolve) => {
60
- cli.once('data', () => {
61
- resolve(Date.now() - time);
62
- });
63
- });
64
- }
65
- /**
66
- * Parses the MOTD & Server status
67
- * @param {string} stringJson Parseable JSON string
68
- * @param {number} ping Ping of the server
69
- * @returns {Object} Object
70
- */
71
- function parseData (stringJson, ping) {
72
- try {
73
- return new ServerInfo(JSON.parse(stringJson), ping);
74
- } catch (e) {
75
- return undefined;
76
- }
77
- }
1
+ const net = require('net');
2
+ const Errors = require('../Errors');
3
+ const ServerInfo = require('../structures/ServerInfo');
4
+ 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.
6
+ module.exports = async function (repeats) {
7
+ if (repeats < 0 || typeof repeats !== 'number') repeats = 3;
8
+ if (repeats > 10) repeats = 10;
9
+ let aggregatedData = '';
10
+ let dataLength = 0;
11
+ return await new Promise((resolve, reject) => {
12
+ const cli = net.createConnection(25565, 'mc.hypixel.net', () => {
13
+ cli.write(packetsToSend[0]);
14
+ cli.write(packetsToSend[1]);
15
+ });
16
+ cli.on('error', () => {
17
+ reject(Errors.CONNECTION_ERROR);
18
+ });
19
+ cli.on('data', async (data) => {
20
+ if (!aggregatedData) {
21
+ const varIntBorder = data.findIndex((x) => x === 0x00) + 1;
22
+ dataLength = varInt(
23
+ data
24
+ .toString('hex', 0, varIntBorder)
25
+ .match(/(..)/g)
26
+ .map((x) => parseInt(x, 16))
27
+ );
28
+ dataLength -= varIntBorder * 8;
29
+ aggregatedData += data.toString('utf-8', 5);
30
+ } else aggregatedData += data.toString('utf-8');
31
+
32
+ if (dataLength >= aggregatedData.length) return;
33
+ cli.removeAllListeners('data'); // Remove this listener
34
+ resolve(parseData(aggregatedData, await getPing(repeats, cli)));
35
+ });
36
+ });
37
+ };
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,8 +1,8 @@
1
- const toUuid = require('../utils/toUuid');
2
- module.exports = async function (query) {
3
- const Status = require('../structures/Status');
4
- query = await toUuid(query);
5
- const res = await this._makeRequest(`/status?uuid=${query}`);
6
- if (res.raw) return res;
7
- return new Status(res.session);
8
- };
1
+ const toUuid = require('../utils/toUuid');
2
+ module.exports = async function (query) {
3
+ const Status = require('../structures/Status');
4
+ query = await toUuid(query);
5
+ const res = await this._makeRequest(`/status?uuid=${query}`);
6
+ if (res.raw) return res;
7
+ return new Status(res.session);
8
+ };
@@ -1,6 +1,6 @@
1
- module.exports = async function () {
2
- const WatchdogStats = require('../structures/Watchdog/Stats');
3
- const res = await this._makeRequest('/punishmentstats');
4
- if (res.raw) return res;
5
- return new WatchdogStats(res);
6
- };
1
+ module.exports = async function () {
2
+ const WatchdogStats = require('../structures/Watchdog/Stats');
3
+ const res = await this._makeRequest('/punishmentstats');
4
+ if (res.raw) return res;
5
+ return new WatchdogStats(res);
6
+ };
package/src/API/index.js CHANGED
@@ -1,23 +1,19 @@
1
- module.exports = {
2
- getAPIStatus: require('./getAPIStatus'),
3
- getBoosters: require('./getBoosters'),
4
- getFriends: require('./getFriends'),
5
- getGameCounts: require('./getGameCounts'),
6
- getGuild: require('./getGuild'),
7
- getKeyInfo: require('./getKeyInfo'),
8
- getLeaderboards: require('./getLeaderboards'),
9
- getPlayer: require('./getPlayer'),
10
- getRankedSkyWars: require('./getRankedSkyWars'),
11
- getRecentGames: require('./getRecentGames'),
12
- getServerInfo: require('./getServerInfo'),
13
- getStatus: require('./getStatus'),
14
- getWatchdogStats: require('./getWatchdogStats'),
15
-
16
- getEndedSkyblockAuctions: require('./skyblock/getEndedSkyblockAuctions'),
17
- getSkyblockAuctions: require('./skyblock/getSkyblockAuctions'),
18
- getSkyblockAuctionsByPlayer: require('./skyblock/getSkyblockAuctionsByPlayer'),
19
- getSkyblockBazaar: require('./skyblock/getSkyblockBazaar'),
20
- getSkyblockMember: require('./skyblock/getSkyblockMember'),
21
- getSkyblockNews: require('./skyblock/getSkyblockNews'),
22
- getSkyblockProfiles: require('./skyblock/getSkyblockProfiles')
23
- };
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')
19
+ };