From 7056b9fdd149ade60cd34b547c0e0f907438b2d9 Mon Sep 17 00:00:00 2001 From: eduardozgz Date: Thu, 24 Oct 2024 15:18:35 +0200 Subject: [PATCH] sort user guilds by perms --- apps/website/src/server/api/services/discord.ts | 13 +++++++++++-- pnpm-lock.yaml | 3 --- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/website/src/server/api/services/discord.ts b/apps/website/src/server/api/services/discord.ts index d7a2caa77..c4ed84e6c 100644 --- a/apps/website/src/server/api/services/discord.ts +++ b/apps/website/src/server/api/services/discord.ts @@ -1,8 +1,9 @@ import type { DiscordUser } from "@mc/validators/DiscordUser"; import type { DiscordUserGuild } from "@mc/validators/DiscordUserGuilds"; import { REST } from "@discordjs/rest"; -import { Routes } from "discord-api-types/v10"; +import { PermissionFlagsBits, Routes } from "discord-api-types/v10"; +import { BitField } from "@mc/common/BitField"; import { DiscordUserSchema } from "@mc/validators/DiscordUser"; import { DiscordUserGuildsSchema } from "@mc/validators/DiscordUserGuilds"; @@ -32,7 +33,15 @@ export async function userGuilds( return { userGuilds: new Map( - DiscordUserGuildsSchema.parse(guilds).map((guild) => [guild.id, guild]), + DiscordUserGuildsSchema.parse(guilds) + .sort((guild) => + new BitField(guild.permissions).any( + PermissionFlagsBits.Administrator | PermissionFlagsBits.ManageGuild, + ) + ? -1 + : 1, + ) + .map((guild) => [guild.id, guild]), ), }; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 750204ee9..c6a990023 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -377,9 +377,6 @@ importers: '@mc/redis': specifier: workspace:* version: link:../redis - '@mc/validators': - specifier: workspace:* - version: link:../validators '@t3-oss/env-nextjs': specifier: ^0.10.1 version: 0.10.1(typescript@5.4.5)(zod@3.23.6)