feat: add /transfer command

This commit is contained in:
Isaac 2022-10-29 19:59:09 +01:00
parent 26ab229c97
commit 4b40f2cdbd
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
2 changed files with 49 additions and 2 deletions

View File

@ -1,5 +1,10 @@
const { SlashCommand } = require('@eartharoid/dbf'); 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 { module.exports = class TransferSlashCommand extends SlashCommand {
constructor(client, options) { 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(),
})),
],
});
}
}; };

View File

@ -220,6 +220,7 @@ commands:
member: member:
description: The member to transfer ownership to description: The member to transfer ownership to
name: member name: member
transferred: 📨 {user} has transferred this ticket from {from} to {to}.
user: user:
create: create:
name: Create a ticket for user name: Create a ticket for user