From 0efbdfb37043b22006fb166221d22d4957deb618 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 19 Oct 2023 23:39:05 +0200 Subject: [PATCH] Added new db env management options --- commands/config.js | 237 +++++++------------------------------- commands/setup.js | 219 +++++++++++++++++++++++++++++++++++ schemas/settingsSchema.js | 9 ++ 3 files changed, 270 insertions(+), 195 deletions(-) create mode 100644 commands/setup.js create mode 100644 schemas/settingsSchema.js diff --git a/commands/config.js b/commands/config.js index 42e0911..b751c0b 100644 --- a/commands/config.js +++ b/commands/config.js @@ -1,219 +1,66 @@ -const { SlashCommandBuilder, PermissionFlagsBits, ButtonBuilder, ActionRowBuilder, ButtonStyle, } = require("discord.js"); +const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js'); const { color } = require("../config/options.json"); +const settings = require("../schemas/settingsSchema.js"); +const mongoose = require("mongoose"); module.exports = { name: "config", - description: "Configure the bot.", - type: "slash", + description: "Configure the bot", data: new SlashCommandBuilder() .setName("config") - .setDescription("Configure the bot.") - .addSubcommand((subcommand) => - subcommand - .setName("sendguildapplication") - .setDescription("Send the application message to a channel.") - .addChannelOption((option) => - option - .setName("channel") - .setDescription("The channel to send the application to.") - .setRequired(true)) + .setDescription("Configure the bot") + .addStringOption(option => + option + .setName("setting") + .setDescription("The setting to configure") + .setRequired(true)) + .addStringOption(option => + option + .setName("value") + .setDescription("The value to set") + .setRequired(true) ) - .addSubcommand((subcommand) => - subcommand - .setName("sendstaffapplication") - .setDescription("Send the application message to a channel.") - .addChannelOption((option) => - option - .setName("channel") - .setDescription("The channel to send the application to.") - .setRequired(true))) - .addSubcommand((subcommand) => - subcommand - .setName("sendverfiymessage") - .setDescription("Send the verfiy message to a channel.") - .addChannelOption((option) => - option - .setName("channel") - .setDescription("The channel to send the verfiy message to.") - .setRequired(true))) - .addSubcommand((subcommand) => - subcommand - .setName("sendwaitinglistmessage") - .setDescription("Send the waiting list message to a channel.") - .addChannelOption((option) => - option - .setName("channel") - .setDescription("The channel to send the waiting list message to.") - .setRequired(true))) - .addSubcommand((subcommand) => - subcommand - .setName("sendinactivityapplication") - .setDescription("Send the application message to a channel.") - .addChannelOption((option) => - option - .setName("channel") - .setDescription("The channel to send the application to.") - .setRequired(true))) - .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) - .setDMPermission(false), + .setDMPermission(false) + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), async execute(interaction) { - const user = interaction.user; - const guild = interaction.guild; - const subcommand = interaction.options.getSubcommand(); + + await interaction.deferReply(); + + const setting = interaction.options.getString("setting"); + const value = interaction.options.getString("value"); const embedColor = Number(color.replace("#", "0x")); + const settingsData = await settings.findOne({ name: setting }); - if (subcommand === "sendguildapplication") { - const channel = interaction.options.getChannel("channel"); + if (!settingsData) { - await channel.send({ - embeds: [ - { - title: "Guild Application", - description: "You can apply for the guild by clicking the button below.", - color: embedColor, - footer: { - text: interaction.guild.name + " | Developed by @Taken#0002", - iconURL: interaction.guild.iconURL({ dynamic: true }) - }, - thumbnail: { - url: interaction.guild.iconURL({ dynamic: true }) - } - } - ], - components: [ - new ActionRowBuilder() - .addComponents(new ButtonBuilder() - .setCustomId("guildapply") - .setLabel("Apply") - .setStyle(ButtonStyle.Primary) - .setEmoji({ name: "✅" })) - ] - }); - await interaction.reply({ content: "Message sent", ephemeral: true }); - } - - if (subcommand === "sendstaffapplication") { - const channel = interaction.options.getChannel("channel"); - - await channel.send({ - embeds: [ - { - title: "Staff Application", - description: "You can apply for the staff team by clicking the button below.", - color: embedColor, - footer: { - text: interaction.guild.name + " | Developed by @Taken#0002", - iconURL: interaction.guild.iconURL({ dynamic: true }) - }, - thumbnail: { - url: interaction.guild.iconURL({ dynamic: true }) - } - } - ], - components: [ - new ActionRowBuilder() - .addComponents(new ButtonBuilder() - .setCustomId("staffapply") - .setLabel("Apply") - .setStyle(ButtonStyle.Primary) - .setEmoji({ name: "✅" })) - ] + await settings.create({ + _id: mongoose.Types.ObjectId(), + name: setting, + value: value }); - await interaction.reply({ content: "Message sent", ephemeral: true }); - } - - if (subcommand === "sendinactivityapplication") { - const channel = interaction.options.getChannel("channel"); - - await channel.send({ - embeds: [ - { - title: "Inactivity Log", - description: "You can send an inactivity log by clicking the button below.", - color: embedColor, - footer: { - text: interaction.guild.name + " | Developed by @Taken#0002", - iconURL: interaction.guild.iconURL({ dynamic: true }) - }, - thumbnail: { - url: interaction.guild.iconURL({ dynamic: true }) - } - } - ], - components: [ - new ActionRowBuilder() - .addComponents(new ButtonBuilder() - .setCustomId("guildinactivitylog") - .setLabel("Submit") - .setStyle(ButtonStyle.Primary) - .setEmoji({ name: "✅" })) - ] - }); - - await interaction.reply({ content: "Message sent", ephemeral: true }); - } - - if (subcommand === "sendverfiymessage") { - const channel = interaction.options.getChannel("channel"); - - await channel.send({ + await interaction.editReply({ embeds: [{ - title: "Verification", - description: "You can verify by clicking the button below.", - color: embedColor, - footer: { - text: interaction.guild.name + " | Developed by @Taken#0002", - iconURL: interaction.guild.iconURL({ dynamic: true }) - }, - thumbnail: { - url: interaction.guild.iconURL({ dynamic: true }) - } - }], - components: [ - new ActionRowBuilder() - .addComponents(new ButtonBuilder() - .setCustomId("verifybutton") - .setLabel("Verify") - .setStyle(ButtonStyle.Primary) - .setEmoji({ name: "✅" })) - ] + description: "Successfully created `" + setting + "` with value `" + value + "`.", + color: embedColor + }] }); - await interaction.reply({ content: "Message sent", ephemeral: true }); + } else { - } + await settings.findOneAndUpdate( + { name: setting }, + { value: value } + ); - if (subcommand === "sendwaitinglistmessage") { - const channel = interaction.options.getChannel("channel"); - - await channel.send({ + await interaction.editReply({ embeds: [{ - title: "Waiting List", - description: "The people below were accepted into the guild\n" + - "Try to invite them in order.", - color: embedColor, - footer: { - text: interaction.guild.name + " | Developed by @Taken#0002", - iconURL: interaction.guild.iconURL({ dynamic: true }) - }, - thumbnail: { - url: interaction.guild.iconURL({ dynamic: true }) - } - }], - components: [ - new ActionRowBuilder() - .addComponents(new ButtonBuilder() - .setCustomId("waitinglistupdate") - .setLabel("Update") - .setStyle(ButtonStyle.Primary) - .setEmoji({ name: "🔄" })) - ] - }); - await interaction.reply({ content: "Message sent", ephemeral: true }); + description: "Successfully updated `" + setting + "` to value `" + value + "`.", + }] + }) } } -}; +} diff --git a/commands/setup.js b/commands/setup.js new file mode 100644 index 0000000..a869f88 --- /dev/null +++ b/commands/setup.js @@ -0,0 +1,219 @@ +const { SlashCommandBuilder, PermissionFlagsBits, ButtonBuilder, ActionRowBuilder, ButtonStyle, } = require("discord.js"); +const { color } = require("../config/options.json"); + +module.exports = { + name: "setup", + description: "Used for setup of the bot.", + type: "slash", + + data: new SlashCommandBuilder() + .setName("setup") + .setDescription("Configure the bot.") + .addSubcommand((subcommand) => + subcommand + .setName("sendguildapplication") + .setDescription("Send the application message to a channel.") + .addChannelOption((option) => + option + .setName("channel") + .setDescription("The channel to send the application to.") + .setRequired(true)) + ) + .addSubcommand((subcommand) => + subcommand + .setName("sendstaffapplication") + .setDescription("Send the application message to a channel.") + .addChannelOption((option) => + option + .setName("channel") + .setDescription("The channel to send the application to.") + .setRequired(true))) + .addSubcommand((subcommand) => + subcommand + .setName("sendverfiymessage") + .setDescription("Send the verfiy message to a channel.") + .addChannelOption((option) => + option + .setName("channel") + .setDescription("The channel to send the verfiy message to.") + .setRequired(true))) + .addSubcommand((subcommand) => + subcommand + .setName("sendwaitinglistmessage") + .setDescription("Send the waiting list message to a channel.") + .addChannelOption((option) => + option + .setName("channel") + .setDescription("The channel to send the waiting list message to.") + .setRequired(true))) + .addSubcommand((subcommand) => + subcommand + .setName("sendinactivityapplication") + .setDescription("Send the application message to a channel.") + .addChannelOption((option) => + option + .setName("channel") + .setDescription("The channel to send the application to.") + .setRequired(true))) + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) + .setDMPermission(false), + + async execute(interaction) { + const user = interaction.user; + const guild = interaction.guild; + const subcommand = interaction.options.getSubcommand(); + const embedColor = Number(color.replace("#", "0x")); + + + if (subcommand === "sendguildapplication") { + const channel = interaction.options.getChannel("channel"); + + await channel.send({ + embeds: [ + { + title: "Guild Application", + description: "You can apply for the guild by clicking the button below.", + color: embedColor, + footer: { + text: interaction.guild.name + " | Developed by @Taken#0002", + iconURL: interaction.guild.iconURL({ dynamic: true }) + }, + thumbnail: { + url: interaction.guild.iconURL({ dynamic: true }) + } + } + ], + components: [ + new ActionRowBuilder() + .addComponents(new ButtonBuilder() + .setCustomId("guildapply") + .setLabel("Apply") + .setStyle(ButtonStyle.Primary) + .setEmoji({ name: "✅" })) + ] + }); + await interaction.reply({ content: "Message sent", ephemeral: true }); + } + + if (subcommand === "sendstaffapplication") { + const channel = interaction.options.getChannel("channel"); + + await channel.send({ + embeds: [ + { + title: "Staff Application", + description: "You can apply for the staff team by clicking the button below.", + color: embedColor, + footer: { + text: interaction.guild.name + " | Developed by @Taken#0002", + iconURL: interaction.guild.iconURL({ dynamic: true }) + }, + thumbnail: { + url: interaction.guild.iconURL({ dynamic: true }) + } + } + ], + components: [ + new ActionRowBuilder() + .addComponents(new ButtonBuilder() + .setCustomId("staffapply") + .setLabel("Apply") + .setStyle(ButtonStyle.Primary) + .setEmoji({ name: "✅" })) + ] + }); + + await interaction.reply({ content: "Message sent", ephemeral: true }); + } + + if (subcommand === "sendinactivityapplication") { + const channel = interaction.options.getChannel("channel"); + + await channel.send({ + embeds: [ + { + title: "Inactivity Log", + description: "You can send an inactivity log by clicking the button below.", + color: embedColor, + footer: { + text: interaction.guild.name + " | Developed by @Taken#0002", + iconURL: interaction.guild.iconURL({ dynamic: true }) + }, + thumbnail: { + url: interaction.guild.iconURL({ dynamic: true }) + } + } + ], + components: [ + new ActionRowBuilder() + .addComponents(new ButtonBuilder() + .setCustomId("guildinactivitylog") + .setLabel("Submit") + .setStyle(ButtonStyle.Primary) + .setEmoji({ name: "✅" })) + ] + }); + + await interaction.reply({ content: "Message sent", ephemeral: true }); + } + + if (subcommand === "sendverfiymessage") { + const channel = interaction.options.getChannel("channel"); + + await channel.send({ + embeds: [{ + title: "Verification", + description: "You can verify by clicking the button below.", + color: embedColor, + footer: { + text: interaction.guild.name + " | Developed by @Taken#0002", + iconURL: interaction.guild.iconURL({ dynamic: true }) + }, + thumbnail: { + url: interaction.guild.iconURL({ dynamic: true }) + } + }], + components: [ + new ActionRowBuilder() + .addComponents(new ButtonBuilder() + .setCustomId("verifybutton") + .setLabel("Verify") + .setStyle(ButtonStyle.Primary) + .setEmoji({ name: "✅" })) + ] + }); + await interaction.reply({ content: "Message sent", ephemeral: true }); + + } + + if (subcommand === "sendwaitinglistmessage") { + const channel = interaction.options.getChannel("channel"); + + await channel.send({ + embeds: [{ + title: "Waiting List", + description: "The people below were accepted into the guild\n" + + "Try to invite them in order.", + color: embedColor, + footer: { + text: interaction.guild.name + " | Developed by @Taken#0002", + iconURL: interaction.guild.iconURL({ dynamic: true }) + }, + thumbnail: { + url: interaction.guild.iconURL({ dynamic: true }) + } + }], + components: [ + new ActionRowBuilder() + .addComponents(new ButtonBuilder() + .setCustomId("waitinglistupdate") + .setLabel("Update") + .setStyle(ButtonStyle.Primary) + .setEmoji({ name: "🔄" })) + ] + }); + await interaction.reply({ content: "Message sent", ephemeral: true }); + } + + } +}; diff --git a/schemas/settingsSchema.js b/schemas/settingsSchema.js new file mode 100644 index 0000000..d7d4952 --- /dev/null +++ b/schemas/settingsSchema.js @@ -0,0 +1,9 @@ +const { Schema, model } = require('mongoose'); + +const settingsSchema = new Schema({ + _id: Schema.Types.ObjectId, + name: { type: String, required: true }, + value: { type: String, required: true }, +}); + +module.exports = model('settings', settingsSchema, 'settings');