mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-25 16:24:45 +00:00
is it a hack if it works?
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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 }),
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user