From 5be5eca351a36f40398c5d0a89f0753d584096ef Mon Sep 17 00:00:00 2001 From: pineafan Date: Thu, 19 May 2022 21:37:08 +0100 Subject: [PATCH] changes to tickets --- src/automations/tickets/create.ts | 5 +++++ src/automations/tickets/delete.ts | 26 +++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/automations/tickets/create.ts b/src/automations/tickets/create.ts index 1fd743b..fd0ae57 100644 --- a/src/automations/tickets/create.ts +++ b/src/automations/tickets/create.ts @@ -118,6 +118,11 @@ export default async function (interaction) { allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"], type: "member" }] as Discord.OverwriteResolvable[]; + overwrites.push({ + id: interaction.guild.roles.everyone, + deny: ["VIEW_CHANNEL"], + type: "role" + }) if (config.tickets.supportRole != null) { overwrites.push({ id: interaction.guild.roles.cache.get(config.tickets.supportRole), diff --git a/src/automations/tickets/delete.ts b/src/automations/tickets/delete.ts index 8feeb4b..32315bc 100644 --- a/src/automations/tickets/delete.ts +++ b/src/automations/tickets/delete.ts @@ -9,10 +9,10 @@ export default async function (interaction) { let config = await readConfig(interaction.guild.id); let channel = (interaction.channel as Discord.TextChannel) - if (config.tickets.category != channel.parent.id) { + if (!channel.parent || config.tickets.category != channel.parent.id) { return interaction.reply({embeds: [new generateEmojiEmbed() .setTitle("Close Ticket") - .setDescription("This ticket is not in your tickets category, so cannot be deleted.") + .setDescription("This ticket is not in your tickets category, so cannot be deleted. You cannot run close in a thread.") // TODO bridge to cross later! .setStatus("Danger") .setEmoji("CONTROL.BLOCKCROSS") ], ephemeral: true}); @@ -56,7 +56,26 @@ export default async function (interaction) { .setEmoji("GUILD.TICKET.ARCHIVED") ]}); setTimeout(async () =>{ - channel.permissionsFor(await interaction.guild.members.fetch(channel.topic.split(" ")[0])).remove("VIEW_CHANNEL"); + let overwrites = [ + { + id: channel.topic.split(" ")[0], + deny: ["VIEW_CHANNEL"], + type: "member" + }, + { + id: interaction.guild.id, + deny: ["VIEW_CHANNEL"], + type: "role" + } + ] as Discord.OverwriteResolvable[]; + if (config.tickets.supportRole != null) { + overwrites.push({ + id: interaction.guild.roles.cache.get(config.tickets.supportRole), + allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"], + type: "role" + }) + } + channel.edit({permissionOverwrites: overwrites}) channel.setTopic(`${channel.topic.split(" ")[0]} Archived`); let data = { meta:{ @@ -98,6 +117,7 @@ async function purgeByUser(member, guild) { let config = await readConfig(guild.id); if (!config.tickets.category) return; let tickets = guild.channels.cache.get(config.tickets.category); + if (!tickets) return; let ticketChannels = tickets.children; let deleted = 0 ticketChannels.forEach(element => {