Skip to content

Commit

Permalink
SkyStats Nightly 1.4.5
Browse files Browse the repository at this point in the history
minor changes to how getNetworth() is called, and backend changes to getSkyHelper(), networthEmbed(), networthCommand
  • Loading branch information
axlecoffee committed Jan 4, 2024
1 parent 13ec35d commit 6e51339
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 60 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "skystats",
"version": "1.4.0",
"version": "1.4.5",
"description": "A Hypixel Skyblock Metrics Bot For Discord.",
"changelog": "Bump packages\\nFix `/networth` fields after a year\\nFix multiple preformance issues with getPets() and getItems()\\nThe bot now works with the new api version!",
"changelog": "SkyStats Nightly Build minor changes to how getNetworth() is called, and backend changes to getSkyHelper(), networthEmbed(), networthCommand",
"main": "index.js",
"scripts": {
"start": "pm2 start --only SkyStats-Production",
Expand Down
4 changes: 1 addition & 3 deletions src/discord/commands/embeds/networthEmbed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

const config = require(`../../../../config.json`);
const { getNetworth } = require(`../../../functions/get/getNetworth/getNetworth`);
const { addNotation, addCommas } = require(`../../../contracts/helperFunctions`);
const messages = config.messages.discord;
const EMOJIS = {
Expand All @@ -21,8 +20,7 @@ const EMOJIS = {
PERSONAL_VAULT_ICON: `<:item_2654:1061455349338615859>`,
MISC_ICON: `<:wheat:1059664236038590584>`,
}
async function networthEmbed(embed_ID, uuid, profileid, username, profilename) {
const networth = await getNetworth(uuid, profileid) || {};
async function networthEmbed(embed_ID, uuid, profileid, username, profilename, networth) {
if (embed_ID === `totals_embed`) {
return {
color: 0xffa600,
Expand Down
31 changes: 16 additions & 15 deletions src/discord/commands/networthCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { ActionRowBuilder, StringSelectMenuBuilder } = require('discord.js');
const { getPlayer } = require("../../functions/get/getPlayer");
const { networthEmbed } = require("./embeds/networthEmbed.js");
const { handleError } = require("../../functions/handle/handleError");

const { getNetworth } = require(`../../functions/get/getNetworth/getNetworth`);

module.exports = {
name: "networth",
Expand Down Expand Up @@ -71,27 +71,28 @@ module.exports = {
}
]);
const row1 = new ActionRowBuilder().addComponents(selectMenu);
function networthEmbeds(uuid, profileId, username, profileName) {
async function networthEmbeds(uuid, profileId, username, profileName, networth) {
const embedData = {
"totals_embed": "Totals",
"wardrobe_embed": "Wardrobe",
"inventory_embed": "Inventory",
"enderchest_embed": "Enderchest",
"storage_embed": "Storage",
"pet_embed": "Pet",
"talisman_bag_embed": "Talisman Bag",
"museum_embed": "Museum"
"totals_embed": "Totals",
"wardrobe_embed": "Wardrobe",
"inventory_embed": "Inventory",
"enderchest_embed": "Enderchest",
"storage_embed": "Storage",
"pet_embed": "Pet",
"talisman_bag_embed": "Talisman Bag",
"museum_embed": "Museum"
};
const embedPromises = [];
for (const [key, value] of Object.entries(embedData)) {
embedPromises.push(networthEmbed(key, uuid, profileId, username, profileName, value));
embedPromises.push(networthEmbed(key, uuid, profileId, username, profileName, networth, value));
}
const embeds = Promise.all(embedPromises);
return embeds;
}
const [totals_embed, wardrobe_embed, inventory_embed, enderchest_embed, storage_embed, pet_embed, talisman_bag_embed, museum_embed] = await networthEmbeds(uuid2, profileid, username, profilename);


}

const networth = await getNetworth(uuid2, profileid) || {};
const embeds = await networthEmbeds(uuid2, profileid, username, profilename, networth);
const [totals_embed, wardrobe_embed, inventory_embed, enderchest_embed, storage_embed, pet_embed, talisman_bag_embed, museum_embed] = embeds;
await interaction.editReply({ embeds: [totals_embed], components: [row1] });

client.on('interactionCreate', async (interaction) => {
Expand Down
70 changes: 31 additions & 39 deletions src/functions/get/getNetworth/getNetworth.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ async function getCookiePrice() {
console.error(error);
}
}

function handleSplits(value) {
if (value === 0 || value === NaN || value === undefined || value === Infinity /* (yeah infinity happened once we dont talk about it) */) {
return value;
} else {
return Math.round(value.toString());
}
}

async function getNetworth(uuid, profileid) {
const cookiePrice = await getCookiePrice();
const networthRaw = await getSkyHelper(profileid, uuid)
const networthRaw = await getSkyHelper(profileid, uuid);
const { total: petTotal, items: petItems } = networthRaw.networth.types.pets;

const createPetString = (pet) => {
Expand Down Expand Up @@ -90,15 +96,14 @@ const createItemString = (item) => {
if (!item) return '';

const isRecombobulated = item.calculation.some((a) => a.id === 'RECOMBOBULATOR_3000');
const price = addNotation('oneLetters', item.price) || 0;
const price = addNotation('oneLetters', handleSplits(item.price)) || 0;

if (item.count >= 2) {
return `→ \`${item.count}x\` ${item.name}${isRecombobulated ? `${RECOMBOBULATOR_3000}` : ''} (**${price}**)`;
} else {
return `→ ${item.name}${isRecombobulated ? `${RECOMBOBULATOR_3000}` : ''} (**${price}**)`;
}
}

const createItemStrings = (items, maxItems) => {
const itemStrings = items.slice(0, maxItems).map(createItemString);
/*
Expand All @@ -112,47 +117,34 @@ const createItemStrings = (items, maxItems) => {

return itemStrings.join('\n');
};
const formattedNetworth = addNotation("numbers", addCommas(networthRaw.networth.networth.toString().split(".")[0]));
const shortNetworth = addNotation("oneLetters", networthRaw.networth.networth);
const formattedSoulbound = addNotation("numbers", addCommas(networthRaw.networth.unsoulboundNetworth.toString().split(".")[0]));
const shortUnsoulbound = addNotation("oneLetters", networthRaw.networth.unsoulboundNetworth);
const cookies = Math.round(networthRaw.networth.networth / cookiePrice)
const value = addNotation("numbers", addCommas(Math.round(cookies * 2.27)));
const formattedBank = addNotation("oneLetters", networthRaw.networth.bank);
const purse = Math.round(networthRaw.networth.purse);
const sack = networthRaw.networth.types.sacks.total;
const essence = networthRaw.networth.types.essence.total;
const fishingBag = networthRaw.networth.types.fishing_bag.total;
const sackValue = Math.round((sack + essence + fishingBag) * 100) / 100;

return {
networth: {
soulbound: {
formatted: formattedSoulbound,
short: shortUnsoulbound,
formatted: addNotation("numbers", addCommas(networthRaw.networth.unsoulboundNetworth.toString().split(".")[0])),
short: addNotation("oneLetters", networthRaw.networth.unsoulboundNetworth),
},
bank: {
formatted: formattedBank.toString().split(".")[0],
purse: purse,
formatted: addNotation("oneLetters", handleSplits(networthRaw.networth.bank)),
purse: Math.round(networthRaw.networth.purse),
},
total: {
irl_value: value,
total_networth: formattedNetworth,
short_networth: shortNetworth,
irl_value: addNotation("numbers", addCommas(Math.round(Math.round(networthRaw.networth.networth / cookiePrice) * 2.27))),
total_networth: addNotation("numbers", addCommas(networthRaw.networth.networth.toString().split(".")[0])),
short_networth: addNotation("oneLetters", networthRaw.networth.networth),
items_total: {
museum: {
museum_value: museum.toString().split(".")[0],
special_museum_value: museumSpecial.toString().split(".")[0],
museum_value: handleSplits(museum),
special_museum_value: handleSplits(museumSpecial),
},
inventory_value: inventory.toString().split(".")[0],
talisman_bag_value: accessories.toString().split(".")[0],
armor_value: armor.toString().split(".")[0],
enderchest_value: enderchest.toString().split(".")[0],
wardrobe_value: wardrobe.toString().split(".")[0],
equipment_value: equipment.toString().split(".")[0],
personal_vault_value: personal_vault.toString().split(".")[0],
storage_value: storage.toString().split(".")[0],
pet_value: petTotal.toString().split(".")[0],
inventory_value: handleSplits(inventory),
talisman_bag_value: handleSplits(accessories),
armor_value: handleSplits(armor),
enderchest_value: handleSplits(enderchest),
wardrobe_value: handleSplits(wardrobe),
equipment_value: handleSplits(equipment),
personal_vault_value: handleSplits(personal_vault),
storage_value: handleSplits(storage),
pet_value: handleSplits(petTotal),
},
}
},
Expand Down Expand Up @@ -180,10 +172,10 @@ const createItemStrings = (items, maxItems) => {
},
},
sacks: {
total: sackValue,
fishing_bag: fishingBag,
essence: essence,
sacks: sack,
total: Math.round((networthRaw.networth.types.sacks.total + networthRaw.networth.types.essence.total + networthRaw.networth.types.fishing_bag.total) * 100) / 100,
fishing_bag: networthRaw.networth.types.fishing_bag.total,
essence: networthRaw.networth.types.essence.total,
sacks: networthRaw.networth.types.sacks.total,
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/get/getNetworth/getSkyHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const apiKey = process.env.KEY;
const fetchMuseumData = async (profile, uuid) => {
const url = `https://api.hypixel.net/v2/skyblock/museum?key=${apiKey}&profile=${profile}`;
try {
const response = await axios.get(url);
const response = await axios.get(url)
const museumData = response.data.members[uuid];

if (!museumData || !museumData.value) {
Expand Down

0 comments on commit 6e51339

Please sign in to comment.