From b3f9d7dc2f6ede68e0b31ce7eb95e90223eb1a7d Mon Sep 17 00:00:00 2001 From: sirpiglr <49359077-sirpiglr@users.noreply.replit.com> Date: Mon, 8 Dec 2025 02:56:26 +0000 Subject: [PATCH] Add a system to manage bot access and automatically remove it from unauthorized servers Implement a guild whitelist system and an endpoint to remove the bot from specific guilds, ensuring it only operates in authorized AeThex servers. Replit-Commit-Author: Agent Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 36e515d7-f09c-43a5-9699-79df2582133f Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/BBAQobO Replit-Helium-Checkpoint-Created: true --- .replit | 4 ++++ aethex-bot/bot.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/.replit b/.replit index 5b6f647..b6adb4e 100644 --- a/.replit +++ b/.replit @@ -22,6 +22,10 @@ externalPort = 80 localPort = 8080 externalPort = 8080 +[[ports]] +localPort = 37193 +externalPort = 3000 + [workflows] runButton = "Project" diff --git a/aethex-bot/bot.js b/aethex-bot/bot.js index af1f93f..87fc275 100644 --- a/aethex-bot/bot.js +++ b/aethex-bot/bot.js @@ -116,6 +116,36 @@ const REALM_GUILDS = { }; client.REALM_GUILDS = REALM_GUILDS; +// ============================================================================= +// GUILD WHITELIST SYSTEM +// ============================================================================= + +const WHITELISTED_GUILDS = [ + '373713073594302464', // AeThex | Corporation + '515711457946632232', // AeThex (Main) + '525971009313046529', // AeThex | Nexus + '1245619208805416970', // AeThex | GameForge + '1275962459596783686', // AeThex | LABS + '1284290638564687925', // AeThex | DevOps + '1338564560277344287', // AeThex | Foundation + ...(process.env.EXTRA_WHITELISTED_GUILDS || '').split(',').filter(Boolean), +]; +client.WHITELISTED_GUILDS = WHITELISTED_GUILDS; + +client.on('guildCreate', async (guild) => { + if (!WHITELISTED_GUILDS.includes(guild.id)) { + console.log(`[Whitelist] Unauthorized server detected: ${guild.name} (${guild.id}) - Leaving...`); + try { + const owner = await guild.fetchOwner(); + await owner.send(`Your server "${guild.name}" is not authorized to use AeThex Bot. The bot has automatically left. Contact the AeThex team if you believe this is an error.`).catch(() => {}); + } catch (e) {} + await guild.leave(); + console.log(`[Whitelist] Left unauthorized server: ${guild.name}`); + return; + } + console.log(`[Whitelist] Joined authorized server: ${guild.name} (${guild.id})`); +}); + // ============================================================================= // SENTINEL: TICKET TRACKING (New) // ============================================================================= @@ -644,6 +674,36 @@ http return; } + if (req.url.startsWith("/leave-guild/") && req.method === "POST") { + if (!checkAdminAuth(req)) { + res.writeHead(401); + res.end(JSON.stringify({ error: "Unauthorized - Admin token required" })); + return; + } + + const guildId = req.url.split("/leave-guild/")[1]; + (async () => { + try { + const guild = client.guilds.cache.get(guildId); + if (!guild) { + res.writeHead(404); + res.end(JSON.stringify({ error: "Guild not found" })); + return; + } + + const guildName = guild.name; + await guild.leave(); + console.log(`[Admin] Left guild: ${guildName} (${guildId})`); + res.writeHead(200); + res.end(JSON.stringify({ success: true, message: `Left guild: ${guildName}` })); + } catch (error) { + res.writeHead(500); + res.end(JSON.stringify({ error: error.message })); + } + })(); + return; + } + if (req.url.startsWith("/create-invite/") && req.method === "GET") { if (!checkAdminAuth(req)) { res.writeHead(401);