From 27e2251555689f032e254162c0dcf5f7fd828fa3 Mon Sep 17 00:00:00 2001 From: MeowcaTheoRange Date: Mon, 2 Sep 2024 10:13:57 -0500 Subject: [PATCH] webhooks ???? lol ????????????? --- index.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/index.js b/index.js index bb5a9df..29cdf03 100644 --- a/index.js +++ b/index.js @@ -226,6 +226,35 @@ app.post('/mininq/mbox/r', async (req, res) => { switch (body.action) { case "public": + if (process.env.MININQ_WEBHOOK != null) { + const mininq_pub = await db + .selectFrom('mininq') + .selectAll() + .where('id', '=', body.id) + .executeTakeFirst(); + + await fetch(process.env.MININQ_WEBHOOK, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + "content": "New mininq:", + "embeds": [ + { + "description": mininq_pub.msg, + "color": 12298956, + "author": mininq_pub.url != '' ? { + "name": `${mininq_pub.name} @ ${new URL(mininq_pub.url).host} sent:`, + "url": mininq_pub.url + } : { + "name": `${mininq_pub.name} sent:` + } + } + ], + "attachments": [] + }) + }); + } + await db .updateTable('mininq') .set({ @@ -246,6 +275,43 @@ app.post('/mininq/mbox/r', async (req, res) => { if (body.msg.length < 1) return res.status(400).send("msg is required"); if (body.msg.length > 4000) return res.status(400).send("msg must not be longer than 4000 characters"); + if (process.env.MININQ_WEBHOOK != null) { + const mininq = await db + .selectFrom('mininq') + .selectAll() + .where('id', '=', body.id) + .executeTakeFirst(); + + await fetch(process.env.MININQ_WEBHOOK, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + "content": "New mininq:", + "embeds": [ + { + "description": mininq.msg, + "color": 12298956, + "author": mininq.url != '' ? { + "name": `${mininq.name} @ ${new URL(mininq.url).host} sent:`, + "url": mininq.url + } : { + "name": `${mininq.name} sent:` + } + }, + { + "description": mininq.reply, + "color": 13421772, + "author": { + "name": "sysadmin reply:", + "url": `https://abtmtr.link/mininq/#${mininq.id}` + } + } + ], + "attachments": [] + }) + }); + } + await db .updateTable('mininq') .set({