2022-08-28 17:03:15 +02:00
|
|
|
import { ButtonStyle, SlashCommandBuilder, ButtonBuilder, ActionRowBuilder } from 'discord.js';
|
2022-08-17 16:21:58 +02:00
|
|
|
import db from '../../models/index.js';
|
|
|
|
const Blacklists = db.Blacklists;
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('ublacklist')
|
|
|
|
.setDescription('Blacklist a user from the bot')
|
|
|
|
.addStringOption(option =>
|
|
|
|
option.setName('command')
|
|
|
|
.setDescription('Which command do you want to get a user blacklisted from?')
|
|
|
|
.setRequired(true))
|
|
|
|
.addStringOption(option =>
|
|
|
|
option.setName('userid')
|
|
|
|
.setDescription('Who do you want to blacklist?')
|
|
|
|
.setRequired(true))
|
|
|
|
.addStringOption(option =>
|
|
|
|
option.setName('reason')
|
|
|
|
.setDescription('The reason of the blacklist.')
|
|
|
|
.setRequired(false)),
|
2022-08-28 17:03:15 +02:00
|
|
|
category: 'owner',
|
2022-08-17 16:21:58 +02:00
|
|
|
ownerOnly: true,
|
|
|
|
async execute(interaction) {
|
|
|
|
await interaction.deferReply({ ephemeral: true });
|
|
|
|
const client = interaction.client;
|
|
|
|
const command = interaction.options.getString('command');
|
|
|
|
const userid = interaction.options.getString('userid');
|
|
|
|
const reason = interaction.options.getString('reason');
|
|
|
|
|
|
|
|
const blacklist = await Blacklists.findOne({ where: { type:command, uid:userid } });
|
|
|
|
|
|
|
|
if (!blacklist) {
|
|
|
|
const body = { type:command, uid: userid, reason: reason };
|
|
|
|
Blacklists.create(body);
|
|
|
|
let user = userid;
|
|
|
|
if (command !== 'guild') {user = client.users.resolve(userid).tag;}
|
|
|
|
|
|
|
|
return interaction.editReply(`${user} has been blacklisted from ${command} with the following reason ${reason}`);
|
|
|
|
}
|
|
|
|
else {
|
2022-08-28 17:03:15 +02:00
|
|
|
const row = new ActionRowBuilder()
|
2022-08-17 16:21:58 +02:00
|
|
|
.addComponents(
|
2022-08-28 17:03:15 +02:00
|
|
|
new ButtonBuilder()
|
2022-09-14 11:31:19 +02:00
|
|
|
.setCustomId(`yes${interaction.user.id}`)
|
2022-08-17 16:21:58 +02:00
|
|
|
.setLabel('Yes')
|
2022-08-28 17:03:15 +02:00
|
|
|
.setStyle(ButtonStyle.Primary),
|
2022-08-17 16:21:58 +02:00
|
|
|
)
|
|
|
|
.addComponents(
|
2022-08-28 17:03:15 +02:00
|
|
|
new ButtonBuilder()
|
2022-09-14 11:31:19 +02:00
|
|
|
.setCustomId(`no${interaction.user.id}`)
|
2022-08-17 16:21:58 +02:00
|
|
|
.setLabel('No')
|
2022-08-28 17:03:15 +02:00
|
|
|
.setStyle(ButtonStyle.Danger),
|
2022-08-17 16:21:58 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
await interaction.editReply({ content: 'This user is already blacklisted, do you want to unblacklist him?', ephemeral: true, components: [row] });
|
|
|
|
|
2022-09-10 09:35:32 +02:00
|
|
|
interaction.client.on('interactionCreate', async (interactionMenu) => {
|
|
|
|
if (interaction.user !== interactionMenu.user) return;
|
2022-08-17 16:21:58 +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-17 16:21:58 +02:00
|
|
|
Blacklists.destroy({ where: { type:command, uid:userid } });
|
|
|
|
return interaction.editReply(`The following ID have been unblacklisted from ${command}: ${userid}`);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return interaction.editReply('No one has been unblacklisted.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|