diff --git a/src/minecraft/commands/personalBestCommand.js b/src/minecraft/commands/personalBestCommand.js index 148bbb52..e491e90d 100644 --- a/src/minecraft/commands/personalBestCommand.js +++ b/src/minecraft/commands/personalBestCommand.js @@ -29,6 +29,16 @@ class PersonalBestCommand extends minecraftCommand { username = this.getArgs(message)[0] || username; const floor = (this.getArgs(message)[1] ?? "M7").toLowerCase(); const rank = (this.getArgs(message)[2] ?? "S+").toLowerCase(); + const floors = ["e", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "m1", "m2", "m3", "m4", "m5", "m6", "m7"]; + const ranks = ["", "s", "s+"]; + if (floors.includes(floor) === false) { + // eslint-disable-next-line no-throw-literal + throw "Invalid Usage: !pb [user] [floor (m7/f4/etc)] [rank (S+, S, any)]"; + } + if (ranks.includes(rank) === false) { + // eslint-disable-next-line no-throw-literal + throw "Invalid Usage: !pb [user] [floor (m7/f4/etc)] [rank (S+, S, any)]"; + } const data = await getLatestProfile(username); @@ -41,41 +51,42 @@ class PersonalBestCommand extends minecraftCommand { throw `${username} has never played dungeons on ${data.profileData.cute_name}.`; } - let requested_floor = dungeons.catacombs; + let requested_floor = null; let time = 0; const floor_type = floor.charAt(floor.length - 2); const floor_number = floor.charAt(floor.length - 1); switch (floor_type) { case "m": - requested_floor = dungeons.catacombs?.MASTER_MODE_FLOORS?.[`floor_${floor_number}`] ?? null; + requested_floor = dungeons.catacombs?.MASTER_MODE_FLOORS?.[`floor_${floor_number}`] || null; break; case "f": - requested_floor = dungeons.catacombs?.floors?.[`floor_${floor_number}`] ?? null; + requested_floor = dungeons.catacombs?.floors?.[`floor_${floor_number}`] || null; break; case "e": - requested_floor = dungeons.catacombs?.floors?.entrance ?? null; + requested_floor = dungeons.catacombs?.floors?.entrance || null; break; default: - this.send("/gc Invalid Usage: !pb [user] [floor (m7/f4/etc)] [rank (S+, S, any)]"); - break; + // eslint-disable-next-line no-throw-literal + throw "Invalid Usage: !pb [user] [floor (m7/f4/etc)] [rank (S+, S, any)]"; } // eslint-disable-next-line no-throw-literal if (requested_floor === null) throw `${username} has never gotten a ${rank} on ${floor} before.`; switch (rank) { case "s+": - time = requested_floor.fastest_s_plus; + time = requested_floor?.fastest_s_plus || 0; break; case "s": - time = requested_floor.fastest_s; + time = requested_floor?.fastest_s || 0; break; default: - this.send("/gc Invalid Usage: !pb [user] [floor (m7/f4/etc)] [rank (S+, S, any)]"); + time = requested_floor?.fastest || 0; break; } if (time === 0) { - this.send(`/gc ${username} has no PB on ${floor} ${rank}`); + // eslint-disable-next-line no-throw-literal + throw `${username} has no PB on ${floor} ${rank}`; } else { this.send(`/gc ${username}'s PB on ${floor} with ${rank} rank is ${millisToMinutesAndSeconds(time)}`); }