DiscordTickets/src/commands/remove.js

114 lines
3.6 KiB
JavaScript
Raw Normal View History

2021-05-16 17:11:24 +03:00
const Command = require('../modules/commands/command');
2021-05-22 02:04:18 +03:00
const {
Message, // eslint-disable-line no-unused-vars
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, {
aliases: [],
args: [
{
description: i18n('commands.remove.args.member.description'),
example: i18n('commands.remove.args.member.example'),
2021-05-22 02:04:18 +03:00
name: i18n('commands.remove.args.member.name'),
required: true
2021-05-16 17:11:24 +03:00
},
{
description: i18n('commands.remove.args.ticket.description'),
example: i18n('commands.remove.args.ticket.example'),
2021-05-22 02:04:18 +03:00
name: i18n('commands.remove.args.ticket.name'),
required: false
2021-05-16 17:11:24 +03:00
}
2021-05-22 02:04:18 +03:00
],
description: i18n('commands.remove.description'),
internal: true,
name: i18n('commands.remove.name'),
process_args: false
2021-05-16 17:11:24 +03:00
});
}
2021-05-17 23:16:58 +03:00
/**
* @param {Message} message
* @param {string} args
* @returns {Promise<void|any>}
*/
2021-05-16 17:11:24 +03:00
async execute(message, args) {
const settings = await this.client.utils.getSettings(message.guild);
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-05-18 20:12:07 +03:00
const ticket = message.mentions.channels.first() ?? message.channel;
const t_row = await this.client.tickets.resolve(ticket.id, message.guild.id);
2021-05-16 21:48:02 +03:00
if (!t_row) {
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.remove.response.not_a_ticket.title'))
.setDescription(i18n('commands.remove.response.not_a_ticket.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
2021-05-16 21:48:02 +03:00
}
2021-05-18 20:12:07 +03:00
const member = message.mentions.members.first() ?? message.guild.members.cache.get(args);
2021-05-16 21:48:02 +03:00
if (!member) {
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.remove.response.no_member.title'))
.setDescription(i18n('commands.remove.response.no_member.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
2021-05-16 21:48:02 +03:00
}
if (t_row.creator !== message.author.id && !await this.client.utils.isStaff(message.member)) {
return await message.channel.send({
embeds: [
new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('commands.remove.response.no_permission.title'))
.setDescription(i18n('commands.remove.response.no_permission.description'))
.setFooter(settings.footer, message.guild.iconURL())
]
});
2021-05-16 21:48:02 +03:00
}
if (message.channel.id !== ticket.id) {
await message.channel.send({
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(), ticket.toString()))
.setFooter(settings.footer, message.guild.iconURL())
]
});
}
await ticket.send({
embeds: [
2021-05-16 21:48:02 +03:00
new MessageEmbed()
.setColor(settings.colour)
2021-05-16 21:48:02 +03:00
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('ticket.member_removed.title'))
.setDescription(i18n('ticket.member_removed.description', member.toString(), message.author.toString()))
2021-05-16 21:48:02 +03:00
.setFooter(settings.footer, message.guild.iconURL())
]
});
2021-05-16 21:48:02 +03:00
await ticket.permissionOverwrites
.get(member.user.id)
?.delete(`${message.author.tag} removed ${member.user.tag} from the ticket`);
this.client.log.info(`${message.author.tag} removed ${member.user.tag} from ${ticket.id}`);
2021-05-16 17:11:24 +03:00
}
};