From 4b40f2cdbd296f2325bdb0b9006a5be9fb4f5fc3 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 29 Oct 2022 19:59:09 +0100 Subject: [PATCH] feat: add `/transfer` command --- src/commands/slash/transfer.js | 50 ++++++++++++++++++++++++++++++++-- src/i18n/en-GB.yml | 1 + 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/commands/slash/transfer.js b/src/commands/slash/transfer.js index fb23a3e..66b1b4e 100644 --- a/src/commands/slash/transfer.js +++ b/src/commands/slash/transfer.js @@ -1,5 +1,10 @@ const { SlashCommand } = require('@eartharoid/dbf'); -const { ApplicationCommandOptionType } = require('discord.js'); +const { + ApplicationCommandOptionType, + EmbedBuilder, +} = require('discord.js'); +const Cryptr = require('cryptr'); +const { decrypt } = new Cryptr(process.env.ENCRYPTION_KEY); module.exports = class TransferSlashCommand extends SlashCommand { constructor(client, options) { @@ -26,5 +31,46 @@ module.exports = class TransferSlashCommand extends SlashCommand { }); } - async run(interaction) {} + /** + * @param {import("discord.js").ChatInputCommandInteraction} interaction + */ + async run(interaction) { + /** @type {import("client")} */ + const client = this.client; + + await interaction.deferReply({ ephemeral: false }); + + const member = interaction.options.getMember('member', true); + + let ticket = await client.prisma.ticket.findUnique({ where: { id: interaction.channel.id } }); + const from = ticket.createdById; + + ticket = await client.prisma.ticket.update({ + data: { + createdBy: { + connectOrCreate: { + create: { id: member.id }, + where: { id: member.id }, + }, + }, + }, + include: { guild: true }, + 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', { + from: `<@${from}>`, + to: member.toString(), + user: interaction.user.toString(), + })), + + ], + }); + } }; diff --git a/src/i18n/en-GB.yml b/src/i18n/en-GB.yml index 9a10e85..ccf46a6 100644 --- a/src/i18n/en-GB.yml +++ b/src/i18n/en-GB.yml @@ -220,6 +220,7 @@ commands: member: description: The member to transfer ownership to name: member + transferred: 📨 {user} has transferred this ticket from {from} to {to}. user: create: name: Create a ticket for user