From cba907cd29ed01d437b24e8f5e54c74862efbf13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A7=81Ash=C3=BB=EA=A7=82?= <30575805+Ashu11-A@users.noreply.github.com> Date: Fri, 14 Jun 2024 00:40:46 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=AB=20Don't=20let=20the=20Template=20b?= =?UTF-8?q?e=20deleted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/discord/events/messageDelete.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/plugins/tickets/src/discord/events/messageDelete.ts b/plugins/tickets/src/discord/events/messageDelete.ts index 7b543906..0e72948d 100644 --- a/plugins/tickets/src/discord/events/messageDelete.ts +++ b/plugins/tickets/src/discord/events/messageDelete.ts @@ -5,6 +5,9 @@ import Claim from "@/entity/Claim.entry.js" import Ticket from "@/entity/Ticket.entry.js" import { AuditLogEvent, EmbedBuilder, Message, MessageFlagsBitField } from "discord.js" import { Event } from "../base/Event.js" +import { templateDB, ticketDB } from "@/functions/database.js" +import { TemplateBuilder } from "@/class/TemplateBuilder.js" +import { TemplateButtonBuilder } from "@/class/TemplateButtonBuilder.js" const ticket = new Database({ table: 'Ticket' }) const claim = new Database({ table: 'Claim' }) @@ -34,6 +37,30 @@ new Event({ }, }) +/** + * Se o Template for apagado (Recrie-o) + */ +new Event({ + name: 'messageDelete', + async run(message) { + if (!message.author?.bot || !(message instanceof Message) || !message.inGuild()) return + const template = await templateDB.findOne({ where: { messageId: message.id } }) + if (template === null) return + + const embed = new TemplateBuilder({ interaction: message }) + .render(message.embeds[0].toJSON()) + const buttons = new TemplateButtonBuilder() + .setProperties(template.properties) + .setSelects(template.selects) + .setMode('production') + .render() + + const newMessage = await message.channel.send({ embeds: [embed], components: buttons }) + + await templateDB.update({ id: template.id }, { messageId: newMessage.id }) + }, +}) + /** * Se a mensagem inicial do ticket for apagada (isso irĂ¡ recriar ela). */