fix: limit rank input and change to method

This commit is contained in:
ethanf 2024-01-23 04:29:14 -06:00
parent 4f99552725
commit 74e482ed90

View File

@ -298,7 +298,7 @@ client.on("messageCreate", async (message) => {
return; return;
} }
const args = message.content.toLowerCase.split(" "); const args = message.content.toLowerCase().split(" ");
if (args[0] === "setrank") { if (args[0] === "setrank") {
const pickupGuild = client.guilds.cache.get(GUILD_ID); const pickupGuild = client.guilds.cache.get(GUILD_ID);
@ -312,6 +312,12 @@ client.on("messageCreate", async (message) => {
const playerId = player.id; const playerId = player.id;
const rank = parseInt(args[2]); const rank = parseInt(args[2]);
if (isNaN(rank) || rank < 0 || rank > 5) {
await interaction.reply(
`invalid rank ${args[2]}. must be an integer between 0 and 5`
);
return;
}
// create rankings.json if it doesn't exist // create rankings.json if it doesn't exist
const rankingsPath = path.join(__dirname, "rankings.json"); const rankingsPath = path.join(__dirname, "rankings.json");