DiscordTickets/src/commands/remove.js
Puneet Gopinath 0f10908ee0
refactor: update to discord.js v13 (#203)
* build: bump djs version

* refactor(add): update

* refactor(blacklist): update

* refactor(close): update

* refactor(help): update

* refactor(new): update

* refactor(panel): update

* refactor(remove): update

* refactor(stats): update

* refactor(survey): update

* refactor(tag): update

* refactor(topic): update

* refactor(guild): update, now Structures doesn't exist

Also I don't know if this would work actually, let's see

* refactor(guild_member)

* refactor(index.js): add intents

I can't understand how you do the indentation, sorry if I made a mistake

* Update package.json

* fix(intents): add `DIRECT_MESSAGES` intents


- also fix code style and indentation

* style: fix properties order and indentation

* fix(guild)

* Update and rename message.js to messageCreate.js

* Update guild.js

* refactor(manager): fix

* Update manager.js

* fix(help)

* style: fix spacing

* fix: permission overwrites

* fix(new)

* fix(presence): rename activity to activities

* fix(presence): fix debug message

* fix: update channel types

* Update new.js

* fix(embeds): update footer function

* fix: broken code

* style: add new lines around embed blocks

* fix(messages): update remaining `send()` calls

* fix(messages): i missed one

* build: replace fastify logger with standard logger

* refactor: update message and reaction collectors

Co-authored-by: Isaac <git@eartharoid.me>
2021-08-16 21:05:20 +01:00

114 lines
3.6 KiB
JavaScript

const Command = require('../modules/commands/command');
const {
Message, // eslint-disable-line no-unused-vars
MessageEmbed
} = require('discord.js');
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'),
name: i18n('commands.remove.args.member.name'),
required: true
},
{
description: i18n('commands.remove.args.ticket.description'),
example: i18n('commands.remove.args.ticket.example'),
name: i18n('commands.remove.args.ticket.name'),
required: false
}
],
description: i18n('commands.remove.description'),
internal: true,
name: i18n('commands.remove.name'),
process_args: false
});
}
/**
* @param {Message} message
* @param {string} args
* @returns {Promise<void|any>}
*/
async execute(message, args) {
const settings = await this.client.utils.getSettings(message.guild);
const i18n = this.client.i18n.getLocale(settings.locale);
const ticket = message.mentions.channels.first() ?? message.channel;
const t_row = await this.client.tickets.resolve(ticket.id, message.guild.id);
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())
]
});
}
const member = message.mentions.members.first() ?? message.guild.members.cache.get(args);
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())
]
});
}
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())
]
});
}
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: [
new MessageEmbed()
.setColor(settings.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(i18n('ticket.member_removed.title'))
.setDescription(i18n('ticket.member_removed.description', member.toString(), message.author.toString()))
.setFooter(settings.footer, message.guild.iconURL())
]
});
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}`);
}
};