fix: edit channel name when transferring (closes #470)

This commit is contained in:
Isaac 2023-08-25 01:06:26 +01:00
parent 59a6358b37
commit 77e5b45aa8
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33

View File

@ -42,10 +42,16 @@ module.exports = class TransferSlashCommand extends SlashCommand {
const member = interaction.options.getMember('member', true);
let ticket = await client.prisma.ticket.findUnique({ where: { id: interaction.channel.id } });
const ticket = await client.prisma.ticket.findUnique({
include: {
category: true,
guild: true,
},
where: { id: interaction.channel.id },
});
const from = ticket.createdById;
ticket = await client.prisma.ticket.update({
await client.prisma.ticket.update({
data: {
createdBy: {
connectOrCreate: {
@ -54,10 +60,19 @@ module.exports = class TransferSlashCommand extends SlashCommand {
},
},
},
include: { guild: true },
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()
@ -71,8 +86,6 @@ 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,
{