diff --git a/README.md b/README.md index cd67f87..001f29b 100644 --- a/README.md +++ b/README.md @@ -61,3 +61,17 @@ Users that spam requests can be blocked by creating an environment variable call  6. Redeploy the site with **Deploys** -> **Trigger deploy** -> **Deploy site**. + +## Using webhooks + +When you use the `DISCORD_WEBHOOK_URL`, you don't need to specify the `DISCORD_BOT_TOKEN`, `GUILD_ID`, and `APPEALS_CHANNEL` in the environment variables. The message will be sent using the webhook without an unban button. To do this: + +1. On your [Netlify dashboard](https://app.netlify.com), click **Deploys** and navigate to **Deploy settings**, and then to the **Environment** option. + +2. Under **Environment variables**, click **Edit variables**. + +3. Right-click on any channel and click **Edit Channel** -> **Integrations** -> **Webhooks** -> **Copy Webhook URL**. + +4. Click **New variable**, and create an environment variable with `DISCORD_WEBHOOK_URL` as its key. For the value, paste the Webhook URL you copied in the previous step. + +5. Redeploy the site with **Deploys** -> **Trigger deploy** -> **Deploy site**. diff --git a/build.js b/build.js index 5a7ab2c..82d4a2a 100644 --- a/build.js +++ b/build.js @@ -40,19 +40,21 @@ async function main() { } }); - if (process.env.DISABLE_UNBAN_LINK) { + if (process.env.DISABLE_UNBAN_LINK || process.env.DISCORD_WEBHOOK_URL) { fs.unlink(path.resolve(func, "unban.js"), assertSuccess); } - // Make sure the bot connected to the gateway at least once. - const bot = new Eris(process.env.DISCORD_BOT_TOKEN); - bot.on("ready", () => bot.disconnect()); - - try { - await bot.connect(); - } catch (e) { - console.log(e); - process.exit(1); + if(!process.env.DISCORD_WEBHOOK_URL) { + // Make sure the bot connected to the gateway at least once. + const bot = new Eris(process.env.DISCORD_BOT_TOKEN); + bot.on("ready", () => bot.disconnect()); + + try { + await bot.connect(); + } catch (e) { + console.log(e); + process.exit(1); + } } } diff --git a/func/oauth-callback.js b/func/oauth-callback.js index b1dd8c8..cd02980 100644 --- a/func/oauth-callback.js +++ b/func/oauth-callback.js @@ -62,7 +62,7 @@ export async function handler(event, context) { }; } - if (process.env.GUILD_ID && !process.env.SKIP_BAN_CHECK) { + if (process.env.GUILD_ID && !process.env.SKIP_BAN_CHECK && !process.env.DISCORD_WEBHOOK_URL) { const ban = await getBan(user.id, process.env.GUILD_ID, process.env.DISCORD_BOT_TOKEN); if (ban === null) { return { diff --git a/func/submission-created.js b/func/submission-created.js index 1749528..60d5e94 100644 --- a/func/submission-created.js +++ b/func/submission-created.js @@ -68,7 +68,7 @@ export async function handler(event, context) { } } - if (process.env.GUILD_ID) { + if (process.env.GUILD_ID && !process.env.DISCORD_WEBHOOK_URL) { try { const ban = await getBan(userInfo.id, process.env.GUILD_ID, process.env.DISCORD_BOT_TOKEN); if (ban !== null && ban.reason) { @@ -98,14 +98,27 @@ export async function handler(event, context) { } } - const result = await fetch(`${API_ENDPOINT}/channels/${encodeURIComponent(process.env.APPEALS_CHANNEL)}/messages`, { - method: "POST", - headers: { - "Content-Type": "application/json", - "Authorization": `Bot ${process.env.DISCORD_BOT_TOKEN}` - }, - body: JSON.stringify(message) - }); + let result; + if (!process.env.DISCORD_WEBHOOK_URL) { + result = await fetch(`${API_ENDPOINT}/channels/${encodeURIComponent(process.env.APPEALS_CHANNEL)}/messages`, { + method: "POST", + headers: { + "Content-Type": "application/json", + "Authorization": `Bot ${process.env.DISCORD_BOT_TOKEN}` + }, + body: JSON.stringify(message) + }); + } else { + result = await fetch(`${process.env.DISCORD_WEBHOOK_URL}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + embeds: [message.embed] + }) + }); + } if (result.ok) { if (process.env.USE_NETLIFY_FORMS) { diff --git a/public/form.html b/public/form.html index 661b29e..04d6563 100644 --- a/public/form.html +++ b/public/form.html @@ -56,7 +56,7 @@
const jsonPayload = decodeURIComponent(atob(base64).split('').map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join('')); return JSON.parse(jsonPayload); - }; + } const params = new URLSearchParams(document.location.search.substring(1)); if (!params.has("token")) {