mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-23 00:03:09 +02:00
fix: make /move
edit the channel name and permission overwrites
This commit is contained in:
parent
3b50135cc0
commit
a953308532
@ -62,6 +62,7 @@ module.exports = class MoveSlashCommand extends SlashCommand {
|
||||
});
|
||||
}
|
||||
|
||||
const creator = await interaction.guild.members.fetch(ticket.createdById);
|
||||
const newCategory = await client.prisma.category.findUnique({ where: { id: interaction.options.getInteger('category', true) } });
|
||||
const discordCategory = await interaction.guild.channels.fetch(newCategory.discordCategory);
|
||||
const getMessage = client.i18n.getLocale(ticket.guild.locale);
|
||||
@ -80,6 +81,7 @@ module.exports = class MoveSlashCommand extends SlashCommand {
|
||||
ephemeral: true,
|
||||
});
|
||||
} else {
|
||||
// don't reassign `ticket`, the previous value is used below
|
||||
await client.prisma.ticket.update({
|
||||
data: { category: { connect: { id: newCategory.id } } },
|
||||
where: { id: ticket.id },
|
||||
@ -97,10 +99,43 @@ module.exports = class MoveSlashCommand extends SlashCommand {
|
||||
$newCategory[ticket.createdById] ||= 0;
|
||||
$newCategory[ticket.createdById]++;
|
||||
|
||||
await interaction.channel.setParent(discordCategory, {
|
||||
lockPermissions: false,
|
||||
reason: `Moved by ${interaction.user.tag}`,
|
||||
});
|
||||
// these 3 could be done separately,
|
||||
// but using `setParent`, `setName` etc instead of a single `edit` call increases the number of API requests
|
||||
if (
|
||||
newCategory.staffRoles !== ticket.category.staffRoles ||
|
||||
newCategory.channelName !== ticket.category.channelName ||
|
||||
newCategory.discordCategory !== ticket.category.discordCategory
|
||||
) {
|
||||
const allow = ['ViewChannel', 'ReadMessageHistory', 'SendMessages', 'EmbedLinks', 'AttachFiles'];
|
||||
const channelName = newCategory.channelName
|
||||
.replace(/{+\s?(user)?name\s?}+/gi, creator.user.username)
|
||||
.replace(/{+\s?(nick|display)(name)?\s?}+/gi, creator.displayName)
|
||||
.replace(/{+\s?num(ber)?\s?}+/gi, ticket.number === 1488 ? '1487b' : ticket.number);
|
||||
await interaction.channel.edit({
|
||||
lockPermissions: false,
|
||||
name: channelName,
|
||||
parent: discordCategory,
|
||||
permissionOverwrites: [
|
||||
{
|
||||
deny: ['ViewChannel'],
|
||||
id: interaction.guild.roles.everyone,
|
||||
},
|
||||
{
|
||||
allow,
|
||||
id: this.client.user.id,
|
||||
},
|
||||
{
|
||||
allow,
|
||||
id: creator.id,
|
||||
},
|
||||
...newCategory.staffRoles.map(id => ({
|
||||
allow,
|
||||
id,
|
||||
})),
|
||||
],
|
||||
reason: `Moved by ${interaction.user.tag}`,
|
||||
});
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
|
Loading…
Reference in New Issue
Block a user