is it a hack if it works?

This commit is contained in:
MathMan05
2025-11-22 16:07:00 -06:00
committed by Rory&
parent 85d09bd445
commit 8bf62e1f57
3 changed files with 32 additions and 3 deletions
+1 -1
View File
@@ -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({
+1 -1
View File
@@ -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 }),
+30 -1
View File
@@ -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<Message>) {
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<Message>): Promise<Message> {
Message.addDefault(options as FindOneOptions<Message>);
//@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<Message>): Promise<Message> {
Message.addDefault(options as FindOneOptions<Message>);
//@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<Message>): Promise<Message[]> {
Message.addDefault(options as FindOneOptions<Message>);
//@ts-expect-error how to use generics on call, who knows!
return BaseEntity.find.call(Message, options);
};