Skip to content

Commit

Permalink
fix: edit channel name when transferring (closes #470)
Browse files Browse the repository at this point in the history
  • Loading branch information
eartharoid committed Aug 25, 2023
1 parent 59a6358 commit 77e5b45
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/commands/slash/transfer.js
Expand Up @@ -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: {
Expand All @@ -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()
Expand All @@ -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,
{
Expand Down

0 comments on commit 77e5b45

Please sign in to comment.