From 850a6fb827cdaf8ae712a58ad1162c69d7e79dc5 Mon Sep 17 00:00:00 2001 From: Supositware Date: Mon, 29 Aug 2022 21:06:27 +0200 Subject: [PATCH] Enable/Disable quotation server wide --- commands/admin/quotation.js | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 commands/admin/quotation.js diff --git a/commands/admin/quotation.js b/commands/admin/quotation.js new file mode 100644 index 0000000..89426ac --- /dev/null +++ b/commands/admin/quotation.js @@ -0,0 +1,48 @@ +import { SlashCommandBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, PermissionFlagsBits } from 'discord.js'; +import db from '../../models/index.js'; + +export default { + data: new SlashCommandBuilder() + .setName('quotation') + .setDescription('Enable or disable quotations'), + category: 'utility', + userPermissions: [PermissionFlagsBits.ManageMessages], + async execute(interaction, args, client) { + const quotationstat = await db.quotationstat.findOne({ where: { serverID: interaction.guild.id } }); + + if (quotationstat.stat !== 'enable') { + const body = { serverID: interaction.guild.id, stat: 'enable' }; + await db.quotationstat.create(body); + return await interaction.reply({ content: 'Quotation has been enabled.' }); + } + + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId('yes') + .setLabel('Yes') + .setStyle(ButtonStyle.Primary), + ) + .addComponents( + new ButtonBuilder() + .setCustomId('no') + .setLabel('No') + .setStyle(ButtonStyle.Danger), + ); + + await interaction.reply({ content: 'Quotation is already enabled, do you wish to disable it?', components: [row] }); + + client.once('interactionCreate', async (interactionMenu) => { + if (!interactionMenu.isButton) return; + interactionMenu.update({ components: [] }); + if (interactionMenu.customId === 'yes') { + const body = { serverID: interaction.guild.id, stat: 'disable' }; + await db.quotationstat.update(body, { where: { serverID: interaction.guild.id } }); + return interaction.editReply('Quotation has been disabled.'); + } + else { + return interaction.editReply('Nothing has been changed.'); + } + }); + }, +};