chapterjs 0.1.1 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/asset.d.ts +46 -0
- package/dist/assets/asset.js +86 -0
- package/dist/assets/public.d.ts +19 -0
- package/dist/assets/public.js +120 -0
- package/dist/cache/cache.d.ts +62 -0
- package/dist/cache/cache.js +80 -0
- package/dist/cache/store.d.ts +45 -0
- package/dist/cache/store.js +53 -0
- package/dist/cli/build.d.ts +41 -0
- package/dist/cli/build.js +206 -0
- package/dist/cli/cli.js +108 -25
- package/dist/cli/cluster.d.ts +70 -0
- package/dist/cli/cluster.js +213 -0
- package/dist/cli/dev.d.ts +18 -1
- package/dist/cli/dev.js +252 -198
- package/dist/cli/env.d.ts +31 -0
- package/dist/cli/env.js +93 -0
- package/dist/cli/log.d.ts +13 -0
- package/dist/cli/log.js +17 -0
- package/dist/cli/node-version.d.ts +8 -0
- package/dist/cli/node-version.js +13 -0
- package/dist/cli/preflight.d.ts +36 -0
- package/dist/cli/preflight.js +122 -0
- package/dist/cli/project.d.ts +122 -0
- package/dist/cli/project.js +452 -0
- package/dist/cli/start.d.ts +25 -0
- package/dist/cli/start.js +225 -0
- package/dist/commands/autocomplete.d.ts +13 -0
- package/dist/commands/autocomplete.js +159 -0
- package/dist/commands/command.d.ts +346 -0
- package/dist/commands/command.js +28 -0
- package/dist/commands/convention.d.ts +64 -0
- package/dist/commands/convention.js +464 -0
- package/dist/commands/register.d.ts +18 -0
- package/dist/commands/register.js +42 -0
- package/dist/commands/router.d.ts +20 -0
- package/dist/commands/router.js +228 -0
- package/dist/commands/tree.d.ts +43 -0
- package/dist/commands/tree.js +206 -0
- package/dist/commands/twins.d.ts +15 -0
- package/dist/commands/twins.js +78 -0
- package/dist/components/button.d.ts +79 -0
- package/dist/components/button.js +108 -0
- package/dist/components/component.d.ts +140 -0
- package/dist/components/component.js +39 -0
- package/dist/components/convention.d.ts +35 -0
- package/dist/components/convention.js +339 -0
- package/dist/components/custom-id.d.ts +72 -0
- package/dist/components/custom-id.js +128 -0
- package/dist/components/embed.d.ts +28 -0
- package/dist/components/embed.js +11 -0
- package/dist/components/file.d.ts +30 -0
- package/dist/components/file.js +52 -0
- package/dist/components/instance.d.ts +100 -0
- package/dist/components/instance.js +86 -0
- package/dist/components/layout.d.ts +103 -0
- package/dist/components/layout.js +279 -0
- package/dist/components/modal.d.ts +244 -0
- package/dist/components/modal.js +399 -0
- package/dist/components/options.d.ts +41 -0
- package/dist/components/options.js +101 -0
- package/dist/components/render.d.ts +12 -0
- package/dist/components/render.js +58 -0
- package/dist/components/router.d.ts +18 -0
- package/dist/components/router.js +256 -0
- package/dist/components/select.d.ts +144 -0
- package/dist/components/select.js +179 -0
- package/dist/core/bot.d.ts +99 -0
- package/dist/core/bot.js +174 -0
- package/dist/core/memory.d.ts +66 -0
- package/dist/core/memory.js +115 -0
- package/dist/discord/api.d.ts +112 -0
- package/dist/discord/api.js +115 -0
- package/dist/discord/cdn.d.ts +67 -0
- package/dist/discord/cdn.js +100 -0
- package/dist/discord/codes.d.ts +171 -0
- package/dist/discord/codes.js +421 -0
- package/dist/discord/endpoint.d.ts +56 -0
- package/dist/discord/endpoint.js +53 -0
- package/dist/discord/endpoints.d.ts +1529 -0
- package/dist/discord/endpoints.js +1139 -0
- package/dist/discord/formatting.d.ts +67 -0
- package/dist/discord/formatting.js +87 -0
- package/dist/discord/index.d.ts +10 -0
- package/dist/discord/index.js +13 -0
- package/dist/discord/intents.d.ts +48 -0
- package/dist/discord/intents.js +128 -0
- package/dist/discord/permissions.d.ts +94 -0
- package/dist/discord/permissions.js +185 -0
- package/dist/discord/snowflake.d.ts +21 -0
- package/dist/discord/snowflake.js +36 -0
- package/dist/discord/types/application-command.d.ts +332 -0
- package/dist/discord/types/application-command.js +48 -0
- package/dist/discord/types/application-role-connection-metadata.d.ts +42 -0
- package/dist/discord/types/application-role-connection-metadata.js +22 -0
- package/dist/discord/types/application.d.ts +208 -0
- package/dist/discord/types/application.js +48 -0
- package/dist/discord/types/audit-log.d.ts +255 -0
- package/dist/discord/types/audit-log.js +144 -0
- package/dist/discord/types/auto-moderation.d.ts +167 -0
- package/dist/discord/types/auto-moderation.js +52 -0
- package/dist/discord/types/channel.d.ts +557 -0
- package/dist/discord/types/channel.js +88 -0
- package/dist/discord/types/common.d.ts +54 -0
- package/dist/discord/types/common.js +38 -0
- package/dist/discord/types/component.d.ts +775 -0
- package/dist/discord/types/component.js +76 -0
- package/dist/discord/types/emoji.d.ts +74 -0
- package/dist/discord/types/emoji.js +1 -0
- package/dist/discord/types/entitlement.d.ts +84 -0
- package/dist/discord/types/entitlement.js +22 -0
- package/dist/discord/types/gateway-events.d.ts +1148 -0
- package/dist/discord/types/gateway-events.js +54 -0
- package/dist/discord/types/gateway.d.ts +38 -0
- package/dist/discord/types/gateway.js +1 -0
- package/dist/discord/types/guild-scheduled-event.d.ts +257 -0
- package/dist/discord/types/guild-scheduled-event.js +68 -0
- package/dist/discord/types/guild-template.d.ts +51 -0
- package/dist/discord/types/guild-template.js +1 -0
- package/dist/discord/types/guild.d.ts +910 -0
- package/dist/discord/types/guild.js +153 -0
- package/dist/discord/types/index.d.ts +31 -0
- package/dist/discord/types/index.js +31 -0
- package/dist/discord/types/interaction.d.ts +321 -0
- package/dist/discord/types/interaction.js +47 -0
- package/dist/discord/types/invite.d.ts +158 -0
- package/dist/discord/types/invite.js +39 -0
- package/dist/discord/types/message.d.ts +834 -0
- package/dist/discord/types/message.js +159 -0
- package/dist/discord/types/oauth2.d.ts +22 -0
- package/dist/discord/types/oauth2.js +1 -0
- package/dist/discord/types/permissions.d.ts +183 -0
- package/dist/discord/types/permissions.js +118 -0
- package/dist/discord/types/poll.d.ts +106 -0
- package/dist/discord/types/poll.js +8 -0
- package/dist/discord/types/sku.d.ts +47 -0
- package/dist/discord/types/sku.js +26 -0
- package/dist/discord/types/soundboard.d.ts +71 -0
- package/dist/discord/types/soundboard.js +1 -0
- package/dist/discord/types/stage-instance.d.ts +58 -0
- package/dist/discord/types/stage-instance.js +10 -0
- package/dist/discord/types/sticker.d.ts +115 -0
- package/dist/discord/types/sticker.js +20 -0
- package/dist/discord/types/subscription.d.ts +54 -0
- package/dist/discord/types/subscription.js +12 -0
- package/dist/discord/types/team.d.ts +55 -0
- package/dist/discord/types/team.js +21 -0
- package/dist/discord/types/user.d.ts +273 -0
- package/dist/discord/types/user.js +83 -0
- package/dist/discord/types/voice.d.ts +72 -0
- package/dist/discord/types/voice.js +1 -0
- package/dist/discord/types/webhook.d.ts +184 -0
- package/dist/discord/types/webhook.js +12 -0
- package/dist/events/convention.d.ts +25 -0
- package/dist/events/convention.js +97 -0
- package/dist/events/event.d.ts +8 -0
- package/dist/events/event.js +20 -0
- package/dist/events/registry.d.ts +706 -0
- package/dist/events/registry.js +839 -0
- package/dist/events/router.d.ts +45 -0
- package/dist/events/router.js +133 -0
- package/dist/events/types.d.ts +7 -0
- package/dist/events/types.js +48 -0
- package/dist/gateway/errors.d.ts +18 -0
- package/dist/gateway/errors.js +47 -0
- package/dist/gateway/gateway.d.ts +64 -0
- package/dist/gateway/gateway.js +117 -0
- package/dist/gateway/identify-queue.d.ts +25 -0
- package/dist/gateway/identify-queue.js +29 -0
- package/dist/gateway/shard.d.ts +94 -0
- package/dist/gateway/shard.js +414 -0
- package/dist/gateway/state.d.ts +11 -0
- package/dist/gateway/state.js +184 -0
- package/dist/index.d.ts +55 -18
- package/dist/index.js +38 -12
- package/dist/interactions/cooldown.d.ts +33 -0
- package/dist/interactions/cooldown.js +74 -0
- package/dist/interactions/dispatch.d.ts +91 -0
- package/dist/interactions/dispatch.js +110 -0
- package/dist/loader/generated.d.ts +37 -0
- package/dist/loader/generated.js +114 -0
- package/dist/loader/hot.d.ts +13 -0
- package/dist/loader/hot.js +85 -0
- package/dist/loader/loader.d.ts +72 -0
- package/dist/loader/loader.js +135 -0
- package/dist/loader/locate.d.ts +10 -0
- package/dist/loader/locate.js +36 -0
- package/dist/loader/watch.d.ts +17 -0
- package/dist/loader/watch.js +66 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.js +6 -0
- package/dist/messages/commands.d.ts +23 -0
- package/dist/messages/commands.js +123 -0
- package/dist/messages/convention.d.ts +89 -0
- package/dist/messages/convention.js +347 -0
- package/dist/messages/messages.d.ts +219 -0
- package/dist/messages/messages.js +30 -0
- package/dist/messages/phrases.d.ts +23 -0
- package/dist/messages/phrases.js +44 -0
- package/dist/messages/translate.d.ts +100 -0
- package/dist/messages/translate.js +249 -0
- package/dist/presence/convention.d.ts +26 -0
- package/dist/presence/convention.js +133 -0
- package/dist/presence/presence.d.ts +57 -0
- package/dist/presence/presence.js +27 -0
- package/dist/rest/errors.d.ts +55 -0
- package/dist/rest/errors.js +92 -0
- package/dist/rest/rate-limiter.d.ts +46 -0
- package/dist/rest/rate-limiter.js +153 -0
- package/dist/rest/rest.d.ts +63 -0
- package/dist/rest/rest.js +194 -0
- package/dist/structures/base.d.ts +48 -0
- package/dist/structures/base.js +84 -0
- package/dist/structures/channel.d.ts +380 -0
- package/dist/structures/channel.js +627 -0
- package/dist/structures/context.d.ts +30 -0
- package/dist/structures/context.js +7 -0
- package/dist/structures/emoji.d.ts +46 -0
- package/dist/structures/emoji.js +65 -0
- package/dist/structures/entities.d.ts +62 -0
- package/dist/structures/entities.js +226 -0
- package/dist/structures/guild.d.ts +348 -0
- package/dist/structures/guild.js +466 -0
- package/dist/structures/interaction.d.ts +197 -0
- package/dist/structures/interaction.js +396 -0
- package/dist/structures/invite.d.ts +38 -0
- package/dist/structures/invite.js +57 -0
- package/dist/structures/known.d.ts +28 -0
- package/dist/structures/known.js +58 -0
- package/dist/structures/member.d.ts +140 -0
- package/dist/structures/member.js +260 -0
- package/dist/structures/message.d.ts +197 -0
- package/dist/structures/message.js +268 -0
- package/dist/structures/payload.d.ts +91 -0
- package/dist/structures/payload.js +184 -0
- package/dist/structures/role.d.ts +69 -0
- package/dist/structures/role.js +112 -0
- package/dist/structures/user.d.ts +59 -0
- package/dist/structures/user.js +94 -0
- package/dist/structures/webhook.d.ts +46 -0
- package/dist/structures/webhook.js +79 -0
- package/dist/tasks/convention.d.ts +26 -0
- package/dist/tasks/convention.js +78 -0
- package/dist/tasks/schedule.d.ts +54 -0
- package/dist/tasks/schedule.js +236 -0
- package/dist/tasks/scheduler.d.ts +33 -0
- package/dist/tasks/scheduler.js +107 -0
- package/dist/tasks/task.d.ts +76 -0
- package/dist/tasks/task.js +28 -0
- package/dist/util/case.d.ts +13 -0
- package/dist/util/case.js +54 -0
- package/dist/util/duration.d.ts +8 -0
- package/dist/util/duration.js +29 -0
- package/dist/util/websocket.d.ts +9 -0
- package/dist/util/websocket.js +31 -0
- package/dist/voice/connection.d.ts +90 -0
- package/dist/voice/connection.js +494 -0
- package/dist/voice/dave.d.ts +109 -0
- package/dist/voice/dave.js +245 -0
- package/dist/voice/opus.d.ts +19 -0
- package/dist/voice/opus.js +273 -0
- package/dist/voice/session.d.ts +55 -0
- package/dist/voice/session.js +405 -0
- package/dist/voice/source.d.ts +22 -0
- package/dist/voice/source.js +195 -0
- package/dist/voice/transport.d.ts +43 -0
- package/dist/voice/transport.js +140 -0
- package/dist/voice/usage.d.ts +4 -0
- package/dist/voice/usage.js +33 -0
- package/package.json +26 -7
- package/vendor/dave/LICENSE +231 -0
- package/vendor/dave/libdave.d.mts +99 -0
- package/vendor/dave/libdave.mjs +2 -0
- package/vendor/dave/libdave.wasm +0 -0
- package/dist/components.d.ts +0 -97
- package/dist/components.js +0 -260
- package/dist/context.d.ts +0 -72
- package/dist/context.js +0 -273
- package/dist/discord/client.d.ts +0 -35
- package/dist/discord/client.js +0 -66
- package/dist/discord/constants.d.ts +0 -49
- package/dist/discord/constants.js +0 -61
- package/dist/discord/events.d.ts +0 -129
- package/dist/discord/events.js +0 -102
- package/dist/discord/gateway.d.ts +0 -61
- package/dist/discord/gateway.js +0 -320
- package/dist/discord/payloads.d.ts +0 -275
- package/dist/discord/payloads.js +0 -3
- package/dist/discord/presence.d.ts +0 -42
- package/dist/discord/presence.js +0 -51
- package/dist/discord/rest.d.ts +0 -49
- package/dist/discord/rest.js +0 -271
- package/dist/discord/types.d.ts +0 -334
- package/dist/discord/types.js +0 -4
- package/dist/events.d.ts +0 -94
- package/dist/events.js +0 -255
- package/dist/presence.d.ts +0 -92
- package/dist/presence.js +0 -250
- package/dist/structures/Channel.d.ts +0 -110
- package/dist/structures/Channel.js +0 -171
- package/dist/structures/Guild.d.ts +0 -70
- package/dist/structures/Guild.js +0 -105
- package/dist/structures/Interaction.d.ts +0 -113
- package/dist/structures/Interaction.js +0 -274
- package/dist/structures/Member.d.ts +0 -70
- package/dist/structures/Member.js +0 -124
- package/dist/structures/Message.d.ts +0 -87
- package/dist/structures/Message.js +0 -182
- package/dist/structures/Reaction.d.ts +0 -38
- package/dist/structures/Reaction.js +0 -64
- package/dist/structures/Role.d.ts +0 -43
- package/dist/structures/Role.js +0 -77
- package/dist/structures/User.d.ts +0 -41
- package/dist/structures/User.js +0 -79
- package/dist/structures/utils.d.ts +0 -72
- package/dist/structures/utils.js +0 -59
- package/dist/utils/errors.d.ts +0 -5
- package/dist/utils/errors.js +0 -28
- package/dist/utils/modules.d.ts +0 -39
- package/dist/utils/modules.js +0 -156
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Snowflake } from './types/common.js';
|
|
2
|
+
/** `<@USER_ID>`: mentions a user. */
|
|
3
|
+
export declare function userMention(userId: Snowflake): `<@${string}>`;
|
|
4
|
+
/** `<#CHANNEL_ID>`: links a channel. */
|
|
5
|
+
export declare function channelMention(channelId: Snowflake): `<#${string}>`;
|
|
6
|
+
/** `<@&ROLE_ID>`: mentions a role. */
|
|
7
|
+
export declare function roleMention(roleId: Snowflake): `<@&${string}>`;
|
|
8
|
+
/**
|
|
9
|
+
* `</NAME:COMMAND_ID>`: a clickable slash command. The name includes the
|
|
10
|
+
* subcommand group and subcommand when there are some (`"foo group bar"`).
|
|
11
|
+
*/
|
|
12
|
+
export declare function commandMention(name: string, commandId: Snowflake): `</${string}:${string}>`;
|
|
13
|
+
/** `<:NAME:ID>` or `<a:NAME:ID>`: a custom emoji. */
|
|
14
|
+
export declare function emojiMention(name: string, emojiId: Snowflake, animated?: boolean): string;
|
|
15
|
+
/**
|
|
16
|
+
* Timestamp Styles
|
|
17
|
+
* @see https://docs.discord.com/developers/reference#message-formatting-timestamp-styles
|
|
18
|
+
*/
|
|
19
|
+
export declare const TimestampStyle: {
|
|
20
|
+
/** 16:20 */
|
|
21
|
+
readonly ShortTime: 't';
|
|
22
|
+
/** 16:20:30 */
|
|
23
|
+
readonly MediumTime: 'T';
|
|
24
|
+
/** 20/04/2021 */
|
|
25
|
+
readonly ShortDate: 'd';
|
|
26
|
+
/** April 20, 2021 */
|
|
27
|
+
readonly LongDate: 'D';
|
|
28
|
+
/** April 20, 2021 at 16:20 (default) */
|
|
29
|
+
readonly LongDateShortTime: 'f';
|
|
30
|
+
/** Tuesday, April 20, 2021 at 16:20 */
|
|
31
|
+
readonly FullDateShortTime: 'F';
|
|
32
|
+
/** 20/04/2021, 16:20 */
|
|
33
|
+
readonly ShortDateShortTime: 's';
|
|
34
|
+
/** 20/04/2021, 16:20:30 */
|
|
35
|
+
readonly ShortDateMediumTime: 'S';
|
|
36
|
+
/** 4 years ago */
|
|
37
|
+
readonly Relative: 'R';
|
|
38
|
+
};
|
|
39
|
+
export type TimestampStyle = (typeof TimestampStyle)[keyof typeof TimestampStyle];
|
|
40
|
+
/**
|
|
41
|
+
* `<t:TIMESTAMP>` or `<t:TIMESTAMP:STYLE>`: a date shown to each reader in
|
|
42
|
+
* their own timezone and language. Timestamps are expressed in seconds.
|
|
43
|
+
*/
|
|
44
|
+
export declare function timestamp(date: Date | number, style?: TimestampStyle): string;
|
|
45
|
+
/**
|
|
46
|
+
* Guild Navigation Types: links to a tab of the current server.
|
|
47
|
+
* @see https://docs.discord.com/developers/reference#message-formatting-guild-navigation-types
|
|
48
|
+
*/
|
|
49
|
+
export declare const GuildNavigation: {
|
|
50
|
+
/** Channel & Roles tab with Onboarding prompts */
|
|
51
|
+
readonly Customize: '<id:customize>';
|
|
52
|
+
/** Browse Channels tab */
|
|
53
|
+
readonly Browse: '<id:browse>';
|
|
54
|
+
/** Server Guide tab */
|
|
55
|
+
readonly Guide: '<id:guide>';
|
|
56
|
+
/** Linked Roles tab */
|
|
57
|
+
readonly LinkedRoles: '<id:linked-roles>';
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* The emoji of a reaction as REST paths expect it: the emoji itself for a
|
|
61
|
+
* standard one, `name:id` for a custom one.
|
|
62
|
+
* @see https://docs.discord.com/developers/resources/message#create-reaction
|
|
63
|
+
*/
|
|
64
|
+
export declare function reactionEmoji(emoji: {
|
|
65
|
+
id?: Snowflake | null;
|
|
66
|
+
name?: string | null;
|
|
67
|
+
}): string;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// The text formats Discord turns into mentions, emojis and dates.
|
|
2
|
+
// https://docs.discord.com/developers/reference#message-formatting
|
|
3
|
+
/** `<@USER_ID>`: mentions a user. */
|
|
4
|
+
export function userMention(userId) {
|
|
5
|
+
return `<@${userId}>`;
|
|
6
|
+
}
|
|
7
|
+
/** `<#CHANNEL_ID>`: links a channel. */
|
|
8
|
+
export function channelMention(channelId) {
|
|
9
|
+
return `<#${channelId}>`;
|
|
10
|
+
}
|
|
11
|
+
/** `<@&ROLE_ID>`: mentions a role. */
|
|
12
|
+
export function roleMention(roleId) {
|
|
13
|
+
return `<@&${roleId}>`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `</NAME:COMMAND_ID>`: a clickable slash command. The name includes the
|
|
17
|
+
* subcommand group and subcommand when there are some (`"foo group bar"`).
|
|
18
|
+
*/
|
|
19
|
+
export function commandMention(name, commandId) {
|
|
20
|
+
return `</${name}:${commandId}>`;
|
|
21
|
+
}
|
|
22
|
+
/** `<:NAME:ID>` or `<a:NAME:ID>`: a custom emoji. */
|
|
23
|
+
export function emojiMention(name, emojiId, animated = false) {
|
|
24
|
+
return `<${animated ? 'a' : ''}:${name}:${emojiId}>`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Timestamp Styles
|
|
28
|
+
* @see https://docs.discord.com/developers/reference#message-formatting-timestamp-styles
|
|
29
|
+
*/
|
|
30
|
+
export const TimestampStyle = {
|
|
31
|
+
/** 16:20 */
|
|
32
|
+
ShortTime: 't',
|
|
33
|
+
/** 16:20:30 */
|
|
34
|
+
MediumTime: 'T',
|
|
35
|
+
/** 20/04/2021 */
|
|
36
|
+
ShortDate: 'd',
|
|
37
|
+
/** April 20, 2021 */
|
|
38
|
+
LongDate: 'D',
|
|
39
|
+
/** April 20, 2021 at 16:20 (default) */
|
|
40
|
+
LongDateShortTime: 'f',
|
|
41
|
+
/** Tuesday, April 20, 2021 at 16:20 */
|
|
42
|
+
FullDateShortTime: 'F',
|
|
43
|
+
/** 20/04/2021, 16:20 */
|
|
44
|
+
ShortDateShortTime: 's',
|
|
45
|
+
/** 20/04/2021, 16:20:30 */
|
|
46
|
+
ShortDateMediumTime: 'S',
|
|
47
|
+
/** 4 years ago */
|
|
48
|
+
Relative: 'R',
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* `<t:TIMESTAMP>` or `<t:TIMESTAMP:STYLE>`: a date shown to each reader in
|
|
52
|
+
* their own timezone and language. Timestamps are expressed in seconds.
|
|
53
|
+
*/
|
|
54
|
+
export function timestamp(date, style) {
|
|
55
|
+
const ms = Number(date);
|
|
56
|
+
if (!Number.isFinite(ms)) {
|
|
57
|
+
throw new TypeError('timestamp() needs a valid date.');
|
|
58
|
+
}
|
|
59
|
+
const seconds = Math.floor(ms / 1000);
|
|
60
|
+
return style ? `<t:${seconds}:${style}>` : `<t:${seconds}>`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Guild Navigation Types: links to a tab of the current server.
|
|
64
|
+
* @see https://docs.discord.com/developers/reference#message-formatting-guild-navigation-types
|
|
65
|
+
*/
|
|
66
|
+
export const GuildNavigation = {
|
|
67
|
+
/** Channel & Roles tab with Onboarding prompts */
|
|
68
|
+
Customize: '<id:customize>',
|
|
69
|
+
/** Browse Channels tab */
|
|
70
|
+
Browse: '<id:browse>',
|
|
71
|
+
/** Server Guide tab */
|
|
72
|
+
Guide: '<id:guide>',
|
|
73
|
+
/** Linked Roles tab */
|
|
74
|
+
LinkedRoles: '<id:linked-roles>',
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The emoji of a reaction as REST paths expect it: the emoji itself for a
|
|
78
|
+
* standard one, `name:id` for a custom one.
|
|
79
|
+
* @see https://docs.discord.com/developers/resources/message#create-reaction
|
|
80
|
+
*/
|
|
81
|
+
export function reactionEmoji(emoji) {
|
|
82
|
+
if (emoji.id)
|
|
83
|
+
return `${emoji.name ?? '_'}:${emoji.id}`;
|
|
84
|
+
if (!emoji.name)
|
|
85
|
+
throw new TypeError('An emoji needs a name or an id.');
|
|
86
|
+
return emoji.name;
|
|
87
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './api.js';
|
|
2
|
+
export * from './cdn.js';
|
|
3
|
+
export * from './codes.js';
|
|
4
|
+
export * from './endpoint.js';
|
|
5
|
+
export * as Endpoints from './endpoints.js';
|
|
6
|
+
export * from './formatting.js';
|
|
7
|
+
export * from './intents.js';
|
|
8
|
+
export * from './permissions.js';
|
|
9
|
+
export * from './snowflake.js';
|
|
10
|
+
export * from './types/index.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Everything the framework knows about Discord that never changes at
|
|
2
|
+
// runtime: constants, payload types and pure helpers, each linked to the
|
|
3
|
+
// page of the official documentation it comes from.
|
|
4
|
+
export * from './api.js';
|
|
5
|
+
export * from './cdn.js';
|
|
6
|
+
export * from './codes.js';
|
|
7
|
+
export * from './endpoint.js';
|
|
8
|
+
export * as Endpoints from './endpoints.js';
|
|
9
|
+
export * from './formatting.js';
|
|
10
|
+
export * from './intents.js';
|
|
11
|
+
export * from './permissions.js';
|
|
12
|
+
export * from './snowflake.js';
|
|
13
|
+
export * from './types/index.js';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { GatewayDispatchEventName } from './types/gateway-events.js';
|
|
2
|
+
/**
|
|
3
|
+
* Gateway Intents: which groups of events Discord sends to the bot.
|
|
4
|
+
* @see https://docs.discord.com/developers/events/gateway#list-of-intents
|
|
5
|
+
*/
|
|
6
|
+
export declare const GatewayIntent: {
|
|
7
|
+
readonly Guilds: number;
|
|
8
|
+
readonly GuildMembers: number;
|
|
9
|
+
readonly GuildModeration: number;
|
|
10
|
+
readonly GuildExpressions: number;
|
|
11
|
+
readonly GuildIntegrations: number;
|
|
12
|
+
readonly GuildWebhooks: number;
|
|
13
|
+
readonly GuildInvites: number;
|
|
14
|
+
readonly GuildVoiceStates: number;
|
|
15
|
+
readonly GuildPresences: number;
|
|
16
|
+
readonly GuildMessages: number;
|
|
17
|
+
readonly GuildMessageReactions: number;
|
|
18
|
+
readonly GuildMessageTyping: number;
|
|
19
|
+
readonly DirectMessages: number;
|
|
20
|
+
readonly DirectMessageReactions: number;
|
|
21
|
+
readonly DirectMessageTyping: number;
|
|
22
|
+
readonly MessageContent: number;
|
|
23
|
+
readonly GuildScheduledEvents: number;
|
|
24
|
+
readonly AutoModerationConfiguration: number;
|
|
25
|
+
readonly AutoModerationExecution: number;
|
|
26
|
+
readonly GuildMessagePolls: number;
|
|
27
|
+
readonly DirectMessagePolls: number;
|
|
28
|
+
};
|
|
29
|
+
export type GatewayIntent = (typeof GatewayIntent)[keyof typeof GatewayIntent];
|
|
30
|
+
export type GatewayIntentName = keyof typeof GatewayIntent;
|
|
31
|
+
/**
|
|
32
|
+
* Intents that must be enabled by hand in the Developer Portal.
|
|
33
|
+
* @see https://docs.discord.com/developers/events/gateway#privileged-intents
|
|
34
|
+
*/
|
|
35
|
+
export declare const PRIVILEGED_INTENTS: readonly GatewayIntentName[];
|
|
36
|
+
/**
|
|
37
|
+
* The intents that make Discord send each event, exactly as the list of
|
|
38
|
+
* intents of the documentation groups them. An event listed under several
|
|
39
|
+
* intents is sent when any of them is set (the guild one for what happens in
|
|
40
|
+
* a server, the direct message one for DMs). An event that is not here needs
|
|
41
|
+
* no intent.
|
|
42
|
+
* @see https://docs.discord.com/developers/events/gateway#list-of-intents
|
|
43
|
+
*/
|
|
44
|
+
export declare const EVENT_INTENTS: Readonly<Partial<Record<GatewayDispatchEventName, readonly GatewayIntent[]>>>;
|
|
45
|
+
/** Combines intents into the number sent when identifying. */
|
|
46
|
+
export declare function combineIntents(intents: Iterable<GatewayIntent | GatewayIntentName>): number;
|
|
47
|
+
/** The names of the intents set in a number, in the order of the docs. */
|
|
48
|
+
export declare function intentNames(bits: number): GatewayIntentName[];
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gateway Intents: which groups of events Discord sends to the bot.
|
|
3
|
+
* @see https://docs.discord.com/developers/events/gateway#list-of-intents
|
|
4
|
+
*/
|
|
5
|
+
export const GatewayIntent = {
|
|
6
|
+
Guilds: 1 << 0,
|
|
7
|
+
GuildMembers: 1 << 1,
|
|
8
|
+
GuildModeration: 1 << 2,
|
|
9
|
+
GuildExpressions: 1 << 3,
|
|
10
|
+
GuildIntegrations: 1 << 4,
|
|
11
|
+
GuildWebhooks: 1 << 5,
|
|
12
|
+
GuildInvites: 1 << 6,
|
|
13
|
+
GuildVoiceStates: 1 << 7,
|
|
14
|
+
GuildPresences: 1 << 8,
|
|
15
|
+
GuildMessages: 1 << 9,
|
|
16
|
+
GuildMessageReactions: 1 << 10,
|
|
17
|
+
GuildMessageTyping: 1 << 11,
|
|
18
|
+
DirectMessages: 1 << 12,
|
|
19
|
+
DirectMessageReactions: 1 << 13,
|
|
20
|
+
DirectMessageTyping: 1 << 14,
|
|
21
|
+
MessageContent: 1 << 15,
|
|
22
|
+
GuildScheduledEvents: 1 << 16,
|
|
23
|
+
AutoModerationConfiguration: 1 << 20,
|
|
24
|
+
AutoModerationExecution: 1 << 21,
|
|
25
|
+
GuildMessagePolls: 1 << 24,
|
|
26
|
+
DirectMessagePolls: 1 << 25,
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Intents that must be enabled by hand in the Developer Portal.
|
|
30
|
+
* @see https://docs.discord.com/developers/events/gateway#privileged-intents
|
|
31
|
+
*/
|
|
32
|
+
export const PRIVILEGED_INTENTS = [
|
|
33
|
+
'GuildPresences',
|
|
34
|
+
'GuildMembers',
|
|
35
|
+
'MessageContent',
|
|
36
|
+
];
|
|
37
|
+
const I = GatewayIntent;
|
|
38
|
+
/**
|
|
39
|
+
* The intents that make Discord send each event, exactly as the list of
|
|
40
|
+
* intents of the documentation groups them. An event listed under several
|
|
41
|
+
* intents is sent when any of them is set (the guild one for what happens in
|
|
42
|
+
* a server, the direct message one for DMs). An event that is not here needs
|
|
43
|
+
* no intent.
|
|
44
|
+
* @see https://docs.discord.com/developers/events/gateway#list-of-intents
|
|
45
|
+
*/
|
|
46
|
+
export const EVENT_INTENTS = {
|
|
47
|
+
GUILD_CREATE: [I.Guilds],
|
|
48
|
+
GUILD_UPDATE: [I.Guilds],
|
|
49
|
+
GUILD_DELETE: [I.Guilds],
|
|
50
|
+
GUILD_ROLE_CREATE: [I.Guilds],
|
|
51
|
+
GUILD_ROLE_UPDATE: [I.Guilds],
|
|
52
|
+
GUILD_ROLE_DELETE: [I.Guilds],
|
|
53
|
+
CHANNEL_CREATE: [I.Guilds],
|
|
54
|
+
CHANNEL_UPDATE: [I.Guilds],
|
|
55
|
+
CHANNEL_DELETE: [I.Guilds],
|
|
56
|
+
CHANNEL_PINS_UPDATE: [I.Guilds, I.DirectMessages],
|
|
57
|
+
THREAD_CREATE: [I.Guilds],
|
|
58
|
+
THREAD_UPDATE: [I.Guilds],
|
|
59
|
+
THREAD_DELETE: [I.Guilds],
|
|
60
|
+
THREAD_LIST_SYNC: [I.Guilds],
|
|
61
|
+
THREAD_MEMBER_UPDATE: [I.Guilds],
|
|
62
|
+
THREAD_MEMBERS_UPDATE: [I.Guilds, I.GuildMembers],
|
|
63
|
+
STAGE_INSTANCE_CREATE: [I.Guilds],
|
|
64
|
+
STAGE_INSTANCE_UPDATE: [I.Guilds],
|
|
65
|
+
STAGE_INSTANCE_DELETE: [I.Guilds],
|
|
66
|
+
VOICE_CHANNEL_STATUS_UPDATE: [I.Guilds],
|
|
67
|
+
VOICE_CHANNEL_START_TIME_UPDATE: [I.Guilds],
|
|
68
|
+
GUILD_MEMBER_ADD: [I.GuildMembers],
|
|
69
|
+
GUILD_MEMBER_UPDATE: [I.GuildMembers],
|
|
70
|
+
GUILD_MEMBER_REMOVE: [I.GuildMembers],
|
|
71
|
+
GUILD_AUDIT_LOG_ENTRY_CREATE: [I.GuildModeration],
|
|
72
|
+
GUILD_BAN_ADD: [I.GuildModeration],
|
|
73
|
+
GUILD_BAN_REMOVE: [I.GuildModeration],
|
|
74
|
+
GUILD_EMOJIS_UPDATE: [I.GuildExpressions],
|
|
75
|
+
GUILD_STICKERS_UPDATE: [I.GuildExpressions],
|
|
76
|
+
GUILD_SOUNDBOARD_SOUND_CREATE: [I.GuildExpressions],
|
|
77
|
+
GUILD_SOUNDBOARD_SOUND_UPDATE: [I.GuildExpressions],
|
|
78
|
+
GUILD_SOUNDBOARD_SOUND_DELETE: [I.GuildExpressions],
|
|
79
|
+
GUILD_SOUNDBOARD_SOUNDS_UPDATE: [I.GuildExpressions],
|
|
80
|
+
GUILD_INTEGRATIONS_UPDATE: [I.GuildIntegrations],
|
|
81
|
+
INTEGRATION_CREATE: [I.GuildIntegrations],
|
|
82
|
+
INTEGRATION_UPDATE: [I.GuildIntegrations],
|
|
83
|
+
INTEGRATION_DELETE: [I.GuildIntegrations],
|
|
84
|
+
WEBHOOKS_UPDATE: [I.GuildWebhooks],
|
|
85
|
+
INVITE_CREATE: [I.GuildInvites],
|
|
86
|
+
INVITE_DELETE: [I.GuildInvites],
|
|
87
|
+
VOICE_CHANNEL_EFFECT_SEND: [I.GuildVoiceStates],
|
|
88
|
+
VOICE_STATE_UPDATE: [I.GuildVoiceStates],
|
|
89
|
+
PRESENCE_UPDATE: [I.GuildPresences],
|
|
90
|
+
MESSAGE_CREATE: [I.GuildMessages, I.DirectMessages],
|
|
91
|
+
MESSAGE_UPDATE: [I.GuildMessages, I.DirectMessages],
|
|
92
|
+
MESSAGE_DELETE: [I.GuildMessages, I.DirectMessages],
|
|
93
|
+
MESSAGE_DELETE_BULK: [I.GuildMessages],
|
|
94
|
+
MESSAGE_REACTION_ADD: [I.GuildMessageReactions, I.DirectMessageReactions],
|
|
95
|
+
MESSAGE_REACTION_REMOVE: [I.GuildMessageReactions, I.DirectMessageReactions],
|
|
96
|
+
MESSAGE_REACTION_REMOVE_ALL: [
|
|
97
|
+
I.GuildMessageReactions,
|
|
98
|
+
I.DirectMessageReactions,
|
|
99
|
+
],
|
|
100
|
+
MESSAGE_REACTION_REMOVE_EMOJI: [
|
|
101
|
+
I.GuildMessageReactions,
|
|
102
|
+
I.DirectMessageReactions,
|
|
103
|
+
],
|
|
104
|
+
TYPING_START: [I.GuildMessageTyping, I.DirectMessageTyping],
|
|
105
|
+
GUILD_SCHEDULED_EVENT_CREATE: [I.GuildScheduledEvents],
|
|
106
|
+
GUILD_SCHEDULED_EVENT_UPDATE: [I.GuildScheduledEvents],
|
|
107
|
+
GUILD_SCHEDULED_EVENT_DELETE: [I.GuildScheduledEvents],
|
|
108
|
+
GUILD_SCHEDULED_EVENT_USER_ADD: [I.GuildScheduledEvents],
|
|
109
|
+
GUILD_SCHEDULED_EVENT_USER_REMOVE: [I.GuildScheduledEvents],
|
|
110
|
+
AUTO_MODERATION_RULE_CREATE: [I.AutoModerationConfiguration],
|
|
111
|
+
AUTO_MODERATION_RULE_UPDATE: [I.AutoModerationConfiguration],
|
|
112
|
+
AUTO_MODERATION_RULE_DELETE: [I.AutoModerationConfiguration],
|
|
113
|
+
AUTO_MODERATION_ACTION_EXECUTION: [I.AutoModerationExecution],
|
|
114
|
+
MESSAGE_POLL_VOTE_ADD: [I.GuildMessagePolls, I.DirectMessagePolls],
|
|
115
|
+
MESSAGE_POLL_VOTE_REMOVE: [I.GuildMessagePolls, I.DirectMessagePolls],
|
|
116
|
+
};
|
|
117
|
+
/** Combines intents into the number sent when identifying. */
|
|
118
|
+
export function combineIntents(intents) {
|
|
119
|
+
let bits = 0;
|
|
120
|
+
for (const intent of intents) {
|
|
121
|
+
bits |= typeof intent === 'number' ? intent : GatewayIntent[intent];
|
|
122
|
+
}
|
|
123
|
+
return bits;
|
|
124
|
+
}
|
|
125
|
+
/** The names of the intents set in a number, in the order of the docs. */
|
|
126
|
+
export function intentNames(bits) {
|
|
127
|
+
return Object.keys(GatewayIntent).filter(name => (bits & GatewayIntent[name]) !== 0);
|
|
128
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Snowflake } from './types/common.js';
|
|
2
|
+
import { PermissionFlags } from './types/permissions.js';
|
|
3
|
+
export type PermissionName = keyof typeof PermissionFlags;
|
|
4
|
+
/** A permission, or several: by name, as bits, or as a set. */
|
|
5
|
+
export type PermissionResolvable = PermissionName | bigint | Permissions | readonly (PermissionName | bigint)[];
|
|
6
|
+
/** Every permission that exists, combined. */
|
|
7
|
+
export declare const ALL_PERMISSIONS: bigint;
|
|
8
|
+
/**
|
|
9
|
+
* Permissions that only make sense on a moderator: Discord asks for
|
|
10
|
+
* two-factor authentication to use them on servers that require it.
|
|
11
|
+
* @see https://docs.discord.com/developers/topics/permissions#permissions-bitwise-permission-flags
|
|
12
|
+
*/
|
|
13
|
+
export declare const ELEVATED_PERMISSIONS: readonly PermissionName[];
|
|
14
|
+
/**
|
|
15
|
+
* A set of permissions that never changes: every operation returns a new
|
|
16
|
+
* set. Discord serializes permissions as text because they don't fit in a
|
|
17
|
+
* regular number.
|
|
18
|
+
* @see https://docs.discord.com/developers/topics/permissions
|
|
19
|
+
*/
|
|
20
|
+
export declare class Permissions {
|
|
21
|
+
/** The permissions as one number, each bit being a permission. */
|
|
22
|
+
readonly bits: bigint;
|
|
23
|
+
constructor(bits?: PermissionResolvable | string);
|
|
24
|
+
/**
|
|
25
|
+
* Whether every given permission is in the set. An administrator has
|
|
26
|
+
* every permission, unless `{ checkAdmin: false }` is passed.
|
|
27
|
+
*/
|
|
28
|
+
has(permission: PermissionResolvable, { checkAdmin }?: {
|
|
29
|
+
checkAdmin?: boolean;
|
|
30
|
+
}): boolean;
|
|
31
|
+
/** Whether at least one of the given permissions is in the set. */
|
|
32
|
+
any(permission: PermissionResolvable, { checkAdmin }?: {
|
|
33
|
+
checkAdmin?: boolean;
|
|
34
|
+
}): boolean;
|
|
35
|
+
/** The given permissions that are not in the set, by name. */
|
|
36
|
+
missing(permission: PermissionResolvable): PermissionName[];
|
|
37
|
+
/** A new set with the given permissions added. */
|
|
38
|
+
add(permission: PermissionResolvable): Permissions;
|
|
39
|
+
/** A new set without the given permissions. */
|
|
40
|
+
remove(permission: PermissionResolvable): Permissions;
|
|
41
|
+
/** The names of the permissions in the set, in the order of the docs. */
|
|
42
|
+
toArray(): PermissionName[];
|
|
43
|
+
/** The text Discord expects in a request. */
|
|
44
|
+
toString(): string;
|
|
45
|
+
/** The text Discord expects in a request. */
|
|
46
|
+
toJSON(): string;
|
|
47
|
+
}
|
|
48
|
+
/** What the permission computation needs to know about a role. */
|
|
49
|
+
export interface PermissionRole {
|
|
50
|
+
id: Snowflake;
|
|
51
|
+
permissions: bigint;
|
|
52
|
+
}
|
|
53
|
+
/** What the permission computation needs to know about an overwrite. */
|
|
54
|
+
export interface PermissionOverwrite {
|
|
55
|
+
id: Snowflake;
|
|
56
|
+
allow: bigint;
|
|
57
|
+
deny: bigint;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The permissions of a member in a server, before channel overwrites:
|
|
61
|
+
* `compute_base_permissions` of the documentation.
|
|
62
|
+
* @see https://docs.discord.com/developers/topics/permissions#permission-overwrites
|
|
63
|
+
*/
|
|
64
|
+
export declare function computeBasePermissions(input: {
|
|
65
|
+
guildId: Snowflake;
|
|
66
|
+
ownerId: Snowflake;
|
|
67
|
+
userId: Snowflake;
|
|
68
|
+
/** The ids of the roles of the member (@everyone is implied). */
|
|
69
|
+
memberRoleIds: readonly Snowflake[];
|
|
70
|
+
/** Every role of the server, @everyone included. */
|
|
71
|
+
roles: Iterable<PermissionRole>;
|
|
72
|
+
}): bigint;
|
|
73
|
+
/**
|
|
74
|
+
* The permissions of a member in a channel, from their server permissions:
|
|
75
|
+
* `compute_overwrites` of the documentation.
|
|
76
|
+
* @see https://docs.discord.com/developers/topics/permissions#permission-overwrites
|
|
77
|
+
*/
|
|
78
|
+
export declare function computeOverwrites(basePermissions: bigint, input: {
|
|
79
|
+
guildId: Snowflake;
|
|
80
|
+
userId: Snowflake;
|
|
81
|
+
memberRoleIds: readonly Snowflake[];
|
|
82
|
+
overwrites: Iterable<PermissionOverwrite>;
|
|
83
|
+
}): bigint;
|
|
84
|
+
/**
|
|
85
|
+
* Removes what a member can't do in practice in a channel they can't see
|
|
86
|
+
* or can't write in.
|
|
87
|
+
* @see https://docs.discord.com/developers/topics/permissions#implicit-permissions
|
|
88
|
+
*/
|
|
89
|
+
export declare function applyImplicitPermissions(permissions: bigint): bigint;
|
|
90
|
+
/**
|
|
91
|
+
* What is left of the permissions of a timed out member.
|
|
92
|
+
* @see https://docs.discord.com/developers/topics/permissions#permissions-for-timed-out-members
|
|
93
|
+
*/
|
|
94
|
+
export declare function applyTimeout(permissions: bigint): bigint;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { PermissionFlags } from './types/permissions.js';
|
|
2
|
+
/** Every permission that exists, combined. */
|
|
3
|
+
export const ALL_PERMISSIONS = Object.values(PermissionFlags).reduce((all, flag) => all | flag, 0n);
|
|
4
|
+
/**
|
|
5
|
+
* Permissions that only make sense on a moderator: Discord asks for
|
|
6
|
+
* two-factor authentication to use them on servers that require it.
|
|
7
|
+
* @see https://docs.discord.com/developers/topics/permissions#permissions-bitwise-permission-flags
|
|
8
|
+
*/
|
|
9
|
+
export const ELEVATED_PERMISSIONS = [
|
|
10
|
+
'KickMembers',
|
|
11
|
+
'BanMembers',
|
|
12
|
+
'Administrator',
|
|
13
|
+
'ManageChannels',
|
|
14
|
+
'ManageGuild',
|
|
15
|
+
'ManageMessages',
|
|
16
|
+
'ManageRoles',
|
|
17
|
+
'ManageWebhooks',
|
|
18
|
+
'ManageGuildExpressions',
|
|
19
|
+
'ManageThreads',
|
|
20
|
+
'ViewCreatorMonetizationAnalytics',
|
|
21
|
+
];
|
|
22
|
+
function resolve(permission) {
|
|
23
|
+
if (typeof permission === 'bigint')
|
|
24
|
+
return permission;
|
|
25
|
+
if (permission instanceof Permissions)
|
|
26
|
+
return permission.bits;
|
|
27
|
+
if (typeof permission === 'string') {
|
|
28
|
+
const flag = PermissionFlags[permission];
|
|
29
|
+
if (flag === undefined) {
|
|
30
|
+
throw new TypeError(`"${permission}" is not a permission. Permissions are: ${Object.keys(PermissionFlags).join(', ')}.`);
|
|
31
|
+
}
|
|
32
|
+
return flag;
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(permission)) {
|
|
35
|
+
return permission.reduce((bits, one) => bits | resolve(one), 0n);
|
|
36
|
+
}
|
|
37
|
+
throw new TypeError(`A permission is a name like "BanMembers", got ${typeof permission}.`);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A set of permissions that never changes: every operation returns a new
|
|
41
|
+
* set. Discord serializes permissions as text because they don't fit in a
|
|
42
|
+
* regular number.
|
|
43
|
+
* @see https://docs.discord.com/developers/topics/permissions
|
|
44
|
+
*/
|
|
45
|
+
export class Permissions {
|
|
46
|
+
/** The permissions as one number, each bit being a permission. */
|
|
47
|
+
bits;
|
|
48
|
+
constructor(bits = 0n) {
|
|
49
|
+
this.bits =
|
|
50
|
+
typeof bits === 'string' && /^\d+$/.test(bits)
|
|
51
|
+
? BigInt(bits)
|
|
52
|
+
: resolve(bits);
|
|
53
|
+
Object.freeze(this);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Whether every given permission is in the set. An administrator has
|
|
57
|
+
* every permission, unless `{ checkAdmin: false }` is passed.
|
|
58
|
+
*/
|
|
59
|
+
has(permission, { checkAdmin = true } = {}) {
|
|
60
|
+
if (checkAdmin && (this.bits & PermissionFlags.Administrator) !== 0n) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
const wanted = resolve(permission);
|
|
64
|
+
return (this.bits & wanted) === wanted;
|
|
65
|
+
}
|
|
66
|
+
/** Whether at least one of the given permissions is in the set. */
|
|
67
|
+
any(permission, { checkAdmin = true } = {}) {
|
|
68
|
+
if (checkAdmin && (this.bits & PermissionFlags.Administrator) !== 0n) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return (this.bits & resolve(permission)) !== 0n;
|
|
72
|
+
}
|
|
73
|
+
/** The given permissions that are not in the set, by name. */
|
|
74
|
+
missing(permission) {
|
|
75
|
+
if ((this.bits & PermissionFlags.Administrator) !== 0n)
|
|
76
|
+
return [];
|
|
77
|
+
return new Permissions(resolve(permission) & ~this.bits).toArray();
|
|
78
|
+
}
|
|
79
|
+
/** A new set with the given permissions added. */
|
|
80
|
+
add(permission) {
|
|
81
|
+
return new Permissions(this.bits | resolve(permission));
|
|
82
|
+
}
|
|
83
|
+
/** A new set without the given permissions. */
|
|
84
|
+
remove(permission) {
|
|
85
|
+
return new Permissions(this.bits & ~resolve(permission));
|
|
86
|
+
}
|
|
87
|
+
/** The names of the permissions in the set, in the order of the docs. */
|
|
88
|
+
toArray() {
|
|
89
|
+
return Object.keys(PermissionFlags).filter(name => (this.bits & PermissionFlags[name]) !== 0n);
|
|
90
|
+
}
|
|
91
|
+
/** The text Discord expects in a request. */
|
|
92
|
+
toString() {
|
|
93
|
+
return this.bits.toString();
|
|
94
|
+
}
|
|
95
|
+
/** The text Discord expects in a request. */
|
|
96
|
+
toJSON() {
|
|
97
|
+
return this.toString();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The permissions of a member in a server, before channel overwrites:
|
|
102
|
+
* `compute_base_permissions` of the documentation.
|
|
103
|
+
* @see https://docs.discord.com/developers/topics/permissions#permission-overwrites
|
|
104
|
+
*/
|
|
105
|
+
export function computeBasePermissions(input) {
|
|
106
|
+
if (input.ownerId === input.userId)
|
|
107
|
+
return ALL_PERMISSIONS;
|
|
108
|
+
const owned = new Set(input.memberRoleIds);
|
|
109
|
+
let permissions = 0n;
|
|
110
|
+
for (const role of input.roles) {
|
|
111
|
+
// The @everyone role has the id of the server.
|
|
112
|
+
if (role.id === input.guildId || owned.has(role.id)) {
|
|
113
|
+
permissions |= role.permissions;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if ((permissions & PermissionFlags.Administrator) !== 0n) {
|
|
117
|
+
return ALL_PERMISSIONS;
|
|
118
|
+
}
|
|
119
|
+
return permissions;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The permissions of a member in a channel, from their server permissions:
|
|
123
|
+
* `compute_overwrites` of the documentation.
|
|
124
|
+
* @see https://docs.discord.com/developers/topics/permissions#permission-overwrites
|
|
125
|
+
*/
|
|
126
|
+
export function computeOverwrites(basePermissions, input) {
|
|
127
|
+
if ((basePermissions & PermissionFlags.Administrator) !== 0n) {
|
|
128
|
+
return ALL_PERMISSIONS;
|
|
129
|
+
}
|
|
130
|
+
const owned = new Set(input.memberRoleIds);
|
|
131
|
+
let everyone;
|
|
132
|
+
let member;
|
|
133
|
+
let allow = 0n;
|
|
134
|
+
let deny = 0n;
|
|
135
|
+
for (const overwrite of input.overwrites) {
|
|
136
|
+
if (overwrite.id === input.guildId)
|
|
137
|
+
everyone = overwrite;
|
|
138
|
+
else if (overwrite.id === input.userId)
|
|
139
|
+
member = overwrite;
|
|
140
|
+
else if (owned.has(overwrite.id)) {
|
|
141
|
+
allow |= overwrite.allow;
|
|
142
|
+
deny |= overwrite.deny;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
let permissions = basePermissions;
|
|
146
|
+
if (everyone) {
|
|
147
|
+
permissions &= ~everyone.deny;
|
|
148
|
+
permissions |= everyone.allow;
|
|
149
|
+
}
|
|
150
|
+
permissions &= ~deny;
|
|
151
|
+
permissions |= allow;
|
|
152
|
+
if (member) {
|
|
153
|
+
permissions &= ~member.deny;
|
|
154
|
+
permissions |= member.allow;
|
|
155
|
+
}
|
|
156
|
+
return permissions;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Removes what a member can't do in practice in a channel they can't see
|
|
160
|
+
* or can't write in.
|
|
161
|
+
* @see https://docs.discord.com/developers/topics/permissions#implicit-permissions
|
|
162
|
+
*/
|
|
163
|
+
export function applyImplicitPermissions(permissions) {
|
|
164
|
+
if ((permissions & PermissionFlags.Administrator) !== 0n)
|
|
165
|
+
return permissions;
|
|
166
|
+
if ((permissions & PermissionFlags.ViewChannel) === 0n)
|
|
167
|
+
return 0n;
|
|
168
|
+
if ((permissions & PermissionFlags.SendMessages) === 0n) {
|
|
169
|
+
permissions &= ~(PermissionFlags.MentionEveryone |
|
|
170
|
+
PermissionFlags.SendTtsMessages |
|
|
171
|
+
PermissionFlags.AttachFiles |
|
|
172
|
+
PermissionFlags.EmbedLinks);
|
|
173
|
+
}
|
|
174
|
+
return permissions;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* What is left of the permissions of a timed out member.
|
|
178
|
+
* @see https://docs.discord.com/developers/topics/permissions#permissions-for-timed-out-members
|
|
179
|
+
*/
|
|
180
|
+
export function applyTimeout(permissions) {
|
|
181
|
+
if ((permissions & PermissionFlags.Administrator) !== 0n)
|
|
182
|
+
return permissions;
|
|
183
|
+
return (permissions &
|
|
184
|
+
(PermissionFlags.ViewChannel | PermissionFlags.ReadMessageHistory));
|
|
185
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Snowflake } from './types/common.js';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a value looks like a Discord id: used to reject a wrong value
|
|
4
|
+
* (a name, a mention, a number) before it is sent to Discord.
|
|
5
|
+
* @see https://docs.discord.com/developers/reference#snowflakes
|
|
6
|
+
*/
|
|
7
|
+
export declare function isSnowflake(value: unknown): value is Snowflake;
|
|
8
|
+
/**
|
|
9
|
+
* When the thing a snowflake identifies was created, in milliseconds since
|
|
10
|
+
* the Unix epoch: `(snowflake >> 22) + 1420070400000`.
|
|
11
|
+
* @see https://docs.discord.com/developers/reference#snowflake-id-format-structure-left-to-right
|
|
12
|
+
*/
|
|
13
|
+
export declare function snowflakeTimestamp(id: Snowflake): number;
|
|
14
|
+
/**
|
|
15
|
+
* The smallest snowflake created at a given time: lets `before` / `after`
|
|
16
|
+
* pagination start from a date.
|
|
17
|
+
* @see https://docs.discord.com/developers/reference#snowflake-ids-in-pagination
|
|
18
|
+
*/
|
|
19
|
+
export declare function snowflakeFromTimestamp(timestamp: number | Date): Snowflake;
|
|
20
|
+
/** Sorts ids from the oldest to the newest; as text they would sort wrong. */
|
|
21
|
+
export declare function compareSnowflakes(a: Snowflake, b: Snowflake): number;
|