Skip to content

Commit

Permalink
added suggestion command
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-NCSU committed Aug 7, 2022
1 parent 09e0cdb commit a8cc4aa
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 12 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
token=""
id=""
guildid=""
hypixel=""
mongourl=""
srcapi=""
3 changes: 2 additions & 1 deletion commands/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
3 changes: 2 additions & 1 deletion commands/dream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion commands/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
Expand Down
3 changes: 2 additions & 1 deletion commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
3 changes: 2 additions & 1 deletion commands/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion commands/unverified.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
3 changes: 2 additions & 1 deletion commands/verified.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
3 changes: 2 additions & 1 deletion guildcommands/hypixel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
51 changes: 51 additions & 0 deletions guildcommands/suggest.js
Original file line number Diff line number Diff line change
@@ -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,
})
},
};
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a8cc4aa

Please sign in to comment.