From ca3779c0a58ad09290bcb9dc3c5cfe4ea60be643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0spik?= Date: Thu, 22 Oct 2026 15:24:59 +0300 Subject: [PATCH] feat: managed roles and bot default permissions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: İspik --- src/classes/Bot.ts | 11 +++++++++++ src/classes/PublicBot.ts | 11 ++++++++++- src/classes/ServerRole.ts | 2 ++ src/hydration/bot.ts | 3 +++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/classes/Bot.ts b/src/classes/Bot.ts index 7256b8a1..e3150f74 100644 --- a/src/classes/Bot.ts +++ b/src/classes/Bot.ts @@ -124,6 +124,13 @@ export class Bot { return this.#collection.getUnderlyingObject(this.id).flags; } + /** + * Bot default permissions + */ + get defaultPermissions(): number | undefined { + return this.#collection.getUnderlyingObject(this.id).defaultPermissions; + } + /** * Instantiate `PublicBot` class from this bot */ @@ -132,6 +139,10 @@ export class Bot { _id: this.id, username: this.user?.username ?? "", avatar: this.user?.avatar?.id, + default_permissions: + this.defaultPermissions !== undefined + ? Number(this.defaultPermissions) + : undefined, }); } diff --git a/src/classes/PublicBot.ts b/src/classes/PublicBot.ts index ef9b0c1f..6e197be9 100644 --- a/src/classes/PublicBot.ts +++ b/src/classes/PublicBot.ts @@ -16,6 +16,10 @@ export class PublicBot { readonly username: string; readonly avatar?: File; readonly description?: string; + /** + * Permissions the bot asks for (0n when unset or the instance doesn't send them) + */ + readonly defaultPermissions: bigint; /** * Construct Public Bot @@ -33,15 +37,20 @@ export class PublicBot { } as APIFile) : undefined; this.description = data.description!; + + const requested = data.default_permissions as number | null | undefined; + this.defaultPermissions = requested != null ? BigInt(requested) : 0n; } /** * Add the bot to a server * @param server Server + * @param permissions Permissions to grant the bot (requires Manage Roles) */ - addToServer(server: Server | string): void { + addToServer(server: Server | string, permissions?: bigint): void { this.#client.api.post(`/bots/${this.id as ""}/invite`, { server: server instanceof Server ? server.id : server, + permissions: permissions ? Number(permissions) : undefined, }); } diff --git a/src/classes/ServerRole.ts b/src/classes/ServerRole.ts index b2cf3793..ca7c6dd4 100644 --- a/src/classes/ServerRole.ts +++ b/src/classes/ServerRole.ts @@ -21,6 +21,7 @@ export class ServerRole { readonly colour?: string; readonly hoist: boolean; readonly rank: number; + readonly owner: string; /** * Construct server role @@ -43,6 +44,7 @@ export class ServerRole { this.colour = data.colour ?? undefined; this.hoist = data.hoist || false; this.rank = data.rank ?? 0; + this.owner = data.owner ?? ""; } /** diff --git a/src/hydration/bot.ts b/src/hydration/bot.ts index 0d63b176..e66fa747 100644 --- a/src/hydration/bot.ts +++ b/src/hydration/bot.ts @@ -13,6 +13,7 @@ export type HydratedBot = { termsOfServiceUrl?: string; privacyPolicyUrl?: string; flags: BotFlags; + defaultPermissions?: number; }; export const botHydration: Hydrate = { @@ -22,6 +23,7 @@ export const botHydration: Hydrate = { interactions_url: "interactionsUrl", terms_of_service_url: "termsOfServiceUrl", privacy_policy_url: "privacyPolicyUrl", + default_permissions: "defaultPermissions", }, functions: { id: (bot) => bot._id, @@ -34,6 +36,7 @@ export const botHydration: Hydrate = { termsOfServiceUrl: (bot) => bot.terms_of_service_url!, privacyPolicyUrl: (bot) => bot.privacy_policy_url!, flags: (bot) => bot.flags!, + defaultPermissions: (bot) => bot.default_permissions!, }, initialHydration: () => ({}), };