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,
|
2022-10-13 15:49:31 +02:00
|
|
|
async execute(interaction, args) {
|
2022-08-17 16:21:58 +02:00
|
|
|
await interaction.deferReply({ ephemeral: true });
|
|
|
|
const client = interaction.client;
|
2022-10-13 15:49:31 +02:00
|
|
|
const command = args.command;
|
|
|
|
const userid = args.userid;
|
2022-11-24 21:34:39 +01:00
|
|
|
const reason = args.reason ? args.reason : 'No reason has been specified.';
|
2022-08-17 16:21:58 +02:00
|
|
|
|
|
|
|
const blacklist = await Blacklists.findOne({ where: { type:command, uid:userid } });
|
|
|
|
|
|
|
|
if (!blacklist) {
|
|
|
|
const body = { type:command, uid: userid, reason: reason };
|
|
|
|
Blacklists.create(body);
|
2024-06-30 20:05:09 +02:00
|
|
|
if (command === 'guild') {
|
|
|
|
let guildid = userid;
|
|
|
|
await client.guilds.fetch(guildid);
|
|
|
|
const guild =client.guilds.resolve(guildid).name;
|
|
|
|
|
|
|
|
return interaction.editReply(`The guild ${guild} (${guildid}) has been blacklisted with the following reason \`${reason}\``);
|
2022-08-17 16:21:58 +02:00
|
|
|
|
2024-06-30 20:05:09 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
let user = userid;
|
|
|
|
await client.users.fetch(userid);
|
|
|
|
user = client.users.resolve(userid).username;
|
|
|
|
|
|
|
|
|
|
|
|
return interaction.editReply(`${user} (${userid}) has been blacklisted from ${command} with the following reason \`${reason}\``);
|
|
|
|
}
|
2022-08-17 16:21:58 +02:00
|
|
|
}
|
|
|
|
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()
|
2023-04-05 18:12:56 +02:00
|
|
|
.setCustomId(`yes${interaction.user.id}${interaction.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()
|
2023-04-05 18:12:56 +02:00
|
|
|
.setCustomId(`no${interaction.user.id}${interaction.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] });
|
|
|
|
|
2023-04-05 18:12:56 +02:00
|
|
|
return listenButton(client, interaction, command, userid, interaction.user);
|
2022-08-17 16:21:58 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
2023-04-05 18:12:56 +02:00
|
|
|
|
|
|
|
async function listenButton(client, interaction, command, userid, user = interaction.user, originalId = interaction.id) {
|
|
|
|
client.once('interactionCreate', async (interactionMenu) => {
|
|
|
|
if (user !== interactionMenu.user) return listenButton(client, interaction, command, userid, user, originalId);
|
|
|
|
if (!interactionMenu.isButton()) return;
|
|
|
|
|
|
|
|
await interactionMenu.update({ components: [] });
|
|
|
|
|
|
|
|
if (interactionMenu.customId === `yes${interaction.user.id}${originalId}`) {
|
|
|
|
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.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|