-
-
Notifications
You must be signed in to change notification settings - Fork 443
/
transfer.js
100 lines (89 loc) · 2.84 KB
/
transfer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const { SlashCommand } = require('@eartharoid/dbf');
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) {
const name = 'transfer';
super(client, {
...options,
description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false,
name,
nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
options: [
{
name: 'member',
required: true,
type: ApplicationCommandOptionType.User,
},
].map(option => {
option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`);
option.description = option.descriptionLocalizations['en-GB'];
option.nameLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.name`);
return option;
}),
});
}
/**
* @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);
const ticket = await client.prisma.ticket.findUnique({
include: {
category: true,
guild: true,
},
where: { id: interaction.channel.id },
});
const from = ticket.createdById;
await client.prisma.ticket.update({
data: {
createdBy: {
connectOrCreate: {
create: { id: member.id },
where: { id: member.id },
},
},
},
where: { id: interaction.channel.id },
});
const channelName = ticket.category.channelName
.replace(/{+\s?(user)?name\s?}+/gi, member.user.username)
.replace(/{+\s?(nick|display)(name)?\s?}+/gi, member.displayName)
.replace(/{+\s?num(ber)?\s?}+/gi, ticket.number === 1488 ? '1487b' : ticket.number);
await interaction.channel.edit({
name: channelName,
topic: `${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${interaction.member.id !== from ? '_from' : ''}`, {
from: `<@${from}>`,
to: member.toString(),
user: interaction.user.toString(),
})),
],
});
await interaction.channel.permissionOverwrites.edit(
member,
{
AttachFiles: true,
EmbedLinks: true,
ReadMessageHistory: true,
SendMessages: true,
ViewChannel: true,
},
);
}
};