Skip to content

Commit

Permalink
Merge pull request #290 from Kathund/remove-extra-request
Browse files Browse the repository at this point in the history
Remove Small API Request
  • Loading branch information
Killermaschine88 authored Dec 25, 2024
2 parents a0d0ede + 4bb66b7 commit 095f002
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 33 deletions.
10 changes: 2 additions & 8 deletions API/functions/getLatestProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,16 @@ async function getLatestProfile(uuid, options = { museum: false, garden: false }
}
}

const [{ data: playerRes }, { data: profileRes }] = await Promise.all([
axios.get(`https://api.hypixel.net/v2/player?key=${config.minecraft.API.hypixelAPIkey}&uuid=${uuid}`),
const [{ data: profileRes }] = await Promise.all([
axios.get(`https://api.hypixel.net/v2/skyblock/profiles?key=${config.minecraft.API.hypixelAPIkey}&uuid=${uuid}`),
]).catch((error) => {
throw error?.response?.data?.cause ?? "Request to Hypixel API failed. Please try again!";
});

if (playerRes.success === false || profileRes.success === false) {
if (profileRes.success === false) {
throw "Request to Hypixel API failed. Please try again!";
}

if (playerRes.player == null) {
throw "Player not found. It looks like this player has never joined the Hypixel.";
}

if (profileRes.profiles == null || profileRes.profiles.length == 0) {
throw "Player has no SkyBlock profiles.";
}
Expand All @@ -57,7 +52,6 @@ async function getLatestProfile(uuid, options = { museum: false, garden: false }
profiles: profileRes.profiles,
profile: profile,
profileData: profileData,
playerRes: playerRes.player,
uuid: uuid,
...(options.museum ? await getMuseum(profileData.profile_id, uuid) : {}),
...(options.garden ? await getGarden(profileData.profile_id) : {}),
Expand Down
20 changes: 1 addition & 19 deletions API/stats/hotm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,8 @@ const miningConst = require("../constants/mining.js");
const calcSkill = require("../constants/skills.js");
const moment = require("moment");

module.exports = (player, profile) => {
module.exports = (profile) => {
try {
const commissions = {
total: player?.achievements?.skyblock_hard_working_miner ?? 0,
milestone: 0,
};

// CREDITS: https://github.com/SkyCryptWebsite/SkyCrypt/blob/b9842bea6f1494fa2d2fd005b64f57d84646c188/src/stats/mining.js#L129
if (profile.objectives?.tutorial !== undefined) {
for (const key of profile.objectives.tutorial) {
if (key.startsWith("commission_milestone_reward_mining_xp_tier_") === false) {
continue;
}

const tier = parseInt(key.slice(43));
commissions.milestone = Math.max(commissions.milestone, tier);
}
}

const forgeItems = [];
if (profile.forge?.forge_processes?.forge_1) {
const forge = Object.values(profile.forge.forge_processes.forge_1);
Expand Down Expand Up @@ -80,7 +63,6 @@ module.exports = (player, profile) => {
},
level: calcSkill("hotm", profile?.mining_core?.experience || 0),
ability: titleCase(profile?.mining_core?.selected_pickaxe_ability || "none", true),
commissions: commissions,
forge: forgeItems,
};
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/minecraft/commands/forgeCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ForgeCommand extends minecraftCommand {

username = formatUsername(username, data.profileData?.game_mode);

const hotm = getHotm(data.playerRes, data.profile);
const hotm = getHotm(data.profile);

if (hotm == null) {
// eslint-disable-next-line no-throw-literal
Expand Down
6 changes: 2 additions & 4 deletions src/minecraft/commands/hotmCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class HotmCommand extends minecraftCommand {

username = formatUsername(username, data.profileData?.game_mode);

const hotm = getHotm(data.playerRes, data.profile);
const hotm = getHotm(data.profile);

if (hotm == null) {
// eslint-disable-next-line no-throw-literal
Expand All @@ -42,9 +42,7 @@ class HotmCommand extends minecraftCommand {
hotm.powder.gemstone.total
)} | Mithril Powder: ${formatNumber(hotm.powder.mithril.total)} | Glacite Powder: ${formatNumber(
hotm.powder.glacite.total
)} | Selected Ability: ${hotm.ability} | Commissions Milestone: ${
hotm.commissions.milestone
} (${hotm.commissions.total.toLocaleString()})`
)} | Selected Ability: ${hotm.ability}`
);
} catch (error) {
this.send(`/gc [ERROR] ${error}`);
Expand Down
2 changes: 1 addition & 1 deletion src/minecraft/commands/skyblockCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SkyblockCommand extends minecraftCommand {
}),
getDungeons(data.profile),
getTalismans(data.profile),
getHotm(data.player, data.profile),
getHotm(data.profile),
]);

const skillAverage = (
Expand Down

0 comments on commit 095f002

Please sign in to comment.