From 9ce1c99cff371c90b4ae5c428b6e1a6777421de0 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: Thu, 13 Jun 2024 22:02:24 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=89=20Reduce=20unnecessary=20requests?= =?UTF-8?q?=20to=20the=20database?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tickets/src/discord/events/messageCreate.ts | 7 ++++--- .../tickets/src/discord/events/messageDelete.ts | 16 ++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/plugins/tickets/src/discord/events/messageCreate.ts b/plugins/tickets/src/discord/events/messageCreate.ts index 32dd9736..b060a20c 100644 --- a/plugins/tickets/src/discord/events/messageCreate.ts +++ b/plugins/tickets/src/discord/events/messageCreate.ts @@ -1,7 +1,8 @@ +import { TicketBuilder } from "@/class/TicketBuilder.js" import { Database } from "@/controller/database.js" -import { Event } from "../base/Event.js" import Ticket from "@/entity/Ticket.entry.js" -import { TicketBuilder } from "@/class/TicketBuilder.js" +import { MessageFlagsBitField } from "discord.js" +import { Event } from "../base/Event.js" const ticket = new Database({ table: 'Ticket' }) @@ -11,7 +12,7 @@ const ticket = new Database({ table: 'Ticket' }) new Event({ name: 'messageCreate', async run(message) { - if (!message.inGuild()) return + if (message.flags.has(MessageFlagsBitField.Flags.Ephemeral) || !message.inGuild()) return const { channelId, author, content, id, client } = message if (author.id === client.user.id) return const ticketData = await ticket.findOne({ where: { channelId: channelId } }) diff --git a/plugins/tickets/src/discord/events/messageDelete.ts b/plugins/tickets/src/discord/events/messageDelete.ts index fd58fc57..7b543906 100644 --- a/plugins/tickets/src/discord/events/messageDelete.ts +++ b/plugins/tickets/src/discord/events/messageDelete.ts @@ -1,10 +1,10 @@ +import { ClaimBuilder } from "@/class/ClaimBuilder.js" import { TicketBuilder } from "@/class/TicketBuilder.js" -import { Event } from "../base/Event.js" -import { AuditLogEvent, EmbedBuilder, Message } from "discord.js" import { Database } from "@/controller/database.js" -import Ticket from "@/entity/Ticket.entry.js" import Claim from "@/entity/Claim.entry.js" -import { ClaimBuilder } from "@/class/ClaimBuilder.js" +import Ticket from "@/entity/Ticket.entry.js" +import { AuditLogEvent, EmbedBuilder, Message, MessageFlagsBitField } from "discord.js" +import { Event } from "../base/Event.js" const ticket = new Database({ table: 'Ticket' }) const claim = new Database({ table: 'Claim' }) @@ -15,7 +15,7 @@ const claim = new Database({ table: 'Claim' }) new Event({ name: 'messageDelete', async run(message) { - if (!(message instanceof Message) || !message.inGuild()) return + if (!(message instanceof Message) || !message.inGuild() || message.author?.bot || message.flags.has(MessageFlagsBitField.Flags.Ephemeral)) return const { channelId, id } = message const ticketData = await ticket.findOne({ where: { channelId } }) if (ticketData === null) return @@ -35,12 +35,12 @@ new Event({ }) /** - * Se a mensagem inicial do ticket for apagada )isso irá recriar ela). + * Se a mensagem inicial do ticket for apagada (isso irá recriar ela). */ new Event({ name: 'messageDelete', async run(message) { - if (!message.inGuild() || await message.fetch().catch(() => null) !== null) return + if (!message.author?.bot || message.flags.has(MessageFlagsBitField.Flags.Ephemeral) || !message.inGuild() || await message.fetch().catch(() => null) !== null) return const { id } = message const ticketData = await ticket.findOne({ where: { messageId: id } }) if (ticketData === null) return @@ -73,7 +73,7 @@ new Event({ new Event({ name: 'messageDelete', async run(message) { - if (!message.inGuild()) return + if (!message.author?.bot || message.flags.has(MessageFlagsBitField.Flags.Ephemeral) || !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