Make channel ID optional when replying

This commit is contained in:
TomatoCake 2024-07-17 12:31:09 +02:00 committed by Madeline
parent df9153f5ba
commit d3ece937e6
4 changed files with 6320 additions and 8 deletions

File diff suppressed because it is too large Load Diff

View File

@ -91,11 +91,10 @@ router.patch(
}
} else rights.hasThrow("SELF_EDIT_MESSAGES");
// @ts-expect-error Something is wrong with message_reference here, TS complains since "channel_id" is optional in MessageCreateSchema
const new_message = await handleMessage({
...message,
// TODO: should message_reference be overridable?
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
message_reference: message.message_reference,
...body,
author_id: message.author_id,

View File

@ -117,6 +117,12 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
const guild = await Guild.findOneOrFail({
where: { id: channel.guild_id },
});
if (!opts.message_reference.guild_id)
opts.message_reference.guild_id = channel.guild_id;
if (!opts.message_reference.channel_id)
opts.message_reference.channel_id = opts.channel_id;
if (!guild.features.includes("CROSS_CHANNEL_REPLIES")) {
if (opts.message_reference.guild_id !== channel.guild_id)
throw new HTTPError(
@ -127,6 +133,8 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
"You can only reference messages from this channel",
);
}
message.message_reference = opts.message_reference;
}
/** Q: should be checked if the referenced message exists? ANSWER: NO
otherwise backfilling won't work **/

View File

@ -42,7 +42,7 @@ export interface MessageCreateSchema {
};
message_reference?: {
message_id: string;
channel_id: string;
channel_id?: string;
guild_id?: string;
fail_if_not_exists?: boolean;
};