2022-08-29 20:56:26 +02:00
|
|
|
import { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
|
|
|
|
import db from '../../models/index.js';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('optout')
|
2023-04-04 00:30:30 +02:00
|
|
|
.setDescription('Opt out of the non commands features and arguments logging (for debugging purposes)'),
|
2022-08-29 20:56:26 +02:00
|
|
|
category: 'utility',
|
|
|
|
async execute(interaction, args, client) {
|
|
|
|
const isOptOut = await db.optout.findOne({ where: { userID: interaction.user.id } });
|
|
|
|
|
|
|
|
if (!isOptOut) {
|
|
|
|
const body = { userID: interaction.user.id };
|
|
|
|
await db.optout.create(body);
|
|
|
|
return await interaction.reply({ content: 'You have successfully been opt out.' });
|
|
|
|
}
|
|
|
|
|
|
|
|
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 20:56:26 +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 20:56:26 +02:00
|
|
|
.setLabel('No')
|
|
|
|
.setStyle(ButtonStyle.Danger),
|
|
|
|
);
|
|
|
|
|
|
|
|
await interaction.reply({ content: 'You are already opt out, do you wish to opt in?', components: [row] });
|
|
|
|
|
2023-04-05 18:12:56 +02:00
|
|
|
return listenButton(client, interaction, interaction.user);
|
2022-08-29 20:56:26 +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;
|
|
|
|
|
|
|
|
await interactionMenu.update({ components: [] });
|
|
|
|
|
|
|
|
if (interactionMenu.customId === `yes${interaction.user.id}${originalId}`) {
|
|
|
|
db.optout.destroy({ where: { userID: interaction.user.id } });
|
|
|
|
return interaction.editReply('You have successfully been opt in');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return interaction.editReply('Nothing has been changed.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|