From e1dde1a0276a462dda4575aef2ffe0f27d7ac3be Mon Sep 17 00:00:00 2001 From: Shni Date: Wed, 15 Oct 2025 03:23:50 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20A=C3=B1adir=20opci=C3=B3n=20para=20invi?= =?UTF-8?q?tar=20bot=20en=20la=20interfaz=20de=20usuario=20del=20panel=20d?= =?UTF-8?q?e=20control?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/server.ts | 25 +++++++++++++++++++++ src/server/views/pages/dashboard.ejs | 7 +++++- src/server/views/partials/dashboard_nav.ejs | 3 +++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/server/server.ts b/src/server/server.ts index 854abd5..1d50d21 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -1128,6 +1128,31 @@ export const server = createServer( // /dashboard -> main dashboard if (url.pathname === "/dashboard" || url.pathname === "/dashboard/") { + // determine whether bot is in each guild (if we have a bot token) + try { + const botToken = process.env.DISCORD_BOT_TOKEN; + if (botToken && Array.isArray(guilds) && guilds.length) { + await Promise.all( + guilds.map(async (g: any) => { + try { + const check = await fetch( + `https://discord.com/api/guilds/${encodeURIComponent( + String(g.id) + )}`, + { headers: { Authorization: `Bot ${botToken}` } } + ); + g.botInGuild = check.ok; + } catch (e) { + g.botInGuild = false; + } + }) + ); + } else if (Array.isArray(guilds)) { + guilds.forEach((g: any) => (g.botInGuild = false)); + } + } catch (err) { + // ignore + } await renderTemplate(req, res, "dashboard", { appName: pkg.name ?? "Amayo Bot", user, diff --git a/src/server/views/pages/dashboard.ejs b/src/server/views/pages/dashboard.ejs index 4c486b1..8057389 100644 --- a/src/server/views/pages/dashboard.ejs +++ b/src/server/views/pages/dashboard.ejs @@ -55,7 +55,12 @@
<%= g.name %>
-
+
+ <% if (typeof g.botInGuild === 'boolean' && !g.botInGuild) { %> + Invitar bot + <% } %> +
+
<% }) %> <% } else { %> diff --git a/src/server/views/partials/dashboard_nav.ejs b/src/server/views/partials/dashboard_nav.ejs index b528c95..0e176e6 100644 --- a/src/server/views/partials/dashboard_nav.ejs +++ b/src/server/views/partials/dashboard_nav.ejs @@ -31,6 +31,9 @@
S
<% } %>
<%= g.name %>
+ <% if (typeof g.botInGuild === 'boolean' && !g.botInGuild) { %> + Invitar bot + <% } %> <% }) %> <% } else { %>