From 5e219a154c62043e685c2004f16ebd037b875756 Mon Sep 17 00:00:00 2001 From: Ayden Jahola Date: Sat, 31 Aug 2024 10:03:09 +0100 Subject: [PATCH] adjust the email domain to take multiple arguments/domains and add .env.example --- .env.example | 18 ++++++++++++++++++ README.md | 31 ++++++++++++++++++++++--------- bot.js | 8 ++++---- 3 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..dc0f817 --- /dev/null +++ b/.env.example @@ -0,0 +1,18 @@ +# Bot token +BOT_TOKEN=YOUR_BOT_TOKEN + +# Nodemailer +EMAIL_NAME="Example" +EMAIL_USER=example@example.com +EMAIL_PASS=YOUR_EMAIL_PASS + +# Allowed domains for email verification +EMAIL_DOMAINS=example@example.com // or it can be a list, example: "example.com,example2.com" + +# Discord +GUILD_ID=YOUR_GUILD_ID +VERIFICATION_CHANNEL_NAME=YOUR_VERIFICATION_CHANNEL_NAME +VERIFIED_ROLE_NAME=YOUR_VERIFIED_ROLE_NAME + +# Database +MONGODB_URI=YOUR_MONGODB_URI \ No newline at end of file diff --git a/README.md b/README.md index 57abd1d..b2666f0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Esports Verification Bot +# Discord Verification Bot -Welcome to the **Esports Verification Bot**! This bot is designed to handle user verification for Discord servers, specifically for esports communities. It verifies users through their student email addresses and manages roles based on their verification status. +Welcome to the **Discord Verification Bot**! This bot is designed to handle user verification for Discord servers. It verifies users through their student email addresses and manages roles based on their verification status. ## Features @@ -39,15 +39,28 @@ npm install Create a `.env` file in the root directory and add the following: ```env -BOT_TOKEN=your_discord_bot_token -MONGODB_URI=your_mongodb_connection_string -EMAIL_USER=your_email@gmail.com -EMAIL_PASS=your_email_password -VERIFIED_ROLE_NAME=YourVerifiedRoleName -EMAIL_DOMAIN=mail.dcu.ie -GUILD_ID=your_discord_guild_id +# Bot token +BOT_TOKEN=YOUR_BOT_TOKEN + +# Nodemailer +EMAIL_NAME="Example" +EMAIL_USER=example@example.com +EMAIL_PASS=YOUR_EMAIL_PASS + +# Allowed domains for email verification +EMAIL_DOMAINS=example@example.com // or it can be a list, example: "example.com,example2.com" + +# Discord +GUILD_ID=YOUR_GUILD_ID +VERIFICATION_CHANNEL_NAME=YOUR_VERIFICATION_CHANNEL_NAME +VERIFIED_ROLE_NAME=YOUR_VERIFIED_ROLE_NAME + +# Database +MONGODB_URI=YOUR_MONGODB_URI ``` +this can also be seen in in the [.env.example](./.env.example) + 4. **Run the Bot** ```sh diff --git a/bot.js b/bot.js index 4edcb13..ce27829 100644 --- a/bot.js +++ b/bot.js @@ -13,7 +13,7 @@ const client = new Client({ }); const VERIFIED_ROLE_NAME = process.env.VERIFIED_ROLE_NAME; // Role name to assign after verification -const EMAIL_DOMAIN = process.env.EMAIL_DOMAIN; // Domain to verify against +const EMAIL_DOMAINS = process.env.EMAIL_DOMAINS.split(","); // Domains to verify against, converted to an array const GUILD_ID = process.env.GUILD_ID; // Guild ID to restrict the bot const VERIFICATION_CHANNEL_NAME = process.env.VERIFICATION_CHANNEL_NAME; // Channel name to restrict the bot @@ -56,14 +56,14 @@ client.on("messageCreate", async (message) => { if (!email) { return verificationChannel.send( - "Please provide your email address. Usage: `!verify your_email@mail.dcu.ie`" + "Please provide your email address. Usage: `!verify your_email@example.com`" ); } const emailDomain = email.split("@")[1]; - if (emailDomain !== EMAIL_DOMAIN) { + if (!EMAIL_DOMAINS.includes(emailDomain)) { return verificationChannel.send( - "You must use a valid DCU student email address." + "You must use a valid DCU email address." ); }