feat: add /move command

This commit is contained in:
Isaac
2022-10-31 21:15:44 +00:00
parent d10965d541
commit 9f18958c75
6 changed files with 130 additions and 16 deletions

View File

@@ -17,12 +17,6 @@ module.exports = class CloseSlashCommand extends SlashCommand {
required: false,
type: ApplicationCommandOptionType.String,
},
{
autocomplete: true,
name: 'ticket',
required: false,
type: ApplicationCommandOptionType.String,
},
].map(option => {
option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`);
option.description = option.descriptionLocalizations['en-GB'];

View File

@@ -1,5 +1,6 @@
const { SlashCommand } = require('@eartharoid/dbf');
const { ApplicationCommandOptionType } = require('discord.js');
const ExtendedEmbedBuilder = require('../../lib/embed');
module.exports = class MoveSlashCommand extends SlashCommand {
constructor(client, options) {
@@ -27,8 +28,92 @@ module.exports = class MoveSlashCommand extends SlashCommand {
});
}
/**
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
async run(interaction) {
// TODO: check discordCategory max but not category max (ignore)
// TODO: update cached count for both categories and category-members (from and to)
/** @type {import("client")} */
const client = this.client;
await interaction.deferReply({ ephemeral: false });
const ticket = await client.prisma.ticket.findUnique({
include: {
category: true,
guild: true,
},
where: { id: interaction.channel.id },
});
if (!ticket) {
const { locale } = await client.prisma.guild.findUnique({ where: { id: interaction.guild.id } });
const getMessage = client.i18n.getLocale(locale);
return await interaction.editReply({
embeds: [
new ExtendedEmbedBuilder({
iconURL: interaction.guild.iconURL(),
text: ticket.guild.footer,
})
.setColor(ticket.guild.errorColour)
.setTitle(getMessage('misc.not_ticket.title'))
.setDescription(getMessage('misc.not_ticket.description')),
],
ephemeral: true,
});
}
const newCategory = await client.prisma.category.findUnique({ where: { id: interaction.options.getInteger('category', true) } });
const discordCategory = await interaction.guild.channels.fetch(newCategory.discordCategory);
const getMessage = client.i18n.getLocale(ticket.guild.locale);
if (discordCategory.children.cache.size === 50) {
return await interaction.editReply({
embeds: [
new ExtendedEmbedBuilder({
iconURL: interaction.guild.iconURL(),
text: ticket.guild.footer,
})
.setColor(ticket.guild.errorColour)
.setTitle(getMessage('misc.category_full.title'))
.setDescription(getMessage('misc.category_full.description')),
],
ephemeral: true,
});
} else {
await client.prisma.ticket.update({
data: { category: { connect: { id: newCategory.id } } },
where: { id: ticket.id },
});
const $oldCategory = client.tickets.$.categories[ticket.categoryId];
const $newCategory = client.tickets.$.categories[newCategory.id];
$oldCategory.total--;
$oldCategory[ticket.createdById]--;
if (!$newCategory.total) $newCategory.total = 0;
$newCategory.total++;
if (!$newCategory[ticket.createdById]) $newCategory[ticket.createdById] = 0;
$newCategory[ticket.createdById]++;
await interaction.channel.setParent(discordCategory, {
lockPermissions: false,
reason: `Moved by ${interaction.user.tag}`,
});
await interaction.editReply({
embeds: [
new ExtendedEmbedBuilder()
.setColor(ticket.guild.primaryColour)
.setDescription(getMessage('commands.slash.move.moved', {
by: interaction.user.toString(),
from: ticket.category.name,
to: newCategory.name,
})),
],
});
}
}
};

View File

@@ -44,7 +44,7 @@ module.exports = class TransferSlashCommand extends SlashCommand {
let ticket = await client.prisma.ticket.findUnique({ where: { id: interaction.channel.id } });
const from = ticket.createdById;
console.log(1)
ticket = await client.prisma.ticket.update({
data: {
createdBy: {
@@ -58,13 +58,11 @@ module.exports = class TransferSlashCommand extends SlashCommand {
where: { id: interaction.channel.id },
});
await interaction.channel.setTopic(`${member.toString()}${ticket.topic?.length > 0 ? ` | ${decrypt(ticket.topic)}` : ''}`);
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor(ticket.guild.primaryColour)
.setDescription(client.i18n.getMessage(ticket.guild.locale, 'commands.slash.transfer.transferred', {
.setDescription(client.i18n.getMessage(ticket.guild.locale, `commands.slash.transfer.transferred${interaction.member.id !== from ? '_from' : ''}`, {
from: `<@${from}>`,
to: member.toString(),
user: interaction.user.toString(),
@@ -72,5 +70,18 @@ module.exports = class TransferSlashCommand extends SlashCommand {
],
});
await interaction.channel.setTopic(`${member.toString()}${ticket.topic?.length > 0 ? ` | ${decrypt(ticket.topic)}` : ''}`);
await interaction.channel.permissionOverwrites.edit(
member,
{
AttachFiles: true,
EmbedLinks: true,
ReadMessageHistory: true,
SendMessages: true,
ViewChannel: true,
},
);
}
};