From b75e1e6947212b46ccb885919e9e85e91646482c Mon Sep 17 00:00:00 2001 From: YoggieS <61660055+yoggys@users.noreply.github.com> Date: Sat, 20 Jul 2024 19:11:28 +0200 Subject: [PATCH 1/5] add DISCORD_WEBHOOK_URL to env --- build.js | 20 +++++++++++--------- func/oauth-callback.js | 2 +- func/submission-created.js | 31 ++++++++++++++++++++++--------- netlify.toml | 1 + public/form.html | 2 +- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/build.js b/build.js index 5a7ab2c..c45f570 100644 --- a/build.js +++ b/build.js @@ -44,15 +44,17 @@ async function main() { 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/netlify.toml b/netlify.toml index f8b6710..4e759a0 100644 --- a/netlify.toml +++ b/netlify.toml @@ -16,6 +16,7 @@ DISCORD_CLIENT_ID = "Your Discord App's client ID" DISCORD_CLIENT_SECRET = "Your Discord App's client secret" DISCORD_BOT_TOKEN = "Your Discord Bot Token" + DISCORD_WEBHOOK_URL = "Your Discord Webhook URL (if used, only a message is sent to the channel)" GUILD_ID = "ID of the guild this deployment targets" APPEALS_CHANNEL = "ID of the channel used for appeal form submission" JWT_SECRET = "JSON Web Token secret, mash keyboard plz" 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")) { From 7ac161695827dbd8dba4d3d1cd6c7856c98002be Mon Sep 17 00:00:00 2001 From: YoggieS <61660055+yoggys@users.noreply.github.com> Date: Sat, 20 Jul 2024 19:22:44 +0200 Subject: [PATCH 2/5] add more info and unlink unban --- build.js | 2 +- netlify.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.js b/build.js index c45f570..82d4a2a 100644 --- a/build.js +++ b/build.js @@ -40,7 +40,7 @@ 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); } diff --git a/netlify.toml b/netlify.toml index 4e759a0..a4ea9a0 100644 --- a/netlify.toml +++ b/netlify.toml @@ -16,7 +16,7 @@ DISCORD_CLIENT_ID = "Your Discord App's client ID" DISCORD_CLIENT_SECRET = "Your Discord App's client secret" DISCORD_BOT_TOKEN = "Your Discord Bot Token" - DISCORD_WEBHOOK_URL = "Your Discord Webhook URL (if used, only a message is sent to the channel)" GUILD_ID = "ID of the guild this deployment targets" APPEALS_CHANNEL = "ID of the channel used for appeal form submission" + DISCORD_WEBHOOK_URL = "Your Discord Webhook URL (if used, fill only JWT_SECRET)" JWT_SECRET = "JSON Web Token secret, mash keyboard plz" From ac2757831b115cffe5d60a479eedaec70d13bbc6 Mon Sep 17 00:00:00 2001 From: YoggieS <61660055+yoggys@users.noreply.github.com> Date: Sat, 20 Jul 2024 19:33:28 +0200 Subject: [PATCH 3/5] clear info and move it to README --- netlify.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlify.toml b/netlify.toml index a4ea9a0..39940b4 100644 --- a/netlify.toml +++ b/netlify.toml @@ -16,7 +16,7 @@ DISCORD_CLIENT_ID = "Your Discord App's client ID" DISCORD_CLIENT_SECRET = "Your Discord App's client secret" DISCORD_BOT_TOKEN = "Your Discord Bot Token" + DISCORD_WEBHOOK_URL = "Your Discord Webhook URL" GUILD_ID = "ID of the guild this deployment targets" APPEALS_CHANNEL = "ID of the channel used for appeal form submission" - DISCORD_WEBHOOK_URL = "Your Discord Webhook URL (if used, fill only JWT_SECRET)" JWT_SECRET = "JSON Web Token secret, mash keyboard plz" From c15829ff160b5041eae875a229bca3a94eb34c16 Mon Sep 17 00:00:00 2001 From: YoggieS <61660055+yoggys@users.noreply.github.com> Date: Sat, 20 Jul 2024 19:35:41 +0200 Subject: [PATCH 4/5] clear info and move it to README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index cd67f87..a8711f7 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ By using OAuth2, it ensures users can't forge or fake appeals. | Client ID | You can get this from the **General Information** section for the application you created in step 1. | | Client secret | You can get this from the **General Information** section for the application you created in step 1. | | Bot token | Get this in the **Bot** section that you used in step 2. | + | Webhook URL | You can create it in Discord Channel Settings -> Integrations -> Webhooks | | Guild ID | This is where the developer mode you enabled in step 4 comes in handy. Right-click your server icon and press **Copy ID**. | | Channel ID | Same deal than the guild ID, but with the channel you created in step 3. | | JSON Web Token secret | Use a password manager to generate a password with ~50 characters, or mash your keyboard. | @@ -44,6 +45,10 @@ By using OAuth2, it ensures users can't forge or fake appeals. 13. You should be good to go! You might want to test if it works as intended with an alt account, and if you encounter any problems feel free to [create an issue on GitHub](https://github.com/sylveon/discord-ban-appeals/issues/new). +## 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. + ## Blocking users Users that spam requests can be blocked by creating an environment variable called `BLOCKED_USERS`, which should contain a comma-separated list of quoted user IDs. To do this: From f818d8e2e8d8adfc7825e292c40cfffd9b5deeb4 Mon Sep 17 00:00:00 2001 From: YoggieS <61660055+yoggys@users.noreply.github.com> Date: Sun, 21 Jul 2024 14:15:58 +0200 Subject: [PATCH 5/5] Remove webhook url from template env, add more info to readme section --- README.md | 19 ++++++++++++++----- netlify.toml | 1 - 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a8711f7..001f29b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,6 @@ By using OAuth2, it ensures users can't forge or fake appeals. | Client ID | You can get this from the **General Information** section for the application you created in step 1. | | Client secret | You can get this from the **General Information** section for the application you created in step 1. | | Bot token | Get this in the **Bot** section that you used in step 2. | - | Webhook URL | You can create it in Discord Channel Settings -> Integrations -> Webhooks | | Guild ID | This is where the developer mode you enabled in step 4 comes in handy. Right-click your server icon and press **Copy ID**. | | Channel ID | Same deal than the guild ID, but with the channel you created in step 3. | | JSON Web Token secret | Use a password manager to generate a password with ~50 characters, or mash your keyboard. | @@ -45,10 +44,6 @@ By using OAuth2, it ensures users can't forge or fake appeals. 13. You should be good to go! You might want to test if it works as intended with an alt account, and if you encounter any problems feel free to [create an issue on GitHub](https://github.com/sylveon/discord-ban-appeals/issues/new). -## 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. - ## Blocking users Users that spam requests can be blocked by creating an environment variable called `BLOCKED_USERS`, which should contain a comma-separated list of quoted user IDs. To do this: @@ -66,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/netlify.toml b/netlify.toml index 39940b4..f8b6710 100644 --- a/netlify.toml +++ b/netlify.toml @@ -16,7 +16,6 @@ DISCORD_CLIENT_ID = "Your Discord App's client ID" DISCORD_CLIENT_SECRET = "Your Discord App's client secret" DISCORD_BOT_TOKEN = "Your Discord Bot Token" - DISCORD_WEBHOOK_URL = "Your Discord Webhook URL" GUILD_ID = "ID of the guild this deployment targets" APPEALS_CHANNEL = "ID of the channel used for appeal form submission" JWT_SECRET = "JSON Web Token secret, mash keyboard plz"