From dda37b78930ec6ef6d9fa9d1bd6c6f476594b6d2 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Mon, 5 Oct 2020 15:00:28 -0600 Subject: [PATCH] Added new command: vip --- bot.js | 2 ++ commands/vip.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ events/ready.js | 4 ++-- models/guild.js | 23 ++++++++++++----------- 4 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 commands/vip.js diff --git a/bot.js b/bot.js index 5afd98c..845618c 100644 --- a/bot.js +++ b/bot.js @@ -13,5 +13,7 @@ async function init() { ['command', 'event'].forEach(x => require(`./handle/${x}`)(client)); client.developers = ["330547934951112705", "673477059904929802"]; + client.utils = {}; + client.utils.logch = async () => {return client.guilds.cache.get('762707532417335296').channels.cache.get('762732961753595915');}; } init(); \ No newline at end of file diff --git a/commands/vip.js b/commands/vip.js new file mode 100644 index 0000000..3d7aa3a --- /dev/null +++ b/commands/vip.js @@ -0,0 +1,48 @@ +const Discord = require("discord.js"); + +module.exports = { + name: "vip", + aliases: ["premium"], + help: new Discord.MessageEmbed() + .setTitle("Help -> VIP") + .setDescription("Toggle a server as VIP. This allows ") + .addField("Syntax", "`vip `") + .addField("Notice", "This command is **developer-only**."), + async execute(message, msg, args, cmd, prefix, mention, client) { + if (!message.guild) {return message.reply("This command is server-only!");} + if (!args.length) {return message.channel.send(`Syntax: \`${prefix}vip \``);} + if (!client.developers.includes(message.author.id) && !['check', 'c', 'view', 'v'].includes(args[0])) {return message.reply("Unfortunately, this is a **developer-only command**!");} + const GuildSettings = require('../models/guild'); + const logemb = (act) => new Discord.MessageEmbed() + .setAuthor(`VIP Server ${act}`, message.author.avatarURL()) + .setDescription("A Server's VIP status was updated.") + .setThumbnail(message.guild.iconURL({size: 1024})) + .addField("Name", message.guild.name, true) + .addField("Admin", message.author.username, true) + .setColor("e8da3a") + .setFooter("Natsuki") + .setTimestamp(); + + if (['add', 'a', 'make', 'm'].includes(args[0])) { + let tguild = await GuildSettings.findOne({gid: message.guild.id}) + ? await GuildSettings.findOne({gid: message.guild.id}) + : new GuildSettings({gid: message.guild.id}); + if (tguild.vip === true) {return message.reply("This server is already a VIP server.");} + tguild.vip = true; + tguild.save(); + client.guilds.cache.get('762707532417335296').channels.cache.get('762732961753595915').send(logemb("Added")); + return message.reply("This server is now a VIP server!"); + } else if (['remove', 'r', 'delete', 'd'].includes(args[0])) { + let tguild = await GuildSettings.findOne({gid: message.guild.id}); + if (tguild) { + if (tguild.vip === false) {return message.reply("This server wasn't a VIP server anyways...");} + await GuildSettings.findOneAndUpdate({gid: message.guild.id, vip: false}); + client.guilds.cache.get('762707532417335296').channels.cache.get('762732961753595915').send(logemb("Removed")); + } else {return message.reply("This server wasn't a VIP server anyways...");} + return message.reply("This server is no longer a VIP server!"); + } else if (['check', 'c', 'view', 'v'].includes(args[0])) { + let tguild = await GuildSettings.findOne({gid: message.guild.id}); + return message.reply((tguild && tguild.vip) ? 'This server is a VIP server.' : 'This server is not a VIP server.'); + } + } +}; \ No newline at end of file diff --git a/events/ready.js b/events/ready.js index 51bbfbd..56f3a59 100644 --- a/events/ready.js +++ b/events/ready.js @@ -9,8 +9,8 @@ module.exports = async client => { const config = client.config; try { await mongoose.connect(`mongodb+srv://${config.database.user}:${config.database.password}@${config.database.cluster}.3jpp4.mongodb.net/test`, { - useFindAndModify: false, useNewUrlParser: true, dbName: 'Natsuki-Main', useUnifiedTopology: true - }); + useFindAndModify: false, useNewUrlParser: true, dbName: 'Natsuki-Main', useUnifiedTopology: true, useCreateIndex: true + }); } catch (e) { let date = new Date; date = date.toString().slice(date.toString().search(":") - 2, date.toString().search(":") + 6); console.error(`\n${chalk.red('[ERROR]')} >> ${chalk.yellow(`At [${date}] | Occurred while trying to connect to Mongo Cluster`)}`, e); diff --git a/models/guild.js b/models/guild.js index 6a77944..dc4e2c1 100644 --- a/models/guild.js +++ b/models/guild.js @@ -2,17 +2,18 @@ const mongoose = require('mongoose'); const guildSchema = new mongoose.Schema({ gid: {type: String, unique: true}, - staffrole: String, - vip: Boolean, - wch: String, - lch: String, - logch: String, - chests: String, - autoquote: String, - welcomeroll: String, - joinrole: String, - cooldowns: Boolean, - levelmessage: String + staffrole: {type: String, default: ''}, + vip: {type: Boolean, default: false}, + wch: {type: String, default: ''}, + lch: {type: String, default: ''}, + logch: {type: String, default: ''}, + chests: {type: Boolean, default: false}, + autoquote: {type: Boolean, default: true}, + welcomerole: {type: String, default: ''}, + joinrole: {type: String, default: ''}, + cooldowns: {type: Boolean, default: false}, + levelmessage: {type: String, default: '**{{u}}** has reached level **{{l}}**! :tada:'}, + levelmessages: {type: Boolean, default: false} }); module.exports = mongoose.model("guild", guildSchema); \ No newline at end of file