From a8cc4aa7cfae6822b3838d714c32c7c1426c1879 Mon Sep 17 00:00:00 2001 From: nathomp3 Date: Sun, 7 Aug 2022 17:06:44 -0400 Subject: [PATCH] added suggestion command --- .env.example | 1 + commands/categories.js | 3 ++- commands/dream.js | 3 ++- commands/help.js | 3 ++- commands/leaderboard.js | 3 ++- commands/link.js | 3 ++- commands/ping.js | 3 ++- commands/search.js | 3 ++- commands/unverified.js | 3 ++- commands/verified.js | 3 ++- guildcommands/hypixel.js | 3 ++- guildcommands/suggest.js | 51 ++++++++++++++++++++++++++++++++++++++++ index.js | 10 ++++++-- 13 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 guildcommands/suggest.js diff --git a/.env.example b/.env.example index e47c47b..c546d41 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ token="" id="" +guildid="" hypixel="" mongourl="" srcapi="" \ No newline at end of file diff --git a/commands/categories.js b/commands/categories.js index 6438ffa..c5a2c8c 100644 --- a/commands/categories.js +++ b/commands/categories.js @@ -17,7 +17,8 @@ module.exports = { .setDescription("Game to show categories") .setRequired(true) ), - async execute(interaction) { + async execute(params) { + const { interaction } = params; const game = interaction.options.get("game").value.toLowerCase(); // Fetches the categories const { data } = await tokens.fetch(`https://www.speedrun.com/api/v1/games?abbreviation=${game}&embed=categories.variables`); diff --git a/commands/dream.js b/commands/dream.js index a250a7e..d57e305 100644 --- a/commands/dream.js +++ b/commands/dream.js @@ -15,7 +15,8 @@ module.exports = { option.setName("simulations") .setDescription("Number of simulations to run (Max 100,000") ), - async execute(interaction) { + async execute(params) { + const { interaction } = params; let sim = interaction.options.get("simulations"); // If the number of simulations was not specified then set sim to 1 if(!sim) { diff --git a/commands/help.js b/commands/help.js index 8134d26..a4e515d 100644 --- a/commands/help.js +++ b/commands/help.js @@ -11,7 +11,8 @@ module.exports = { data: new SlashCommandBuilder() .setName("help") .setDescription("Provides a list of commands and descriptions."), - async execute(interaction) { + async execute(params) { + const { interaction } = params; const embed = new EmbedBuilder() .setColor("#118855") .setTitle("Help") diff --git a/commands/leaderboard.js b/commands/leaderboard.js index 31144ef..73967c5 100644 --- a/commands/leaderboard.js +++ b/commands/leaderboard.js @@ -29,7 +29,8 @@ module.exports = { option.setName("ils") .setDescription("Include Individual Levels? Default: true") ), - async execute(interaction) { + async execute(params) { + const { interaction } = params; // From rsp via https://stackoverflow.com/questions/12303989/cartesian-product-of-multiple-arrays-in-javascript // Provides cartesian product of arrays const cartesian = (...a) => a.reduce((a, b) => a.flatMap(d => b.map(e => [d, e].flat()))); diff --git a/commands/link.js b/commands/link.js index 6cb22b4..2338312 100644 --- a/commands/link.js +++ b/commands/link.js @@ -17,7 +17,8 @@ module.exports = { .setDescription("Game to link") .setRequired(true) ), - async execute(interaction) { + async execute(params) { + const { interaction } = params; const game = interaction.options.get("game").value.toLowerCase(); // Gets the requested game const {data} = await tokens.fetch(`https://www.speedrun.com/api/v1/games?abbreviation=${game}`); diff --git a/commands/ping.js b/commands/ping.js index b78c687..a0a3088 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -11,7 +11,8 @@ module.exports = { data: new SlashCommandBuilder() .setName("ping") .setDescription("Provides bot response time."), - async execute(interaction) { + async execute(params) { + const { interaction } = params; const embed = new EmbedBuilder() .setColor("#118855") .setThumbnail("https://www.speedrun.com/images/1st.png") diff --git a/commands/search.js b/commands/search.js index f763a5b..9224da2 100644 --- a/commands/search.js +++ b/commands/search.js @@ -21,7 +21,8 @@ module.exports = { option.setName("page") .setDescription("Which page would you like to view?") ), - async execute(interaction) { + async execute(params) { + const { interaction } = params; const search = interaction.options.get("query").value.toLowerCase(); let page = interaction.options.get("page"); // If page is not specified default to 1 diff --git a/commands/unverified.js b/commands/unverified.js index c4ecd28..8189063 100644 --- a/commands/unverified.js +++ b/commands/unverified.js @@ -17,7 +17,8 @@ module.exports = { .setDescription("Game to search") .setRequired(true) ), - async execute(interaction) { + async execute(params) { + const { interaction } = params; const game = interaction.options.get("game").value.toLowerCase(); // Gets the game for the id const gameData = await tokens.fetch(`https://www.speedrun.com/api/v1/games/${game}`); diff --git a/commands/verified.js b/commands/verified.js index a2648c7..8fbfd4d 100644 --- a/commands/verified.js +++ b/commands/verified.js @@ -17,7 +17,8 @@ module.exports = { .setDescription("User to search") .setRequired(true) ), - async execute(interaction) { + async execute(params) { + const { interaction } = params; const user = interaction.options.get("user").value.toLowerCase(); // Search for user on speedrun.com const playerData = await tokens.fetch(`https://www.speedrun.com/api/v1/users/${user}`); diff --git a/guildcommands/hypixel.js b/guildcommands/hypixel.js index 29e35cb..ee38fca 100644 --- a/guildcommands/hypixel.js +++ b/guildcommands/hypixel.js @@ -11,7 +11,8 @@ module.exports = { data: new SlashCommandBuilder() .setName("hypixel") .setDescription("Provides helpful links for Hypixel Speedruns"), - async execute(interaction) { + async execute(params) { + const { interaction } = params; // Initial running of the command if(interaction.type === InteractionType.ApplicationCommand) { const row = new ActionRowBuilder() diff --git a/guildcommands/suggest.js b/guildcommands/suggest.js new file mode 100644 index 0000000..fea4fa3 --- /dev/null +++ b/guildcommands/suggest.js @@ -0,0 +1,51 @@ +const { EmbedBuilder } = require("discord.js"); +const { SlashCommandBuilder } = require("@discordjs/builders"); +const tokens = require("../index.js"); + +/** + * Function to provide a list of categories for the given game + */ +module.exports = { + /** + * Builds /categories [string:game] + */ + data: new SlashCommandBuilder() + .setName("suggest") + .setDescription("Create a suggestion") + .addStringOption(option => + option.setName("title") + .setDescription("Title of the suggestion (max 256 characters).") + .setRequired(true) + ) + .addStringOption(option => + option.setName("description") + .setDescription("Description fo the suggestion (max 4096 characters).") + .setRequired(true) + ), + async execute(params) { + const { interaction, client } = params; + const channel = await client.channels.cache.get("1005944361709731981"); + const title = interaction.options.get("title").value; + const description = interaction.options.get("description").value; + + let date = new Date().toISOString().slice(0, 10); + let embed = new EmbedBuilder() + .setColor("#118855") + .setTitle(title.slice(0, 256)) + .setFooter({ text: `${date}` }) + .setDescription(description.slice(0, 4096)) + .addFields([ + { name: 'Submitted by:', value: `<@${interaction.user.id}>`} + ]); + let message = await channel.send({ embeds: [embed] }); + message.react('👍'); + message.react('👎'); + const thread = message.startThread({ + name: title.slice(0, 64), + }); + await interaction.editReply({ + content: 'Suggestion has been created: ' + message.url, + ephemeral: true, + }) + }, +}; \ No newline at end of file diff --git a/index.js b/index.js index b3d794e..b823174 100644 --- a/index.js +++ b/index.js @@ -101,9 +101,15 @@ client.on("interactionCreate", async interaction => { await interaction.deferReply(); try { if(client.commands.has(interaction.commandName)) { - await client.commands.get(interaction.commandName).execute(interaction); + await client.commands.get(interaction.commandName).execute({ + interaction, + client + }); } else { - await client.guildCommands.get(interaction.commandName).execute(interaction); + await client.guildCommands.get(interaction.commandName).execute({ + interaction, + client + }); } } catch (error) { console.error(error);