2022-08-29 21:06:27 +02:00
|
|
|
import { SlashCommandBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, PermissionFlagsBits } from 'discord.js';
|
|
|
|
import db from '../../models/index.js';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('quotation')
|
2022-08-30 22:58:23 +02:00
|
|
|
.setDescription('Enable or disable quotations')
|
|
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages),
|
2022-08-30 04:06:15 +02:00
|
|
|
category: 'admin',
|
2022-08-29 21:06:27 +02:00
|
|
|
async execute(interaction, args, client) {
|
2022-09-10 10:33:41 +02:00
|
|
|
const quotationstat = await db.quotationStat.findOne({ where: { serverID: interaction.guild.id } });
|
2022-08-29 21:06:27 +02:00
|
|
|
|
2022-10-10 18:56:58 +02:00
|
|
|
if (!quotationstat) {
|
2022-08-29 21:06:27 +02:00
|
|
|
const body = { serverID: interaction.guild.id, stat: 'enable' };
|
2022-09-10 10:33:41 +02:00
|
|
|
await db.quotationStat.create(body);
|
2022-08-30 04:06:15 +02:00
|
|
|
return await interaction.reply({ content: 'Quotation has been enabled.', ephemeral: true });
|
2022-08-29 21:06:27 +02:00
|
|
|
}
|
|
|
|
|
2022-10-10 18:56:58 +02:00
|
|
|
|
2022-08-29 21:06:27 +02:00
|
|
|
const row = new ActionRowBuilder()
|
|
|
|
.addComponents(
|
|
|
|
new ButtonBuilder()
|
2023-04-05 18:12:56 +02:00
|
|
|
.setCustomId(`yes${interaction.user.id}${interaction.id}`)
|
2022-08-29 21:06:27 +02:00
|
|
|
.setLabel('Yes')
|
|
|
|
.setStyle(ButtonStyle.Primary),
|
|
|
|
)
|
|
|
|
.addComponents(
|
|
|
|
new ButtonBuilder()
|
2023-04-05 18:12:56 +02:00
|
|
|
.setCustomId(`no${interaction.user.id}${interaction.id}`)
|
2022-08-29 21:06:27 +02:00
|
|
|
.setLabel('No')
|
|
|
|
.setStyle(ButtonStyle.Danger),
|
|
|
|
);
|
|
|
|
|
2022-10-10 18:56:58 +02:00
|
|
|
if (quotationstat.stat === 'enable') {
|
|
|
|
await interaction.reply({ content: 'Quotation 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: 'Quotation has been enabled.', ephemeral: true });
|
|
|
|
}
|
2022-08-29 21:06:27 +02:00
|
|
|
|
2023-04-05 18:12:56 +02:00
|
|
|
return listenButton(client, interaction, interaction.user);
|
2022-08-29 21:06:27 +02:00
|
|
|
},
|
|
|
|
};
|
2023-04-05 18:12:56 +02:00
|
|
|
|
|
|
|
async function listenButton(client, interaction, user = interaction.user, originalId = interaction.id) {
|
|
|
|
client.once('interactionCreate', async (interactionMenu) => {
|
|
|
|
if (user !== interactionMenu.user) return listenButton(client, interaction, user, originalId);
|
|
|
|
if (!interactionMenu.isButton()) return;
|
|
|
|
|
|
|
|
interactionMenu.update({ components: [] });
|
|
|
|
|
|
|
|
if (interactionMenu.customId === `yes${interaction.user.id}${originalId}`) {
|
|
|
|
await db.quotationStat.destroy({ where: { serverID: interaction.guild.id } });
|
|
|
|
return interaction.editReply({ content: 'Quotation has been disabled.', ephemeral: true });
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|