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); 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; const from = ticket.createdById;
ticket = await client.prisma.ticket.update({ await client.prisma.ticket.update({
data: { data: {
createdBy: { createdBy: {
connectOrCreate: { connectOrCreate: {
@ -54,10 +60,19 @@ module.exports = class TransferSlashCommand extends SlashCommand {
}, },
}, },
}, },
include: { guild: true },
where: { id: interaction.channel.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({ await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() 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( await interaction.channel.permissionOverwrites.edit(
member, member,
{ {