2022-08-29 21:06:18 +02:00
|
|
|
import { SlashCommandBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, PermissionFlagsBits } from 'discord.js';
|
2022-08-29 20:37:59 +02:00
|
|
|
import db from '../../models/index.js';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('autoresponse')
|
2022-08-30 22:58:23 +02:00
|
|
|
.setDescription('Enable or disable autoresponse')
|
|
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages),
|
2022-08-30 04:06:15 +02:00
|
|
|
category: 'admin',
|
2022-08-29 20:37:59 +02:00
|
|
|
async execute(interaction, args, client) {
|
|
|
|
const autoresponseStat = await db.autoresponseStat.findOne({ where: { serverID: interaction.guild.id } });
|
2022-10-10 18:56:58 +02:00
|
|
|
if (!autoresponseStat) {
|
2022-08-29 20:37:59 +02:00
|
|
|
const body = { serverID: interaction.guild.id, stat: 'enable' };
|
|
|
|
await db.autoresponseStat.create(body);
|
2022-08-30 04:06:15 +02:00
|
|
|
return await interaction.reply({ content: 'Autoresponse has been enabled.', ephemeral: true });
|
2022-08-29 20:37:59 +02:00
|
|
|
}
|
|
|
|
|
2022-10-10 18:56:58 +02:00
|
|
|
|
2022-08-29 20:37:59 +02:00
|
|
|
const row = new ActionRowBuilder()
|
|
|
|
.addComponents(
|
|
|
|
new ButtonBuilder()
|
2022-09-14 11:31:19 +02:00
|
|
|
.setCustomId(`yes${interaction.user.id}`)
|
2022-08-29 20:37:59 +02:00
|
|
|
.setLabel('Yes')
|
|
|
|
.setStyle(ButtonStyle.Primary),
|
|
|
|
)
|
|
|
|
.addComponents(
|
|
|
|
new ButtonBuilder()
|
2022-09-14 11:31:19 +02:00
|
|
|
.setCustomId(`no${interaction.user.id}`)
|
2022-08-29 20:37:59 +02:00
|
|
|
.setLabel('No')
|
|
|
|
.setStyle(ButtonStyle.Danger),
|
|
|
|
);
|
|
|
|
|
2022-10-10 18:56:58 +02:00
|
|
|
if (autoresponseStat.stat === 'enable') {
|
|
|
|
await interaction.reply({ content: 'Autoresponse is already enabled, do you wish to disable it?', components: [row], ephemeral: true });
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const body = { serverID: interaction.guild.id, stat: 'enable' };
|
|
|
|
await db.autoresponseStat.update(body, { where: { serverID: interaction.guild.id } });
|
|
|
|
return interaction.editReply({ content: 'Auto response has been enabled.', ephemeral: true });
|
|
|
|
}
|
2022-08-29 20:37:59 +02:00
|
|
|
|
2022-09-10 09:35:32 +02:00
|
|
|
client.on('interactionCreate', async (interactionMenu) => {
|
|
|
|
if (interaction.user !== interactionMenu.user) return;
|
2022-08-29 20:37:59 +02:00
|
|
|
if (!interactionMenu.isButton) return;
|
|
|
|
interactionMenu.update({ components: [] });
|
2022-09-14 11:31:19 +02:00
|
|
|
if (interactionMenu.customId === `yes${interaction.user.id}`) {
|
2022-08-29 20:37:59 +02:00
|
|
|
const body = { serverID: interaction.guild.id, stat: 'disable' };
|
|
|
|
await db.autoresponseStat.update(body, { where: { serverID: interaction.guild.id } });
|
2022-08-30 04:06:15 +02:00
|
|
|
return interaction.editReply({ content: 'Auto response has been disabled.', ephemeral: true });
|
2022-08-29 20:37:59 +02:00
|
|
|
}
|
|
|
|
else {
|
2022-08-30 04:06:15 +02:00
|
|
|
return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true });
|
2022-08-29 20:37:59 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2022-10-10 18:56:58 +02:00
|
|
|
};
|