From 45be3023025dfac216bc4457e3a97af07b647a91 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Wed, 19 Nov 2025 08:39:30 -0600 Subject: [PATCH] some fixes --- src/api/util/handlers/Webhook.ts | 42 ++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/api/util/handlers/Webhook.ts b/src/api/util/handlers/Webhook.ts index f3c31644..e77bcbde 100644 --- a/src/api/util/handlers/Webhook.ts +++ b/src/api/util/handlers/Webhook.ts @@ -7,6 +7,7 @@ import { WebhookExecuteSchema } from "@spacebar/schemas"; export const executeWebhook = async (req: Request, res: Response) => { const { wait } = req.query; + if (!wait) { res.status(204).send(); } @@ -18,7 +19,11 @@ export const executeWebhook = async (req: Request, res: Response) => { // ensure one of content, embeds, components, or file is present if (!body.content && !body.embeds && !body.components && !body.file && !body.attachments) { - throw DiscordApiErrors.CANNOT_SEND_EMPTY_MESSAGE; + if (wait) { + throw DiscordApiErrors.CANNOT_SEND_EMPTY_MESSAGE; + } else { + return; + } } // block username from containing certain words @@ -46,17 +51,30 @@ export const executeWebhook = async (req: Request, res: Response) => { }, relations: ["channel", "guild", "application"], }); + console.log("in here?", wait); if (!webhook) { - throw DiscordApiErrors.UNKNOWN_WEBHOOK; + if (wait) { + throw DiscordApiErrors.UNKNOWN_WEBHOOK; + } else { + return; + } } if (!webhook.channel.isWritable()) { - throw new HTTPError(`Cannot send messages to channel of type ${webhook.channel.type}`, 400); + if (wait) { + throw new HTTPError(`Cannot send messages to channel of type ${webhook.channel.type}`, 400); + } else { + return; + } } if (webhook.token !== token) { - throw DiscordApiErrors.INVALID_WEBHOOK_TOKEN_PROVIDED; + if (wait) { + throw DiscordApiErrors.INVALID_WEBHOOK_TOKEN_PROVIDED; + } else { + return; + } } // TODO: creating messages by users checks if the user can bypass rate limits, we cant do that on webhooks, but maybe we could check the application if there is one? @@ -70,12 +88,16 @@ export const executeWebhook = async (req: Request, res: Response) => { }); if (count >= limits.absoluteRate.sendMessage.limit) - throw FieldErrors({ - channel_id: { - code: "TOO_MANY_MESSAGES", - message: req.t("common:toomany.MESSAGE"), - }, - }); + if (wait) { + throw FieldErrors({ + channel_id: { + code: "TOO_MANY_MESSAGES", + message: req.t("common:toomany.MESSAGE"), + }, + }); + } else { + return; + } } const files = (req.files as Express.Multer.File[]) ?? [];