diff --git a/src/api/routes/interactions/index.ts b/src/api/routes/interactions/index.ts index 6c192c692..9f1543952 100644 --- a/src/api/routes/interactions/index.ts +++ b/src/api/routes/interactions/index.ts @@ -91,7 +91,7 @@ router.post("/", route({}), async (req: Request, res: Response) => { } if (body.type === InteractionType.MessageComponent || body.data.type === InteractionType.ModalSubmit) { - interactionData.message = await Message.findOneOrFail({ where: { id: body.message_id }, relations: ["author"] }); + interactionData.message = await Message.findOneOrFail({ where: { id: body.message_id, flags: undefined }, relations: ["author"] }); } emitEvent({ diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts index 7f144a0c4..5e33850ae 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts @@ -530,7 +530,7 @@ export async function sendMessage(opts: MessageOptions) { const ephermal = (message.flags & (1 << 6)) !== 0; await Promise.all([ - ephermal ? null : Message.insert(message), + Message.insert(message), emitEvent({ event: "MESSAGE_CREATE", ...(ephermal ? { user_id: message.interaction_metadata?.user_id } : { channel_id: message.channel_id }), diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts index 8bedf805a..21892e397 100644 --- a/src/util/entities/Message.ts +++ b/src/util/entities/Message.ts @@ -22,7 +22,7 @@ import { Role } from "./Role"; import { Channel } from "./Channel"; import { InteractionType } from "../interfaces/Interaction"; import { Application } from "./Application"; -import { Column, CreateDateColumn, Entity, Index, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, RelationId } from "typeorm"; +import { Column, CreateDateColumn, Entity, Index, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, RelationId, FindOneOptions, Raw, Not, BaseEntity } from "typeorm"; import { BaseClass } from "./BaseClass"; import { Guild } from "./Guild"; import { Webhook } from "./Webhook"; @@ -306,4 +306,33 @@ export class Message extends BaseClass { }); return message; } + static addDefault(options: FindOneOptions) { + if (options.where) { + const arr = options.where instanceof Array ? options.where : [options.where]; + for (const thing of arr) { + if (!("flags" in thing)) { + thing.flags = Not(Raw((alias) => `${alias} & ${1 << 6} = ${1 << 6}`)); + } + } + } + } } + +//@ts-expect-error It works but TS types hate it +Message.findOneOrFail = function (this: Message, options: FindOneOptions): Promise { + Message.addDefault(options as FindOneOptions); + //@ts-expect-error how to use generics on call, who knows! + return BaseEntity.findOneOrFail.call(Message, options); +}; +//@ts-expect-error It works but TS types hate it +Message.findOne = function (this: Message, options: FindOneOptions): Promise { + Message.addDefault(options as FindOneOptions); + //@ts-expect-error how to use generics on call, who knows! + return BaseEntity.findOne.call(Message, options); +}; +//@ts-expect-error It works but TS types hate it +Message.find = function (this: Message, options: FindOneOptions): Promise { + Message.addDefault(options as FindOneOptions); + //@ts-expect-error how to use generics on call, who knows! + return BaseEntity.find.call(Message, options); +};