feat: Añadir opción para invitar bot en la interfaz de usuario del panel de control

This commit is contained in:
Shni
2025-10-15 03:23:50 -05:00
parent c3f20f99c2
commit e1dde1a027
3 changed files with 34 additions and 1 deletions

View File

@@ -1128,6 +1128,31 @@ export const server = createServer(
// /dashboard -> main dashboard // /dashboard -> main dashboard
if (url.pathname === "/dashboard" || url.pathname === "/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", { await renderTemplate(req, res, "dashboard", {
appName: pkg.name ?? "Amayo Bot", appName: pkg.name ?? "Amayo Bot",
user, user,

View File

@@ -55,8 +55,13 @@
<div class="font-medium"><%= g.name %></div> <div class="font-medium"><%= g.name %></div>
</div> </div>
</div> </div>
<div class="flex items-center gap-2">
<% if (typeof g.botInGuild === 'boolean' && !g.botInGuild) { %>
<a href="https://discord.com/oauth2/authorize?client_id=991062751633883136&permissions=2416176272&integration_type=0&scope=bot&guild_id=<%= g.id %>" class="text-xs text-sky-400 hover:underline mr-2" target="_blank" rel="noopener">Invitar bot</a>
<% } %>
<div class="text-slate-300">&rsaquo;</div> <div class="text-slate-300">&rsaquo;</div>
</div> </div>
</div>
<% }) %> <% }) %>
<% } else { %> <% } else { %>
<div class="p-4 text-slate-300">No servers available</div> <div class="p-4 text-slate-300">No servers available</div>

View File

@@ -31,6 +31,9 @@
<div class="w-5 h-5 rounded-full bg-white/8 flex items-center justify-center text-xs text-white">S</div> <div class="w-5 h-5 rounded-full bg-white/8 flex items-center justify-center text-xs text-white">S</div>
<% } %> <% } %>
<div class="flex-1 text-sm truncate pl-1"><%= g.name %></div> <div class="flex-1 text-sm truncate pl-1"><%= g.name %></div>
<% if (typeof g.botInGuild === 'boolean' && !g.botInGuild) { %>
<a href="https://discord.com/oauth2/authorize?client_id=991062751633883136&permissions=2416176272&integration_type=0&scope=bot&guild_id=<%= g.id %>" class="text-xs text-sky-400 hover:underline ml-2" target="_blank" rel="noopener">Invitar bot</a>
<% } %>
</div> </div>
<% }) %> <% }) %>
<% } else { %> <% } else { %>