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 { %>