From dc07d5a59c4e5ff71bf8e2215d087bf9dd7ec77e Mon Sep 17 00:00:00 2001 From: vKxni Date: Sat, 5 Feb 2022 14:50:36 +0100 Subject: [PATCH] added gtn --- src/commands/Games/GTN/gtn.js | 65 +++++++++++++++++++++++++++++++++++ src/models/Games/gtn.js | 25 ++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/commands/Games/GTN/gtn.js create mode 100644 src/models/Games/gtn.js diff --git a/src/commands/Games/GTN/gtn.js b/src/commands/Games/GTN/gtn.js new file mode 100644 index 00000000..7d413695 --- /dev/null +++ b/src/commands/Games/GTN/gtn.js @@ -0,0 +1,65 @@ +"use strict"; + +const { SlashCommandBuilder } = require("@discordjs/builders"); +const { CommandInteraction, Permissions, MessageEmbed } = require("discord.js"); + +const emojis = require("../../../../Controller/emojis/emojis"); + +const Guild = require("../../../models/Games/gtn"); + +module.exports.cooldown = { + length: 10000, /* in ms */ + users: new Set() +}; + +/** + * Runs the command. + * @param {CommandInteraction} interaction The Command Interaciton + * @param {any} utils Additional util + */ +module.exports.run = async (interaction, utils) => +{ + try + { + + const ranNum = Math.round(Math.random() * 1000); + const channel = interaction.options.getChannel("channel") || interaction.channel; + const number = interaction.options.getNumber("number") || ranNum; + + if(number === 0) return interaction.reply({ content: `${emojis.error} | Number can't be 0.`, ephemeral: true }); + + const isRunning = await Guild.findOne({ id: interaction.guild.id }) + if(isRunning) return interaction.reply({ content: `${emojis.error} | A GTN Event is already running.`, ephemeral: true }); + + const newEvent = new Guild({ + id: interaction.guild.id, + channel: channel.id, + number: number + }) + newEvent.save(); + + const embed = new MessageEmbed() + .setTitle(`${emojis.diamond} New Event`) + .setDescription(`A new Event has started!\n\nGuess the number between \`1 - 1000\`.`) + .setTimestamp() + + await channel.send({ embeds: [embed] }); + interaction.reply({ content: `${emojis.success} | Successfully started Guess the Number Event in ${channel}`, ephemeral: true }); + } + catch (err) + { + return Promise.reject(err); + } +}; + +module.exports.permissions = { + clientPermissions: [Permissions.FLAGS.SEND_MESSAGES], + userPermissions: [Permissions.FLAGS.ADMINISTRATOR] +}; + +module.exports.data = new SlashCommandBuilder() + .setName("gtn") + .setDescription("Setup a Guess the Number Event") + .addChannelOption((option) => option.setName("channel").setDescription("Select the Channel for the Event").setRequired(false)) + .addNumberOption((option) => option.setName("number").setDescription("What Number should be guessed?").setRequired(false)); + diff --git a/src/models/Games/gtn.js b/src/models/Games/gtn.js new file mode 100644 index 00000000..2a404f9e --- /dev/null +++ b/src/models/Games/gtn.js @@ -0,0 +1,25 @@ +const { Schema, Types, model } = require("mongoose"); + +const gtnSchema = new Schema({ + id: + { + type: String, + unique: true, + required: true + }, + channel: + { + type: String, + unique: true, + required: true + }, + number: { + type: Number, + required: true + } + +}, { timestamps: true }); + +const Guessnumber = model("Games", gtnSchema); + +module.exports = Guessnumber; \ No newline at end of file