Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@vladfrangu/async_event_emitter": "^2.4.7",
"json-with-bigint": "^3.4.4",
"solid-js": "^1.9.14",
"stoat-api": "0.15.3",
"stoat-api": "0.16.0",
"ulid": "^3.0.2"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

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

11 changes: 11 additions & 0 deletions src/classes/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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,
});
}

Expand Down
11 changes: 10 additions & 1 deletion src/classes/PublicBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/classes/ServerRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class ServerRole {
readonly colour?: string;
readonly hoist: boolean;
readonly rank: number;
readonly owner: string;

/**
* Construct server role
Expand All @@ -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 ?? "";
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/hydration/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type HydratedBot = {
termsOfServiceUrl?: string;
privacyPolicyUrl?: string;
flags: BotFlags;
defaultPermissions?: number;
};

export const botHydration: Hydrate<APIBot, HydratedBot> = {
Expand All @@ -22,6 +23,7 @@ export const botHydration: Hydrate<APIBot, HydratedBot> = {
interactions_url: "interactionsUrl",
terms_of_service_url: "termsOfServiceUrl",
privacy_policy_url: "privacyPolicyUrl",
default_permissions: "defaultPermissions",
},
functions: {
id: (bot) => bot._id,
Expand All @@ -34,6 +36,7 @@ export const botHydration: Hydrate<APIBot, HydratedBot> = {
termsOfServiceUrl: (bot) => bot.terms_of_service_url!,
privacyPolicyUrl: (bot) => bot.privacy_policy_url!,
flags: (bot) => bot.flags!,
defaultPermissions: (bot) => bot.default_permissions!,
},
initialHydration: () => ({}),
};
Expand Down
Loading