From c3f89d86db0dafe675612da2d711827bbc0800a5 Mon Sep 17 00:00:00 2001 From: Regalijan Date: Sun, 18 Feb 2024 18:28:02 -0500 Subject: [PATCH] Send webhook notifications for inactivity updates --- functions/api/inactivity/[id].ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/functions/api/inactivity/[id].ts b/functions/api/inactivity/[id].ts index 479b8da..480af12 100644 --- a/functions/api/inactivity/[id].ts +++ b/functions/api/inactivity/[id].ts @@ -157,6 +157,32 @@ export async function onRequestPut(context: RequestContext) { }, ); + const departmentWebhooks = []; + for (const department of departments) + departmentWebhooks.push(context.env[`${department}_INACTIVITY_WEBHOOK`]); + + const webhookPromises = []; + for (const webhook of departmentWebhooks) + webhookPromises.push( + fetch(webhook, { + body: JSON.stringify({ + embeds: [ + { + title: "Inactivity Notice Modified", + color: 37562560, + description: `View the updated notice at https://carcrushers.cc/mod-queue?id=${context.params.id}&type=inactivity`, + }, + ], + }), + headers: { + "content-type": "application/json", + }, + method: "POST", + }), + ); + + await Promise.allSettled(webhookPromises); + return new Response(null, { status: 204, });