2021-05-16 17:11:24 +03:00
|
|
|
const Command = require('../modules/commands/command');
|
2021-05-22 02:04:18 +03:00
|
|
|
const {
|
2021-09-24 17:32:36 +03:00
|
|
|
Interaction, // eslint-disable-line no-unused-vars
|
2021-05-22 02:04:18 +03:00
|
|
|
MessageEmbed
|
|
|
|
} = require('discord.js');
|
2021-05-16 17:11:24 +03:00
|
|
|
|
|
|
|
module.exports = class RemoveCommand extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
const i18n = client.i18n.getLocale(client.config.locale);
|
|
|
|
super(client, {
|
2021-09-24 17:32:36 +03:00
|
|
|
description: i18n('commands.remove.description'),
|
|
|
|
internal: true,
|
|
|
|
name: i18n('commands.remove.name'),
|
|
|
|
options: [
|
2021-05-16 17:11:24 +03:00
|
|
|
{
|
2021-09-24 17:32:36 +03:00
|
|
|
description: i18n('commands.remove.options.member.description'),
|
|
|
|
name: i18n('commands.remove.options.member.name'),
|
|
|
|
required: true,
|
|
|
|
type: Command.option_types.USER
|
2021-05-16 17:11:24 +03:00
|
|
|
},
|
|
|
|
{
|
2021-09-24 17:32:36 +03:00
|
|
|
description: i18n('commands.remove.options.ticket.description'),
|
|
|
|
name: i18n('commands.remove.options.ticket.name'),
|
|
|
|
required: false,
|
|
|
|
type: Command.option_types.CHANNEL
|
2021-05-16 17:11:24 +03:00
|
|
|
}
|
2021-09-24 17:32:36 +03:00
|
|
|
]
|
2021-05-16 17:11:24 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-17 23:16:58 +03:00
|
|
|
/**
|
2021-09-24 17:32:36 +03:00
|
|
|
* @param {Interaction} interaction
|
2021-05-17 23:16:58 +03:00
|
|
|
* @returns {Promise<void|any>}
|
|
|
|
*/
|
2021-09-24 17:32:36 +03:00
|
|
|
async execute(interaction) {
|
|
|
|
const settings = await this.client.utils.getSettings(interaction.guild.id);
|
|
|
|
const default_i18n = this.client.i18n.getLocale(this.client.config.defaults.locale); // command properties could be in a different locale
|
2021-05-16 17:11:24 +03:00
|
|
|
const i18n = this.client.i18n.getLocale(settings.locale);
|
2021-05-16 21:48:02 +03:00
|
|
|
|
2021-09-24 17:32:36 +03:00
|
|
|
const channel = interaction.options.getChannel(default_i18n('commands.remove.options.channel.name')) ?? interaction.channel;
|
|
|
|
const t_row = await this.client.tickets.resolve(channel.id, interaction.guild.id);
|
2021-05-16 21:48:02 +03:00
|
|
|
|
|
|
|
if (!t_row) {
|
2021-10-27 01:25:38 +03:00
|
|
|
return await interaction.reply({
|
2021-08-16 23:05:20 +03:00
|
|
|
embeds: [
|
|
|
|
new MessageEmbed()
|
|
|
|
.setColor(settings.error_colour)
|
2021-09-24 17:32:36 +03:00
|
|
|
.setTitle(i18n('commands.remove.response.not_a_channel.title'))
|
|
|
|
.setDescription(i18n('commands.remove.response.not_a_channel.description'))
|
|
|
|
.setFooter(settings.footer, interaction.guild.iconURL())
|
|
|
|
],
|
|
|
|
ephemeral: true
|
2021-08-16 23:05:20 +03:00
|
|
|
});
|
2021-05-16 21:48:02 +03:00
|
|
|
}
|
|
|
|
|
2021-09-24 17:32:36 +03:00
|
|
|
const member = interaction.options.getMember(default_i18n('commands.remove.options.member.name'));
|
2021-05-16 21:48:02 +03:00
|
|
|
|
|
|
|
if (!member) {
|
2021-10-27 01:25:38 +03:00
|
|
|
return await interaction.reply({
|
2021-08-16 23:05:20 +03:00
|
|
|
embeds: [
|
|
|
|
new MessageEmbed()
|
|
|
|
.setColor(settings.error_colour)
|
|
|
|
.setTitle(i18n('commands.remove.response.no_member.title'))
|
|
|
|
.setDescription(i18n('commands.remove.response.no_member.description'))
|
2021-09-24 17:32:36 +03:00
|
|
|
.setFooter(settings.footer, interaction.guild.iconURL())
|
|
|
|
],
|
|
|
|
ephemeral: true
|
2021-08-16 23:05:20 +03:00
|
|
|
});
|
2021-05-16 21:48:02 +03:00
|
|
|
}
|
|
|
|
|
2021-09-24 17:32:36 +03:00
|
|
|
if (t_row.creator !== interaction.user.id && !await this.client.utils.isStaff(interaction.member)) {
|
2021-10-27 01:25:38 +03:00
|
|
|
return await interaction.reply({
|
2021-08-16 23:05:20 +03:00
|
|
|
embeds: [
|
|
|
|
new MessageEmbed()
|
|
|
|
.setColor(settings.error_colour)
|
|
|
|
.setTitle(i18n('commands.remove.response.no_permission.title'))
|
|
|
|
.setDescription(i18n('commands.remove.response.no_permission.description'))
|
2021-09-24 17:32:36 +03:00
|
|
|
.setFooter(settings.footer, interaction.guild.iconURL())
|
|
|
|
],
|
|
|
|
ephemeral: true
|
2021-08-16 23:05:20 +03:00
|
|
|
});
|
2021-05-16 21:48:02 +03:00
|
|
|
}
|
|
|
|
|
2021-10-27 01:25:38 +03:00
|
|
|
await interaction.reply({
|
2021-09-24 17:32:36 +03:00
|
|
|
embeds: [
|
|
|
|
new MessageEmbed()
|
|
|
|
.setColor(settings.success_colour)
|
|
|
|
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
|
|
|
.setTitle(i18n('commands.remove.response.removed.title'))
|
|
|
|
.setDescription(i18n('commands.remove.response.removed.description', member.toString(), channel.toString()))
|
|
|
|
.setFooter(settings.footer, interaction.guild.iconURL())
|
|
|
|
],
|
|
|
|
ephemeral: true
|
|
|
|
});
|
2021-08-16 23:05:20 +03:00
|
|
|
|
2021-09-24 17:32:36 +03:00
|
|
|
await channel.send({
|
2021-08-16 23:05:20 +03:00
|
|
|
embeds: [
|
2021-05-16 21:48:02 +03:00
|
|
|
new MessageEmbed()
|
2021-08-16 23:05:20 +03:00
|
|
|
.setColor(settings.colour)
|
2021-05-16 21:48:02 +03:00
|
|
|
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
2021-08-16 23:05:20 +03:00
|
|
|
.setTitle(i18n('ticket.member_removed.title'))
|
2021-09-24 17:32:36 +03:00
|
|
|
.setDescription(i18n('ticket.member_removed.description', member.toString(), interaction.user.toString()))
|
|
|
|
.setFooter(settings.footer, interaction.guild.iconURL())
|
2021-08-16 23:05:20 +03:00
|
|
|
]
|
|
|
|
});
|
2021-05-16 21:48:02 +03:00
|
|
|
|
2021-09-24 17:32:36 +03:00
|
|
|
await channel.permissionOverwrites.delete(member.user.id, `${interaction.user.tag} removed ${member.user.tag} from the ticket`);
|
2021-05-16 21:48:02 +03:00
|
|
|
|
2021-09-24 17:32:36 +03:00
|
|
|
this.client.log.info(`${interaction.user.tag} removed ${member.user.tag} from ${channel.id}`);
|
2021-05-16 17:11:24 +03:00
|
|
|
}
|
2021-08-16 23:05:20 +03:00
|
|
|
};
|