From 099d0d75e4df4b8943c573825ab739b301803ddb Mon Sep 17 00:00:00 2001 From: Supositware Date: Mon, 29 Aug 2022 20:37:59 +0200 Subject: [PATCH] Enable/Disable autoresponse --- commands/admin/autoresponse.js | 47 ++++++++++++++++++++++++++++++++++ scripts/deploy-commands.cjs | 4 +++ 2 files changed, 51 insertions(+) create mode 100644 commands/admin/autoresponse.js diff --git a/commands/admin/autoresponse.js b/commands/admin/autoresponse.js new file mode 100644 index 00000000..172657b5 --- /dev/null +++ b/commands/admin/autoresponse.js @@ -0,0 +1,47 @@ +import { SlashCommandBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder } from 'discord.js'; +import db from '../../models/index.js'; + +export default { + data: new SlashCommandBuilder() + .setName('autoresponse') + .setDescription('Enable or disable autoresponse'), + category: 'utility', + async execute(interaction, args, client) { + const autoresponseStat = await db.autoresponseStat.findOne({ where: { serverID: interaction.guild.id } }); + + if (autoresponseStat.stat !== 'enable') { + const body = { serverID: interaction.guild.id, stat: 'enable' }; + await db.autoresponseStat.create(body); + return await interaction.reply({ content: 'Autoresponse 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: 'Autoresponse 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.autoresponseStat.update(body, { where: { serverID: interaction.guild.id } }); + return interaction.editReply('Auto response has been disabled.'); + } + else { + return interaction.editReply('Nothing has been changed.'); + } + }); + }, +}; diff --git a/scripts/deploy-commands.cjs b/scripts/deploy-commands.cjs index 720a12ef..fef25872 100644 --- a/scripts/deploy-commands.cjs +++ b/scripts/deploy-commands.cjs @@ -114,6 +114,10 @@ const commands = [ .setDescription('🤫') .setRequired(true)), + new SlashCommandBuilder() + .setName('autoresponse') + .setDescription('Enable or disable autoresponse'), + new SlashCommandBuilder() .setName('die') .setDescription('Kill the bot'),