chapterjs 0.1.2 → 0.2.0
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 +205 -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 +253 -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 +135 -0
- package/dist/cli/project.js +517 -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 +360 -0
- package/dist/commands/command.js +28 -0
- package/dist/commands/declaration.d.ts +77 -0
- package/dist/commands/declaration.js +492 -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 +47 -0
- package/dist/commands/tree.js +216 -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 +106 -0
- package/dist/components/component.d.ts +140 -0
- package/dist/components/component.js +39 -0
- package/dist/components/custom-id.d.ts +72 -0
- package/dist/components/custom-id.js +128 -0
- package/dist/components/declaration.d.ts +42 -0
- package/dist/components/declaration.js +342 -0
- package/dist/components/declared.d.ts +29 -0
- package/dist/components/declared.js +49 -0
- package/dist/components/embed.d.ts +29 -0
- package/dist/components/embed.js +11 -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 +245 -0
- package/dist/components/modal.js +398 -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 +19 -0
- package/dist/components/router.js +251 -0
- package/dist/components/select.d.ts +146 -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/declaration.d.ts +16 -0
- package/dist/events/declaration.js +80 -0
- package/dist/events/event.d.ts +45 -0
- package/dist/events/event.js +34 -0
- package/dist/events/registry.d.ts +697 -0
- package/dist/events/registry.js +839 -0
- package/dist/events/router.d.ts +46 -0
- package/dist/events/router.js +133 -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 +57 -18
- package/dist/index.js +40 -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 +10 -0
- package/dist/loader/generated.js +80 -0
- package/dist/loader/hot.d.ts +13 -0
- package/dist/loader/hot.js +85 -0
- package/dist/loader/loader.d.ts +85 -0
- package/dist/loader/loader.js +119 -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 +2 -0
- package/dist/main.js +5 -0
- package/dist/messages/commands.d.ts +23 -0
- package/dist/messages/commands.js +142 -0
- package/dist/messages/declaration.d.ts +89 -0
- package/dist/messages/declaration.js +455 -0
- package/dist/messages/messages.d.ts +241 -0
- package/dist/messages/messages.js +31 -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/declaration.d.ts +19 -0
- package/dist/presence/declaration.js +118 -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/declaration.d.ts +16 -0
- package/dist/tasks/declaration.js +56 -0
- package/dist/tasks/schedule.d.ts +54 -0
- package/dist/tasks/schedule.js +236 -0
- package/dist/tasks/scheduler.d.ts +35 -0
- package/dist/tasks/scheduler.js +107 -0
- package/dist/tasks/task.d.ts +75 -0
- package/dist/tasks/task.js +27 -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,241 @@
|
|
|
1
|
+
import type { CommandTranslation } from '../commands/command.js';
|
|
2
|
+
import type { Locale } from '../discord/types/common.js';
|
|
3
|
+
/**
|
|
4
|
+
* A text with several forms, one per quantity: `t('members', { count })`
|
|
5
|
+
* picks the form of the language for that number (`one` for 1 in
|
|
6
|
+
* English, `other` for the rest; French, Russian or Arabic have others).
|
|
7
|
+
* `other` is always there; the forms a language does not use are left
|
|
8
|
+
* out. `{count}` in a form is the number itself.
|
|
9
|
+
*/
|
|
10
|
+
export interface PluralText {
|
|
11
|
+
zero?: string;
|
|
12
|
+
one?: string;
|
|
13
|
+
two?: string;
|
|
14
|
+
few?: string;
|
|
15
|
+
many?: string;
|
|
16
|
+
other: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* One text of a language: a string, with its `{placeholders}`, or a text
|
|
20
|
+
* with several forms, picked by `count`.
|
|
21
|
+
*/
|
|
22
|
+
export type MessageText = string | PluralText;
|
|
23
|
+
/** The texts of one language, by key. */
|
|
24
|
+
export type MessageTexts = Record<string, MessageText>;
|
|
25
|
+
/**
|
|
26
|
+
* What the bot answers by itself, when it can't run what was asked: where
|
|
27
|
+
* a command or a component can't be used, a button of an old message, a
|
|
28
|
+
* `run` that failed... Every phrase has an English version; a language
|
|
29
|
+
* file gives its own in `framework`, the ones it wants. `{what}` is the
|
|
30
|
+
* word for what was used: `command`, `button`, `menu` or `form`, given
|
|
31
|
+
* here too.
|
|
32
|
+
*/
|
|
33
|
+
export interface FrameworkTexts {
|
|
34
|
+
/** The word for a command: "command". */
|
|
35
|
+
command: string;
|
|
36
|
+
/** The word for a button: "button". */
|
|
37
|
+
button: string;
|
|
38
|
+
/** The word for a select menu: "menu". */
|
|
39
|
+
menu: string;
|
|
40
|
+
/** The word for a form: "form". */
|
|
41
|
+
form: string;
|
|
42
|
+
/** "This {what} can only be used in a server." */
|
|
43
|
+
guildOnly: string;
|
|
44
|
+
/** "This {what} can only be used in a private message with me." */
|
|
45
|
+
dmOnly: string;
|
|
46
|
+
/** "This {what} can not be used here." */
|
|
47
|
+
notHere: string;
|
|
48
|
+
/** "This command is not available right now." (its file is gone or broken) */
|
|
49
|
+
unavailable: string;
|
|
50
|
+
/** "This {what} is not available any more." (an old message, its file is gone) */
|
|
51
|
+
gone: string;
|
|
52
|
+
/** "This {what} is out of date." (an old message, its `data` changed) */
|
|
53
|
+
outdated: string;
|
|
54
|
+
/** "Only the person who used the command can use this {what}." */
|
|
55
|
+
authorOnly: string;
|
|
56
|
+
/** "Something went wrong while running this {what}." */
|
|
57
|
+
failed: string;
|
|
58
|
+
/** "I don't have the permission to do that here." */
|
|
59
|
+
missingPermission: string;
|
|
60
|
+
/**
|
|
61
|
+
* "You can use this {what} again {when}." (a `cooldown` not over yet);
|
|
62
|
+
* `{when}` is a Discord timestamp, shown as "in 5 seconds" (or a date
|
|
63
|
+
* and time past 15 minutes) in the language of the person.
|
|
64
|
+
*/
|
|
65
|
+
cooldown: string;
|
|
66
|
+
/**
|
|
67
|
+
* "You need the {permissions} permission to use this command." A plural
|
|
68
|
+
* of `count`, how many permissions are missing; `{permissions}` is their
|
|
69
|
+
* names, separated by commas.
|
|
70
|
+
*/
|
|
71
|
+
needsPermissions: MessageText;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The commands of the project, as the editor sees them: the name of each
|
|
75
|
+
* command, `true` when the language files describe it, `false` when the
|
|
76
|
+
* command has its own `description`. Filled in by the `.chapterjs/` folder
|
|
77
|
+
* of the project, so that the `commands` of a language file offers the
|
|
78
|
+
* ones it may translate. The options and choices are checked when the
|
|
79
|
+
* files load.
|
|
80
|
+
*/
|
|
81
|
+
export interface ProjectCommands {
|
|
82
|
+
}
|
|
83
|
+
/** The names of the commands the language files describe. */
|
|
84
|
+
type TranslatableCommand = {
|
|
85
|
+
[Path in keyof ProjectCommands]: ProjectCommands[Path] extends true ? Path : never;
|
|
86
|
+
}[keyof ProjectCommands];
|
|
87
|
+
/**
|
|
88
|
+
* What Discord shows of the commands in one language: by the name of the
|
|
89
|
+
* command (`'ping'`, `'mod ban'`), its name, description, options and
|
|
90
|
+
* choices in that language, as the `locales` of a command take them. The
|
|
91
|
+
* editor offers the commands of the project that have no `description`
|
|
92
|
+
* (one that has owns its texts, `locales` included); their options and
|
|
93
|
+
* choices are checked when the files load.
|
|
94
|
+
*/
|
|
95
|
+
export type CommandsTranslations = [keyof ProjectCommands] extends [never] ? Readonly<Record<string, CommandTranslation>> : [TranslatableCommand] extends [never] ? Readonly<Record<string, never>> : {
|
|
96
|
+
readonly [Path in TranslatableCommand]?: CommandTranslation;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The languages that say `default: true` when more than one does, as the
|
|
100
|
+
* editor sees them: one key per language. Filled in by the `.chapterjs/`
|
|
101
|
+
* folder of the project, so that each of them is underlined; empty when at
|
|
102
|
+
* most one language says it.
|
|
103
|
+
*/
|
|
104
|
+
export interface ProjectLanguageDefaults {
|
|
105
|
+
}
|
|
106
|
+
/** What a file gives to `language()`. */
|
|
107
|
+
export interface LanguageConfig<T extends MessageTexts = MessageTexts, L extends Locale = Locale> {
|
|
108
|
+
/** The language these texts are in: `'en-US'`, `'fr'`... */
|
|
109
|
+
locale: L;
|
|
110
|
+
/**
|
|
111
|
+
* Whether this is the language used when the one of a person or of a
|
|
112
|
+
* server is not declared. Exactly one language says so; with one
|
|
113
|
+
* language, it goes without saying. When another language already says
|
|
114
|
+
* it, this is refused: only one can be the default.
|
|
115
|
+
*/
|
|
116
|
+
default?: L extends keyof ProjectLanguageDefaults ? false : boolean;
|
|
117
|
+
/** The texts of the bot in this language, by key. */
|
|
118
|
+
texts: T;
|
|
119
|
+
/** What Discord shows of the commands in this language. */
|
|
120
|
+
commands?: CommandsTranslations;
|
|
121
|
+
/**
|
|
122
|
+
* What the bot answers by itself in this language, when it can't run
|
|
123
|
+
* what was asked: the phrases of `FrameworkTexts`, the ones this file
|
|
124
|
+
* wants to translate. The others stay in English.
|
|
125
|
+
*/
|
|
126
|
+
framework?: Partial<FrameworkTexts>;
|
|
127
|
+
}
|
|
128
|
+
/** The text of a key, when it is one. */
|
|
129
|
+
type TextOf<M, K extends keyof M> = M[K] extends MessageText ? M[K] : string;
|
|
130
|
+
/**
|
|
131
|
+
* The placeholders found in a string, read from left to right like the
|
|
132
|
+
* bot does: `{{` is a `{` written as is, and a `{` with another `{` before
|
|
133
|
+
* its `}` is one too.
|
|
134
|
+
*/
|
|
135
|
+
type Found<S extends string> = S extends `${string}{${infer After}` ? After extends `{${infer Rest}` ? Found<Rest> : After extends `${infer Name}}${infer Rest}` ? Name extends `${string}{${string}` ? Found<After> : Name | Found<Rest> : never : never;
|
|
136
|
+
/**
|
|
137
|
+
* The placeholders of a text: `'Hello {name}'` has `'name'`. Written
|
|
138
|
+
* between braces, a placeholder is a name made of letters, digits and `_`;
|
|
139
|
+
* `{{` and `}}` are braces written as is. A plural has `count`, and the
|
|
140
|
+
* placeholders of its forms.
|
|
141
|
+
*/
|
|
142
|
+
export type Placeholders<T extends MessageText> = T extends string ? Found<T> : T extends PluralText ? 'count' | Found<Extract<T[keyof T], string>> : never;
|
|
143
|
+
/**
|
|
144
|
+
* What `t` takes for a text: one value per placeholder, or nothing when
|
|
145
|
+
* the text has none. A number is written the way the language writes
|
|
146
|
+
* numbers (`1,234` in English, `1 234` in French): give a text to keep it
|
|
147
|
+
* as is. The `count` of a plural is a number.
|
|
148
|
+
*/
|
|
149
|
+
export type ParamsOf<T extends MessageText> = {
|
|
150
|
+
[Name in Placeholders<T>]: Name extends 'count' ? T extends PluralText ? number : string | number : string | number;
|
|
151
|
+
};
|
|
152
|
+
/** The arguments of `t` after the key: the params, only when there are some. */
|
|
153
|
+
export type ParamsArgs<T extends MessageText> = string extends T ? [params?: Record<string, string | number>] : [Placeholders<T>] extends [never] ? [] : [params: ParamsOf<T>];
|
|
154
|
+
/**
|
|
155
|
+
* The languages of the project, as the editor sees them: one key per
|
|
156
|
+
* language declared. Filled in by the `.chapterjs/` folder of the project,
|
|
157
|
+
* empty when the project has no language.
|
|
158
|
+
*/
|
|
159
|
+
export interface ProjectLocales {
|
|
160
|
+
}
|
|
161
|
+
/** A language of the project: `'en-US'`, `'fr'`... */
|
|
162
|
+
export type ProjectLocale = keyof ProjectLocales & string;
|
|
163
|
+
/**
|
|
164
|
+
* A language given to `t.in()`: the editor offers the ones of the
|
|
165
|
+
* project, and any language of Discord is accepted (the one of a
|
|
166
|
+
* person, of a server), `t` then taking the closest one declared. A word
|
|
167
|
+
* that is no language of Discord is underlined, with the ones of the
|
|
168
|
+
* project.
|
|
169
|
+
*/
|
|
170
|
+
export type LocaleGiven<L extends string> = L extends Locale ? L : ProjectLocale;
|
|
171
|
+
/**
|
|
172
|
+
* `t`, as handlers receive it: gives a text of the language files in the
|
|
173
|
+
* language of who will read the message, with its placeholders filled in.
|
|
174
|
+
* `M` is the texts of the default language, which types the keys and the
|
|
175
|
+
* params: a text another language does not have is taken from it.
|
|
176
|
+
*/
|
|
177
|
+
export interface Translator<M extends object = ProjectMessages> {
|
|
178
|
+
<K extends keyof M & string>(key: K, ...params: ParamsArgs<TextOf<M, K>>): string;
|
|
179
|
+
/** The language the texts come from: the one asked, or the closest one declared. */
|
|
180
|
+
readonly locale: Locale;
|
|
181
|
+
/**
|
|
182
|
+
* A text in another language: `t.in('fr', 'welcome', { name })`, or
|
|
183
|
+
* `t.in(owner.locale, 'pong')`. The language of the person who will read
|
|
184
|
+
* it, when it is not the one `t` speaks.
|
|
185
|
+
*/
|
|
186
|
+
in<L extends ProjectLocale | (string & {}), K extends keyof M & string>(locale: LocaleGiven<L>, key: K, ...params: ParamsArgs<TextOf<M, K>>): string;
|
|
187
|
+
/** The same `t` for another language, to write several texts: `t.in('fr')('welcome', { name })`. */
|
|
188
|
+
in<L extends ProjectLocale | (string & {})>(locale: LocaleGiven<L>): Translator<M>;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The texts of the project, as the editor sees them: the keys `t` accepts
|
|
192
|
+
* and the placeholders of each. Filled in by the `.chapterjs/` folder of
|
|
193
|
+
* the project when it has a language, empty otherwise.
|
|
194
|
+
*/
|
|
195
|
+
export interface ProjectMessages {
|
|
196
|
+
}
|
|
197
|
+
/** What `t` is typed from, for a language: its texts. */
|
|
198
|
+
export type MessagesOf<F> = F extends LanguageDeclaration<infer T> ? T : never;
|
|
199
|
+
/**
|
|
200
|
+
* The texts of several declarations, the first one winning for a key
|
|
201
|
+
* several have: what `t` is typed from when a project has several
|
|
202
|
+
* languages, the default one first, then the others (a text the default
|
|
203
|
+
* language does not have is taken from the language that has it).
|
|
204
|
+
*/
|
|
205
|
+
export type MergedMessages<T extends readonly object[]> = T extends readonly [
|
|
206
|
+
infer First extends object,
|
|
207
|
+
...infer Rest extends readonly object[]
|
|
208
|
+
] ? string extends keyof First ? MergedMessages<Rest> : First & Omit<MergedMessages<Rest>, keyof First> : {};
|
|
209
|
+
/**
|
|
210
|
+
* What every handler receives when the project has a language: `t`.
|
|
211
|
+
* Nothing otherwise.
|
|
212
|
+
*/
|
|
213
|
+
export type TranslationContext = [keyof ProjectMessages] extends [never] ? {} : {
|
|
214
|
+
/** The texts of the language files, in the right language. */ t: Translator;
|
|
215
|
+
};
|
|
216
|
+
/** What `language()` returns: a declaration the framework finds in the exports of a file. */
|
|
217
|
+
export interface LanguageDeclaration<T extends MessageTexts = MessageTexts, L extends Locale = Locale> {
|
|
218
|
+
/** What the file gave to `language()`, not checked yet. */
|
|
219
|
+
readonly config: LanguageConfig<T, L>;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Declares one language of the bot, or more texts of it. Export the result
|
|
223
|
+
* from any file of `src/`; `locale` says which language: every handler
|
|
224
|
+
* then receives `t`, which gives a text in the language of who will read
|
|
225
|
+
* the message, with its `{placeholders}` filled in. A language may be
|
|
226
|
+
* declared in several places: the texts of a feature next to it, with the
|
|
227
|
+
* same `locale`, add to the others.
|
|
228
|
+
*
|
|
229
|
+
* ```ts
|
|
230
|
+
* import { language } from 'chapterjs';
|
|
231
|
+
*
|
|
232
|
+
* export default language({
|
|
233
|
+
* locale: 'fr',
|
|
234
|
+
* texts: { pong: 'Pong !', welcome: 'Bienvenue {name} !' },
|
|
235
|
+
* });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
export declare function language<const T extends MessageTexts, L extends Locale>(config: LanguageConfig<T, L>): LanguageDeclaration<T, L>;
|
|
239
|
+
/** Whether a value was made by `language()`. */
|
|
240
|
+
export declare function isLanguageDeclaration(value: unknown): value is LanguageDeclaration;
|
|
241
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// `language()`, as user files import it from 'chapterjs': every text the
|
|
2
|
+
// bot answers with in one language, and `t`, which handlers receive to pick
|
|
3
|
+
// the right one.
|
|
4
|
+
// https://docs.discord.com/developers/reference#locales
|
|
5
|
+
const BRAND = Symbol.for('chapterjs.language');
|
|
6
|
+
/**
|
|
7
|
+
* Declares one language of the bot, or more texts of it. Export the result
|
|
8
|
+
* from any file of `src/`; `locale` says which language: every handler
|
|
9
|
+
* then receives `t`, which gives a text in the language of who will read
|
|
10
|
+
* the message, with its `{placeholders}` filled in. A language may be
|
|
11
|
+
* declared in several places: the texts of a feature next to it, with the
|
|
12
|
+
* same `locale`, add to the others.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { language } from 'chapterjs';
|
|
16
|
+
*
|
|
17
|
+
* export default language({
|
|
18
|
+
* locale: 'fr',
|
|
19
|
+
* texts: { pong: 'Pong !', welcome: 'Bienvenue {name} !' },
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function language(config) {
|
|
24
|
+
return Object.freeze({ [BRAND]: true, config });
|
|
25
|
+
}
|
|
26
|
+
/** Whether a value was made by `language()`. */
|
|
27
|
+
export function isLanguageDeclaration(value) {
|
|
28
|
+
return (typeof value === 'object' &&
|
|
29
|
+
value !== null &&
|
|
30
|
+
value[BRAND] === true);
|
|
31
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Context } from '../structures/context.js';
|
|
2
|
+
import type { FrameworkTexts } from './messages.js';
|
|
3
|
+
import { type Template } from './translate.js';
|
|
4
|
+
/** The phrases of the framework, in English. */
|
|
5
|
+
export declare const FRAMEWORK_TEXTS: Readonly<FrameworkTexts>;
|
|
6
|
+
/** A phrase of the framework. */
|
|
7
|
+
export type FrameworkKey = keyof FrameworkTexts;
|
|
8
|
+
/** The word for what was used, in `{what}`. */
|
|
9
|
+
export type What = 'command' | 'button' | 'menu' | 'form';
|
|
10
|
+
/** The phrases of the framework, compiled, by key. */
|
|
11
|
+
export declare const FRAMEWORK: ReadonlyMap<FrameworkKey, Template>;
|
|
12
|
+
/** The keys a language file may translate, in the order of the docs. */
|
|
13
|
+
export declare const FRAMEWORK_KEYS: (keyof FrameworkTexts)[];
|
|
14
|
+
/**
|
|
15
|
+
* A phrase of the framework in the language of who will read it: the one
|
|
16
|
+
* of the language file that translates it, else the English one.
|
|
17
|
+
*/
|
|
18
|
+
export declare function phrase(ctx: Pick<Context, 'messages'>, locale: string | null, key: FrameworkKey, params?: {
|
|
19
|
+
what?: What;
|
|
20
|
+
permissions?: string;
|
|
21
|
+
count?: number;
|
|
22
|
+
when?: string;
|
|
23
|
+
}): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// What the bot answers by itself, when it can't run what was asked: in
|
|
2
|
+
// English here, and in the language files that translate
|
|
3
|
+
// them (the `framework` of a language file).
|
|
4
|
+
import { fill, pickLocale, templateOf } from './translate.js';
|
|
5
|
+
/** The phrases of the framework, in English. */
|
|
6
|
+
export const FRAMEWORK_TEXTS = Object.freeze({
|
|
7
|
+
command: 'command',
|
|
8
|
+
button: 'button',
|
|
9
|
+
menu: 'menu',
|
|
10
|
+
form: 'form',
|
|
11
|
+
guildOnly: 'This {what} can only be used in a server.',
|
|
12
|
+
dmOnly: 'This {what} can only be used in a private message with me.',
|
|
13
|
+
notHere: 'This {what} can not be used here.',
|
|
14
|
+
unavailable: 'This command is not available right now.',
|
|
15
|
+
gone: 'This {what} is not available any more.',
|
|
16
|
+
outdated: 'This {what} is out of date.',
|
|
17
|
+
authorOnly: 'Only the person who used the command can use this {what}.',
|
|
18
|
+
failed: 'Something went wrong while running this {what}.',
|
|
19
|
+
missingPermission: "I don't have the permission to do that here.",
|
|
20
|
+
cooldown: 'You can use this {what} again {when}.',
|
|
21
|
+
needsPermissions: {
|
|
22
|
+
one: 'You need the {permissions} permission to use this command.',
|
|
23
|
+
other: 'You need the {permissions} permissions to use this command.',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
/** The phrases of the framework, compiled, by key. */
|
|
27
|
+
export const FRAMEWORK = new Map(Object.entries(FRAMEWORK_TEXTS).map(([key, text]) => [key, templateOf(text)]));
|
|
28
|
+
/** The keys a language file may translate, in the order of the docs. */
|
|
29
|
+
export const FRAMEWORK_KEYS = [...FRAMEWORK.keys()];
|
|
30
|
+
/**
|
|
31
|
+
* A phrase of the framework in the language of who will read it: the one
|
|
32
|
+
* of the language file that translates it, else the English one.
|
|
33
|
+
*/
|
|
34
|
+
export function phrase(ctx, locale, key, params = {}) {
|
|
35
|
+
const { messages } = ctx;
|
|
36
|
+
const picked = messages ? pickLocale(messages, locale) : null;
|
|
37
|
+
const own = picked ? messages.framework.get(picked)?.get(key) : undefined;
|
|
38
|
+
const template = own ?? FRAMEWORK.get(key);
|
|
39
|
+
const spoken = own ? picked : 'en-US';
|
|
40
|
+
return fill(key, template, {
|
|
41
|
+
...params,
|
|
42
|
+
...(params.what ? { what: phrase(ctx, locale, params.what) } : {}),
|
|
43
|
+
}, spoken);
|
|
44
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Locale } from '../discord/types/common.js';
|
|
2
|
+
import type { Context } from '../structures/context.js';
|
|
3
|
+
import type { Guild } from '../structures/guild.js';
|
|
4
|
+
import type { MessageText, MessageTexts, PluralText, Translator } from './messages.js';
|
|
5
|
+
/** A text, cut once: its literal parts and the placeholders between them. */
|
|
6
|
+
export interface TextTemplate {
|
|
7
|
+
readonly text: string;
|
|
8
|
+
/** Odd entries are placeholder names, even ones literal text. */
|
|
9
|
+
readonly parts: readonly string[];
|
|
10
|
+
readonly params: readonly string[];
|
|
11
|
+
}
|
|
12
|
+
/** The forms of a plural, by name. */
|
|
13
|
+
export type PluralForm = keyof PluralText;
|
|
14
|
+
/** A text with several forms, one per quantity, picked by `count`. */
|
|
15
|
+
export interface PluralTemplate {
|
|
16
|
+
readonly forms: ReadonlyMap<PluralForm, TextTemplate>;
|
|
17
|
+
/** `count`, then the placeholders of every form. */
|
|
18
|
+
readonly params: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
export type Template = TextTemplate | PluralTemplate;
|
|
21
|
+
/** The languages of the project, checked and assembled: what `t` reads. */
|
|
22
|
+
export interface LoadedMessages {
|
|
23
|
+
readonly default: Locale;
|
|
24
|
+
/** The texts of each language declared, compiled. */
|
|
25
|
+
readonly locales: ReadonlyMap<Locale, ReadonlyMap<string, Template>>;
|
|
26
|
+
/** The phrases of the framework each language translates, compiled. */
|
|
27
|
+
readonly framework: ReadonlyMap<Locale, ReadonlyMap<string, Template>>;
|
|
28
|
+
/**
|
|
29
|
+
* The `commands` section of each language that has one, by the path of
|
|
30
|
+
* the command file, not checked yet: the commands of the project are
|
|
31
|
+
* needed for that.
|
|
32
|
+
*/
|
|
33
|
+
readonly commands: ReadonlyMap<Locale, Readonly<Record<string, unknown>>>;
|
|
34
|
+
/** The file each language is declared in. */
|
|
35
|
+
readonly files: ReadonlyMap<Locale, string>;
|
|
36
|
+
}
|
|
37
|
+
/** The forms a plural can have, in the order of the docs. */
|
|
38
|
+
export declare const PLURAL_FORMS: readonly PluralForm[];
|
|
39
|
+
/**
|
|
40
|
+
* Cuts a text around its placeholders, read from left to right: `{name}`
|
|
41
|
+
* is a placeholder, `{{` and `}}` are braces written as is, and a `{`
|
|
42
|
+
* with another `{` before its `}` is a brace too.
|
|
43
|
+
*/
|
|
44
|
+
export declare function compile(text: string): TextTemplate;
|
|
45
|
+
/** Puts the forms of a plural together: `count` picks one when filled. */
|
|
46
|
+
export declare function compilePlural(forms: ReadonlyMap<PluralForm, TextTemplate>): PluralTemplate;
|
|
47
|
+
/** A text of a language file, trusted, compiled. */
|
|
48
|
+
export declare function templateOf(text: MessageText): Template;
|
|
49
|
+
/** Whether a template is a plural. */
|
|
50
|
+
export declare const isPlural: (template: Template) => template is PluralTemplate;
|
|
51
|
+
/** Every locale Discord knows. */
|
|
52
|
+
export declare const LOCALES: ReadonlySet<string>;
|
|
53
|
+
/**
|
|
54
|
+
* The language of the file to use for one asked: the same one, else one
|
|
55
|
+
* of the same language in another region (`en-GB` → `en-US`, `es-419` →
|
|
56
|
+
* `es-ES`, `zh-TW` → `zh-CN`), else the default.
|
|
57
|
+
*/
|
|
58
|
+
export declare function pickLocale(messages: LoadedMessages, locale: string | null): Locale;
|
|
59
|
+
/**
|
|
60
|
+
* Fills the placeholders of a template, with an error naming a missing
|
|
61
|
+
* one. Numbers are written the way `locale` writes them, and a plural
|
|
62
|
+
* takes the form that language uses for `count`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function fill(key: string, template: Template, params: Record<string, unknown> | undefined, locale?: string): string;
|
|
65
|
+
/** `t` for one language of the file, the same object every time. */
|
|
66
|
+
export declare function translatorFor(messages: LoadedMessages, locale: string | null): Translator<MessageTexts>;
|
|
67
|
+
/** Who will read what is sent. */
|
|
68
|
+
export interface Audience {
|
|
69
|
+
/** The language of the person (the one of an interaction), when known. */
|
|
70
|
+
person?: string | null | undefined;
|
|
71
|
+
/** The server the message goes to; `null` in private messages. */
|
|
72
|
+
guild?: Guild | null | undefined;
|
|
73
|
+
/** Whether the person alone sees it. */
|
|
74
|
+
ephemeral?: boolean | undefined;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The language of those who will read what is sent: the person when they
|
|
78
|
+
* alone see it (an ephemeral answer, a private message), else the language
|
|
79
|
+
* of the server when Discord knows it (it only does for Community servers:
|
|
80
|
+
* elsewhere `preferred_locale` is always `en-US`), else none, which means
|
|
81
|
+
* the default language of the file.
|
|
82
|
+
* @see https://docs.discord.com/developers/resources/guild#guild-object-guild-structure
|
|
83
|
+
*/
|
|
84
|
+
export declare function audienceLocale({ person, guild, ephemeral, }: Audience): string | null;
|
|
85
|
+
/** A `t` for a project without a language: it says so when called. */
|
|
86
|
+
export declare function missingTranslator(locale: string | null): Translator<MessageTexts>;
|
|
87
|
+
/**
|
|
88
|
+
* `t` for what the bot sends, in the language of who will read it. Without
|
|
89
|
+
* a language, a `t` that explains it is missing when called: the
|
|
90
|
+
* texts of a component may still be functions of it.
|
|
91
|
+
*/
|
|
92
|
+
export declare function translatorOf(ctx: Pick<Context, 'messages'>, audience: Audience): Translator<MessageTexts>;
|
|
93
|
+
/**
|
|
94
|
+
* What a handler receives about translations: `t` in the language asked
|
|
95
|
+
* when the project has a language, nothing otherwise. Spread it
|
|
96
|
+
* into the context of any handler.
|
|
97
|
+
*/
|
|
98
|
+
export declare function translation(ctx: Pick<Context, 'messages'>, locale: string | null): {
|
|
99
|
+
t?: Translator<MessageTexts>;
|
|
100
|
+
};
|