Skip to content

Commit

Permalink
🚫 Don't let the Template be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Jun 14, 2024
1 parent 11f4837 commit cba907c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions plugins/tickets/src/discord/events/messageDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ticket>({ table: 'Ticket' })
const claim = new Database<Claim>({ table: 'Claim' })
Expand Down Expand Up @@ -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).
*/
Expand Down

0 comments on commit cba907c

Please sign in to comment.