From 62b6f2628f85243edf09b49b9bc6e26b79abf1c6 Mon Sep 17 00:00:00 2001 From: Carter Penterman Date: Fri, 13 May 2022 00:06:45 -0500 Subject: [PATCH] added multiple game support --- bot.js | 4 ++++ commands/take.js | 44 +++++++++++++++++++++++++++++++++++--------- example_config.json | 4 +++- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/bot.js b/bot.js index 323b82c..097d161 100644 --- a/bot.js +++ b/bot.js @@ -29,6 +29,10 @@ client.on('interactionCreate', async interaction => { } }); +client.on("error", async error => { + +}); + client.once("ready", () => { console.log("Ready"); }); diff --git a/commands/take.js b/commands/take.js index b9be987..f592e94 100644 --- a/commands/take.js +++ b/commands/take.js @@ -1,27 +1,53 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const noblox = require("noblox.js"); -const {cookie} = require("../config.json"); +const { bhopCookie, surfCookie, deathrunCookie } = require("../config.json"); module.exports = { data: new SlashCommandBuilder() .setName('take') .setDescription('Takes an asset ID') + .addStringOption(option => + option.setName("game") + .setDescription("Select the maptest game") + .setRequired(true) + .addChoices({name: "bhop", value: "bhop"}, {name: "surf", value: "surf"}, {name: "deathrun", value: "deathrun"})) .addIntegerOption(option => option.setName("asset_id") .setDescription("The asset ID of the model") .setRequired(true)) , async 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 { + await interaction.reply("Invalid game specified!"); + return; + } const id = interaction.options.getInteger("asset_id"); - await noblox.setCookie(cookie) - .then(async () => { - noblox.buy(id, 0) + await noblox.setCookie(cookie).then(async () => { + noblox.buy(id, 0).then(async () => { + await interaction.reply( +` +Now that your map (id: ${id}) has been taken by the ${game} maptest bot you can load it into the ${game} maptest place. To load your map, join the game and say +\`\`\` +!map ${id} +\`\`\`Read what it says. If your map successfully loaded type !rtv and then choose your map. +If it did not load successfully, you can expand the chat to view the full error message by clicking and dragging on the edge of the chat. +` + ); + }) .catch(async (error) => { - await interaction.reply("Could not take model!"); - console.log("Could not take model: ") - console.log(error) + if (error.message == "You already own this item.") { + await interaction.reply("The bot has already taken this model!"); + } else { + await interaction.reply(`An error occured trying to take the model (id: ${id}). Make sure it is uncopylocked!`); + console.log(`Could not take asset ID ${id}: `); + console.log(error); + } }); }); - await interaction.reply("Model was taken successfully!"); - }, + } }; \ No newline at end of file diff --git a/example_config.json b/example_config.json index 7b54dd8..8d40460 100644 --- a/example_config.json +++ b/example_config.json @@ -1,5 +1,7 @@ { "token": "", "clientId": "", - "cookie": "" + "bhopCookie": "", + "surfCookie": "", + "deathrunCookie": "" } \ No newline at end of file