use centralized dictionary instead of hardcoded if-else for each game

This commit is contained in:
2023-03-08 12:37:40 -08:00
parent f6600f3f74
commit 378c456b85
5 changed files with 29 additions and 22 deletions

@ -1,14 +1,11 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const noblox = require("noblox.js");
const { bhopCookie, surfCookie, deathrunCookie } = require("../config/config.json");
const { cookies, commands } = require("../config/config.js");
async function execute(interaction) {
const game = interaction.options.getString("game");
let cookie;
if (game === "bhop") cookie = bhopCookie;
else if (game === "surf") cookie = surfCookie;
else if (game === "deathrun") cookie = deathrunCookie;
else {
const cookie = cookies[game];
if (cookie === undefined) {
await interaction.reply({content: "Invalid game specified!", ephemeral: true});
return;
}
@ -59,7 +56,7 @@ module.exports = {
option.setName("game")
.setDescription("Select the maptest game")
.setRequired(true)
.addChoices({name: "bhop", value: "bhop"}, {name: "surf", value: "surf"}, {name: "deathrun", value: "deathrun"}))
.addChoices(commands))
.addIntegerOption(option =>
option.setName("asset_id")
.setDescription("The asset ID of the model")
@ -151,4 +148,4 @@ function getProductInfo (asset) {
return reject(error);
}
})
}
}