Skip to content

Commit

Permalink
added gtn
Browse files Browse the repository at this point in the history
  • Loading branch information
vKxni committed Feb 5, 2022
1 parent a3c5718 commit dc07d5a
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/commands/Games/GTN/gtn.js
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));

25 changes: 25 additions & 0 deletions src/models/Games/gtn.js
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;

0 comments on commit dc07d5a

Please sign in to comment.