Skip to content

Commit

Permalink
feat: add /transfer command
Browse files Browse the repository at this point in the history
  • Loading branch information
eartharoid committed Oct 29, 2022
1 parent 26ab229 commit 4b40f2c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
50 changes: 48 additions & 2 deletions 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) {
Expand All @@ -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(),
})),

],
});
}
};
1 change: 1 addition & 0 deletions src/i18n/en-GB.yml
Expand Up @@ -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
Expand Down

0 comments on commit 4b40f2c

Please sign in to comment.