Skip to content

Commit

Permalink
sort user guilds by perms
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardozgz committed Oct 24, 2024
1 parent 2a036da commit 7056b9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 11 additions & 2 deletions apps/website/src/server/api/services/discord.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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]),
),
};
}
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7056b9f

Please sign in to comment.