[deploy] filter dashboard guilds to manageable ones
All checks were successful
Deploy Discord Bot / deploy (push) Successful in 42s
All checks were successful
Deploy Discord Bot / deploy (push) Successful in 42s
This commit is contained in:
@@ -30,13 +30,29 @@ router.get('/me', requireAuth, (req, res) => {
|
|||||||
res.json({ user: { ...req.session.user, isAdmin } });
|
res.json({ user: { ...req.session.user, isAdmin } });
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/guilds', requireAuth, (_req, res) => {
|
router.get('/guilds', requireAuth, (req, res) => {
|
||||||
|
const sessionGuilds = Array.isArray(req.session?.guilds) ? req.session.guilds : [];
|
||||||
|
// Only allow guilds the user owns or can manage (manage_guild or admin) and where the bot is present
|
||||||
|
const allowedIds = new Set(
|
||||||
|
sessionGuilds
|
||||||
|
.filter((g: any) => {
|
||||||
|
if (!g) return false;
|
||||||
|
if (g.owner) return true;
|
||||||
|
const perms = g.permissions ? BigInt(g.permissions) : 0n;
|
||||||
|
const hasAdmin = (perms & 0x8n) === 0x8n;
|
||||||
|
const hasManageGuild = (perms & 0x20n) === 0x20n;
|
||||||
|
return hasAdmin || hasManageGuild;
|
||||||
|
})
|
||||||
|
.map((g: any) => g.id)
|
||||||
|
);
|
||||||
const guilds =
|
const guilds =
|
||||||
context.client?.guilds.cache.map((g) => ({
|
context.client?.guilds.cache
|
||||||
id: g.id,
|
.filter((g) => allowedIds.has(g.id))
|
||||||
name: g.name,
|
.map((g) => ({
|
||||||
icon: g.icon
|
id: g.id,
|
||||||
})) ?? [];
|
name: g.name,
|
||||||
|
icon: g.icon
|
||||||
|
})) ?? [];
|
||||||
res.json({ guilds });
|
res.json({ guilds });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user