Skip to content

Commit cf876dc

Browse files
committed
fix some bugs in commands
1 parent 3030719 commit cf876dc

File tree

7 files changed

+155
-42
lines changed

7 files changed

+155
-42
lines changed

API/stats/chocolateFactory.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ module.exports = (profile) => {
1717
cousin: profile.events?.easter?.employees.rabbit_cousin || 0,
1818
sis: profile.events?.easter?.employees.rabbit_sis || 0,
1919
father: profile.events?.easter?.employees.rabbit_father || 0,
20-
grandma: profile.events?.easter?.employees.rabbit_grandma || 0
20+
grandma: profile.events?.easter?.employees.rabbit_grandma || 0,
21+
uncle: profile.events?.easter?.employees.rabbit_uncle || 0,
22+
dog: profile.events?.easter?.employees.rabbit_dog || 0
2123
},
2224
level: profile.events?.easter?.chocolate_level || 0
2325
};

API/stats/dungeonsPersonalBest.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module.exports = (profile) => {
2+
try {
3+
const catacombs = profile?.dungeons?.dungeon_types.catacombs ?? {};
4+
const masterCatacombs = profile?.dungeons?.dungeon_types.master_catacombs ?? {};
5+
6+
const availableFloors = Object.keys(profile?.dungeons?.dungeon_types.catacombs.times_played || [])
7+
.filter((floor) => floor !== "total" && floor !== "best")
8+
.map((floor) => parseInt(floor));
9+
10+
const floors = {},
11+
master = {};
12+
for (let i = 0; i <= Math.max(...availableFloors); i++) {
13+
floors[`floor_${i}`] = {
14+
fastest: catacombs.fastest_time?.[i] ?? null,
15+
fastest_s: catacombs.fastest_time_s?.[i] || null,
16+
fastest_s_plus: catacombs.fastest_time_s_plus?.[i] || null
17+
};
18+
19+
master[`floor_${i}`] = {
20+
fastest: masterCatacombs.fastest_time?.[i] ?? null,
21+
fastest_s: masterCatacombs.fastest_time_s?.[i] || null,
22+
fastest_s_plus: masterCatacombs.fastest_time_s_plus?.[i] || null
23+
};
24+
}
25+
26+
return {
27+
normal: floors,
28+
master: master
29+
};
30+
} catch (e) {
31+
console.log(e);
32+
return null;
33+
}
34+
};

API/stats/essence.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = (profile) => {
2+
try {
3+
return {
4+
diamond: profile.currencies?.essence?.DIAMOND?.current || 0,
5+
dragon: profile.currencies?.essence?.DRAGON?.current || 0,
6+
spider: profile.currencies?.essence?.SPIDER?.current || 0,
7+
wither: profile.currencies?.essence?.WITHER?.current || 0,
8+
undead: profile.currencies?.essence?.UNDEAD?.current || 0,
9+
gold: profile.currencies?.essence?.GOLD?.current || 0,
10+
ice: profile.currencies?.essence?.ICE?.current || 0,
11+
crimson: profile.currencies?.essence?.CRIMSON?.current || 0
12+
};
13+
} catch (error) {
14+
console.error(error);
15+
return null;
16+
}
17+
};

src/minecraft/commands/chocolateCommand.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { titleCase } = require("../../../API/constants/functions.js");
77
class ChocolateCommand extends minecraftCommand {
88
constructor(minecraft) {
99
super(minecraft);
10-
10+
2
1111
this.name = "chocolatefactory";
1212
this.aliases = ["cf", "factory", "chocolate"];
1313
this.description = "Skyblock Chocolate Factory Stats of specified user.";

src/minecraft/commands/essenceCommand.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const { formatNumber } = require("../../contracts/helperFunctions.js");
22
const { getLatestProfile } = require("../../../API/functions/getLatestProfile.js");
33
const minecraftCommand = require("../../contracts/minecraftCommand.js");
4-
const getDungeons = require("../../../API/stats/dungeons.js");
4+
const getEssence = require("../../../API/stats/essence.js");
5+
const { titleCase } = require("../../../API/constants/functions.js");
56

67
class EssenceCommand extends minecraftCommand {
78
constructor(minecraft) {
@@ -27,23 +28,16 @@ class EssenceCommand extends minecraftCommand {
2728

2829
const { username, profile, profileData } = await getLatestProfile(player);
2930

30-
const dungeons = getDungeons(profile);
31-
if (dungeons == null) {
32-
throw `${username} has never played dungeons on ${profileData.cute_name}.`;
31+
const essence = getEssence(profile);
32+
if (essence == null) {
33+
throw `${username} has never unlocked essence on ${profileData.cute_name}.`;
3334
}
3435

35-
this.send(
36-
`${username}'s Diamond Essence: ${formatNumber(dungeons.essence.diamond, 0)} | Dragon: ${formatNumber(
37-
dungeons.essence.dragon,
38-
0
39-
)} Spider: ${formatNumber(dungeons.essence.spider, 0)} | Wither: ${formatNumber(
40-
dungeons.essence.wither,
41-
0
42-
)} | Undead: ${formatNumber(dungeons.essence.undead, 0)} | Gold: ${formatNumber(
43-
dungeons.essence.gold,
44-
0
45-
)} | Ice: ${formatNumber(dungeons.essence.ice, 0)} | Crimson: ${formatNumber(dungeons.essence.crimson, 0)}`
46-
);
36+
const essenceString = Object.entries(essence)
37+
.map(([key, value]) => `${titleCase(key)}: ${formatNumber(value)}`)
38+
.join(", ");
39+
40+
this.send(`${username}'s Essence: ${essenceString}`);
4741
} catch (error) {
4842
console.error(error);
4943

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const { getLatestProfile } = require("../../../API/functions/getLatestProfile.js");
2+
const getPersonalBest = require("../../../API/stats/dungeonsPersonalBest.js");
3+
const minecraftCommand = require("../../contracts/minecraftCommand.js");
4+
5+
class PersonalBestCommand extends minecraftCommand {
6+
constructor(minecraft) {
7+
super(minecraft);
8+
9+
this.name = "personalbest";
10+
this.aliases = ["personalbest", "pb"];
11+
this.description = "Returns the fastest time (s+) of any dungeon";
12+
this.options = [
13+
{
14+
name: "username",
15+
description: "Minecraft Username",
16+
required: false
17+
},
18+
{
19+
name: "Floor",
20+
description: "Floor of dungeons (M7, F7, ect)",
21+
required: false
22+
}
23+
];
24+
}
25+
26+
async onCommand(player, message) {
27+
// CREDITS: by @dallincotton06 (https://github.com/dallincotton06)
28+
const args = this.getArgs(message);
29+
player = args[0] || player;
30+
31+
const { username, profile } = await getLatestProfile(player);
32+
33+
const floor = (this.getArgs(message)[1] ?? "M7").toLowerCase();
34+
const rank = (this.getArgs(message)[2] ?? "S+").toLowerCase();
35+
const floors = ["e", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "m1", "m2", "m3", "m4", "m5", "m6", "m7"];
36+
const ranks = ["", "any", "s", "s+"];
37+
if (floors.includes(floor) === false) {
38+
// eslint-disable-next-line no-throw-literal
39+
throw "Invalid Usage: !pb [user] [floor (m7/f4/etc)] [rank (S+, S, any)]";
40+
}
41+
42+
if (ranks.includes(rank) === false) {
43+
// eslint-disable-next-line no-throw-literal
44+
throw "Invalid Usage: !pb [user] [floor (m7/f4/etc)] [rank (S+, S, any)]";
45+
}
46+
47+
const personalBest = getPersonalBest(profile);
48+
if (personalBest === null) {
49+
// eslint-disable-next-line no-throw-literal
50+
throw `${username} has never done dungeons before.`;
51+
}
52+
53+
console.log(floor);
54+
console.log(rank);
55+
56+
const dungeon = floor.at(0) === "m" ? personalBest.master : personalBest.normal;
57+
const floorNumber = floor.at(1);
58+
const floorData = dungeon[`floor_${floorNumber}`];
59+
const rankType = rank === "s+" ? "fastest_s_plus" : rank === "s" ? "fastest_s" : "fastest";
60+
61+
const time = floorData[rankType];
62+
if (time === null) {
63+
// eslint-disable-next-line no-throw-literal
64+
throw `${username} has no PB on ${floor} ${rank}`;
65+
}
66+
67+
this.send(
68+
`${username}'s PB on ${floor.toUpperCase()} with ${rank.toUpperCase()} rank is ${millisToMinutesAndSeconds(time)}`
69+
);
70+
}
71+
}
72+
73+
function millisToMinutesAndSeconds(time) {
74+
const minutes = Math.floor(time / 60000);
75+
const seconds = ((time % 60000) / 1000).toFixed(0);
76+
return minutes + ":" + (seconds < 10 ? "0" : "") + seconds;
77+
}
78+
79+
module.exports = PersonalBestCommand;

src/minecraft/commands/skyblockCommand.js

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ const { getLatestProfile } = require("../../../API/functions/getLatestProfile.js
33
const minecraftCommand = require("../../contracts/minecraftCommand.js");
44
const getTalismans = require("../../../API/stats/talismans.js");
55
const getDungeons = require("../../../API/stats/dungeons.js");
6-
const getSkills = require("../../../API/stats/skills.js");
76
const getSlayer = require("../../../API/stats/slayer.js");
87
const getHotm = require("../../../API/stats/hotm.js");
98
const { getNetworth } = require("skyhelper-networth");
9+
const { getSkillAverage } = require("../../../API/constants/skills.js");
1010

1111
class SkyblockCommand extends minecraftCommand {
1212
constructor(minecraft) {
@@ -31,8 +31,8 @@ class SkyblockCommand extends minecraftCommand {
3131
const data = await getLatestProfile(username);
3232
username = formatUsername(username, data.profileData.game_mode);
3333

34-
const [skills, slayer, networth, dungeons, talismans, hotm] = await Promise.all([
35-
getSkills(data.profile, data.profileData),
34+
const [skillAverage, slayer, networth, dungeons, talismans, hotm] = await Promise.all([
35+
getSkillAverage(data.profile, null),
3636
getSlayer(data.profile),
3737
getNetworth(data.profile, data.profileData?.banking?.balance || 0, {
3838
onlyNetworth: true,
@@ -44,33 +44,20 @@ class SkyblockCommand extends minecraftCommand {
4444
getHotm(data.profile)
4545
]);
4646

47-
const skillAverage = (
48-
Object.keys(skills)
49-
.filter((skill) => !["runecrafting", "social"].includes(skill))
50-
.map((skill) => skills[skill].level)
51-
.reduce((a, b) => a + b, 0) /
52-
(Object.keys(skills).length - 2)
53-
).toFixed(1);
54-
5547
const slayerText = Object.keys(slayer)
56-
.reduce(
57-
(acc, slayerType) => `${acc} | ${slayerType.substring(0, 1).toUpperCase()}:${slayer[slayerType].level}`,
58-
""
59-
)
60-
.slice(3);
61-
const catacombsLevel = dungeons.catacombs.skill.level;
62-
const classAverage =
63-
Object.values(dungeons.classes)
64-
.map((value) => value.level)
65-
.reduce((a, b) => a + b, 0) / Object.keys(dungeons.classes).length;
48+
.map((key) => `${slayer[key].level}${key[0].toUpperCase()}`)
49+
.join(", ");
50+
51+
const catacombsLevel = dungeons.dungeons.level;
52+
const classAverage = formatNumber(dungeons.classAverage);
6653
const networthValue = formatNumber(networth.networth);
67-
const hotmLevel = hotm?.level?.level ?? 0;
68-
const mp = formatNumber(talismans?.magicPower ?? 0);
54+
const hotmLevel = hotm.level.level;
55+
const magicalPower = talismans.magicalPower;
6956

7057
this.send(
7158
`${username}'s Level: ${
7259
data.profile.leveling?.experience ? data.profile.leveling.experience / 100 : 0
73-
} | Skill Avg: ${skillAverage} | Slayer: ${slayerText} | Cata: ${catacombsLevel} | Class Avg: ${classAverage} | NW: ${networthValue} | MP: ${mp} | Hotm: ${hotmLevel}`
60+
} | Skill Avg: ${skillAverage} | Slayer: ${slayerText} | Cata: ${catacombsLevel} | Class Avg: ${classAverage} | NW: ${networthValue} | MP: ${magicalPower} | Hotm: ${hotmLevel}`
7461
);
7562
} catch (error) {
7663
this.send(`[ERROR] ${error}`);

0 commit comments

Comments
 (0)