chapterjs 0.1.2 → 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
package/dist/discord/types.d.ts
DELETED
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
/** https://docs.discord.com/developers/reference#snowflakes */
|
|
2
|
-
export type Snowflake = string;
|
|
3
|
-
/** ISO8601 timestamp, e.g. `2026-10-03T15:00:00.000000+00:00`. */
|
|
4
|
-
export type Timestamp = string;
|
|
5
|
-
/** Any object Discord may send, for events not typed in detail yet. */
|
|
6
|
-
export type GatewayObject = {
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
};
|
|
9
|
-
export interface APIUser {
|
|
10
|
-
id: Snowflake;
|
|
11
|
-
username: string;
|
|
12
|
-
discriminator: string;
|
|
13
|
-
global_name: string | null;
|
|
14
|
-
avatar: string | null;
|
|
15
|
-
bot?: boolean;
|
|
16
|
-
system?: boolean;
|
|
17
|
-
mfa_enabled?: boolean;
|
|
18
|
-
banner?: string | null;
|
|
19
|
-
accent_color?: number | null;
|
|
20
|
-
locale?: string;
|
|
21
|
-
verified?: boolean;
|
|
22
|
-
email?: string | null;
|
|
23
|
-
flags?: number;
|
|
24
|
-
premium_type?: number;
|
|
25
|
-
public_flags?: number;
|
|
26
|
-
avatar_decoration_data?: unknown;
|
|
27
|
-
collectibles?: unknown;
|
|
28
|
-
primary_guild?: unknown;
|
|
29
|
-
}
|
|
30
|
-
export interface APIGuildMember {
|
|
31
|
-
user?: APIUser;
|
|
32
|
-
nick?: string | null;
|
|
33
|
-
avatar?: string | null;
|
|
34
|
-
banner?: string | null;
|
|
35
|
-
roles: Snowflake[];
|
|
36
|
-
joined_at: Timestamp | null;
|
|
37
|
-
premium_since?: Timestamp | null;
|
|
38
|
-
deaf: boolean;
|
|
39
|
-
mute: boolean;
|
|
40
|
-
flags: number;
|
|
41
|
-
pending?: boolean;
|
|
42
|
-
permissions?: string;
|
|
43
|
-
communication_disabled_until?: Timestamp | null;
|
|
44
|
-
avatar_decoration_data?: unknown;
|
|
45
|
-
collectibles?: unknown;
|
|
46
|
-
}
|
|
47
|
-
export interface APIUnavailableGuild {
|
|
48
|
-
id: Snowflake;
|
|
49
|
-
unavailable?: boolean;
|
|
50
|
-
}
|
|
51
|
-
export interface APIGuild {
|
|
52
|
-
id: Snowflake;
|
|
53
|
-
name: string;
|
|
54
|
-
icon: string | null;
|
|
55
|
-
icon_hash?: string | null;
|
|
56
|
-
splash: string | null;
|
|
57
|
-
discovery_splash: string | null;
|
|
58
|
-
owner_id: Snowflake;
|
|
59
|
-
afk_channel_id: Snowflake | null;
|
|
60
|
-
afk_timeout: number;
|
|
61
|
-
widget_enabled?: boolean;
|
|
62
|
-
widget_channel_id?: Snowflake | null;
|
|
63
|
-
verification_level: number;
|
|
64
|
-
default_message_notifications: number;
|
|
65
|
-
explicit_content_filter: number;
|
|
66
|
-
roles: unknown[];
|
|
67
|
-
emojis: unknown[];
|
|
68
|
-
features: string[];
|
|
69
|
-
mfa_level: number;
|
|
70
|
-
application_id: Snowflake | null;
|
|
71
|
-
system_channel_id: Snowflake | null;
|
|
72
|
-
system_channel_flags: number;
|
|
73
|
-
rules_channel_id: Snowflake | null;
|
|
74
|
-
max_presences?: number | null;
|
|
75
|
-
max_members?: number;
|
|
76
|
-
vanity_url_code: string | null;
|
|
77
|
-
description: string | null;
|
|
78
|
-
banner: string | null;
|
|
79
|
-
premium_tier: number;
|
|
80
|
-
premium_subscription_count?: number;
|
|
81
|
-
preferred_locale: string;
|
|
82
|
-
public_updates_channel_id: Snowflake | null;
|
|
83
|
-
max_video_channel_users?: number;
|
|
84
|
-
max_stage_video_channel_users?: number;
|
|
85
|
-
welcome_screen?: unknown;
|
|
86
|
-
nsfw_level: number;
|
|
87
|
-
stickers?: unknown[];
|
|
88
|
-
premium_progress_bar_enabled: boolean;
|
|
89
|
-
safety_alerts_channel_id: Snowflake | null;
|
|
90
|
-
incidents_data: unknown;
|
|
91
|
-
}
|
|
92
|
-
export interface PartialEmoji {
|
|
93
|
-
/** null for standard (unicode) emojis. */
|
|
94
|
-
id: Snowflake | null;
|
|
95
|
-
/** The unicode character for standard emojis. */
|
|
96
|
-
name: string | null;
|
|
97
|
-
animated?: boolean;
|
|
98
|
-
}
|
|
99
|
-
export interface APIMessage {
|
|
100
|
-
id: Snowflake;
|
|
101
|
-
channel_id: Snowflake;
|
|
102
|
-
/** For webhook messages, holds the webhook's id, username and avatar. */
|
|
103
|
-
author: APIUser;
|
|
104
|
-
/** Empty without the `MessageContent` intent, except in DMs and when the bot is mentioned. */
|
|
105
|
-
content: string;
|
|
106
|
-
timestamp: Timestamp;
|
|
107
|
-
edited_timestamp: Timestamp | null;
|
|
108
|
-
tts: boolean;
|
|
109
|
-
mention_everyone: boolean;
|
|
110
|
-
/** In MESSAGE_CREATE and MESSAGE_UPDATE, guild mentions carry a partial `member`. */
|
|
111
|
-
mentions: (APIUser & {
|
|
112
|
-
member?: Omit<APIGuildMember, 'user'>;
|
|
113
|
-
})[];
|
|
114
|
-
mention_roles: Snowflake[];
|
|
115
|
-
mention_channels?: unknown[];
|
|
116
|
-
attachments: unknown[];
|
|
117
|
-
embeds: unknown[];
|
|
118
|
-
reactions?: unknown[];
|
|
119
|
-
nonce?: number | string;
|
|
120
|
-
pinned: boolean;
|
|
121
|
-
webhook_id?: Snowflake;
|
|
122
|
-
type: number;
|
|
123
|
-
activity?: unknown;
|
|
124
|
-
application?: unknown;
|
|
125
|
-
application_id?: Snowflake;
|
|
126
|
-
flags?: number;
|
|
127
|
-
message_reference?: unknown;
|
|
128
|
-
message_snapshots?: unknown[];
|
|
129
|
-
referenced_message?: APIMessage | null;
|
|
130
|
-
interaction_metadata?: unknown;
|
|
131
|
-
thread?: GatewayObject;
|
|
132
|
-
components?: unknown[];
|
|
133
|
-
sticker_items?: unknown[];
|
|
134
|
-
position?: number;
|
|
135
|
-
role_subscription_data?: unknown;
|
|
136
|
-
resolved?: unknown;
|
|
137
|
-
poll?: unknown;
|
|
138
|
-
call?: unknown;
|
|
139
|
-
shared_client_theme?: unknown;
|
|
140
|
-
/** Missing for ephemeral messages and DMs. */
|
|
141
|
-
guild_id?: Snowflake;
|
|
142
|
-
/** Without `user`. Missing for ephemeral messages, webhooks and DMs. */
|
|
143
|
-
member?: Omit<APIGuildMember, 'user'>;
|
|
144
|
-
channel_type?: number;
|
|
145
|
-
}
|
|
146
|
-
export interface APIInteraction {
|
|
147
|
-
id: Snowflake;
|
|
148
|
-
application_id: Snowflake;
|
|
149
|
-
/** 1 PING, 2 APPLICATION_COMMAND, 3 MESSAGE_COMPONENT, 4 APPLICATION_COMMAND_AUTOCOMPLETE, 5 MODAL_SUBMIT */
|
|
150
|
-
type: number;
|
|
151
|
-
data?: GatewayObject;
|
|
152
|
-
guild?: GatewayObject;
|
|
153
|
-
guild_id?: Snowflake;
|
|
154
|
-
channel?: GatewayObject;
|
|
155
|
-
channel_id?: Snowflake;
|
|
156
|
-
/** Sent when invoked in a guild. */
|
|
157
|
-
member?: APIGuildMember;
|
|
158
|
-
/** Sent when invoked in a DM. */
|
|
159
|
-
user?: APIUser;
|
|
160
|
-
token: string;
|
|
161
|
-
version: number;
|
|
162
|
-
message?: APIMessage;
|
|
163
|
-
app_permissions: string;
|
|
164
|
-
locale?: string;
|
|
165
|
-
guild_locale?: string;
|
|
166
|
-
entitlements: unknown[];
|
|
167
|
-
authorizing_integration_owners: Record<string, Snowflake>;
|
|
168
|
-
context?: number;
|
|
169
|
-
attachment_size_limit: number;
|
|
170
|
-
}
|
|
171
|
-
export interface APIReadyEvent {
|
|
172
|
-
v: number;
|
|
173
|
-
user: APIUser;
|
|
174
|
-
guilds: APIUnavailableGuild[];
|
|
175
|
-
session_id: string;
|
|
176
|
-
resume_gateway_url: string;
|
|
177
|
-
shard?: [shardId: number, numShards: number];
|
|
178
|
-
application: {
|
|
179
|
-
id: Snowflake;
|
|
180
|
-
flags: number;
|
|
181
|
-
[key: string]: unknown;
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
export interface APIRateLimitedEvent {
|
|
185
|
-
opcode: number;
|
|
186
|
-
retry_after: number;
|
|
187
|
-
meta: GatewayObject;
|
|
188
|
-
}
|
|
189
|
-
export type APIGuildCreateEvent = (APIGuild & {
|
|
190
|
-
joined_at: Timestamp;
|
|
191
|
-
large: boolean;
|
|
192
|
-
unavailable?: false;
|
|
193
|
-
member_count: number;
|
|
194
|
-
voice_states: unknown[];
|
|
195
|
-
members: APIGuildMember[];
|
|
196
|
-
channels: GatewayObject[];
|
|
197
|
-
threads: GatewayObject[];
|
|
198
|
-
presences: unknown[];
|
|
199
|
-
stage_instances: unknown[];
|
|
200
|
-
guild_scheduled_events: unknown[];
|
|
201
|
-
soundboard_sounds: unknown[];
|
|
202
|
-
}) | (APIUnavailableGuild & {
|
|
203
|
-
unavailable: true;
|
|
204
|
-
});
|
|
205
|
-
export interface APIGuildBanEvent {
|
|
206
|
-
guild_id: Snowflake;
|
|
207
|
-
user: APIUser;
|
|
208
|
-
}
|
|
209
|
-
export interface APIGuildMemberAddEvent extends APIGuildMember {
|
|
210
|
-
user: APIUser;
|
|
211
|
-
guild_id: Snowflake;
|
|
212
|
-
}
|
|
213
|
-
export interface APIGuildMemberRemoveEvent {
|
|
214
|
-
guild_id: Snowflake;
|
|
215
|
-
user: APIUser;
|
|
216
|
-
}
|
|
217
|
-
export interface APIGuildMemberUpdateEvent {
|
|
218
|
-
guild_id: Snowflake;
|
|
219
|
-
roles: Snowflake[];
|
|
220
|
-
user: APIUser;
|
|
221
|
-
nick?: string | null;
|
|
222
|
-
avatar: string | null;
|
|
223
|
-
banner: string | null;
|
|
224
|
-
joined_at: Timestamp | null;
|
|
225
|
-
premium_since?: Timestamp | null;
|
|
226
|
-
deaf?: boolean;
|
|
227
|
-
mute?: boolean;
|
|
228
|
-
pending?: boolean;
|
|
229
|
-
communication_disabled_until?: Timestamp | null;
|
|
230
|
-
avatar_decoration_data?: unknown;
|
|
231
|
-
collectibles?: unknown;
|
|
232
|
-
}
|
|
233
|
-
export interface APIMessageDeleteEvent {
|
|
234
|
-
id: Snowflake;
|
|
235
|
-
channel_id: Snowflake;
|
|
236
|
-
guild_id?: Snowflake;
|
|
237
|
-
}
|
|
238
|
-
export interface APIMessageDeleteBulkEvent {
|
|
239
|
-
ids: Snowflake[];
|
|
240
|
-
channel_id: Snowflake;
|
|
241
|
-
guild_id?: Snowflake;
|
|
242
|
-
}
|
|
243
|
-
export interface APIMessageReactionAddEvent extends APIMessageReactionRemoveEvent {
|
|
244
|
-
/** Member who reacted, if it happened in a guild. */
|
|
245
|
-
member?: APIGuildMember;
|
|
246
|
-
message_author_id?: Snowflake;
|
|
247
|
-
burst_colors?: string[];
|
|
248
|
-
}
|
|
249
|
-
export interface APIMessageReactionRemoveEvent {
|
|
250
|
-
user_id: Snowflake;
|
|
251
|
-
channel_id: Snowflake;
|
|
252
|
-
message_id: Snowflake;
|
|
253
|
-
guild_id?: Snowflake;
|
|
254
|
-
emoji: PartialEmoji;
|
|
255
|
-
/** true for a super-reaction. */
|
|
256
|
-
burst: boolean;
|
|
257
|
-
type: number;
|
|
258
|
-
}
|
|
259
|
-
export interface APIMessageReactionRemoveAllEvent {
|
|
260
|
-
channel_id: Snowflake;
|
|
261
|
-
message_id: Snowflake;
|
|
262
|
-
guild_id?: Snowflake;
|
|
263
|
-
}
|
|
264
|
-
export interface APIMessageReactionRemoveEmojiEvent extends APIMessageReactionRemoveAllEvent {
|
|
265
|
-
emoji: PartialEmoji;
|
|
266
|
-
}
|
|
267
|
-
export interface APITypingStartEvent {
|
|
268
|
-
channel_id: Snowflake;
|
|
269
|
-
guild_id?: Snowflake;
|
|
270
|
-
user_id: Snowflake;
|
|
271
|
-
/** Unix time in seconds. */
|
|
272
|
-
timestamp: number;
|
|
273
|
-
member?: APIGuildMember;
|
|
274
|
-
}
|
|
275
|
-
export interface APIChannel {
|
|
276
|
-
id: Snowflake;
|
|
277
|
-
/** https://docs.discord.com/developers/resources/channel#channel-object-channel-types */
|
|
278
|
-
type: number;
|
|
279
|
-
guild_id?: Snowflake;
|
|
280
|
-
position?: number;
|
|
281
|
-
permission_overwrites?: unknown[];
|
|
282
|
-
name?: string | null;
|
|
283
|
-
topic?: string | null;
|
|
284
|
-
nsfw?: boolean;
|
|
285
|
-
last_message_id?: Snowflake | null;
|
|
286
|
-
bitrate?: number;
|
|
287
|
-
user_limit?: number;
|
|
288
|
-
rate_limit_per_user?: number;
|
|
289
|
-
recipients?: APIUser[];
|
|
290
|
-
icon?: string | null;
|
|
291
|
-
owner_id?: Snowflake;
|
|
292
|
-
application_id?: Snowflake | null;
|
|
293
|
-
managed?: boolean;
|
|
294
|
-
parent_id?: Snowflake | null;
|
|
295
|
-
last_pin_timestamp?: Timestamp | null;
|
|
296
|
-
rtc_region?: string | null;
|
|
297
|
-
video_quality_mode?: number;
|
|
298
|
-
message_count?: number;
|
|
299
|
-
member_count?: number;
|
|
300
|
-
thread_metadata?: unknown;
|
|
301
|
-
member?: unknown;
|
|
302
|
-
default_auto_archive_duration?: number;
|
|
303
|
-
permissions?: string;
|
|
304
|
-
app_permissions?: string;
|
|
305
|
-
flags?: number;
|
|
306
|
-
total_message_sent?: number;
|
|
307
|
-
available_tags?: unknown[];
|
|
308
|
-
applied_tags?: Snowflake[];
|
|
309
|
-
default_reaction_emoji?: unknown;
|
|
310
|
-
default_thread_rate_limit_per_user?: number;
|
|
311
|
-
default_sort_order?: number | null;
|
|
312
|
-
default_forum_layout?: number;
|
|
313
|
-
}
|
|
314
|
-
export interface APIRole {
|
|
315
|
-
id: Snowflake;
|
|
316
|
-
name: string;
|
|
317
|
-
/** Deprecated, use `colors`. */
|
|
318
|
-
color: number;
|
|
319
|
-
colors: {
|
|
320
|
-
primary_color: number;
|
|
321
|
-
secondary_color: number | null;
|
|
322
|
-
tertiary_color: number | null;
|
|
323
|
-
};
|
|
324
|
-
hoist: boolean;
|
|
325
|
-
icon?: string | null;
|
|
326
|
-
unicode_emoji?: string | null;
|
|
327
|
-
position: number;
|
|
328
|
-
/** Permission bit set. */
|
|
329
|
-
permissions: string;
|
|
330
|
-
managed: boolean;
|
|
331
|
-
mentionable: boolean;
|
|
332
|
-
tags?: unknown;
|
|
333
|
-
flags: number;
|
|
334
|
-
}
|
package/dist/discord/types.js
DELETED
package/dist/events.d.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { type EventContext } from './context.js';
|
|
2
|
-
import type { Client } from './discord/client.js';
|
|
3
|
-
import { GatewayIntents } from './discord/constants.js';
|
|
4
|
-
import { type EventName } from './discord/events.js';
|
|
5
|
-
/**
|
|
6
|
-
* Runs each time Discord sends the event, with what it is about:
|
|
7
|
-
* `({ client, message }) => message.reply('Hi')`. Errors are logged without
|
|
8
|
-
* stopping the bot.
|
|
9
|
-
*/
|
|
10
|
-
export type EventHandler = (context: EventContext) => unknown;
|
|
11
|
-
export type IntentName = keyof typeof GatewayIntents;
|
|
12
|
-
export interface EventDefinition {
|
|
13
|
-
handler: EventHandler;
|
|
14
|
-
/**
|
|
15
|
-
* Additional intents, e.g. `['MessageContent']` to read the content of
|
|
16
|
-
* messages. The intents the event itself needs are requested automatically.
|
|
17
|
-
*/
|
|
18
|
-
intents?: IntentName[];
|
|
19
|
-
/**
|
|
20
|
-
* messageCreate and messageUpdate only: also receive messages sent by bots,
|
|
21
|
-
* this one included. Ignored by default, so a bot never answers itself or
|
|
22
|
-
* loops with another bot.
|
|
23
|
-
*/
|
|
24
|
-
allowBots?: boolean;
|
|
25
|
-
}
|
|
26
|
-
declare const EVENT: unique symbol;
|
|
27
|
-
/** What `defineEvent` returns, to export by default from a file in `src/events/`. */
|
|
28
|
-
export interface Event {
|
|
29
|
-
readonly [EVENT]: true;
|
|
30
|
-
readonly handler: EventHandler;
|
|
31
|
-
readonly intents: readonly IntentName[];
|
|
32
|
-
readonly allowBots: boolean;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Handles a Discord event in `src/events/`. The file (or folder) name is the
|
|
36
|
-
* event: `src/events/messageCreate.ts`, or several handlers in
|
|
37
|
-
* `src/events/messageCreate/*.ts`. Files and folders starting with `_` are
|
|
38
|
-
* ignored, for shared code.
|
|
39
|
-
*/
|
|
40
|
-
export declare function defineEvent(input: EventHandler | EventDefinition): Event;
|
|
41
|
-
/** An event handler loaded from a file. */
|
|
42
|
-
export interface LoadedEvent {
|
|
43
|
-
/** Path relative to the project, e.g. `src/events/messageCreate.ts`. */
|
|
44
|
-
file: string;
|
|
45
|
-
name: EventName;
|
|
46
|
-
handler: EventHandler;
|
|
47
|
-
/** Intents requested for this handler, event's own included. */
|
|
48
|
-
intents: number;
|
|
49
|
-
/** Intents listed by the user in `defineEvent`. */
|
|
50
|
-
extraIntents: readonly IntentName[];
|
|
51
|
-
/** Whether messages from bots reach this handler (message events only). */
|
|
52
|
-
allowBots: boolean;
|
|
53
|
-
}
|
|
54
|
-
export interface LoadEventsResult {
|
|
55
|
-
/** Sorted by file, so handlers of the same event always run in the same order. */
|
|
56
|
-
events: LoadedEvent[];
|
|
57
|
-
/** One message per invalid file, prefixed with its path. */
|
|
58
|
-
errors: string[];
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Loads every handler of `src/events/`. With `previous`, a file that fails to
|
|
62
|
-
* load keeps its previous handler (hot reload), so a typo doesn't stop the bot.
|
|
63
|
-
*/
|
|
64
|
-
export declare function loadEvents(cwd?: string, previous?: LoadedEvent[]): Promise<LoadEventsResult>;
|
|
65
|
-
/** Intents needed by the events, `Guilds` always included. */
|
|
66
|
-
export declare function eventIntents(events: readonly LoadedEvent[]): number;
|
|
67
|
-
/** `GuildMembers (src/events/guildMemberAdd.ts)` for each privileged intent requested. */
|
|
68
|
-
export declare function privilegedIntentsUsage(events: readonly LoadedEvent[]): string[];
|
|
69
|
-
/**
|
|
70
|
-
* Message handlers without the `MessageContent` intent receive empty contents,
|
|
71
|
-
* except in DMs and for messages mentioning the bot. Returns their files.
|
|
72
|
-
* https://docs.discord.com/developers/events/gateway#message-content-intent
|
|
73
|
-
*/
|
|
74
|
-
export declare function filesMissingMessageContent(events: readonly LoadedEvent[]): string[];
|
|
75
|
-
/**
|
|
76
|
-
* Calls the handlers of each event received by the client. Events are queued
|
|
77
|
-
* until `start`, so handlers see READY and the first GUILD_CREATE events even
|
|
78
|
-
* though the CLI runs its checks first.
|
|
79
|
-
*/
|
|
80
|
-
export declare class EventRouter {
|
|
81
|
-
#private;
|
|
82
|
-
/** Takes an event before the handlers, e.g. clicks on framework components. */
|
|
83
|
-
intercept: ((event: string, data: unknown) => boolean) | null;
|
|
84
|
-
constructor(client: Client, events: readonly LoadedEvent[], onError: (file: string, error: unknown) => void);
|
|
85
|
-
/** Replaces the handlers, e.g. after a reload. */
|
|
86
|
-
setEvents(events: readonly LoadedEvent[]): void;
|
|
87
|
-
/** Listener for the client's `dispatch` event. */
|
|
88
|
-
dispatch: (event: string, data: unknown) => void;
|
|
89
|
-
/** Runs the queued events, then every event as it arrives. */
|
|
90
|
-
start(): void;
|
|
91
|
-
}
|
|
92
|
-
/** Calls `onChange` when anything under `src/events/` changes. */
|
|
93
|
-
export declare function watchEvents(onChange: () => void, cwd?: string): import("fs").FSWatcher | null;
|
|
94
|
-
export {};
|
package/dist/events.js
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { extname, relative, resolve, sep } from 'node:path';
|
|
3
|
-
import { createContext } from './context.js';
|
|
4
|
-
import { GatewayIntents } from './discord/constants.js';
|
|
5
|
-
import { GATEWAY_EVENTS, PRIVILEGED_INTENTS, toDispatchName, } from './discord/events.js';
|
|
6
|
-
import { describeLoadError, importFresh, isScript, readEntries, scriptFiles, watchTree, } from './utils/modules.js';
|
|
7
|
-
/** Events whose bot messages are ignored unless `allowBots` is set. */
|
|
8
|
-
const MESSAGE_EVENTS = new Set([
|
|
9
|
-
'messageCreate',
|
|
10
|
-
'messageUpdate',
|
|
11
|
-
]);
|
|
12
|
-
const EVENT = Symbol.for('chapterjs.event');
|
|
13
|
-
/**
|
|
14
|
-
* Handles a Discord event in `src/events/`. The file (or folder) name is the
|
|
15
|
-
* event: `src/events/messageCreate.ts`, or several handlers in
|
|
16
|
-
* `src/events/messageCreate/*.ts`. Files and folders starting with `_` are
|
|
17
|
-
* ignored, for shared code.
|
|
18
|
-
*/
|
|
19
|
-
export function defineEvent(input) {
|
|
20
|
-
const { handler, intents = [], allowBots = false, } = typeof input === 'function'
|
|
21
|
-
? { handler: input }
|
|
22
|
-
: (input ?? {});
|
|
23
|
-
if (typeof handler !== 'function') {
|
|
24
|
-
throw new Error('defineEvent() needs the function to run, e.g. defineEvent(({ message }) => { … }) ' +
|
|
25
|
-
'or defineEvent({ handler: ({ message }) => { … } }).');
|
|
26
|
-
}
|
|
27
|
-
if (!Array.isArray(intents)) {
|
|
28
|
-
throw new Error("defineEvent(): intents must be a list, e.g. intents: ['MessageContent'].");
|
|
29
|
-
}
|
|
30
|
-
if (typeof allowBots !== 'boolean') {
|
|
31
|
-
throw new Error('defineEvent(): allowBots must be true or false.');
|
|
32
|
-
}
|
|
33
|
-
for (const intent of intents) {
|
|
34
|
-
if (!Object.hasOwn(GatewayIntents, intent)) {
|
|
35
|
-
const suggestion = Object.keys(GatewayIntents).find(name => normalize(name) === normalize(String(intent)));
|
|
36
|
-
throw new Error(`defineEvent(): "${intent}" is not an intent. ` +
|
|
37
|
-
(suggestion
|
|
38
|
-
? `Did you mean "${suggestion}"?`
|
|
39
|
-
: `Valid intents: ${Object.keys(GatewayIntents).join(', ')}.`));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return Object.freeze({
|
|
43
|
-
[EVENT]: true,
|
|
44
|
-
handler,
|
|
45
|
-
intents: Object.freeze([...intents]),
|
|
46
|
-
allowBots,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
/** Lowercase without separators: `message-create`, `MESSAGE_CREATE` and `messageCreate` match. */
|
|
50
|
-
const normalize = (name) => name.replace(/[-_]/g, '').toLowerCase();
|
|
51
|
-
const EVENTS_BY_KEY = new Map(Object.keys(GATEWAY_EVENTS).map(name => [
|
|
52
|
-
normalize(name),
|
|
53
|
-
name,
|
|
54
|
-
]));
|
|
55
|
-
const eventsDir = (cwd) => resolve(cwd, 'src', 'events');
|
|
56
|
-
/**
|
|
57
|
-
* Loads every handler of `src/events/`. With `previous`, a file that fails to
|
|
58
|
-
* load keeps its previous handler (hot reload), so a typo doesn't stop the bot.
|
|
59
|
-
*/
|
|
60
|
-
export async function loadEvents(cwd = process.cwd(), previous = []) {
|
|
61
|
-
const events = [];
|
|
62
|
-
const errors = [];
|
|
63
|
-
for (const entry of scanEvents(eventsDir(cwd))) {
|
|
64
|
-
const file = relative(cwd, entry.path);
|
|
65
|
-
if (!entry.name) {
|
|
66
|
-
errors.push(`${file}: ${entry.error}`);
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
events.push(toLoaded(file, entry.name, (await importFresh(entry.path)).default));
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
errors.push(describeLoadError(error, entry.path, cwd));
|
|
74
|
-
events.push(...previous.filter(event => event.file === file));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return { events, errors };
|
|
78
|
-
}
|
|
79
|
-
function toLoaded(file, name, value) {
|
|
80
|
-
if (!value || typeof value !== 'object' || !(EVENT in value)) {
|
|
81
|
-
throw new Error("doesn't export an event. Add at the end of the file: export default defineEvent(({ client }) => { … })");
|
|
82
|
-
}
|
|
83
|
-
const event = value;
|
|
84
|
-
if (event.allowBots && !MESSAGE_EVENTS.has(name)) {
|
|
85
|
-
throw new Error(`allowBots only works for ${[...MESSAGE_EVENTS].join(' and ')} events: remove it from this file.`);
|
|
86
|
-
}
|
|
87
|
-
const extra = event.intents.reduce((bits, intent) => bits | GatewayIntents[intent], 0);
|
|
88
|
-
return {
|
|
89
|
-
file,
|
|
90
|
-
name,
|
|
91
|
-
handler: event.handler,
|
|
92
|
-
intents: GATEWAY_EVENTS[name] | extra,
|
|
93
|
-
extraIntents: event.intents,
|
|
94
|
-
allowBots: event.allowBots,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Files of `src/events/`: `<event>.ts` at the root, and any file nested in an
|
|
99
|
-
* `<event>/` folder. Entries starting with `_` or `.`, declarations and tests
|
|
100
|
-
* are ignored.
|
|
101
|
-
*/
|
|
102
|
-
function scanEvents(dir) {
|
|
103
|
-
if (!existsSync(dir))
|
|
104
|
-
return [];
|
|
105
|
-
const files = [];
|
|
106
|
-
for (const entry of readEntries(dir)) {
|
|
107
|
-
const path = resolve(dir, entry.name);
|
|
108
|
-
if (entry.isDirectory()) {
|
|
109
|
-
const name = resolveEventName(entry.name);
|
|
110
|
-
const nested = scriptFiles(path);
|
|
111
|
-
if (name)
|
|
112
|
-
files.push(...nested.map(path => ({ path, name })));
|
|
113
|
-
else if (nested.length > 0)
|
|
114
|
-
files.push({ path, error: unknownEventMessage(entry.name) });
|
|
115
|
-
}
|
|
116
|
-
else if (isScript(entry)) {
|
|
117
|
-
const stem = entry.name.slice(0, -extname(entry.name).length);
|
|
118
|
-
const name = resolveEventName(stem);
|
|
119
|
-
files.push(name ? { path, name } : { path, error: unknownEventMessage(stem) });
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return files;
|
|
123
|
-
}
|
|
124
|
-
function resolveEventName(name) {
|
|
125
|
-
return EVENTS_BY_KEY.get(normalize(name));
|
|
126
|
-
}
|
|
127
|
-
function unknownEventMessage(name) {
|
|
128
|
-
const suggestion = closestEvent(name);
|
|
129
|
-
return (`"${name}" is not a Discord event.` +
|
|
130
|
-
(suggestion
|
|
131
|
-
? ` Did you mean "${suggestion}"?`
|
|
132
|
-
: ' See https://docs.discord.com/developers/events/gateway-events#receive-events') +
|
|
133
|
-
` If it is shared code and not an event, start its name with _ (_${name}) so it is ignored.`);
|
|
134
|
-
}
|
|
135
|
-
function closestEvent(name) {
|
|
136
|
-
const key = normalize(name);
|
|
137
|
-
let best;
|
|
138
|
-
let bestDistance = Math.max(2, Math.floor(key.length / 4)) + 1;
|
|
139
|
-
for (const [candidate, event] of EVENTS_BY_KEY) {
|
|
140
|
-
const distance = levenshtein(key, candidate);
|
|
141
|
-
if (distance < bestDistance)
|
|
142
|
-
[best, bestDistance] = [event, distance];
|
|
143
|
-
}
|
|
144
|
-
return best;
|
|
145
|
-
}
|
|
146
|
-
function levenshtein(a, b) {
|
|
147
|
-
let row = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
148
|
-
for (let i = 1; i <= a.length; i++) {
|
|
149
|
-
const next = [i];
|
|
150
|
-
for (let j = 1; j <= b.length; j++) {
|
|
151
|
-
next[j] = Math.min(row[j] + 1, next[j - 1] + 1, row[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
152
|
-
}
|
|
153
|
-
row = next;
|
|
154
|
-
}
|
|
155
|
-
return row[b.length];
|
|
156
|
-
}
|
|
157
|
-
/** Intents needed by the events, `Guilds` always included. */
|
|
158
|
-
export function eventIntents(events) {
|
|
159
|
-
return events.reduce((intents, event) => intents | event.intents, GatewayIntents.Guilds);
|
|
160
|
-
}
|
|
161
|
-
/** `GuildMembers (src/events/guildMemberAdd.ts)` for each privileged intent requested. */
|
|
162
|
-
export function privilegedIntentsUsage(events) {
|
|
163
|
-
return Object.entries(PRIVILEGED_INTENTS).flatMap(([intent, bit]) => {
|
|
164
|
-
const files = events
|
|
165
|
-
.filter(event => event.intents & bit)
|
|
166
|
-
.map(event => event.file);
|
|
167
|
-
return files.length > 0 ? [`${intent} (${files.join(', ')})`] : [];
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Message handlers without the `MessageContent` intent receive empty contents,
|
|
172
|
-
* except in DMs and for messages mentioning the bot. Returns their files.
|
|
173
|
-
* https://docs.discord.com/developers/events/gateway#message-content-intent
|
|
174
|
-
*/
|
|
175
|
-
export function filesMissingMessageContent(events) {
|
|
176
|
-
if (eventIntents(events) & GatewayIntents.MessageContent)
|
|
177
|
-
return [];
|
|
178
|
-
return events
|
|
179
|
-
.filter(event => event.name === 'messageCreate' || event.name === 'messageUpdate')
|
|
180
|
-
.map(event => event.file);
|
|
181
|
-
}
|
|
182
|
-
/** Events received before `start` are kept, up to this number. */
|
|
183
|
-
const MAX_QUEUED_EVENTS = 1_000;
|
|
184
|
-
/**
|
|
185
|
-
* Calls the handlers of each event received by the client. Events are queued
|
|
186
|
-
* until `start`, so handlers see READY and the first GUILD_CREATE events even
|
|
187
|
-
* though the CLI runs its checks first.
|
|
188
|
-
*/
|
|
189
|
-
export class EventRouter {
|
|
190
|
-
#client;
|
|
191
|
-
#onError;
|
|
192
|
-
#handlers = new Map();
|
|
193
|
-
#queue = [];
|
|
194
|
-
/** Takes an event before the handlers, e.g. clicks on framework components. */
|
|
195
|
-
intercept = null;
|
|
196
|
-
constructor(client, events, onError) {
|
|
197
|
-
this.#client = client;
|
|
198
|
-
this.#onError = onError;
|
|
199
|
-
this.setEvents(events);
|
|
200
|
-
}
|
|
201
|
-
/** Replaces the handlers, e.g. after a reload. */
|
|
202
|
-
setEvents(events) {
|
|
203
|
-
const handlers = new Map();
|
|
204
|
-
for (const event of events) {
|
|
205
|
-
const name = toDispatchName(event.name);
|
|
206
|
-
handlers.set(name, [...(handlers.get(name) ?? []), event]);
|
|
207
|
-
}
|
|
208
|
-
this.#handlers = handlers;
|
|
209
|
-
}
|
|
210
|
-
/** Listener for the client's `dispatch` event. */
|
|
211
|
-
dispatch = (event, data) => {
|
|
212
|
-
if (!this.#queue)
|
|
213
|
-
return this.#run(event, data);
|
|
214
|
-
if (this.#queue.length < MAX_QUEUED_EVENTS &&
|
|
215
|
-
(this.#handlers.has(event) || this.intercept)) {
|
|
216
|
-
this.#queue.push([event, data]);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
/** Runs the queued events, then every event as it arrives. */
|
|
220
|
-
start() {
|
|
221
|
-
const queue = this.#queue ?? [];
|
|
222
|
-
this.#queue = null;
|
|
223
|
-
for (const [event, data] of queue)
|
|
224
|
-
this.#run(event, data);
|
|
225
|
-
}
|
|
226
|
-
#run(event, data) {
|
|
227
|
-
if (this.intercept?.(event, data))
|
|
228
|
-
return;
|
|
229
|
-
const fromBot = data?.author?.bot === true;
|
|
230
|
-
const handlers = this.#handlers
|
|
231
|
-
.get(event)
|
|
232
|
-
?.filter(handler => handler.allowBots || !fromBot || !MESSAGE_EVENTS.has(handler.name));
|
|
233
|
-
if (!handlers?.length)
|
|
234
|
-
return;
|
|
235
|
-
let context;
|
|
236
|
-
try {
|
|
237
|
-
context = createContext(handlers[0].name, this.#client, data);
|
|
238
|
-
}
|
|
239
|
-
catch (error) {
|
|
240
|
-
for (const { file } of handlers)
|
|
241
|
-
this.#onError(file, error);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
for (const { file, handler } of handlers) {
|
|
245
|
-
// Each handler runs on its own: a slow or failing one doesn't block the others
|
|
246
|
-
Promise.resolve()
|
|
247
|
-
.then(() => handler(context))
|
|
248
|
-
.catch(error => this.#onError(file, error));
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
/** Calls `onChange` when anything under `src/events/` changes. */
|
|
253
|
-
export function watchEvents(onChange, cwd = process.cwd()) {
|
|
254
|
-
return watchTree(resolve(cwd, 'src'), path => path === 'events' || path.startsWith(`events${sep}`), onChange);
|
|
255
|
-
}
|