Skip to content

Commit

Permalink
🚫 Don't allow the main message to be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Jun 7, 2024
1 parent 747ae53 commit 72a160c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
36 changes: 36 additions & 0 deletions plugins/tickets/src/discord/events/claimMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ClaimBuilder } from "@/class/ClaimBuilder";
import { Database } from "@/controller/database";
import Claim from "@/entity/Claim.entry";
import { AuditLogEvent, EmbedBuilder } from "discord.js";
import { Event } from "../base";
const claim = new Database<Claim>({ table: 'Claim' })

new Event({
name: 'messageDelete',
async run(message) {
if (!message.inGuild()) return
const { id } = message
const claimData = await claim.findOne({ where: { messageId: id }, relations: { ticket: true } })
if (claimData === null || claimData?.ticket?.id === undefined) return

const builder = await new ClaimBuilder({ interaction: message }).setTicketId(claimData.ticket.id).render()
if (builder === undefined) return

const nemMessage = await message.channel.send({
embeds: [builder.embed as EmbedBuilder],
components: builder.buttons
})

await claim.save(Object.assign(claimData, { messageId: nemMessage.id }))

const auditLog = (await message.guild.fetchAuditLogs({ type: AuditLogEvent.MessageDelete })).entries.first()
await message.channel.send({
content: auditLog?.executor?.id !== undefined ? `<@${auditLog?.executor?.id}>` : undefined,
embeds: [new EmbedBuilder({
title: '⚠️ Não é possivel deletar a messagem acima!',
footer: { text: 'Essa mensagem será deletada em 5s' }
}).setColor('Red')]
})
.then(async (msg) => setTimeout(() => { msg.delete() }, 5000))
},
})
39 changes: 35 additions & 4 deletions plugins/tickets/src/discord/events/ticketMessage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Ticket from "@/entity/Ticket.entry";
import { Event } from "../base";
import { Database } from "@/controller/database";
import { TicketBuilder } from "@/class/TicketBuilder";
import { console } from "@/controller/console";
import { Message } from "discord.js";
import { Database } from "@/controller/database";
import Ticket from "@/entity/Ticket.entry";
import { AuditLogEvent, EmbedBuilder, Message } from "discord.js";
import { Event } from "../base";
const ticket = new Database<Ticket>({ table: 'Ticket' })

new Event({
Expand Down Expand Up @@ -58,4 +58,35 @@ new Event({
await builder.setData(ticketData).edit({ id: ticketData.id })
console.info(`⚠️ Uma mensagem foi apagada! ticketId: ${ticketData.id}`)
},
})

new Event({
name: 'messageDelete',
async run(message) {
if (!message.inGuild() || await message.fetch().catch(() => null) !== null) return
const { id } = message
const ticketData = await ticket.findOne({ where: { messageId: id } })
if (ticketData === null) return

const owner = await message.client.users.fetch(ticketData.ownerId).catch(() => null)
if (owner === null) return

const builder = new TicketBuilder({ interaction: message }).setData(ticketData).setUser(owner).render()
const nemMessage = await message.channel.send({
embeds: [builder.embed as EmbedBuilder],
components: builder.buttons
})

ticket.save(Object.assign(ticketData, { messageId: nemMessage.id }))

const auditLog = (await message.guild.fetchAuditLogs({ type: AuditLogEvent.MessageDelete })).entries.first()
await message.channel.send({
content: auditLog?.executor?.id !== undefined ? `<@${auditLog?.executor?.id}>` : undefined,
embeds: [new EmbedBuilder({
title: '⚠️ Não é possivel deletar a messagem acima!',
footer: { text: 'Essa mensagem será deletada em 5s' }
}).setColor('Red')]
})
.then(async (msg) => setTimeout(() => { msg.delete() }, 5000))
}
})

0 comments on commit 72a160c

Please sign in to comment.