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
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import type { PermissionName } from '../discord/permissions.js';
|
|
2
|
+
import type { ChannelType } from '../discord/types/channel.js';
|
|
3
|
+
import type { Locale } from '../discord/types/common.js';
|
|
4
|
+
import type { Channel, DMChannel, GuildTextBasedChannel } from '../structures/channel.js';
|
|
5
|
+
import type { Guild } from '../structures/guild.js';
|
|
6
|
+
import type { DmCommandInteraction, GuildCommandInteraction, PrivateCommandInteraction } from '../structures/interaction.js';
|
|
7
|
+
import type { GuildMember } from '../structures/member.js';
|
|
8
|
+
import type { Attachment } from '../structures/message.js';
|
|
9
|
+
import type { Role } from '../structures/role.js';
|
|
10
|
+
import type { User } from '../structures/user.js';
|
|
11
|
+
import type { TranslationContext } from '../messages/messages.js';
|
|
12
|
+
interface OptionBase {
|
|
13
|
+
/**
|
|
14
|
+
* What the option is for, shown under its name (1-100 characters). Here
|
|
15
|
+
* when the command has its `description` here; otherwise in the default
|
|
16
|
+
* language file of `src/messages/`.
|
|
17
|
+
*/
|
|
18
|
+
description?: string;
|
|
19
|
+
/** Whether the user must fill it in. By default it is optional. */
|
|
20
|
+
required?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** A text the user types, or picks among `choices`. */
|
|
23
|
+
export interface StringOption extends OptionBase {
|
|
24
|
+
/** The kind of option: a text. */
|
|
25
|
+
type: 'string';
|
|
26
|
+
/**
|
|
27
|
+
* The only values the user can pick (25 at most): a list, or an object
|
|
28
|
+
* whose keys are what the user sees and values what your code receives.
|
|
29
|
+
*/
|
|
30
|
+
choices?: readonly string[] | Readonly<Record<string, string>>;
|
|
31
|
+
/** The shortest text accepted, in characters (0 to 6000). */
|
|
32
|
+
minLength?: number;
|
|
33
|
+
/** The longest text accepted, in characters (1 to 6000). */
|
|
34
|
+
maxLength?: number;
|
|
35
|
+
}
|
|
36
|
+
/** A whole number (`integer`) or any number (`number`). */
|
|
37
|
+
export interface NumberOption extends OptionBase {
|
|
38
|
+
/** The kind of option: a whole number, or any number. */
|
|
39
|
+
type: 'integer' | 'number';
|
|
40
|
+
/**
|
|
41
|
+
* The only values the user can pick (25 at most): a list, or an object
|
|
42
|
+
* whose keys are what the user sees and values what your code receives.
|
|
43
|
+
*/
|
|
44
|
+
choices?: readonly number[] | Readonly<Record<string, number>>;
|
|
45
|
+
/** The smallest value accepted. */
|
|
46
|
+
min?: number;
|
|
47
|
+
/** The largest value accepted. */
|
|
48
|
+
max?: number;
|
|
49
|
+
}
|
|
50
|
+
/** A channel the user picks. */
|
|
51
|
+
export interface ChannelOption extends OptionBase {
|
|
52
|
+
/** The kind of option: a channel. */
|
|
53
|
+
type: 'channel';
|
|
54
|
+
/** The kinds of channels that can be picked. By default, all of them. */
|
|
55
|
+
channelTypes?: readonly ChannelType[];
|
|
56
|
+
}
|
|
57
|
+
/** True or false, a user, a role, a user or a role, or a file. */
|
|
58
|
+
export interface SimpleOption extends OptionBase {
|
|
59
|
+
/** The kind of option: what the user picks. */
|
|
60
|
+
type: 'boolean' | 'user' | 'role' | 'mentionable' | 'attachment';
|
|
61
|
+
}
|
|
62
|
+
/** One option of a command. */
|
|
63
|
+
export type CommandOption = StringOption | NumberOption | ChannelOption | SimpleOption;
|
|
64
|
+
/** The options of a command, by name. */
|
|
65
|
+
export type CommandOptions = Readonly<Record<string, CommandOption>>;
|
|
66
|
+
/** What `run` receives for an option of each type. */
|
|
67
|
+
interface OptionValues {
|
|
68
|
+
string: string;
|
|
69
|
+
integer: number;
|
|
70
|
+
number: number;
|
|
71
|
+
boolean: boolean;
|
|
72
|
+
user: User;
|
|
73
|
+
role: Role;
|
|
74
|
+
channel: Channel;
|
|
75
|
+
mentionable: User | Role;
|
|
76
|
+
attachment: Attachment;
|
|
77
|
+
}
|
|
78
|
+
type ValueOf<Option extends CommandOption> = Option extends {
|
|
79
|
+
choices: readonly (infer Choice)[];
|
|
80
|
+
} ? Choice : Option extends {
|
|
81
|
+
choices: Readonly<Record<string, infer Choice>>;
|
|
82
|
+
} ? Choice : OptionValues[Option['type']];
|
|
83
|
+
/**
|
|
84
|
+
* The values of the options, typed from their declaration: a required
|
|
85
|
+
* option is always there, an optional one may be `undefined`.
|
|
86
|
+
*/
|
|
87
|
+
export type OptionValuesOf<Options extends CommandOptions> = {
|
|
88
|
+
[Name in keyof Options]: Options[Name] extends {
|
|
89
|
+
required: true;
|
|
90
|
+
} ? ValueOf<Options[Name]> : ValueOf<Options[Name]> | undefined;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The options as the person has filled them in so far, while they type in
|
|
94
|
+
* one of them: every option may be missing, a `user`, `role`, `channel`,
|
|
95
|
+
* `mentionable` or `attachment` option is its id.
|
|
96
|
+
*/
|
|
97
|
+
export type OptionsSoFar<Options extends CommandOptions> = {
|
|
98
|
+
readonly [Name in keyof Options]?: Options[Name] extends {
|
|
99
|
+
type: 'user' | 'role' | 'channel' | 'mentionable' | 'attachment';
|
|
100
|
+
} ? string : ValueOf<Options[Name]>;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* One suggestion for an option: a value, shown as is, or `{ name, value }`
|
|
104
|
+
* to show a text (1-100 characters) and receive another value. The value
|
|
105
|
+
* is a text (100 characters at most) for a `string` option, a number for
|
|
106
|
+
* an `integer` or `number` option.
|
|
107
|
+
*/
|
|
108
|
+
export type Suggestion<Value extends string | number = string | number> = Value | {
|
|
109
|
+
/** What the person sees in the list (1-100 characters). */
|
|
110
|
+
readonly name: string;
|
|
111
|
+
/** What your `run` receives when they pick it. */
|
|
112
|
+
readonly value: Value;
|
|
113
|
+
};
|
|
114
|
+
/** The place an `autocomplete` function receives, following `where`. */
|
|
115
|
+
type AutocompletePlace<Where extends CommandWhere> = Where extends 'guild' ? Omit<CommandInGuild, 'interaction'> : Where extends 'dm' ? Omit<CommandInDm, 'interaction'> : Omit<CommandInGuild, 'interaction'> | Omit<CommandInPrivate, 'interaction'>;
|
|
116
|
+
/**
|
|
117
|
+
* What an `autocomplete` function receives, each time the person types in
|
|
118
|
+
* its option. Nothing of it can be answered: the suggestions are what the
|
|
119
|
+
* function returns.
|
|
120
|
+
*/
|
|
121
|
+
export type AutocompleteContext<Value extends string | number | undefined = string | number | undefined, Options extends CommandOptions = CommandOptions, Where extends CommandWhere = CommandWhere> = {
|
|
122
|
+
/**
|
|
123
|
+
* What the person has typed so far in the option: a text, maybe empty,
|
|
124
|
+
* for a `string` option; for an `integer` or `number` option, a number,
|
|
125
|
+
* or `undefined` while what they typed is not one yet.
|
|
126
|
+
*/
|
|
127
|
+
value: Value;
|
|
128
|
+
/** What the person has filled in so far, this option included. */
|
|
129
|
+
options: OptionsSoFar<Options>;
|
|
130
|
+
/** Who is typing. */
|
|
131
|
+
user: User;
|
|
132
|
+
/** The language of the person: suggest in it when you can. */
|
|
133
|
+
locale: Locale;
|
|
134
|
+
} & TranslationContext & AutocompletePlace<Where>;
|
|
135
|
+
/** What the person types in an option, as an `autocomplete` function gets it. */
|
|
136
|
+
type AutocompleteValueOf<Option extends CommandOption> = Option extends {
|
|
137
|
+
type: 'string';
|
|
138
|
+
} ? string : number | undefined;
|
|
139
|
+
/** The names of the options that can have suggestions. */
|
|
140
|
+
type Suggestable<Options extends CommandOptions> = {
|
|
141
|
+
[Name in keyof Options]: Options[Name] extends {
|
|
142
|
+
type: 'string' | 'integer' | 'number';
|
|
143
|
+
} ? Options[Name] extends {
|
|
144
|
+
choices: unknown;
|
|
145
|
+
} ? never : Name : never;
|
|
146
|
+
}[keyof Options];
|
|
147
|
+
/**
|
|
148
|
+
* The `autocomplete` of a command: one function per option whose
|
|
149
|
+
* suggestions come from your bot while the person types, by the name of
|
|
150
|
+
* the option. Only a `string`, `integer` or `number` option without
|
|
151
|
+
* `choices` can have one. The function returns the suggestions (25 at
|
|
152
|
+
* most, Discord shows them in that order), or a promise of them: Discord
|
|
153
|
+
* waits 3 seconds. The person may still type something else.
|
|
154
|
+
* @see https://docs.discord.com/developers/interactions/application-commands#autocomplete
|
|
155
|
+
*/
|
|
156
|
+
export type CommandAutocomplete<Options extends CommandOptions = CommandOptions, Where extends CommandWhere = CommandWhere> = [Suggestable<Options>] extends [never] ? {
|
|
157
|
+
readonly [name: string]: 'No option of this command can have suggestions: only a string, integer or number option without choices can.';
|
|
158
|
+
} : {
|
|
159
|
+
readonly [Name in Suggestable<Options>]?: (context: AutocompleteContext<AutocompleteValueOf<Options[Name]>, Options, Where>) => readonly Suggestion<SuggestionValueOf<Options[Name]>>[] | Promise<readonly Suggestion<SuggestionValueOf<Options[Name]>>[]>;
|
|
160
|
+
};
|
|
161
|
+
/** The value a suggestion carries: a text or a number, like the option. */
|
|
162
|
+
type SuggestionValueOf<Option extends CommandOption> = Option extends {
|
|
163
|
+
type: 'string';
|
|
164
|
+
} ? string : number;
|
|
165
|
+
/** What a choice of an option is called in translations. */
|
|
166
|
+
type ChoiceKeys<Option extends CommandOption> = Option extends {
|
|
167
|
+
choices: readonly (infer Choice extends string | number)[];
|
|
168
|
+
} ? `${Choice}` : Option extends {
|
|
169
|
+
choices: Readonly<Record<infer Label, unknown>>;
|
|
170
|
+
} ? Label & string : never;
|
|
171
|
+
/** The translation of one option. Everything is optional. */
|
|
172
|
+
export interface OptionTranslation<Option extends CommandOption = CommandOption> {
|
|
173
|
+
/** The name of the option in that language (same rules as a name). */
|
|
174
|
+
name?: string;
|
|
175
|
+
/** The description of the option in that language (1-100 characters). */
|
|
176
|
+
description?: string;
|
|
177
|
+
/**
|
|
178
|
+
* What each choice is called in that language. The keys are the choices
|
|
179
|
+
* as declared: the values of a list, or the keys of an object.
|
|
180
|
+
*/
|
|
181
|
+
choices?: {
|
|
182
|
+
readonly [Choice in ChoiceKeys<Option>]?: string;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The translation of a command in one language. Everything is optional:
|
|
187
|
+
* what is not translated is shown as declared.
|
|
188
|
+
*/
|
|
189
|
+
export interface CommandTranslation<Options extends CommandOptions = CommandOptions> {
|
|
190
|
+
/** The name of the command in that language (same rules as a name). */
|
|
191
|
+
name?: string;
|
|
192
|
+
/** The description of the command in that language (1-100 characters). */
|
|
193
|
+
description?: string;
|
|
194
|
+
/** The translation of each option, by the name declared in `options`. */
|
|
195
|
+
options?: {
|
|
196
|
+
readonly [Name in keyof Options]?: OptionTranslation<Options[Name]>;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/** The translations of a command, by language. */
|
|
200
|
+
export type CommandLocales<Options extends CommandOptions = CommandOptions> = {
|
|
201
|
+
readonly [Language in Locale]?: CommandTranslation<Options>;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Where a command can be used: in servers (`'guild'`), in private messages
|
|
205
|
+
* with the bot (`'dm'`), or in both.
|
|
206
|
+
* @see https://docs.discord.com/developers/interactions/application-commands#interaction-contexts
|
|
207
|
+
*/
|
|
208
|
+
export type CommandWhere = 'guild' | 'dm' | 'both';
|
|
209
|
+
/**
|
|
210
|
+
* A duration, as a number and a unit: `s`, `m`, `h` or `d`, like `'30s'`,
|
|
211
|
+
* `'10m'`, `'2h'`, `'1d'`. Several parts add up: `'1h30m'`.
|
|
212
|
+
*/
|
|
213
|
+
export type Duration = `${number}${'s' | 'm' | 'h' | 'd'}${string}`;
|
|
214
|
+
/**
|
|
215
|
+
* How long to wait before the command can be used again: a duration, for
|
|
216
|
+
* each person; or one per place, each optional: `user` for each person,
|
|
217
|
+
* `channel` for each channel, `guild` for each server (not for a command
|
|
218
|
+
* of private messages). Someone who uses it too soon gets a private
|
|
219
|
+
* answer saying when they can, and `run` does not run.
|
|
220
|
+
*/
|
|
221
|
+
export type Cooldown = Duration | {
|
|
222
|
+
/** Each person waits this long between two uses, wherever they are. */
|
|
223
|
+
readonly user?: Duration;
|
|
224
|
+
/** Each channel waits this long, whoever used it. */
|
|
225
|
+
readonly channel?: Duration;
|
|
226
|
+
/** Each server waits this long, whoever used it, wherever. */
|
|
227
|
+
readonly guild?: Duration;
|
|
228
|
+
};
|
|
229
|
+
/** What a command used in a server receives about where it was used. */
|
|
230
|
+
export interface CommandInGuild {
|
|
231
|
+
/** The use of the command: what to answer with. */
|
|
232
|
+
interaction: GuildCommandInteraction;
|
|
233
|
+
/** The server the command was used in. */
|
|
234
|
+
guild: Guild;
|
|
235
|
+
/** Who used the command, as a member of the server. */
|
|
236
|
+
member: GuildMember;
|
|
237
|
+
/** The channel the command was used in. */
|
|
238
|
+
channel: GuildTextBasedChannel;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* What a command that works in both places receives when it is used in a
|
|
242
|
+
* private message: `guild` is `null`, and checking it tells the rest.
|
|
243
|
+
*/
|
|
244
|
+
export interface CommandInPrivate {
|
|
245
|
+
/** The use of the command: what to answer with. */
|
|
246
|
+
interaction: PrivateCommandInteraction;
|
|
247
|
+
/** No server: the command was used in a private message. */
|
|
248
|
+
guild: null;
|
|
249
|
+
/** No member: the person is `user`. */
|
|
250
|
+
member: null;
|
|
251
|
+
/** The private conversation the command was used in. */
|
|
252
|
+
channel: DMChannel;
|
|
253
|
+
}
|
|
254
|
+
/** What a command only used in private messages receives: no server. */
|
|
255
|
+
export interface CommandInDm {
|
|
256
|
+
/** The use of the command: what to answer with. */
|
|
257
|
+
interaction: DmCommandInteraction;
|
|
258
|
+
/** The private conversation the command was used in. */
|
|
259
|
+
channel: DMChannel;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* What the `run` function of a command receives. It follows `where`: in a
|
|
263
|
+
* server, the server, the member and the channel are there; in private
|
|
264
|
+
* messages they do not exist; in both, `if (guild)` tells which one it is,
|
|
265
|
+
* for everything at once.
|
|
266
|
+
*/
|
|
267
|
+
export type CommandContext<Options extends CommandOptions = CommandOptions, Where extends CommandWhere = 'guild'> = {
|
|
268
|
+
/** What the user filled in. */
|
|
269
|
+
options: OptionValuesOf<Options>;
|
|
270
|
+
/** Who used the command. */
|
|
271
|
+
user: User;
|
|
272
|
+
} & TranslationContext & (Where extends 'guild' ? CommandInGuild : Where extends 'dm' ? CommandInDm : CommandInGuild | CommandInPrivate);
|
|
273
|
+
/** What a command file gives to `command()`: what the command is and does. */
|
|
274
|
+
export interface CommandConfig<Options extends CommandOptions = CommandOptions, Where extends CommandWhere = 'guild'> {
|
|
275
|
+
/**
|
|
276
|
+
* What the command does, shown under its name (1-100 characters). Here,
|
|
277
|
+
* with `locales` for its translations; or left out, and every text of
|
|
278
|
+
* the command (description, options, their choices, translations) comes
|
|
279
|
+
* from the language files of `src/messages/`. One or the other.
|
|
280
|
+
*/
|
|
281
|
+
description?: string;
|
|
282
|
+
/** What the user can fill in (25 options at most). */
|
|
283
|
+
options?: Options;
|
|
284
|
+
/**
|
|
285
|
+
* The command in other languages: Discord shows each person the names
|
|
286
|
+
* and descriptions of their language. Your code always receives the
|
|
287
|
+
* names declared above, whatever the language.
|
|
288
|
+
* @see https://docs.discord.com/developers/interactions/application-commands#localization
|
|
289
|
+
*/
|
|
290
|
+
locales?: CommandLocales<NoInfer<Options>>;
|
|
291
|
+
/**
|
|
292
|
+
* Suggestions that come from your bot while the person types, for the
|
|
293
|
+
* options named here (a `string`, `integer` or `number` option without
|
|
294
|
+
* `choices`): each function receives what they typed and returns the
|
|
295
|
+
* suggestions. The person may still type something else.
|
|
296
|
+
*/
|
|
297
|
+
autocomplete?: CommandAutocomplete<NoInfer<Options>, NoInfer<Where>>;
|
|
298
|
+
/**
|
|
299
|
+
* The permissions a member needs to use the command. Server admins can
|
|
300
|
+
* change who sees it in the server settings.
|
|
301
|
+
*/
|
|
302
|
+
permissions?: readonly PermissionName[];
|
|
303
|
+
/**
|
|
304
|
+
* Where the command can be used: `'guild'` (in servers, the default),
|
|
305
|
+
* `'dm'` (in private messages with the bot) or `'both'`. What `run`
|
|
306
|
+
* receives follows it.
|
|
307
|
+
*/
|
|
308
|
+
where?: Where;
|
|
309
|
+
/** Only show the command in age-restricted channels. */
|
|
310
|
+
nsfw?: boolean;
|
|
311
|
+
/** Make the answers of the command only visible to who used it. */
|
|
312
|
+
ephemeral?: boolean;
|
|
313
|
+
/**
|
|
314
|
+
* How long to wait before the command can be used again: `'10s'` for
|
|
315
|
+
* each person, or `{ user, channel, guild }` for each place. Someone who
|
|
316
|
+
* uses it too soon gets a private answer saying when they can.
|
|
317
|
+
*/
|
|
318
|
+
cooldown?: Cooldown;
|
|
319
|
+
/** What to do when someone uses the command. */
|
|
320
|
+
run: (context: CommandContext<Options, Where>) => unknown;
|
|
321
|
+
}
|
|
322
|
+
/** What `command()` returns: the default export of a command file. */
|
|
323
|
+
export interface CommandFile<Options extends CommandOptions = CommandOptions, Where extends CommandWhere = CommandWhere> {
|
|
324
|
+
/** What the file gave to `command()`, not checked yet. */
|
|
325
|
+
readonly config: CommandConfig<Options, Where>;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Declares a slash command. Export the result as the default export of a
|
|
329
|
+
* file of `src/commands/`: the path of the file is the name of the command
|
|
330
|
+
* (`src/commands/mod/ban.ts` is `/mod ban`).
|
|
331
|
+
*
|
|
332
|
+
* ```ts
|
|
333
|
+
* import { command } from 'chapterjs';
|
|
334
|
+
*
|
|
335
|
+
* export default command({
|
|
336
|
+
* description: 'Replies with Pong!',
|
|
337
|
+
* async run({ interaction }) {
|
|
338
|
+
* await interaction.reply('Pong!');
|
|
339
|
+
* },
|
|
340
|
+
* });
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
export declare function command<const Options extends CommandOptions = {}, const Where extends CommandWhere = 'guild'>(config: CommandConfig<Options, Where>): CommandFile<Options, Where>;
|
|
344
|
+
/** Whether a value was made by `command()`. */
|
|
345
|
+
export declare function isCommandFile(value: unknown): value is CommandFile;
|
|
346
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// `command()`, as user files import it from 'chapterjs', and the types that
|
|
2
|
+
// make the options a command declares typed in its `run` function.
|
|
3
|
+
const BRAND = Symbol.for('chapterjs.command');
|
|
4
|
+
/**
|
|
5
|
+
* Declares a slash command. Export the result as the default export of a
|
|
6
|
+
* file of `src/commands/`: the path of the file is the name of the command
|
|
7
|
+
* (`src/commands/mod/ban.ts` is `/mod ban`).
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { command } from 'chapterjs';
|
|
11
|
+
*
|
|
12
|
+
* export default command({
|
|
13
|
+
* description: 'Replies with Pong!',
|
|
14
|
+
* async run({ interaction }) {
|
|
15
|
+
* await interaction.reply('Pong!');
|
|
16
|
+
* },
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function command(config) {
|
|
21
|
+
return Object.freeze({ [BRAND]: true, config });
|
|
22
|
+
}
|
|
23
|
+
/** Whether a value was made by `command()`. */
|
|
24
|
+
export function isCommandFile(value) {
|
|
25
|
+
return (typeof value === 'object' &&
|
|
26
|
+
value !== null &&
|
|
27
|
+
value[BRAND] === true);
|
|
28
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Locale } from '../discord/types/common.js';
|
|
2
|
+
import { type CooldownLimits } from '../interactions/cooldown.js';
|
|
3
|
+
import type { Convention } from '../loader/loader.js';
|
|
4
|
+
import { type AutocompleteContext, type CommandContext, type CommandOption, type CommandWhere, type Suggestion } from './command.js';
|
|
5
|
+
/** A name or a description in other languages, as Discord takes them. */
|
|
6
|
+
export type Localizations = Readonly<Partial<Record<Locale, string>>>;
|
|
7
|
+
/** The translations of one option, checked. */
|
|
8
|
+
export interface OptionLocales {
|
|
9
|
+
readonly names: Localizations;
|
|
10
|
+
readonly descriptions: Localizations;
|
|
11
|
+
/** For each choice (by its default name), its name in other languages. */
|
|
12
|
+
readonly choices: Readonly<Record<string, Localizations>>;
|
|
13
|
+
}
|
|
14
|
+
/** An option, checked, with the description it has so far. */
|
|
15
|
+
export type LoadedOption = CommandOption & {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
};
|
|
19
|
+
/** An `autocomplete` function of a file, as the router runs it. */
|
|
20
|
+
export type AutocompleteFunction = (context: AutocompleteContext) => readonly Suggestion[] | Promise<readonly Suggestion[]>;
|
|
21
|
+
/** A command file, checked: what the rest of the feature works with. */
|
|
22
|
+
export interface LoadedCommand {
|
|
23
|
+
/** The name and description of the command in other languages. */
|
|
24
|
+
readonly names: Localizations;
|
|
25
|
+
readonly descriptions: Localizations;
|
|
26
|
+
/** The translations of the options, by option name. */
|
|
27
|
+
readonly optionLocales: Readonly<Record<string, OptionLocales>>;
|
|
28
|
+
/** `['mod', 'ban']` for `src/commands/mod/ban.ts`: `/mod ban`. */
|
|
29
|
+
readonly path: readonly string[];
|
|
30
|
+
/**
|
|
31
|
+
* Whether the file gives its own texts (`description`, `locales`). When
|
|
32
|
+
* it does not, the language files of `src/messages/` do: `description`
|
|
33
|
+
* and the descriptions of the options are empty until `project.ts`
|
|
34
|
+
* fills them in from the default language.
|
|
35
|
+
*/
|
|
36
|
+
readonly described: boolean;
|
|
37
|
+
readonly description: string;
|
|
38
|
+
/** The options, required ones first as Discord wants them. */
|
|
39
|
+
readonly options: readonly LoadedOption[];
|
|
40
|
+
/** The permissions needed, as bits. */
|
|
41
|
+
readonly permissions: bigint;
|
|
42
|
+
/** Where it can be used; in servers when the file does not say. */
|
|
43
|
+
readonly where: CommandWhere;
|
|
44
|
+
readonly nsfw: boolean;
|
|
45
|
+
readonly ephemeral: boolean;
|
|
46
|
+
/** How long each person, channel and server waits between two uses. */
|
|
47
|
+
readonly cooldown: CooldownLimits;
|
|
48
|
+
/** The functions giving suggestions, by the name of their option. */
|
|
49
|
+
readonly autocomplete: Readonly<Record<string, AutocompleteFunction>>;
|
|
50
|
+
readonly run: (context: CommandContext) => unknown;
|
|
51
|
+
}
|
|
52
|
+
/** Checks `locales` and returns it as the dictionaries Discord takes. */
|
|
53
|
+
export declare function checkLocales(locales: unknown, options: readonly LoadedOption[]): {
|
|
54
|
+
names: Localizations;
|
|
55
|
+
descriptions: Localizations;
|
|
56
|
+
optionLocales: Record<string, OptionLocales>;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* `src/commands/`: each file is a slash command, named after its path.
|
|
60
|
+
* One folder makes a command with subcommands (`mod/ban.ts` is `/mod ban`),
|
|
61
|
+
* two make a group (`mod/roles/add.ts` is `/mod roles add`): Discord allows
|
|
62
|
+
* nothing deeper.
|
|
63
|
+
*/
|
|
64
|
+
export declare const commandsConvention: Convention<LoadedCommand>;
|