hypixel-api-reborn 10.0.0 → 11.0.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.
- package/.prettierrc +13 -0
- package/README.md +27 -15
- package/package.json +60 -58
- package/src/API/getAPIStatus.js +8 -8
- package/src/API/getBoosters.js +6 -6
- package/src/API/getGameCounts.js +6 -6
- package/src/API/getGuild.js +18 -18
- package/src/API/getLeaderboards.js +13 -13
- package/src/API/getPlayer.js +22 -27
- package/src/API/getRecentGames.js +18 -18
- package/src/API/getServerInfo.js +66 -77
- package/src/API/getStatus.js +8 -8
- package/src/API/getWatchdogStats.js +6 -6
- package/src/API/index.js +19 -23
- package/src/API/skyblock/getEndedSkyblockAuctions.js +10 -10
- package/src/API/skyblock/getSkyblockAuctions.js +64 -64
- package/src/API/skyblock/getSkyblockAuctionsByPlayer.js +11 -11
- package/src/API/skyblock/getSkyblockBazaar.js +10 -10
- package/src/API/skyblock/getSkyblockMember.js +28 -25
- package/src/API/skyblock/getSkyblockNews.js +6 -6
- package/src/API/skyblock/getSkyblockProfiles.js +44 -41
- package/src/Client.js +406 -450
- package/src/Errors.js +44 -39
- package/src/Private/defaultCache.js +77 -78
- package/src/Private/rateLimit.js +79 -98
- package/src/Private/requests.js +65 -54
- package/src/Private/updater.js +45 -45
- package/src/Private/uuidCache.js +37 -33
- package/src/Private/validate.js +97 -97
- package/src/index.js +82 -83
- package/src/structures/APIIncident.js +78 -78
- package/src/structures/APIStatus.js +47 -47
- package/src/structures/Boosters/Booster.js +83 -87
- package/src/structures/Color.js +129 -129
- package/src/structures/Game.js +164 -160
- package/src/structures/GameCounts.js +151 -151
- package/src/structures/Guild/Guild.js +204 -218
- package/src/structures/Guild/GuildMember.js +66 -66
- package/src/structures/Guild/GuildRank.js +48 -48
- package/src/structures/ItemBytes.js +33 -36
- package/src/structures/Leaderboard.js +31 -31
- package/src/structures/MiniGames/Arcade.js +567 -569
- package/src/structures/MiniGames/ArenaBrawl.js +52 -56
- package/src/structures/MiniGames/BedWars.js +423 -351
- package/src/structures/MiniGames/BlitzSurvivalGames.js +172 -148
- package/src/structures/MiniGames/BuildBattle.js +53 -53
- package/src/structures/MiniGames/CopsAndCrims.js +90 -90
- package/src/structures/MiniGames/Duels.js +694 -630
- package/src/structures/MiniGames/MegaWalls.js +137 -137
- package/src/structures/MiniGames/MurderMystery.js +93 -93
- package/src/structures/MiniGames/Paintball.js +67 -67
- package/src/structures/MiniGames/Pit.js +19 -19
- package/src/structures/MiniGames/Quakecraft.js +101 -101
- package/src/structures/MiniGames/SkyWars.js +508 -559
- package/src/structures/MiniGames/SmashHeroes.js +144 -151
- package/src/structures/MiniGames/SpeedUHC.js +115 -57
- package/src/structures/MiniGames/TNTGames.js +116 -116
- package/src/structures/MiniGames/TurboKartRacers.js +201 -176
- package/src/structures/MiniGames/UHC.js +164 -143
- package/src/structures/MiniGames/VampireZ.js +60 -60
- package/src/structures/MiniGames/Walls.js +52 -52
- package/src/structures/MiniGames/Warlords.js +62 -62
- package/src/structures/MiniGames/WoolWars.js +123 -0
- package/src/structures/Pet.js +96 -97
- package/src/structures/Pets.js +64 -64
- package/src/structures/Player.js +433 -449
- package/src/structures/PlayerCosmetics.js +100 -95
- package/src/structures/RecentGame.js +57 -57
- package/src/structures/ServerInfo.js +78 -78
- package/src/structures/SkyBlock/Auctions/Auction.js +104 -104
- package/src/structures/SkyBlock/Auctions/AuctionInfo.js +54 -54
- package/src/structures/SkyBlock/Auctions/BaseAuction.js +45 -45
- package/src/structures/SkyBlock/Auctions/Bid.js +48 -48
- package/src/structures/SkyBlock/Auctions/PartialAuction.js +25 -25
- package/src/structures/SkyBlock/Bazzar/Order.js +38 -38
- package/src/structures/SkyBlock/Bazzar/Product.js +53 -53
- package/src/structures/SkyBlock/News/SkyblockNews.js +60 -68
- package/src/structures/SkyBlock/SkyblockInventoryItem.js +124 -130
- package/src/structures/SkyBlock/SkyblockMember.js +820 -687
- package/src/structures/SkyBlock/SkyblockPet.js +71 -71
- package/src/structures/SkyBlock/SkyblockProfile.js +60 -60
- package/src/structures/Status.js +41 -41
- package/src/structures/Watchdog/Stats.js +36 -36
- package/src/utils/Constants.js +2789 -809
- package/src/utils/SkyblockUtils.js +208 -164
- package/src/utils/arrayTools.js +4 -4
- package/src/utils/divide.js +5 -5
- package/src/utils/guildExp.js +57 -67
- package/src/utils/index.js +13 -13
- package/src/utils/isGuildID.js +3 -3
- package/src/utils/isUUID.js +5 -5
- package/src/utils/oscillation.js +15 -23
- package/src/utils/removeSnakeCase.js +22 -35
- package/src/utils/rgbToHexColor.js +8 -8
- package/src/utils/romanize.js +11 -13
- package/src/utils/toIGN.js +20 -20
- package/src/utils/toUuid.js +19 -19
- package/src/utils/varInt.js +17 -21
- package/typings/index.d.ts +3532 -2644
- package/src/API/getFriends.js +0 -14
- package/src/API/getKeyInfo.js +0 -10
- package/src/API/getRankedSkyWars.js +0 -11
- package/src/structures/Friend.js +0 -38
- package/src/structures/KeyInfo.js +0 -42
- package/src/structures/MiniGames/SkyWarsRanked.js +0 -45
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const PartialAuction = require('../../structures/SkyBlock/Auctions/PartialAuction');
|
|
2
|
-
const AuctionInfo = require('../../structures/SkyBlock/Auctions/AuctionInfo');
|
|
3
|
-
module.exports = async function (includeItemBytes = false) {
|
|
4
|
-
const res = await this._makeRequest('/skyblock/auctions_ended', false);
|
|
5
|
-
if (res.raw) return res;
|
|
6
|
-
return {
|
|
7
|
-
info: new AuctionInfo({ ...res, totalAuctions: res.auctions.length, totalPages: 1 }),
|
|
8
|
-
auctions: res.auctions.length ? res.auctions.map((a) => new PartialAuction(a, includeItemBytes)) : []
|
|
9
|
-
};
|
|
10
|
-
};
|
|
1
|
+
const PartialAuction = require('../../structures/SkyBlock/Auctions/PartialAuction');
|
|
2
|
+
const AuctionInfo = require('../../structures/SkyBlock/Auctions/AuctionInfo');
|
|
3
|
+
module.exports = async function (includeItemBytes = false) {
|
|
4
|
+
const res = await this._makeRequest('/skyblock/auctions_ended', false);
|
|
5
|
+
if (res.raw) return res;
|
|
6
|
+
return {
|
|
7
|
+
info: new AuctionInfo({ ...res, totalAuctions: res.auctions.length, totalPages: 1 }),
|
|
8
|
+
auctions: res.auctions.length ? res.auctions.map((a) => new PartialAuction(a, includeItemBytes)) : []
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
/* eslint-disable require-jsdoc */
|
|
2
|
-
const Auction = require('../../structures/SkyBlock/Auctions/Auction');
|
|
3
|
-
const AuctionInfo = require('../../structures/SkyBlock/Auctions/AuctionInfo');
|
|
4
|
-
const Errors = require('../../Errors');
|
|
5
|
-
let _makeRequest;
|
|
6
|
-
async function getPage
|
|
7
|
-
const content = await _makeRequest(`/skyblock/auctions?page=${page}`, false);
|
|
8
|
-
const result = {};
|
|
9
|
-
if (!options.noInfo) result.info = new AuctionInfo(content);
|
|
10
|
-
if (options.raw) result.auctions = content.auctions;
|
|
11
|
-
else if (options.noAuctions) result.auctions = [];
|
|
12
|
-
else result.auctions = content.auctions.map((x) => new Auction(x, options.includeItemBytes));
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
async function noReject
|
|
16
|
-
try {
|
|
17
|
-
const result = await promise.call(null, ...args);
|
|
18
|
-
return result;
|
|
19
|
-
} catch (e) {
|
|
20
|
-
if (retries) {
|
|
21
|
-
await new Promise((resolve) => setTimeout(resolve, cooldown));
|
|
22
|
-
return await noReject(promise, args, retries - 1, cooldown);
|
|
23
|
-
} else return null;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
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];
|
|
31
|
-
if (!Array.isArray(range)) range = [parseInt(range), parseInt(range)];
|
|
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);
|
|
35
|
-
range = range.sort();
|
|
36
|
-
const result = { auctions: [] };
|
|
37
|
-
const fetches = [];
|
|
38
|
-
const failedPages = [];
|
|
39
|
-
if (options.noAuctions) return { info: options.noInfo ? null : (await getPage(range[1], { noAuctions: true })).info };
|
|
40
|
-
for (let i = range[0]; i <= range[1]; i++) {
|
|
41
|
-
if (options.race) {
|
|
42
|
-
fetches.push(noReject(getPage, [i, options], options.retries, options.cooldown));
|
|
43
|
-
} else {
|
|
44
|
-
const resp = await noReject(getPage, [i, options], options.retries, options.cooldown);
|
|
45
|
-
if (resp) {
|
|
46
|
-
result.auctions = result.auctions.concat(resp.auctions);
|
|
47
|
-
if (resp.info) result.info = resp.info;
|
|
48
|
-
} else failedPages.push(i);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (fetches.length) {
|
|
52
|
-
result.auctions = (await Promise.all(fetches)).reduce((pV, cV, index) => {
|
|
53
|
-
if (!cV) {
|
|
54
|
-
failedPages.push(index + range[0]);
|
|
55
|
-
return pV;
|
|
56
|
-
}
|
|
57
|
-
if (cV.info) result.info = cV.info;
|
|
58
|
-
if (cV.auctions.length) return pV.concat(cV.auctions);
|
|
59
|
-
return pV;
|
|
60
|
-
}, []);
|
|
61
|
-
}
|
|
62
|
-
result.info = result.info ? result.info._extend('failedPages', failedPages) : { failedPages };
|
|
63
|
-
return result;
|
|
64
|
-
};
|
|
1
|
+
/* eslint-disable require-jsdoc */
|
|
2
|
+
const Auction = require('../../structures/SkyBlock/Auctions/Auction');
|
|
3
|
+
const AuctionInfo = require('../../structures/SkyBlock/Auctions/AuctionInfo');
|
|
4
|
+
const Errors = require('../../Errors');
|
|
5
|
+
let _makeRequest;
|
|
6
|
+
async function getPage(page = 0, options = {}) {
|
|
7
|
+
const content = await _makeRequest(`/skyblock/auctions?page=${page}`, false);
|
|
8
|
+
const result = {};
|
|
9
|
+
if (!options.noInfo) result.info = new AuctionInfo(content);
|
|
10
|
+
if (options.raw) result.auctions = content.auctions;
|
|
11
|
+
else if (options.noAuctions) result.auctions = [];
|
|
12
|
+
else result.auctions = content.auctions.map((x) => new Auction(x, options.includeItemBytes));
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
async function noReject(promise, args = [], retries = 3, cooldown = 100) {
|
|
16
|
+
try {
|
|
17
|
+
const result = await promise.call(null, ...args);
|
|
18
|
+
return result;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
if (retries) {
|
|
21
|
+
await new Promise((resolve) => setTimeout(resolve, cooldown));
|
|
22
|
+
return await noReject(promise, args, retries - 1, cooldown);
|
|
23
|
+
} else return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
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];
|
|
31
|
+
if (!Array.isArray(range)) range = [parseInt(range), parseInt(range)];
|
|
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);
|
|
35
|
+
range = range.sort();
|
|
36
|
+
const result = { auctions: [] };
|
|
37
|
+
const fetches = [];
|
|
38
|
+
const failedPages = [];
|
|
39
|
+
if (options.noAuctions) return { info: options.noInfo ? null : (await getPage(range[1], { noAuctions: true })).info };
|
|
40
|
+
for (let i = range[0]; i <= range[1]; i++) {
|
|
41
|
+
if (options.race) {
|
|
42
|
+
fetches.push(noReject(getPage, [i, options], options.retries, options.cooldown));
|
|
43
|
+
} else {
|
|
44
|
+
const resp = await noReject(getPage, [i, options], options.retries, options.cooldown);
|
|
45
|
+
if (resp) {
|
|
46
|
+
result.auctions = result.auctions.concat(resp.auctions);
|
|
47
|
+
if (resp.info) result.info = resp.info;
|
|
48
|
+
} else failedPages.push(i);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (fetches.length) {
|
|
52
|
+
result.auctions = (await Promise.all(fetches)).reduce((pV, cV, index) => {
|
|
53
|
+
if (!cV) {
|
|
54
|
+
failedPages.push(index + range[0]);
|
|
55
|
+
return pV;
|
|
56
|
+
}
|
|
57
|
+
if (cV.info) result.info = cV.info;
|
|
58
|
+
if (cV.auctions.length) return pV.concat(cV.auctions);
|
|
59
|
+
return pV;
|
|
60
|
+
}, []);
|
|
61
|
+
}
|
|
62
|
+
result.info = result.info ? result.info._extend('failedPages', failedPages) : { failedPages };
|
|
63
|
+
return result;
|
|
64
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const Errors = require('../../Errors');
|
|
2
|
-
const toUuid = require('../../utils/toUuid');
|
|
3
|
-
module.exports = async function (query, includeItemBytes = false) {
|
|
4
|
-
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
|
|
5
|
-
const Auction = require('../../structures/SkyBlock/Auctions/Auction');
|
|
6
|
-
query = await toUuid(query);
|
|
7
|
-
const res = await this._makeRequest(`/skyblock/auction?player=${query}`);
|
|
8
|
-
if (res.raw) return res;
|
|
9
|
-
|
|
10
|
-
return res.auctions.length ? res.auctions.map((a) => new Auction(a, includeItemBytes)) : [];
|
|
11
|
-
};
|
|
1
|
+
const Errors = require('../../Errors');
|
|
2
|
+
const toUuid = require('../../utils/toUuid');
|
|
3
|
+
module.exports = async function (query, includeItemBytes = false) {
|
|
4
|
+
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
|
|
5
|
+
const Auction = require('../../structures/SkyBlock/Auctions/Auction');
|
|
6
|
+
query = await toUuid(query);
|
|
7
|
+
const res = await this._makeRequest(`/skyblock/auction?player=${query}`);
|
|
8
|
+
if (res.raw) return res;
|
|
9
|
+
|
|
10
|
+
return res.auctions.length ? res.auctions.map((a) => new Auction(a, includeItemBytes)) : [];
|
|
11
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
module.exports = async function () {
|
|
2
|
-
const Product = require('../../structures/SkyBlock/Bazzar/Product');
|
|
3
|
-
|
|
4
|
-
const res = await this._makeRequest('/skyblock/bazaar');
|
|
5
|
-
if (res.raw) return res;
|
|
6
|
-
|
|
7
|
-
const productsKeys = Object.keys(res.products);
|
|
8
|
-
|
|
9
|
-
return productsKeys.map((x) => new Product(res.products[x]));
|
|
10
|
-
};
|
|
1
|
+
module.exports = async function () {
|
|
2
|
+
const Product = require('../../structures/SkyBlock/Bazzar/Product');
|
|
3
|
+
|
|
4
|
+
const res = await this._makeRequest('/skyblock/bazaar');
|
|
5
|
+
if (res.raw) return res;
|
|
6
|
+
|
|
7
|
+
const productsKeys = Object.keys(res.products);
|
|
8
|
+
|
|
9
|
+
return productsKeys.map((x) => new Product(res.products[x]));
|
|
10
|
+
};
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
const Errors = require('../../Errors');
|
|
2
|
-
const toUuid = require('../../utils/toUuid');
|
|
3
|
-
const getPlayer = require('../getPlayer');
|
|
4
|
-
module.exports = async function (query, options = { fetchPlayer: false }) {
|
|
5
|
-
const SkyblockMember = require('../../structures/SkyBlock/SkyblockMember');
|
|
6
|
-
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
|
|
7
|
-
query = await toUuid(query);
|
|
8
|
-
const res = await this._makeRequest(`/skyblock/profiles?uuid=${query}`);
|
|
9
|
-
if (res.raw) return res;
|
|
10
|
-
if (!res.profiles || !res.profiles.length) {
|
|
11
|
-
return new Map();
|
|
12
|
-
}
|
|
13
|
-
const player = options.fetchPlayer ? await getPlayer.call(this, query, options) : null;
|
|
14
|
-
const memberByProfileName = new Map();
|
|
15
|
-
for (const profile of res.profiles) {
|
|
16
|
-
profile.members[query].player = player;
|
|
17
|
-
memberByProfileName.set(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
const Errors = require('../../Errors');
|
|
2
|
+
const toUuid = require('../../utils/toUuid');
|
|
3
|
+
const getPlayer = require('../getPlayer');
|
|
4
|
+
module.exports = async function (query, options = { fetchPlayer: false }) {
|
|
5
|
+
const SkyblockMember = require('../../structures/SkyBlock/SkyblockMember');
|
|
6
|
+
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
|
|
7
|
+
query = await toUuid(query);
|
|
8
|
+
const res = await this._makeRequest(`/skyblock/profiles?uuid=${query}`);
|
|
9
|
+
if (res.raw) return res;
|
|
10
|
+
if (!res.profiles || !res.profiles.length) {
|
|
11
|
+
return new Map();
|
|
12
|
+
}
|
|
13
|
+
const player = options.fetchPlayer ? await getPlayer.call(this, query, options) : null;
|
|
14
|
+
const memberByProfileName = new Map();
|
|
15
|
+
for (const profile of res.profiles) {
|
|
16
|
+
profile.members[query].player = player;
|
|
17
|
+
memberByProfileName.set(
|
|
18
|
+
profile.cute_name,
|
|
19
|
+
new SkyblockMember({
|
|
20
|
+
uuid: query,
|
|
21
|
+
profileName: profile.cute_name,
|
|
22
|
+
gameMode: profile.game_mode || null,
|
|
23
|
+
m: profile.members[query]
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return memberByProfileName;
|
|
28
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const SkyblockNews = require('../../structures/SkyBlock/News/SkyblockNews');
|
|
2
|
-
module.exports = async function () {
|
|
3
|
-
const res = await this._makeRequest('/skyblock/news');
|
|
4
|
-
if (res.raw) return res;
|
|
5
|
-
return res.items.map((i) => new SkyblockNews(i));
|
|
6
|
-
};
|
|
1
|
+
const SkyblockNews = require('../../structures/SkyBlock/News/SkyblockNews');
|
|
2
|
+
module.exports = async function () {
|
|
3
|
+
const res = await this._makeRequest('/skyblock/news');
|
|
4
|
+
if (res.raw) return res;
|
|
5
|
+
return res.items.map((i) => new SkyblockNews(i));
|
|
6
|
+
};
|
|
@@ -1,41 +1,44 @@
|
|
|
1
|
-
const Errors = require('../../Errors');
|
|
2
|
-
const toUuid = require('../../utils/toUuid');
|
|
3
|
-
const getPlayer = require('../getPlayer');
|
|
4
|
-
module.exports = async function (query, options = { fetchPlayer: false }) {
|
|
5
|
-
const SkyblockProfile = require('../../structures/SkyBlock/SkyblockProfile');
|
|
6
|
-
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
|
|
7
|
-
query = await toUuid(query);
|
|
8
|
-
const res = await this._makeRequest(`/skyblock/profiles?uuid=${query}`);
|
|
9
|
-
if (res.raw) return res;
|
|
10
|
-
|
|
11
|
-
if (!res.profiles || !res.profiles.length) {
|
|
12
|
-
return [];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const players = new Map();
|
|
16
|
-
if (options.fetchPlayer) {
|
|
17
|
-
const uniqueUuids = [...new Set(
|
|
18
|
-
await Promise.all(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
1
|
+
const Errors = require('../../Errors');
|
|
2
|
+
const toUuid = require('../../utils/toUuid');
|
|
3
|
+
const getPlayer = require('../getPlayer');
|
|
4
|
+
module.exports = async function (query, options = { fetchPlayer: false }) {
|
|
5
|
+
const SkyblockProfile = require('../../structures/SkyBlock/SkyblockProfile');
|
|
6
|
+
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
|
|
7
|
+
query = await toUuid(query);
|
|
8
|
+
const res = await this._makeRequest(`/skyblock/profiles?uuid=${query}`);
|
|
9
|
+
if (res.raw) return res;
|
|
10
|
+
|
|
11
|
+
if (!res.profiles || !res.profiles.length) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const players = new Map();
|
|
16
|
+
if (options.fetchPlayer) {
|
|
17
|
+
const uniqueUuids = [...new Set(res.profiles.map((profile) => Object.keys(profile.members)).flat())];
|
|
18
|
+
await Promise.all(
|
|
19
|
+
uniqueUuids.map(async (uuid) => {
|
|
20
|
+
const player = await getPlayer.call(this, uuid, options);
|
|
21
|
+
players.set(uuid, player);
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const profiles = [];
|
|
27
|
+
for (let i = 0; i < res.profiles.length; i++) {
|
|
28
|
+
if (options.fetchPlayer) {
|
|
29
|
+
for (const memberUuid of Object.keys(res.profiles[i].members)) {
|
|
30
|
+
res.profiles[i].members[memberUuid].player = players.get(memberUuid);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
profiles.push({
|
|
35
|
+
profile_id: res.profiles[i].profile_id,
|
|
36
|
+
profile_name: res.profiles[i].cute_name,
|
|
37
|
+
members: res.profiles[i].members,
|
|
38
|
+
me: query,
|
|
39
|
+
selected: res.profiles[i].selected
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return profiles.map((p) => new SkyblockProfile(p));
|
|
44
|
+
};
|