From 275344016f7210a895bf4f59763e5febf6351417 Mon Sep 17 00:00:00 2001
From: DuckySoLucky
Date: Mon, 5 Feb 2024 21:59:27 +0100
Subject: [PATCH 01/11] test
---
src/stats/items.js | 400 +++++++++++++++++++++++++--------------------
1 file changed, 221 insertions(+), 179 deletions(-)
diff --git a/src/stats/items.js b/src/stats/items.js
index 1f4627f57f..1ce05dac85 100644
--- a/src/stats/items.js
+++ b/src/stats/items.js
@@ -10,201 +10,243 @@ export async function getItems(
packs,
options = { cacheOnly: false, debugId: `${helper.getClusterId()}/unknown@getItems` },
) {
- const output = {};
-
- console.debug(`${options.debugId}: getItems called.`);
- const timeStarted = Date.now();
-
- // Process inventories returned by API
- const inventoryTypes = [
- { name: "armor", property: "inv_armor" },
- { name: "equipment", property: "equipment_contents" },
- { name: "inventory", property: "inv_contents" },
- { name: "wardrobe", property: "wardrobe_contents" },
- { name: "ender chest", property: "ender_chest_contents" },
- { name: "accessory bag", property: "talisman_bag", bagContents: true },
- { name: "fishing bag", property: "fishing_bag", bagContents: true },
- { name: "quiver", property: "quiver", bagContents: true },
- { name: "potion bag", property: "potion_bag", bagContents: true },
- { name: "candy bag", property: "candy_inventory_contents", shared: true },
- { name: "personal vault", property: "personal_vault_contents" },
- ];
-
- const promises = inventoryTypes.map((type) => {
- if (type.shared === true) {
- if (profile.shared_inventory === undefined || profile.shared_inventory[type.property] === undefined) {
- return [];
- }
-
- return processItems(
- profile.shared_inventory[type.property].data,
- type.name,
- customTextures,
- packs,
- options.cacheOnly,
- );
- } else if (type.bagContents === true) {
- if (
- profile.inventory === undefined ||
- profile.inventory.bag_contents === undefined ||
- profile.inventory.bag_contents[type.property] === undefined
- ) {
- return [];
- }
-
- return processItems(
- profile.inventory.bag_contents[type.property].data,
- type.name,
- customTextures,
- packs,
- options.cacheOnly,
- );
- } else {
- if (profile.inventory === undefined || profile.inventory[type.property] === undefined) {
- return [];
- }
-
- return processItems(profile.inventory[type.property].data, type.name, customTextures, packs, options.cacheOnly);
- }
- });
-
- let [
- armor,
- equipment,
- inventory,
- wardrobe_inventory,
- enderchest,
- accessory_bag,
- fishing_bag,
- quiver,
- potion_bag,
- candy_bag,
- personal_vault,
- ] = await Promise.all(promises);
-
- const storage = [];
- if (profile.inventory && profile.inventory.backpack_contents) {
- const storageSize = Math.max(18, Object.keys(profile.inventory.backpack_contents).length);
-
- const promises = [];
-
- for (let slot = 0; slot < storageSize; slot++) {
- storage.push({});
-
- if (profile.inventory.backpack_contents[slot] && profile.inventory.backpack_icons[slot]) {
- const iconPromise = processItems(
- profile.inventory.backpack_icons[slot].data,
- "storage_icons",
+ try {
+ const output = {};
+
+ throw new Error("This function is not implemented yet.");
+
+ console.debug(`${options.debugId}: getItems called.`);
+ const timeStarted = Date.now();
+
+ // Process inventories returned by API
+ const inventoryTypes = [
+ { name: "armor", property: "inv_armor" },
+ { name: "equipment", property: "equipment_contents" },
+ { name: "inventory", property: "inv_contents" },
+ { name: "wardrobe", property: "wardrobe_contents" },
+ { name: "ender chest", property: "ender_chest_contents" },
+ { name: "accessory bag", property: "talisman_bag", bagContents: true },
+ { name: "fishing bag", property: "fishing_bag", bagContents: true },
+ { name: "quiver", property: "quiver", bagContents: true },
+ { name: "potion bag", property: "potion_bag", bagContents: true },
+ { name: "candy bag", property: "candy_inventory_contents", shared: true },
+ { name: "personal vault", property: "personal_vault_contents" },
+ ];
+
+ const promises = inventoryTypes.map((type) => {
+ if (type.shared === true) {
+ if (profile.shared_inventory === undefined || profile.shared_inventory[type.property] === undefined) {
+ return [];
+ }
+
+ return processItems(
+ profile.shared_inventory[type.property].data,
+ type.name,
customTextures,
packs,
options.cacheOnly,
);
- const itemsPromise = await processItems(
- profile.inventory.backpack_contents[slot].data,
- "storage",
+ } else if (type.bagContents === true) {
+ if (
+ profile.inventory === undefined ||
+ profile.inventory.bag_contents === undefined ||
+ profile.inventory.bag_contents[type.property] === undefined
+ ) {
+ return [];
+ }
+
+ return processItems(
+ profile.inventory.bag_contents[type.property].data,
+ type.name,
customTextures,
packs,
options.cacheOnly,
);
+ } else {
+ if (profile.inventory === undefined || profile.inventory[type.property] === undefined) {
+ return [];
+ }
- promises.push(iconPromise, itemsPromise);
-
- (async (slot, iconPromise, itemsPromise) => {
- const [icon, items] = await Promise.all([iconPromise, itemsPromise]);
+ return processItems(profile.inventory[type.property].data, type.name, customTextures, packs, options.cacheOnly);
+ }
+ });
+
+ let [
+ armor,
+ equipment,
+ inventory,
+ wardrobe_inventory,
+ enderchest,
+ accessory_bag,
+ fishing_bag,
+ quiver,
+ potion_bag,
+ candy_bag,
+ personal_vault,
+ ] = await Promise.all(promises);
+
+ const storage = [];
+ if (profile.inventory && profile.inventory.backpack_contents) {
+ const storageSize = Math.max(18, Object.keys(profile.inventory.backpack_contents).length);
+
+ const promises = [];
+
+ for (let slot = 0; slot < storageSize; slot++) {
+ storage.push({});
+
+ if (profile.inventory.backpack_contents[slot] && profile.inventory.backpack_icons[slot]) {
+ const iconPromise = processItems(
+ profile.inventory.backpack_icons[slot].data,
+ "storage_icons",
+ customTextures,
+ packs,
+ options.cacheOnly,
+ );
+ const itemsPromise = await processItems(
+ profile.inventory.backpack_contents[slot].data,
+ "storage",
+ customTextures,
+ packs,
+ options.cacheOnly,
+ );
+
+ promises.push(iconPromise, itemsPromise);
+
+ (async (slot, iconPromise, itemsPromise) => {
+ const [icon, items] = await Promise.all([iconPromise, itemsPromise]);
+
+ for (const [index, item] of items.entries()) {
+ item.isInactive = true;
+ item.inBackpack = true;
+ item.item_index = index;
+ }
+
+ const storageUnit = icon[0];
+ storageUnit.containsItems = items;
+ storage[slot] = storageUnit;
+ })(slot, iconPromise, itemsPromise);
+ }
+ }
- for (const [index, item] of items.entries()) {
- item.isInactive = true;
- item.inBackpack = true;
- item.item_index = index;
- }
+ await Promise.all(promises);
+ }
- const storageUnit = icon[0];
- storageUnit.containsItems = items;
- storage[slot] = storageUnit;
- })(slot, iconPromise, itemsPromise);
+ const wardrobe = items.getWardrobe(wardrobe_inventory);
+
+ const hotm = "mining_core" in profile ? await items.getHotmItems(profile, packs) : [];
+
+ output.armor = items.getArmor(armor.filter((x) => x.rarity));
+ output.equipment = items.getEquipment(equipment.filter((x) => x.rarity));
+ output.wardrobe = wardrobe;
+ output.wardrobe_inventory = wardrobe_inventory;
+ output.inventory = inventory;
+ output.enderchest = enderchest;
+ output.accessory_bag = accessory_bag;
+ output.fishing_bag = fishing_bag;
+ output.quiver = quiver;
+ output.potion_bag = potion_bag;
+ output.personal_vault = personal_vault;
+ output.storage = storage;
+ output.hotm = hotm;
+ output.candy_bag = candy_bag;
+
+ const museum =
+ "museum" in profile ? await items.getMuseumItems(profile, customTextures, packs, options.cacheOnly) : [];
+
+ output.museumItems = museum?.museumItems ?? [];
+ output.museum = museum?.museum ?? [];
+
+ output.bingo_card = await items.getBingoCard(paramBingo, options.cacheOnly);
+
+ const allItems = armor.concat(
+ equipment,
+ inventory,
+ enderchest,
+ accessory_bag,
+ fishing_bag,
+ quiver,
+ potion_bag,
+ personal_vault,
+ wardrobe_inventory,
+ storage,
+ hotm,
+ candy_bag,
+ );
+
+ for (const [index, item] of allItems.entries()) {
+ item.item_index = index;
+ item.itemId = v4("itemId");
+
+ if ("containsItems" in item && Array.isArray(item.containsItems)) {
+ item.containsItems.forEach((a, idx) => {
+ a.backpackIndex = item.item_index;
+ a.itemId = v4("itemId");
+ });
}
}
- await Promise.all(promises);
- }
+ output.accessories = items.getAccessories(profile, armor, accessory_bag, inventory, enderchest, storage);
- const wardrobe = items.getWardrobe(wardrobe_inventory);
-
- const hotm = "mining_core" in profile ? await items.getHotmItems(profile, packs) : [];
-
- output.armor = items.getArmor(armor.filter((x) => x.rarity));
- output.equipment = items.getEquipment(equipment.filter((x) => x.rarity));
- output.wardrobe = wardrobe;
- output.wardrobe_inventory = wardrobe_inventory;
- output.inventory = inventory;
- output.enderchest = enderchest;
- output.accessory_bag = accessory_bag;
- output.fishing_bag = fishing_bag;
- output.quiver = quiver;
- output.potion_bag = potion_bag;
- output.personal_vault = personal_vault;
- output.storage = storage;
- output.hotm = hotm;
- output.candy_bag = candy_bag;
-
- const museum =
- "museum" in profile ? await items.getMuseumItems(profile, customTextures, packs, options.cacheOnly) : [];
-
- output.museumItems = museum?.museumItems ?? [];
- output.museum = museum?.museum ?? [];
-
- output.bingo_card = await items.getBingoCard(paramBingo, options.cacheOnly);
-
- const allItems = armor.concat(
- equipment,
- inventory,
- enderchest,
- accessory_bag,
- fishing_bag,
- quiver,
- potion_bag,
- personal_vault,
- wardrobe_inventory,
- storage,
- hotm,
- candy_bag,
- );
-
- for (const [index, item] of allItems.entries()) {
- item.item_index = index;
- item.itemId = v4("itemId");
-
- if ("containsItems" in item && Array.isArray(item.containsItems)) {
- item.containsItems.forEach((a, idx) => {
- a.backpackIndex = item.item_index;
- a.itemId = v4("itemId");
- });
+ // Add candy bag contents as backpack contents to candy bag
+ for (const item of allItems) {
+ if (helper.getId(item) == "TRICK_OR_TREAT_BAG") {
+ item.containsItems = candy_bag;
+ }
}
- }
-
- output.accessories = items.getAccessories(profile, armor, accessory_bag, inventory, enderchest, storage);
- // Add candy bag contents as backpack contents to candy bag
- for (const item of allItems) {
- if (helper.getId(item) == "TRICK_OR_TREAT_BAG") {
- item.containsItems = candy_bag;
- }
+ output.weapons = items.getWeapons(allItems);
+ output.farming_tools = items.getSkilllTools("farming", allItems);
+ output.mining_tools = items.getSkilllTools("mining", allItems);
+ output.fishing_tools = items.getSkilllTools("fishing", allItems);
+ output.pets = items.getPets(allItems);
+
+ // Check if inventory access disabled by user
+ output.disabled = {
+ inventory: inventory.length === 0,
+ personal_vault: personal_vault.length === 0,
+ };
+
+ output.allItems = allItems;
+
+ console.log(Object.keys(output));
+
+ console.debug(`${options.debugId}: getItems returned. (${Date.now() - timeStarted}ms)`);
+ return output;
+ } catch (error) {
+ console.error(error);
+
+ return {
+ armor: {
+ armor: [],
+ },
+ equipment: {
+ equipment: [],
+ },
+ wardrobe: [],
+ wardrobe_inventory: [],
+ inventory: [],
+ enderchest: [],
+ accessory_bag: [],
+ fishing_bag: [],
+ quiver: [],
+ potion_bag: [],
+ personal_vault: [],
+ storage: [],
+ hotm: [],
+ candy_bag: [],
+ museumItems: {},
+ museum: [],
+ bingo_card: [],
+ accessories: {
+ accessories: [],
+ },
+ weapons: [],
+ farming_tools: [],
+ mining_tools: [],
+ fishing_tools: [],
+ pets: [],
+ disabled: {},
+ allItems: [],
+ };
}
-
- output.weapons = items.getWeapons(allItems);
- output.farming_tools = items.getSkilllTools("farming", allItems);
- output.mining_tools = items.getSkilllTools("mining", allItems);
- output.fishing_tools = items.getSkilllTools("fishing", allItems);
- output.pets = items.getPets(allItems);
-
- // Check if inventory access disabled by user
- output.disabled = {
- inventory: inventory.length === 0,
- personal_vault: personal_vault.length === 0,
- };
-
- output.allItems = allItems;
-
- console.debug(`${options.debugId}: getItems returned. (${Date.now() - timeStarted}ms)`);
- return output;
}
From 731ac4d314ecd1bc8d2d41676c9102257215c998 Mon Sep 17 00:00:00 2001
From: DuckySoLucky
Date: Fri, 16 Feb 2024 19:15:11 +0100
Subject: [PATCH 02/11] fix: fix items processing breaking website
---
src/app.js | 11 ++++++----
src/helper.js | 28 +++++++++++---------------
src/lib.js | 5 ++++-
src/stats/items.js | 19 ++++++++++-------
src/stats/leaderboards.js | 4 +---
views/sections/stats/skills/mining.ejs | 8 +++++---
6 files changed, 41 insertions(+), 34 deletions(-)
diff --git a/src/app.js b/src/app.js
index 2dc6089369..2076c44410 100644
--- a/src/app.js
+++ b/src/app.js
@@ -315,7 +315,9 @@ app.all("/stats/:player/:profile?", async (req, res, next) => {
console.debug(`${debugId}: an error has occurred.`);
console.error(err);
- await helper.sendWebhookMessage(err, req);
+ const username = req.params.player;
+ const profile = req.params.profile;
+ await helper.sendWebhookMessage(err, { username, profile });
const favorites = parseFavorites(req.cookies.favorite);
res.render(
@@ -347,9 +349,10 @@ app.all("/stats/:player/:profile?", async (req, res, next) => {
);
} catch (e) {
if (e instanceof SkyCryptError === false) {
- if (e.message !== "socket hang up") {
- helper.sendWebhookMessage(e, req);
- }
+ const username = req.params.player;
+ const profile = req.params.profile;
+
+ helper.sendWebhookMessage(e, { username, profile });
}
const favorites = parseFavorites(req.cookies.favorite);
diff --git a/src/helper.js b/src/helper.js
index fe52b4b065..6e761480fa 100644
--- a/src/helper.js
+++ b/src/helper.js
@@ -1114,23 +1114,19 @@ export async function applyResourcePack(item, packs) {
return item;
}
-export async function sendWebhookMessage(e, req) {
- const webhookUrl = credentials.discord_webhook;
- if (webhookUrl !== undefined && req.params !== undefined) {
- let description = "";
- const playerUsername = req.params.player;
- if (playerUsername) {
- description += `Username: \`${playerUsername}\`\n`;
+export async function sendWebhookMessage(e, { username, profile }) {
+ try {
+ const webhookUrl = credentials.discord_webhook;
+ if (webhookUrl === undefined || username === undefined) {
+ return;
}
- description += `Options: \`${JSON.stringify(req.params)}\`\n`;
-
- const paramProfile = req.params.profile;
- if (paramProfile) {
- description += `Profile: \`${paramProfile}\`\n`;
+ let description = `Username: \`${username}\`\n`;
+ if (profile) {
+ description += `Profile: \`${profile}\`\n`;
}
- description += `Link: https://sky.shiiyu.moe/stats/${playerUsername}${paramProfile ? `/${paramProfile}` : ""}\n`;
+ description += `Link: https://sky.shiiyu.moe/stats/${username}${profile ? `/${profile}` : ""}\n`;
description += `\`\`\`${e.stack}\`\`\``;
const embed = {
@@ -1140,8 +1136,8 @@ export async function sendWebhookMessage(e, req) {
fields: [],
};
- await axios.post(webhookUrl, { embeds: [embed] }).catch((error) => {
- console.log(error);
- });
+ await axios.post(webhookUrl, { embeds: [embed] });
+ } catch (e) {
+ console.error(e);
}
}
diff --git a/src/lib.js b/src/lib.js
index bb67cd2670..72c8fbe107 100644
--- a/src/lib.js
+++ b/src/lib.js
@@ -227,7 +227,10 @@ export async function getStats(
output.errors = errors;
if (Object.keys(errors).length > 0) {
for (const error in errors) {
- helper.sendWebhookMessage(errors[error], { params: { player: profile.uuid, profile: profile.profile_id } });
+ const username = profile.uuid;
+ const profileId = profile.profile_id;
+
+ helper.sendWebhookMessage(errors[error], { username, profile: profileId });
}
}
diff --git a/src/stats/items.js b/src/stats/items.js
index 1ce05dac85..aab3be5fef 100644
--- a/src/stats/items.js
+++ b/src/stats/items.js
@@ -13,8 +13,6 @@ export async function getItems(
try {
const output = {};
- throw new Error("This function is not implemented yet.");
-
console.debug(`${options.debugId}: getItems called.`);
const timeStarted = Date.now();
@@ -208,13 +206,14 @@ export async function getItems(
output.allItems = allItems;
- console.log(Object.keys(output));
-
console.debug(`${options.debugId}: getItems returned. (${Date.now() - timeStarted}ms)`);
return output;
} catch (error) {
console.error(error);
+ const username = profile.player_id;
+ helper.sendWebhookMessage(error, { username });
+
return {
armor: {
armor: [],
@@ -241,9 +240,15 @@ export async function getItems(
accessories: [],
},
weapons: [],
- farming_tools: [],
- mining_tools: [],
- fishing_tools: [],
+ farming_tools: {
+ tools: [],
+ },
+ mining_tools: {
+ tools: [],
+ },
+ fishing_tools: {
+ tools: [],
+ },
pets: [],
disabled: {},
allItems: [],
diff --git a/src/stats/leaderboards.js b/src/stats/leaderboards.js
index 1f3a35f0ac..a3c84e06a8 100644
--- a/src/stats/leaderboards.js
+++ b/src/stats/leaderboards.js
@@ -334,8 +334,6 @@ export async function updateLeaderboardData(
return;
}
- const req = { params: { player: uuid } };
-
- helper.sendWebhookMessage(e, req, "updateLeaderboardData");
+ helper.sendWebhookMessage(e, { username: uuid });
}
}
diff --git a/views/sections/stats/skills/mining.ejs b/views/sections/stats/skills/mining.ejs
index 4fd1d30452..360bbfde96 100644
--- a/views/sections/stats/skills/mining.ejs
+++ b/views/sections/stats/skills/mining.ejs
@@ -211,9 +211,11 @@ function itemIcon(item, classes) { %>
<%= mining.core.selected_pickaxe_ability || 'None' %>
-
-
-
+ <% if (items.hotm.length > 0) { %>
+
+
+
+ <% } %>
<% if (mining.forge?.processes?.length > 0) {
From c1e32eeb37e6f5263c4671fb206313fab903c5b3 Mon Sep 17 00:00:00 2001
From: DuckySoLucky
Date: Fri, 16 Feb 2024 19:34:28 +0100
Subject: [PATCH 03/11] refactor: smth
---
src/app.js | 9 +++-----
src/lib.js | 45 ++++++++++-----------------------------
src/stats.js | 1 +
src/stats/leaderboards.js | 3 +--
src/stats/missing.js | 6 +++---
src/stats/networth.js | 39 +++++++++++++++++++++++++++++++++
src/stats/pets.js | 6 +++---
7 files changed, 61 insertions(+), 48 deletions(-)
create mode 100644 src/stats/networth.js
diff --git a/src/app.js b/src/app.js
index 2076c44410..db6812b8a1 100644
--- a/src/app.js
+++ b/src/app.js
@@ -277,11 +277,8 @@ app.all("/stats/:player/:profile?", async (req, res, next) => {
const paramBingo =
profile.game_mode === "bingo" ? await lib.getBingoProfile(db, paramPlayer, { cacheOnly, debugId }) : null;
- const items = await stats.getItems(profile.members[profile.uuid], paramBingo, true, req.cookies.pack, {
- cacheOnly,
- debugId,
- });
- const calculated = await lib.getStats(db, profile, paramBingo, allProfiles, items, req.cookies.pack, {
+ console.log(req.cookies);
+ const calculated = await lib.getStats(db, profile, paramBingo, allProfiles, req.cookies.pack, {
cacheOnly,
debugId,
updateLeaderboards: true,
@@ -300,7 +297,7 @@ app.all("/stats/:player/:profile?", async (req, res, next) => {
"stats",
{
req,
- items,
+ items: calculated.items,
calculated,
_,
constants,
diff --git a/src/lib.js b/src/lib.js
index 72c8fbe107..5ea6a21ab5 100644
--- a/src/lib.js
+++ b/src/lib.js
@@ -58,7 +58,6 @@ export async function getStats(
profile,
bingoProfile,
allProfiles,
- items,
packs,
options = {
cacheOnly: false,
@@ -160,40 +159,17 @@ export async function getStats(
output.harp_quest = userProfile.quests?.harp_quest || {};
- const specialMuseumItems = items.museumItems.specialItems
- ? items.museumItems.specialItems.map((a) => a.data).flat()
- : [];
- const normalMuseumItems = items.museumItems.items
- ? Object.values(items.museumItems.items)
- .filter((a) => a && a.data !== undefined && a.borrowing === false)
- .map((a) => a.data)
- .flat()
- : [];
-
- const museumItems = [...normalMuseumItems, ...specialMuseumItems];
-
- const networthItems = {
- armor: items.armor?.armor ?? [],
- equipment: items.equipment?.equipment ?? [],
- wardrobe: items.wardrobe_inventory ?? [],
- inventory: items.inventory ?? [],
- enderchest: items.enderchest ?? [],
- accessories: items.accessory_bag ?? [],
- personal_vault: items.personal_vault ?? [],
- storage: items.storage ? items.storage.concat(items.storage.map((item) => item.containsItems).flat()) : [],
- fishing_bag: items.fishing_bag ?? [],
- potion_bag: items.potion_bag ?? [],
- candy_inventory: items.candy_bag ?? [],
- museum: museumItems,
- };
-
- const bank = profile.banking?.balance ?? 0;
- const networthOptions = { cache: true, onlyNetworth: true, v2Endpoint: true };
-
const profileMembers = profile.members;
const uuid = profile.uuid;
+ // console.log(packs, "pack");
+
const functions = {
+ items: {
+ fn: stats.getItems,
+ args: { userProfile, bingoProfile, packs, cacheOnly: options.cacheOnly },
+ promise: true,
+ },
fairy_souls: { fn: stats.getFairySouls, args: { userProfile, profile } },
skills: { fn: stats.getSkills, args: { userProfile, hypixelProfile, members: profileMembers } },
slayer: { fn: stats.getSlayer, args: { userProfile } },
@@ -214,11 +190,11 @@ export async function getStats(
user_data: { fn: stats.getUserData, args: { userProfile } },
currencies: { fn: stats.getCurrenciesData, args: { userProfile, profile } },
weight: { fn: stats.getWeight, args: { output }, promise: true },
- accessories: { fn: stats.getMissingAccessories, args: { output, items, packs }, promise: true },
+ accessories: { fn: stats.getMissingAccessories, args: { output, packs }, promise: true, awaitPromises: true },
temp_stats: { fn: stats.getTempStats, args: { userProfile } },
rift: { fn: stats.getRift, args: { userProfile } },
- networth: { fn: getPreDecodedNetworth, args: { userProfile, networthItems, bank, networthOptions }, promise: true },
- pets: { fn: stats.getPets, args: { userProfile, output, items, profile }, promise: true, awaitPromises: true },
+ networth: { fn: stats.getNetworth, args: { userProfile, profile, output }, promise: true, awaitPromises: true },
+ pets: { fn: stats.getPets, args: { userProfile, output, profile }, promise: true, awaitPromises: true },
};
const { results, errors } = await executeFunctions(functions, [userProfile, hypixelProfile, profile.members]);
@@ -231,6 +207,7 @@ export async function getStats(
const profileId = profile.profile_id;
helper.sendWebhookMessage(errors[error], { username, profile: profileId });
+ console.log(errors[error]);
}
}
diff --git a/src/stats.js b/src/stats.js
index 5f347be4ce..222c4be837 100644
--- a/src/stats.js
+++ b/src/stats.js
@@ -20,3 +20,4 @@ export * from "./stats/rift.js";
export * from "./stats/items.js";
export * from "./stats/missing.js";
export * from "./stats/leaderboards.js";
+export * from "./stats/networth.js";
diff --git a/src/stats/leaderboards.js b/src/stats/leaderboards.js
index a3c84e06a8..84780ebcf4 100644
--- a/src/stats/leaderboards.js
+++ b/src/stats/leaderboards.js
@@ -61,8 +61,7 @@ export async function updateLeaderboardData(
}
const paramBingo = profile.game_mode === "bingo" ? await lib.getBingoProfile(db, uuid, options) : null;
- const items = await stats.getItems(profile.members[profile.uuid], paramBingo, true, [], options);
- const calculated = await lib.getStats(db, profile, paramBingo, allProfiles, items, [], options);
+ const calculated = await lib.getStats(db, profile, paramBingo, allProfiles, [], options);
if (calculated.skills?.skills !== undefined) {
for (const skill in calculated.skills.skills) {
diff --git a/src/stats/missing.js b/src/stats/missing.js
index 1a7986ee4b..d158dd90a2 100644
--- a/src/stats/missing.js
+++ b/src/stats/missing.js
@@ -85,8 +85,8 @@ function getMissing(accessories) {
};
}
-export async function getMissingAccessories(calculated, items, packs) {
- const accessoryIds = items.accessories?.accessory_ids;
+export async function getMissingAccessories(calculated, packs) {
+ const accessoryIds = calculated.items.accessories?.accessory_ids;
if (!accessoryIds || accessoryIds?.length === 0) {
return;
}
@@ -140,7 +140,7 @@ export async function getMissingAccessories(calculated, items, packs) {
});
}
- const accessories = items.accessories.accessories;
+ const accessories = calculated.items.accessories.accessories;
const activeAccessories = accessories.filter((a) => a.isInactive === false);
output.unique = accessories.filter((a) => a.isUnique === true).length;
diff --git a/src/stats/networth.js b/src/stats/networth.js
new file mode 100644
index 0000000000..af336fee1d
--- /dev/null
+++ b/src/stats/networth.js
@@ -0,0 +1,39 @@
+import { getPreDecodedNetworth } from "skyhelper-networth";
+
+export async function getNetworth(userProfile, profile, calculated) {
+ const networthOptions = { cache: true, onlyNetworth: true, v2Endpoint: true };
+ const bank = profile.banking?.balance ?? 0;
+
+ const specialMuseumItems = calculated.items.museumItems.specialItems
+ ? calculated.items.museumItems.specialItems.map((a) => a.data).flat()
+ : [];
+ const normalMuseumItems = calculated.items.museumItems.items
+ ? Object.values(calculated.items.museumItems.items)
+ .filter((a) => a && a.data !== undefined && a.borrowing === false)
+ .map((a) => a.data)
+ .flat()
+ : [];
+
+ const museumItems = [...normalMuseumItems, ...specialMuseumItems];
+
+ const networthItems = {
+ armor: calculated.items.armor?.armor ?? [],
+ equipment: calculated.items.equipment?.equipment ?? [],
+ wardrobe: calculated.items.wardrobe_inventory ?? [],
+ inventory: calculated.items.inventory ?? [],
+ enderchest: calculated.items.enderchest ?? [],
+ accessories: calculated.items.accessory_bag ?? [],
+ personal_vault: calculated.items.personal_vault ?? [],
+ storage: calculated.items.storage
+ ? calculated.items.storage.concat(calculated.items.storage.map((item) => item.containsItems).flat())
+ : [],
+ fishing_bag: calculated.items.fishing_bag ?? [],
+ potion_bag: calculated.items.potion_bag ?? [],
+ candy_inventory: calculated.items.candy_bag ?? [],
+ museum: museumItems,
+ };
+
+ const networth = await getPreDecodedNetworth(userProfile, networthItems, bank, networthOptions);
+
+ return networth;
+}
diff --git a/src/stats/pets.js b/src/stats/pets.js
index faacb95a3d..c0639f5850 100644
--- a/src/stats/pets.js
+++ b/src/stats/pets.js
@@ -424,15 +424,15 @@ function getPetScore(pets) {
};
}
-export async function getPets(userProfile, calculated, items, profile) {
+export async function getPets(userProfile, calculated, profile) {
const output = {};
// Get pets from profile
const pets = userProfile.pets_data?.pets ?? [];
// Adds pets from inventories
- if (items.pets !== undefined) {
- pets.push(...items.pets);
+ if (calculated.items.pets !== undefined) {
+ pets.push(...calculated.items.pets);
}
// Add Montezume pet from the Rift
From 636b4241f82e188960c569a4d2edff9ef2eac799 Mon Sep 17 00:00:00 2001
From: DuckySoLucky
Date: Fri, 16 Feb 2024 19:58:42 +0100
Subject: [PATCH 04/11] refactor: move items to getStats()
---
src/app.js | 2 +-
src/lib.js | 5 ++---
src/stats/items.js | 8 +++-----
src/stats/missing.js | 2 +-
src/stats/networth.js | 33 ++++++++++++++++-----------------
src/stats/pets.js | 2 +-
6 files changed, 24 insertions(+), 28 deletions(-)
diff --git a/src/app.js b/src/app.js
index db6812b8a1..fe6ccf7363 100644
--- a/src/app.js
+++ b/src/app.js
@@ -277,12 +277,12 @@ app.all("/stats/:player/:profile?", async (req, res, next) => {
const paramBingo =
profile.game_mode === "bingo" ? await lib.getBingoProfile(db, paramPlayer, { cacheOnly, debugId }) : null;
- console.log(req.cookies);
const calculated = await lib.getStats(db, profile, paramBingo, allProfiles, req.cookies.pack, {
cacheOnly,
debugId,
updateLeaderboards: true,
updateGuild: true,
+ customTextures: true,
});
if (isFoolsDay) {
diff --git a/src/lib.js b/src/lib.js
index 5ea6a21ab5..21a24e37ef 100644
--- a/src/lib.js
+++ b/src/lib.js
@@ -64,6 +64,7 @@ export async function getStats(
debugId: `${helper.getClusterId()}/unknown@getStats`,
updateLeaderboards: false,
updateGuild: false,
+ customTextures: false,
},
) {
const output = {};
@@ -162,12 +163,10 @@ export async function getStats(
const profileMembers = profile.members;
const uuid = profile.uuid;
- // console.log(packs, "pack");
-
const functions = {
items: {
fn: stats.getItems,
- args: { userProfile, bingoProfile, packs, cacheOnly: options.cacheOnly },
+ args: { userProfile, bingoProfile, customTextures: options.customTextures, packs, options },
promise: true,
},
fairy_souls: { fn: stats.getFairySouls, args: { userProfile, profile } },
diff --git a/src/stats/items.js b/src/stats/items.js
index aab3be5fef..5c35bdcbca 100644
--- a/src/stats/items.js
+++ b/src/stats/items.js
@@ -208,11 +208,9 @@ export async function getItems(
console.debug(`${options.debugId}: getItems returned. (${Date.now() - timeStarted}ms)`);
return output;
- } catch (error) {
- console.error(error);
-
- const username = profile.player_id;
- helper.sendWebhookMessage(error, { username });
+ } catch (e) {
+ console.log(e);
+ helper.sendWebhookMessage(e, { username: profile.player_id });
return {
armor: {
diff --git a/src/stats/missing.js b/src/stats/missing.js
index d158dd90a2..47be842ff1 100644
--- a/src/stats/missing.js
+++ b/src/stats/missing.js
@@ -86,7 +86,7 @@ function getMissing(accessories) {
}
export async function getMissingAccessories(calculated, packs) {
- const accessoryIds = calculated.items.accessories?.accessory_ids;
+ const accessoryIds = calculated.items?.accessories?.accessory_ids;
if (!accessoryIds || accessoryIds?.length === 0) {
return;
}
diff --git a/src/stats/networth.js b/src/stats/networth.js
index af336fee1d..e69e4dc40e 100644
--- a/src/stats/networth.js
+++ b/src/stats/networth.js
@@ -3,12 +3,13 @@ import { getPreDecodedNetworth } from "skyhelper-networth";
export async function getNetworth(userProfile, profile, calculated) {
const networthOptions = { cache: true, onlyNetworth: true, v2Endpoint: true };
const bank = profile.banking?.balance ?? 0;
+ const items = calculated.items ?? {};
- const specialMuseumItems = calculated.items.museumItems.specialItems
- ? calculated.items.museumItems.specialItems.map((a) => a.data).flat()
+ const specialMuseumItems = items.museumItems?.specialItems
+ ? items.museumItems.specialItems.map((a) => a.data).flat()
: [];
- const normalMuseumItems = calculated.items.museumItems.items
- ? Object.values(calculated.items.museumItems.items)
+ const normalMuseumItems = items.museumItems?.items
+ ? Object.values(items.museumItems.items)
.filter((a) => a && a.data !== undefined && a.borrowing === false)
.map((a) => a.data)
.flat()
@@ -17,19 +18,17 @@ export async function getNetworth(userProfile, profile, calculated) {
const museumItems = [...normalMuseumItems, ...specialMuseumItems];
const networthItems = {
- armor: calculated.items.armor?.armor ?? [],
- equipment: calculated.items.equipment?.equipment ?? [],
- wardrobe: calculated.items.wardrobe_inventory ?? [],
- inventory: calculated.items.inventory ?? [],
- enderchest: calculated.items.enderchest ?? [],
- accessories: calculated.items.accessory_bag ?? [],
- personal_vault: calculated.items.personal_vault ?? [],
- storage: calculated.items.storage
- ? calculated.items.storage.concat(calculated.items.storage.map((item) => item.containsItems).flat())
- : [],
- fishing_bag: calculated.items.fishing_bag ?? [],
- potion_bag: calculated.items.potion_bag ?? [],
- candy_inventory: calculated.items.candy_bag ?? [],
+ armor: items.armor?.armor ?? [],
+ equipment: items.equipment?.equipment ?? [],
+ wardrobe: items.wardrobe_inventory ?? [],
+ inventory: items.inventory ?? [],
+ enderchest: items.enderchest ?? [],
+ accessories: items.accessory_bag ?? [],
+ personal_vault: items.personal_vault ?? [],
+ storage: items.storage ? items.storage.concat(items.storage.map((item) => item.containsItems).flat()) : [],
+ fishing_bag: items.fishing_bag ?? [],
+ potion_bag: items.potion_bag ?? [],
+ candy_inventory: items.candy_bag ?? [],
museum: museumItems,
};
diff --git a/src/stats/pets.js b/src/stats/pets.js
index c0639f5850..2914ffd96f 100644
--- a/src/stats/pets.js
+++ b/src/stats/pets.js
@@ -431,7 +431,7 @@ export async function getPets(userProfile, calculated, profile) {
const pets = userProfile.pets_data?.pets ?? [];
// Adds pets from inventories
- if (calculated.items.pets !== undefined) {
+ if (calculated.items?.pets !== undefined) {
pets.push(...calculated.items.pets);
}
From 85850ccc5a32ea229a67b0a7eeb825ce2049db20 Mon Sep 17 00:00:00 2001
From: DuckySoLucky
Date: Fri, 16 Feb 2024 21:21:35 +0100
Subject: [PATCH 05/11] fix: v1 API endpoints
---
src/routes/api/accessories.js | 13 ++++----
src/routes/api/armor.js | 37 +++++---------------
src/routes/api/cakebag.js | 35 +++++++++----------
src/routes/api/collections.js | 23 +++++++------
src/routes/api/items.js | 33 +++++++++---------
src/routes/api/minions.js | 41 ++++++++---------------
src/routes/api/pets.js | 50 ++++++++++-----------------
src/routes/api/profiles.js | 1 +
src/routes/api/skills.js | 63 +++++++++++++++++++----------------
src/routes/api/wardrobe.js | 39 ++++++----------------
src/routes/api/weapons.js | 58 +++++++++-----------------------
src/routes/apiv2/profile.js | 5 +--
src/routes/apiv2/slayers.js | 43 ++++++++----------------
src/routes/apiv2/talismans.js | 2 +-
14 files changed, 169 insertions(+), 274 deletions(-)
diff --git a/src/routes/api/accessories.js b/src/routes/api/accessories.js
index 31fe10e74b..abef1f3457 100644
--- a/src/routes/api/accessories.js
+++ b/src/routes/api/accessories.js
@@ -18,17 +18,18 @@ router.use(async (req, res, next) => {
const { profile, uuid } = await lib.getProfile(db, req.player, req.profile, req.options);
const userProfile = profile.members[uuid];
- const items = await getItems(userProfile, false, undefined, req.options);
+ const items = await getItems(userProfile, null, false, undefined, req.options);
- const accessories = items.accessories
+ const accessories = items.accessories.accessories
.filter((a) => a.isUnique)
.map((a) => {
return {
- id: a.tag.ExtraAttributes.id,
+ id: helper.getId(a),
rarity: a.rarity,
- reforge: a.reforge,
- name: a.base_name,
- isActive: a.isInactive ? "false" : "true",
+ name: a.display_name,
+ recombobulated: a.recombobulated,
+ enrichment: a.enrichment,
+ isActive: !a.isInactive,
};
});
diff --git a/src/routes/api/armor.js b/src/routes/api/armor.js
index 757fda0646..ae930d33f0 100644
--- a/src/routes/api/armor.js
+++ b/src/routes/api/armor.js
@@ -18,35 +18,16 @@ router.use(async (req, res, next) => {
const { profile, uuid } = await lib.getProfile(db, req.player, req.profile, req.options);
const userProfile = profile.members[uuid];
- const items = await getItems(userProfile, false, undefined, req.options);
+ const items = await getItems(userProfile, null, false, undefined, req.options);
const output = [];
-
- for (const armor of items.armor) {
- const enchantments = armor.tag.ExtraAttributes.enchantments;
- let enchantmentsOutput = enchantments;
-
- const stats = armor.stats;
- let statsOutput = stats;
-
- if (enchantments !== undefined) {
- enchantmentsOutput = [];
-
- for (const enchantment in enchantments) {
- enchantmentsOutput.push(enchantment + "=" + enchantments[enchantment]);
- }
-
- enchantmentsOutput = enchantmentsOutput.join(",");
- }
-
- if (stats !== undefined) {
- statsOutput = [];
-
- for (const stat in stats) {
- statsOutput.push(stat + "=" + stats[stat]);
- }
-
- statsOutput = statsOutput.join(",");
+ for (const armor of items.armor?.armor ?? []) {
+ const armorEnchantments = armor.tag.ExtraAttributes.enchantments;
+ let enchantmentsOutput;
+ if (armorEnchantments) {
+ enchantmentsOutput = Object.entries(armor.tag.ExtraAttributes.enchantments)
+ .map(([key, value]) => `${key}=${value}`)
+ .join(",");
}
output.push({
@@ -54,7 +35,7 @@ router.use(async (req, res, next) => {
name: armor.display_name,
rarity: armor.rarity,
enchantments: enchantmentsOutput,
- stats: statsOutput,
+ recombobulated: armor.recombobulated,
});
}
diff --git a/src/routes/api/cakebag.js b/src/routes/api/cakebag.js
index be7ff969a6..529f897eb9 100644
--- a/src/routes/api/cakebag.js
+++ b/src/routes/api/cakebag.js
@@ -18,29 +18,24 @@ router.use(async (req, res, next) => {
const { profile, uuid } = await lib.getProfile(db, req.player, req.profile, { cacheOnly: true });
const userProfile = profile.members[uuid];
- const items = await getItems(userProfile, false, undefined, req.options);
-
- const allItems = items.armor.concat(items.inventory, items.accessory_bag, items.enderchest);
-
- const cakeBags = allItems.filter((a) => a?.tag?.ExtraAttributes?.id == "NEW_YEAR_CAKE_BAG");
+ const items = await getItems(userProfile, null, false, undefined, req.options);
+ const cakeBags = items.allItems.filter((a) => helper.getId(a) === "NEW_YEAR_CAKE_BAG");
if (cakeBags.length == 0) {
- handleError(req, res, new Error("Player has no cake bag"), 404);
- } else {
- const cakeBag = cakeBags[0];
-
- let cakes = [];
-
- for (const item of cakeBag.containsItems) {
- if (item.tag?.ExtraAttributes?.new_years_cake) {
- cakes.push({ cake: item.tag.ExtraAttributes.new_years_cake });
- }
- }
-
- cakes = cakes.sort((a, b) => a.cake - b.cake);
-
- res.send(tableify(cakes));
+ return handleError(req, res, new Error("Player has no cake bag"), 404);
}
+
+ const cakes = cakeBags
+ .map((a) =>
+ a.containsItems
+ .map((b) => b.tag?.ExtraAttributes?.new_years_cake)
+ .filter((c) => c)
+ .map((c) => ({ cake: c })),
+ )
+ .flat()
+ .sort((a, b) => a.cake - b.cake);
+
+ res.send(tableify(cakes));
} catch (e) {
next(e);
}
diff --git a/src/routes/api/collections.js b/src/routes/api/collections.js
index 6abe838d13..7cf17ddf42 100644
--- a/src/routes/api/collections.js
+++ b/src/routes/api/collections.js
@@ -18,18 +18,19 @@ router.use(async (req, res, next) => {
const { profile, uuid } = await lib.getProfile(db, req.player, req.profile, req.options);
const collections = await stats.getCollections(uuid, profile, req.options.cacheOnly);
+ const collectionData = Object.values(collections)
+ .filter((a) => a.collections !== undefined)
+ .map((a) => a.collections)
+ .flat();
- res.send(
- tableify(
- Object.keys(collections).map((a) => [
- a,
- collections[a].name,
- collections[a].tier,
- collections[a].amount,
- collections[a].totalAmount,
- ]),
- ),
- );
+ const output = collectionData.map((a) => ({
+ name: a.name,
+ tier: a.tier,
+ amount: a.amount,
+ totalAmount: a.totalAmount,
+ }));
+
+ res.send(tableify(output));
} catch (e) {
next(e);
}
diff --git a/src/routes/api/items.js b/src/routes/api/items.js
index 60468084a2..1c4e4801e8 100644
--- a/src/routes/api/items.js
+++ b/src/routes/api/items.js
@@ -20,21 +20,24 @@ router.use(async (req, res, next) => {
const items = await getItems(userProfile, false, undefined, req.options);
- const allItems = items.inventory.concat(items.enderchest);
-
- for (const item of allItems) {
- if (Array.isArray(item.containsItems)) {
- allItems.push(...item.containsItems);
- }
- }
-
- res.send(
- tableify(
- allItems
- .filter((a) => helper.getId(a).length > 0)
- .map((a) => [helper.getId(a), a.Count, a.display_name, a.rarity, a.type]),
- ),
- );
+ const allItems = items.allItems
+ .concat(
+ items.allItems
+ .filter((a) => a.containsItems)
+ .map((a) => a.containsItems)
+ .flat(),
+ )
+ .filter((a) => a && helper.getId(a))
+ .map((a) => ({
+ id: helper.getId(a),
+ Count: a.Count,
+ display_name: a.display_name,
+ rarity: a.rarity,
+ type: a.type,
+ location: a.extra ? a.extra.source.toLowerCase() : undefined,
+ }));
+
+ res.send(tableify(allItems));
} catch (e) {
next(e);
}
diff --git a/src/routes/api/minions.js b/src/routes/api/minions.js
index aed46e1315..489f6aa1b8 100644
--- a/src/routes/api/minions.js
+++ b/src/routes/api/minions.js
@@ -4,6 +4,7 @@ import express from "express";
import { tableify } from "../api.js";
import { db } from "../../mongo.js";
+import { getMinions } from "../../stats.js";
const router = express.Router();
@@ -16,33 +17,19 @@ router.use(async (req, res, next) => {
try {
const { profile } = await lib.getProfile(db, req.player, req.profile, req.options);
- const minions = [];
-
- const coopMembers = profile.members;
-
- for (const member in coopMembers) {
- if (!("crafted_generators" in coopMembers[member])) {
- continue;
- }
-
- for (const minion of coopMembers[member].crafted_generators) {
- const minionName = minion.replaceAll(/(_[0-9]+)/g, "");
-
- const minionLevel = parseInt(minion.split("_").pop());
-
- if (minions.find((a) => a.minion == minionName) == undefined) {
- minions.push({ minion: minionName, level: minionLevel });
- }
-
- const minionObject = minions.find((a) => a.minion == minionName);
-
- if (minionObject.level < minionLevel) {
- minionObject.level = minionLevel;
- }
- }
- }
-
- res.send(tableify(minions));
+ const minions = getMinions(profile).minions;
+ const minionsData = Object.values(minions)
+ .filter((a) => a.minions)
+ .map((a) => a.minions)
+ .flat()
+ .map((a) => ({
+ id: a.id,
+ name: a.name,
+ tier: a.tier,
+ maxTier: a.maxTier,
+ }));
+
+ res.send(tableify(minionsData));
} catch (e) {
next(e);
}
diff --git a/src/routes/api/pets.js b/src/routes/api/pets.js
index 57f8c5cf43..0effc2b4bd 100644
--- a/src/routes/api/pets.js
+++ b/src/routes/api/pets.js
@@ -4,7 +4,7 @@ import express from "express";
import { tableify } from "../api.js";
import { db } from "../../mongo.js";
-import { getPets } from "../../stats.js";
+import { getItems, getPets } from "../../stats.js";
const router = express.Router();
@@ -18,37 +18,23 @@ router.use(async (req, res, next) => {
const { profile, uuid } = await lib.getProfile(db, req.player, req.profile, req.options);
const userProfile = profile.members[uuid];
- const pets = await getPets(userProfile, userProfile, [], profile);
-
- for (const pet of pets) {
- delete pet.lore;
-
- const petLevel = Object.assign({}, pet.level);
- delete pet.level;
- delete pet.tier;
-
- for (const key in petLevel) {
- pet[key] = petLevel[key];
- }
- }
-
- res.send(
- tableify(
- pets.map((a) => [
- a.type,
- a.exp,
- a.active,
- a.rarity,
- a.texture_path,
- a.display_name,
- a.level,
- a.xpCurrent,
- a.xpForNext,
- a.progress,
- a.xpMaxLevel,
- ]),
- ),
- );
+ const pets = await getPets(userProfile, userProfile, profile);
+ const petsData = pets.pets.map((a) => ({
+ type: a.type,
+ exp: a.exp,
+ active: a.active,
+ rarity: a.rarity,
+ texture_path: a.texture_path,
+ display_name: a.display_name,
+ level: a.level.level,
+ xpCurrent: a.level.xpCurrent,
+ xpForNext: a.level.xpForNext,
+ progress: a.level.progress,
+ xpMaxLevel: a.level.xpMaxLevel,
+ skin: a.skin,
+ }));
+
+ res.send(tableify(petsData));
} catch (e) {
next(e);
}
diff --git a/src/routes/api/profiles.js b/src/routes/api/profiles.js
index e926732106..2cb8b59f9d 100644
--- a/src/routes/api/profiles.js
+++ b/src/routes/api/profiles.js
@@ -27,6 +27,7 @@ router.use(async (req, res, next) => {
profile_id: profile.profile_id,
cute_name: profile.cute_name,
members: members.join(", "),
+ selected: profile.selected,
});
}
diff --git a/src/routes/api/skills.js b/src/routes/api/skills.js
index 14e91776f6..c4421b42de 100644
--- a/src/routes/api/skills.js
+++ b/src/routes/api/skills.js
@@ -4,7 +4,7 @@ import express from "express";
import { tableify } from "../api.js";
import { db } from "../../mongo.js";
-import { getItems } from "../../stats.js";
+import { getSkills, getSlayer, getSkyBlockLevel } from "../../stats.js";
const router = express.Router();
@@ -15,46 +15,51 @@ router.use((req, res, next) => {
router.use(async (req, res, next) => {
try {
- const { profile, allProfiles, uuid } = await lib.getProfile(db, req.player, req.profile, req.options);
- const bingoProfile = await lib.getBingoProfile(db, req.player, req.options);
+ const { profile, uuid } = await lib.getProfile(db, req.player, req.profile, req.options);
+ const hypixelProfile = await helper.getRank(profile.uuid, db, req.options);
const userProfile = profile.members[uuid];
- const items = await getItems(userProfile, bingoProfile, false, undefined, req.options);
- const calculated = await lib.getStats(db, profile, bingoProfile, allProfiles, items, req.options);
-
const response = [];
- for (const skill in calculated.skills.skills) {
- const pushArr = [helper.titleCase(skill), calculated.skills.skills[skill].level.toString()];
-
- if ("progress" in req.query) {
- pushArr.push(
- calculated.skills.skills[skill].maxLevel,
- calculated.skills.skills[skill].xp,
- calculated.skills.skills[skill].xpCurrent,
- calculated.skills.skills[skill].xpForNext,
- );
- }
+ const { skills } = await getSkills(userProfile, hypixelProfile, profile.members);
+ for (const skill in skills) {
+ const pushArr = [
+ helper.titleCase(skill),
+ skills[skill].level.toString(),
+ skills[skill].maxLevel,
+ skills[skill].xp,
+ skills[skill].xpCurrent,
+ skills[skill].xpForNext,
+ ];
response.push(pushArr);
}
- for (const slayer in calculated.slayers) {
- const pushArr = [helper.titleCase(slayer), calculated.slayers[slayer].level.currentLevel.toString()];
-
- if ("progress" in req.query) {
- pushArr.push(
- calculated.slayers[slayer].level.maxLevel,
- calculated.slayers[slayer].xp,
- calculated.slayers[slayer].xp,
- calculated.slayers[slayer].level.xpForNext,
- );
- }
+ const { slayers } = getSlayer(userProfile);
+ for (const slayer in slayers) {
+ const pushArr = [
+ helper.titleCase(slayer),
+ slayers[slayer].level.currentLevel.toString(),
+ slayers[slayer].level.maxLevel,
+ slayers[slayer].level.xp,
+ slayers[slayer].level.xpForNext,
+ ];
response.push(pushArr);
}
- response.push(["Fairy Souls", calculated.fairy_souls.collected.toString()]);
+ const skyblockLevel = await getSkyBlockLevel(userProfile);
+ response.push([
+ "SkyBlock Level",
+ skyblockLevel.level,
+ skyblockLevel.maxLevel,
+ skyblockLevel.xp,
+ skyblockLevel.xpCurrent,
+ skyblockLevel.xpForNext,
+ skyblockLevel.maxExperience,
+ ]);
+
+ response.push(["Fairy Souls", userProfile.fairy_soul.total_collected.toString()]);
res.send(tableify(response));
} catch (e) {
diff --git a/src/routes/api/wardrobe.js b/src/routes/api/wardrobe.js
index c66adccb22..f577e89643 100644
--- a/src/routes/api/wardrobe.js
+++ b/src/routes/api/wardrobe.js
@@ -18,41 +18,22 @@ router.use(async (req, res, next) => {
const { profile, uuid } = await lib.getProfile(db, req.player, req.profile, req.options);
const userProfile = profile.members[uuid];
- const items = await getItems(userProfile, false, undefined, req.options);
+ const items = await getItems(userProfile, null, false, undefined, req.options);
const output = [];
-
- for (const wardrobe of items.wardrobe) {
- for (const armor of wardrobe) {
+ for (const set of items.wardrobe) {
+ for (const armor of set) {
if (armor === null) {
output.push({});
continue;
}
- const enchantments = armor.tag.ExtraAttributes.enchantments;
- let enchantmentsOutput = enchantments;
-
- const stats = armor.stats;
- let statsOutput = stats;
-
- if (enchantments !== undefined) {
- enchantmentsOutput = [];
-
- for (const enchantment in enchantments) {
- enchantmentsOutput.push(enchantment + "=" + enchantments[enchantment]);
- }
-
- enchantmentsOutput = enchantmentsOutput.join(",");
- }
-
- if (stats !== undefined) {
- statsOutput = [];
-
- for (const stat in stats) {
- statsOutput.push(stat + "=" + stats[stat]);
- }
-
- statsOutput = statsOutput.join(",");
+ const armorEnchantments = armor.tag.ExtraAttributes.enchantments;
+ let enchantmentsOutput;
+ if (armorEnchantments) {
+ enchantmentsOutput = Object.entries(armor.tag.ExtraAttributes.enchantments)
+ .map(([key, value]) => `${key}=${value}`)
+ .join(",");
}
output.push({
@@ -60,7 +41,7 @@ router.use(async (req, res, next) => {
name: armor.display_name,
rarity: armor.rarity,
enchantments: enchantmentsOutput,
- stats: statsOutput,
+ recombobulated: armor.recombobulated,
});
}
}
diff --git a/src/routes/api/weapons.js b/src/routes/api/weapons.js
index 5d65039122..9f12277f49 100644
--- a/src/routes/api/weapons.js
+++ b/src/routes/api/weapons.js
@@ -18,50 +18,24 @@ router.use(async (req, res, next) => {
const { profile, uuid } = await lib.getProfile(db, req.player, req.profile, req.options);
const userProfile = profile.members[uuid];
- const items = await getItems(userProfile, false, undefined, req.options);
+ const items = await getItems(userProfile, null, false, undefined, req.options);
const output = [];
+ for (const weapon of items.weapons.weapons) {
+ const weaponEnchantments = weapon.tag.ExtraAttributes.enchantments;
+ let enchantmentsOutput;
+ if (weaponEnchantments) {
+ enchantmentsOutput = Object.entries(weapon.tag.ExtraAttributes.enchantments)
+ .map(([key, value]) => `${key}=${value}`)
+ .join(",");
+ }
- for (const weapon of items.weapons) {
- const enchantments = weapon.tag.ExtraAttributes.enchantments;
- let enchantmentsOutput = enchantments;
-
- const stats = weapon.stats;
- let statsOutput = weapon.stats;
-
- const extra = weapon.extra;
- let extraOutput = weapon.extra;
-
- if (weapon.tag?.ExtraAttributes) {
- if (enchantments !== undefined) {
- enchantmentsOutput = [];
-
- for (const enchantment in enchantments) {
- enchantmentsOutput.push(enchantment + "=" + enchantments[enchantment]);
- }
-
- enchantmentsOutput = enchantmentsOutput.join(",");
- }
-
- if (stats !== undefined) {
- statsOutput = [];
-
- for (const stat in stats) {
- statsOutput.push(stat + "=" + stats[stat]);
- }
-
- statsOutput = statsOutput.join(",");
- }
-
- if (extra !== undefined) {
- extraOutput = [];
-
- for (const value in extra) {
- extraOutput.push(value + "=" + extra[value]);
- }
-
- extraOutput = extraOutput.join(",");
- }
+ const weaponExtra = weapon.extra;
+ let extraOutput;
+ if (weaponExtra) {
+ extraOutput = Object.entries(weaponExtra)
+ .map(([key, value]) => `${key}=${JSON.stringify(value)}`)
+ .join(",");
}
output.push({
@@ -69,8 +43,8 @@ router.use(async (req, res, next) => {
name: weapon.display_name,
rarity: weapon.rarity,
enchantments: enchantmentsOutput,
- stats: statsOutput,
extra: extraOutput,
+ recombobulated: weapon.recombobulated,
});
}
diff --git a/src/routes/apiv2/profile.js b/src/routes/apiv2/profile.js
index ed7cbb33ab..12c1505f40 100644
--- a/src/routes/apiv2/profile.js
+++ b/src/routes/apiv2/profile.js
@@ -3,7 +3,6 @@ import * as lib from "../../lib.js";
import express from "express";
import { db } from "../../mongo.js";
-import { getItems } from "../../stats.js";
const router = express.Router();
@@ -22,8 +21,7 @@ router.get("/:player", async (req, res, next) => {
for (const singleProfile of allProfiles) {
const userProfile = singleProfile.members[profile.uuid];
- const items = await getItems(userProfile, bingoProfile, false, "", req.options);
- const data = await lib.getStats(db, singleProfile, bingoProfile, allProfiles, items, req.options);
+ const data = await lib.getStats(db, singleProfile, bingoProfile, allProfiles, [], req.options);
output.profiles[singleProfile.profile_id] = {
profile_id: singleProfile.profile_id,
@@ -31,7 +29,6 @@ router.get("/:player", async (req, res, next) => {
game_mode: singleProfile.game_mode,
current: singleProfile.selected,
raw: userProfile,
- items,
data,
};
}
diff --git a/src/routes/apiv2/slayers.js b/src/routes/apiv2/slayers.js
index a84ba7471e..92fc92ee00 100644
--- a/src/routes/apiv2/slayers.js
+++ b/src/routes/apiv2/slayers.js
@@ -3,7 +3,6 @@ import * as lib from "../../lib.js";
import express from "express";
import { db } from "../../mongo.js";
-import { getItems } from "../../stats.js";
const router = express.Router();
@@ -14,28 +13,20 @@ router.use((req, res, next) => {
router.get("/:player/:profile", async (req, res, next) => {
try {
- const { profile, allProfiles } = await lib.getProfile(db, req.params.player, null, req.options);
-
- let output = {
- error: "Invalid Profile Name!",
- };
+ const { allProfiles } = await lib.getProfile(db, req.params.player, null, req.options);
+ const output = {};
for (const singleProfile of allProfiles) {
- const cuteName = singleProfile.cute_name;
-
- if (cuteName.toLowerCase() != req.params.profile.toLowerCase()) {
+ const profileId = req.params.profile;
+ if (singleProfile.cute_name.toLowerCase() !== profileId.toLowerCase()) {
continue;
}
- const items = await getItems(singleProfile.members[profile.uuid], false, "", req.options);
- const data = await lib.getStats(db, singleProfile, allProfiles, items, req.options);
-
- output = {
+ const data = await lib.getStats(db, singleProfile, null, allProfiles, [], req.options);
+ output[singleProfile.profile_id] = {
profile_id: singleProfile.profile_id,
cute_name: singleProfile.cute_name,
- slayer_xp: data.slayer_xp,
- slayers: data.slayers,
- slayer_coins_spent: data.slayer_coins_spent,
+ data: data.slayer,
};
}
@@ -48,27 +39,19 @@ router.get("/:player/:profile", async (req, res, next) => {
router.get("/:player", async (req, res, next) => {
try {
- const { profile, allProfiles } = await lib.getProfile(db, req.params.player, null, req.options);
- const bingoProfile = await lib.getBingoProfile(db, req.params.player, req.options);
-
- const output = { profiles: {} };
+ const { allProfiles } = await lib.getProfile(db, req.params.player, null, req.options);
+ const output = {};
for (const singleProfile of allProfiles) {
- const userProfile = singleProfile.members[profile.uuid];
-
- const items = await getItems(userProfile, bingoProfile, false, "", req.options);
- const data = await lib.getStats(db, singleProfile, bingoProfile, allProfiles, items, req.options);
-
- output.profiles[singleProfile.profile_id] = {
+ const data = await lib.getStats(db, singleProfile, null, allProfiles, [], req.options);
+ output[singleProfile.profile_id] = {
profile_id: singleProfile.profile_id,
cute_name: singleProfile.cute_name,
- slayer_xp: data.slayer_xp,
- slayers: data.slayers,
- slayer_coins_spent: data.slayer_coins_spent,
+ data: data.slayer,
};
}
- helper.sendMetric("endpoint_apiv2_slayers_player_success");
+ helper.sendMetric("endpoint_apiv2_slayers_profile_success");
res.json(output);
} catch (e) {
next(e);
diff --git a/src/routes/apiv2/talismans.js b/src/routes/apiv2/talismans.js
index 64f07993be..53297b22c9 100644
--- a/src/routes/apiv2/talismans.js
+++ b/src/routes/apiv2/talismans.js
@@ -25,7 +25,7 @@ router.get("/:player/:profile", async (req, res, next) => {
continue;
}
- const items = await getItems(singleProfile.members[profile.uuid], false, "", req.options);
+ const items = await getItems(singleProfile.members[profile.uuid], null, false, null, req.options);
const accessories = items.accessories;
output = {
From dc672342a4cbd456541f6fb9caac3355f4487d12 Mon Sep 17 00:00:00 2001
From: DuckySoLucky
Date: Fri, 16 Feb 2024 21:26:02 +0100
Subject: [PATCH 06/11] fix: eslint
---
src/routes/api/items.js | 2 +-
src/routes/api/pets.js | 2 +-
src/routes/apiv2/talismans.js | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/routes/api/items.js b/src/routes/api/items.js
index 1c4e4801e8..95b9ac7a6f 100644
--- a/src/routes/api/items.js
+++ b/src/routes/api/items.js
@@ -18,7 +18,7 @@ router.use(async (req, res, next) => {
const { profile, uuid } = await lib.getProfile(db, req.player, req.profile, req.options);
const userProfile = profile.members[uuid];
- const items = await getItems(userProfile, false, undefined, req.options);
+ const items = await getItems(userProfile, null, false, undefined, req.options);
const allItems = items.allItems
.concat(
diff --git a/src/routes/api/pets.js b/src/routes/api/pets.js
index 0effc2b4bd..7592bc90c1 100644
--- a/src/routes/api/pets.js
+++ b/src/routes/api/pets.js
@@ -4,7 +4,7 @@ import express from "express";
import { tableify } from "../api.js";
import { db } from "../../mongo.js";
-import { getItems, getPets } from "../../stats.js";
+import { getPets } from "../../stats.js";
const router = express.Router();
diff --git a/src/routes/apiv2/talismans.js b/src/routes/apiv2/talismans.js
index 53297b22c9..03a4396424 100644
--- a/src/routes/apiv2/talismans.js
+++ b/src/routes/apiv2/talismans.js
@@ -56,7 +56,7 @@ router.get("/:player", async (req, res, next) => {
for (const singleProfile of allProfiles) {
const userProfile = singleProfile.members[profile.uuid];
- const items = await getItems(userProfile, false, "", req.options);
+ const items = await getItems(userProfile, null, false, undefined, req.options);
const accessories = items.accessories;
output.profiles[singleProfile.profile_id] = {
From 75833fd231566b23c46e69411b83c88b7098a9b7 Mon Sep 17 00:00:00 2001
From: DuckySoLucky
Date: Fri, 16 Feb 2024 21:26:35 +0100
Subject: [PATCH 07/11] fix: eslint once again
---
src/app.js | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/app.js b/src/app.js
index fe6ccf7363..3565613696 100644
--- a/src/app.js
+++ b/src/app.js
@@ -42,7 +42,6 @@ import * as itemRoute from "./routes/item.js";
import * as headRoute from "./routes/head.js";
import * as leatherRoute from "./routes/leather.js";
import * as potionRoute from "./routes/potion.js";
-import * as stats from "./stats.js";
import { SkyCryptError } from "./constants/error.js";
const folderPath = helper.getFolderPath();
From 9ea6cc278e18eedb86594596f5557dd0a91c6b9d Mon Sep 17 00:00:00 2001
From: DuckySoLucky
Date: Fri, 16 Feb 2024 21:26:54 +0100
Subject: [PATCH 08/11] fix: eslint once again
---
src/lib.js | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/lib.js b/src/lib.js
index 21a24e37ef..fc7f3fe20b 100644
--- a/src/lib.js
+++ b/src/lib.js
@@ -1,4 +1,3 @@
-import { getPreDecodedNetworth } from "skyhelper-networth";
import sanitize from "mongo-sanitize";
import retry from "async-retry";
import axios from "axios";
From 68c4913abf126aecc6d493270c0121e282a89471 Mon Sep 17 00:00:00 2001
From: DuckySoLucky
Date: Fri, 16 Feb 2024 21:31:04 +0100
Subject: [PATCH 09/11] fix: eslint once again
---
src/stats/leaderboards.js | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/stats/leaderboards.js b/src/stats/leaderboards.js
index 84780ebcf4..da77fd0ca7 100644
--- a/src/stats/leaderboards.js
+++ b/src/stats/leaderboards.js
@@ -1,7 +1,6 @@
import { redisClient } from "../redis.js";
import * as helper from "../helper.js";
import * as constants from "../constants.js";
-import * as stats from "../stats.js";
import * as lib from "../lib.js";
import { db } from "../mongo.js";
import _ from "lodash";
From 6a2e067cc096091b961458104238d6e9b8271797 Mon Sep 17 00:00:00 2001
From: DuckySoLucky
Date: Mon, 26 Feb 2024 17:02:51 +0100
Subject: [PATCH 10/11] fix: add selected fiel
---
src/routes/apiv2/coins.js | 2 ++
src/routes/apiv2/dungeons.js | 2 ++
src/routes/apiv2/slayers.js | 2 ++
src/routes/apiv2/talismans.js | 2 ++
4 files changed, 8 insertions(+)
diff --git a/src/routes/apiv2/coins.js b/src/routes/apiv2/coins.js
index 74d75edcc5..5098f2db80 100644
--- a/src/routes/apiv2/coins.js
+++ b/src/routes/apiv2/coins.js
@@ -23,6 +23,7 @@ router.get("/:player/:profile", async (req, res, next) => {
res.json({
profile_id: profile.profile_id,
cute_name: profile.cute_name,
+ selected: profile.selected,
purse: profile.members[profile.uuid]?.currencies?.coin_purse ?? 0,
bank: profile.banking?.balance ?? 0,
});
@@ -40,6 +41,7 @@ router.get("/:player", async (req, res, next) => {
output.profiles[profile.profile_id] = {
profile_id: profile.profile_id,
cute_name: profile.cute_name,
+ selected: profile.selected,
purse: profile.members[profile.uuid]?.currencies?.coin_purse ?? 0,
bank: profile.banking?.balance ?? 0,
};
diff --git a/src/routes/apiv2/dungeons.js b/src/routes/apiv2/dungeons.js
index e341ef80c5..5092f5533b 100644
--- a/src/routes/apiv2/dungeons.js
+++ b/src/routes/apiv2/dungeons.js
@@ -35,6 +35,7 @@ router.get("/:player/:profile", async (req, res, next) => {
output = {
profile_id: singleProfile.profile_id,
cute_name: singleProfile.cute_name,
+ selected: profile.selected,
dungeons: dungeonData,
};
}
@@ -61,6 +62,7 @@ router.get("/:player", async (req, res, next) => {
output.profiles[singleProfile.profile_id] = {
profile_id: singleProfile.profile_id,
cute_name: singleProfile.cute_name,
+ selected: profile.selected,
dungeons: dungeonData,
};
}
diff --git a/src/routes/apiv2/slayers.js b/src/routes/apiv2/slayers.js
index 92fc92ee00..04c9ecad90 100644
--- a/src/routes/apiv2/slayers.js
+++ b/src/routes/apiv2/slayers.js
@@ -26,6 +26,7 @@ router.get("/:player/:profile", async (req, res, next) => {
output[singleProfile.profile_id] = {
profile_id: singleProfile.profile_id,
cute_name: singleProfile.cute_name,
+ selected: singleProfile.selected,
data: data.slayer,
};
}
@@ -47,6 +48,7 @@ router.get("/:player", async (req, res, next) => {
output[singleProfile.profile_id] = {
profile_id: singleProfile.profile_id,
cute_name: singleProfile.cute_name,
+ selected: singleProfile.selected,
data: data.slayer,
};
}
diff --git a/src/routes/apiv2/talismans.js b/src/routes/apiv2/talismans.js
index 03a4396424..0d711de7c2 100644
--- a/src/routes/apiv2/talismans.js
+++ b/src/routes/apiv2/talismans.js
@@ -31,6 +31,7 @@ router.get("/:player/:profile", async (req, res, next) => {
output = {
profile_id: singleProfile.profile_id,
cute_name: singleProfile.cute_name,
+ selected: singleProfile.selected,
accessories,
};
}
@@ -62,6 +63,7 @@ router.get("/:player", async (req, res, next) => {
output.profiles[singleProfile.profile_id] = {
profile_id: singleProfile.profile_id,
cute_name: singleProfile.cute_name,
+ selected: singleProfile.selected,
accessories,
};
}
From e2ef2f9a35a51739383864d2737760ed54104083 Mon Sep 17 00:00:00 2001
From: DuckySoLucky
Date: Mon, 26 Feb 2024 18:59:40 +0100
Subject: [PATCH 11/11] style: pnpm run prettier:fix
---
src/stats/items.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/stats/items.js b/src/stats/items.js
index 5463eb4681..0ce7430886 100644
--- a/src/stats/items.js
+++ b/src/stats/items.js
@@ -191,7 +191,7 @@ export async function getItems(
if (helper.getId(item) == "TRICK_OR_TREAT_BAG") {
item.containsItems = candy_bag;
}
-
+
const itemLore = item.tag?.display?.Lore ?? [];
if (item.containsItems && item.containsItems.length > 0) {
try {