-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |