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
This commit is contained in:
sirpiglr 2025-12-08 02:56:26 +00:00
parent 16a9709e38
commit b3f9d7dc2f
2 changed files with 64 additions and 0 deletions

View file

@ -22,6 +22,10 @@ externalPort = 80
localPort = 8080
externalPort = 8080
[[ports]]
localPort = 37193
externalPort = 3000
[workflows]
runButton = "Project"

View file

@ -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);