@quixotic_mnemonics/swastik 0.0.0-stage → 0.1.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/_template/README.md +34 -0
- package/_template/assets/.gitkeep +1 -0
- package/_template/commands/.gitkeep +1 -0
- package/_template/config/.gitkeep +1 -0
- package/_template/events/.gitkeep +1 -0
- package/_template/jobs/.gitkeep +1 -0
- package/_template/locales/.gitkeep +1 -0
- package/_template/manifest.ts +13 -0
- package/_template/migrations/.gitkeep +1 -0
- package/_template/repositories/.gitkeep +1 -0
- package/_template/services/.gitkeep +1 -0
- package/_template/tests/.gitkeep +1 -0
- package/_template/ui/.gitkeep +1 -0
- package/dist/capabilities.d.ts +110 -0
- package/dist/capabilities.js +107 -0
- package/dist/commands.d.ts +157 -0
- package/dist/commands.js +9 -0
- package/dist/components-v2.d.ts +252 -0
- package/dist/components-v2.js +263 -0
- package/dist/components.d.ts +142 -0
- package/dist/components.js +11 -0
- package/dist/context.d.ts +59 -0
- package/dist/context.js +29 -0
- package/dist/entrypoints/admin.d.ts +26 -0
- package/dist/entrypoints/admin.js +2 -0
- package/dist/entrypoints/core.d.ts +31 -0
- package/dist/entrypoints/core.js +2 -0
- package/dist/entrypoints/marketplace.d.ts +30 -0
- package/dist/entrypoints/marketplace.js +2 -0
- package/dist/entrypoints/standard.d.ts +36 -0
- package/dist/entrypoints/standard.js +2 -0
- package/dist/events.d.ts +15 -0
- package/dist/events.js +19 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +21 -0
- package/dist/manifest-schema.d.ts +261 -0
- package/dist/manifest-schema.js +297 -0
- package/dist/manifest.d.ts +47 -0
- package/dist/manifest.js +6 -0
- package/dist/pages.d.ts +274 -0
- package/dist/pages.js +3 -0
- package/dist/paging.d.ts +32 -0
- package/dist/paging.js +59 -0
- package/dist/permits.d.ts +222 -0
- package/dist/permits.js +16 -0
- package/dist/validate.d.ts +21 -0
- package/dist/validate.js +33 -0
- package/package.json +78 -4
- package/src/capabilities.ts +196 -0
- package/src/commands.ts +181 -0
- package/src/components-v2.ts +533 -0
- package/src/components.ts +162 -0
- package/src/context.ts +83 -0
- package/src/entrypoints/admin.ts +36 -0
- package/src/entrypoints/core.ts +41 -0
- package/src/entrypoints/marketplace.ts +38 -0
- package/src/entrypoints/standard.ts +44 -0
- package/src/events.ts +34 -0
- package/src/index.ts +159 -0
- package/src/manifest-schema.ts +340 -0
- package/src/manifest.ts +68 -0
- package/src/pages.ts +282 -0
- package/src/paging.ts +72 -0
- package/src/permits.ts +250 -0
- package/src/validate.ts +42 -0
- package/README.md +0 -3
package/src/commands.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { ComponentsV2Message } from './components-v2.js';
|
|
2
|
+
/**
|
|
3
|
+
* §1.7 / interface.md §10.5 — the schema-declared authoring model. A module declares a command
|
|
4
|
+
* schema with `defineCommand` and its handler returns page data; the Renderer derives the whole
|
|
5
|
+
* presentation from that data, so module code never constructs components, embeds or flags.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* §6.7 — a declared side effect. A module cannot reach the host process, so it cannot write to the
|
|
9
|
+
* queue, the database or anything else itself; it declares what should happen and the host
|
|
10
|
+
* performs it, which keeps the handler free of side effects during its own execution.
|
|
11
|
+
*/
|
|
12
|
+
export interface CommandEffect {
|
|
13
|
+
readonly kind: string;
|
|
14
|
+
readonly payload: Readonly<Record<string, unknown>>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CommandPageData {
|
|
18
|
+
readonly page: string;
|
|
19
|
+
readonly data: Readonly<Record<string, unknown>>;
|
|
20
|
+
readonly effects?: readonly CommandEffect[];
|
|
21
|
+
/**
|
|
22
|
+
* UR-20261120-157 — the module's OWN message, when the answer is interactive rather than a page.
|
|
23
|
+
*
|
|
24
|
+
* A command could only ever return page data, so a module that had built a full Components V2 surface —
|
|
25
|
+
* as it already may from a component handler — could not deliver it from its own command. That is why the
|
|
26
|
+
* permit console was unreachable: `/permit` returned `{ page: 'permit' }` and the core rendered a page that
|
|
27
|
+
* carried none of the console's controls.
|
|
28
|
+
*
|
|
29
|
+
* Present, it IS the answer and the page is not rendered. Absent, nothing changes.
|
|
30
|
+
*/
|
|
31
|
+
readonly message?: ComponentsV2Message;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* §11 (system-map) — WHO a dispatch is running as, and WHERE.
|
|
36
|
+
*
|
|
37
|
+
* The framework hosts the main bot and any number of personas in ONE process. Before this, a module
|
|
38
|
+
* could not tell which of them was running its command: `CommandContext` carried config and page data
|
|
39
|
+
* and nothing about identity, so a handler had no way to know whose signal it was answering, which
|
|
40
|
+
* application it should speak as, or which guild it was bound to. Every module-facing decision that
|
|
41
|
+
* depended on that had to be made by the core on the module's behalf — which is how the core came to
|
|
42
|
+
* hold facts the modules own.
|
|
43
|
+
*
|
|
44
|
+
* This is the module-facing half of the framework's identity: one object, built once at dispatch from
|
|
45
|
+
* the interaction Discord hands us, and never re-derived.
|
|
46
|
+
*/
|
|
47
|
+
export interface ExecutionIdentity {
|
|
48
|
+
/** `'main'` for the main bot, or the persona's id. The profile running this command. */
|
|
49
|
+
readonly profileId: string;
|
|
50
|
+
/** Which of the two this is. A persona is single-guild and can refuse; the main bot serves all. */
|
|
51
|
+
readonly kind: 'main' | 'persona';
|
|
52
|
+
/** The Discord application this identity speaks as — the one that owns its emoji and commands. */
|
|
53
|
+
readonly applicationId: string;
|
|
54
|
+
/** The identity's display name: the bot's username, or the persona's registered name. */
|
|
55
|
+
readonly profileName: string;
|
|
56
|
+
/** The guild the signal came from. `null` in a direct message. */
|
|
57
|
+
readonly guildId: string | null;
|
|
58
|
+
/**
|
|
59
|
+
* The ONE guild this identity serves. Absent for the main bot, which serves every guild it is
|
|
60
|
+
* installed in; present for a persona, which refuses everywhere else.
|
|
61
|
+
*/
|
|
62
|
+
readonly boundGuildId?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* §11 / §13.2 — the module's OWN standing in the guild this dispatch is running in.
|
|
67
|
+
*
|
|
68
|
+
* "Where is this module installed, where is it running, and whose is it." A standard or marketplace
|
|
69
|
+
* module belongs to ONE profile per guild, first come; core belongs to nobody and runs for everyone.
|
|
70
|
+
*/
|
|
71
|
+
export interface ModuleStanding {
|
|
72
|
+
/** The module this command belongs to. */
|
|
73
|
+
readonly moduleId: string;
|
|
74
|
+
/** The module's tier, as its own manifest declares it. */
|
|
75
|
+
readonly tier: 'admin' | 'core' | 'standard' | 'marketplace';
|
|
76
|
+
/** Whether the module is enabled in this guild. Core is always enabled. */
|
|
77
|
+
readonly enabled: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Which profile HOLDS this module here: `'main'`, a persona id, or `'shared'` for core, which no
|
|
80
|
+
* profile owns and every profile runs.
|
|
81
|
+
*/
|
|
82
|
+
readonly owner: string;
|
|
83
|
+
/** Whether the identity running this dispatch is the one that holds it. */
|
|
84
|
+
readonly ownedByCaller: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface CommandContext {
|
|
88
|
+
readonly config: Readonly<Record<string, unknown>>;
|
|
89
|
+
/**
|
|
90
|
+
* §11 — who is running this command and where. Always present: a handler that needs to know whose
|
|
91
|
+
* signal it is answering can ask, instead of the core having to decide for it.
|
|
92
|
+
*/
|
|
93
|
+
readonly identity: ExecutionIdentity;
|
|
94
|
+
/**
|
|
95
|
+
* §11 / §13.2 — this module's own standing in that guild: its tier, whether it is enabled, which
|
|
96
|
+
* profile holds it, and whether that is the caller.
|
|
97
|
+
*/
|
|
98
|
+
readonly module: ModuleStanding;
|
|
99
|
+
/**
|
|
100
|
+
* Host-supplied data for the command's declared page. The framework gathers it at dispatch —
|
|
101
|
+
* live metrics, the module registry, queue state, persona bindings — so a module can present
|
|
102
|
+
* runtime state without reaching into the host process itself, which it cannot do. Empty when
|
|
103
|
+
* the host supplies nothing for the module.
|
|
104
|
+
*/
|
|
105
|
+
readonly data: Readonly<Record<string, unknown>>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type CommandHandler = (
|
|
109
|
+
interaction: unknown,
|
|
110
|
+
context: CommandContext,
|
|
111
|
+
) => Promise<CommandPageData> | CommandPageData;
|
|
112
|
+
|
|
113
|
+
/** Layer 6 vocabulary, canonical short form (blueprint §21). */
|
|
114
|
+
export type CommandRbacRequirement = 'RESTRICTED' | 'MEMBER' | 'HELPER' | 'MOD' | 'ADMIN' | 'OWNER';
|
|
115
|
+
|
|
116
|
+
export interface CommandPermissionsDeclaration {
|
|
117
|
+
readonly discord?: readonly string[];
|
|
118
|
+
readonly rbac?: CommandRbacRequirement;
|
|
119
|
+
readonly nsfw?: boolean;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A slash-command option (Discord `ApplicationCommandOptionType` number in `type`). */
|
|
123
|
+
export interface CommandOptionDeclaration {
|
|
124
|
+
readonly name: string;
|
|
125
|
+
readonly description: string;
|
|
126
|
+
readonly type: number;
|
|
127
|
+
readonly required?: boolean;
|
|
128
|
+
readonly autocomplete?: boolean;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface CommandDeclaration {
|
|
132
|
+
readonly name: string;
|
|
133
|
+
readonly description: string;
|
|
134
|
+
readonly pages: readonly string[];
|
|
135
|
+
readonly execute: CommandHandler;
|
|
136
|
+
readonly guildOnly?: boolean;
|
|
137
|
+
readonly options?: readonly CommandOptionDeclaration[];
|
|
138
|
+
readonly permissions?: CommandPermissionsDeclaration;
|
|
139
|
+
/** UR-A-03 / finding #3 — the middleware metadata the framework reads. */
|
|
140
|
+
readonly requiresDefer?: boolean;
|
|
141
|
+
readonly ephemeral?: boolean;
|
|
142
|
+
readonly cooldownMs?: number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function defineCommand(declaration: CommandDeclaration): CommandDeclaration {
|
|
146
|
+
if (declaration.name.trim().length === 0) {
|
|
147
|
+
throw new Error('command name is required');
|
|
148
|
+
}
|
|
149
|
+
if (declaration.pages.length === 0) {
|
|
150
|
+
throw new Error(`command "${declaration.name}" must declare at least one page`);
|
|
151
|
+
}
|
|
152
|
+
return declaration;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* UR-20261031-131 (OI-19) — the profile a command registry serves, and the registry surface both the
|
|
157
|
+
* framework and a module rely on.
|
|
158
|
+
*
|
|
159
|
+
* A module hosts commands: it builds a registry for a profile, filters it, and hands it to the framework
|
|
160
|
+
* to deploy. Both sides must agree on what a registry IS, and until now they could not, because the type
|
|
161
|
+
* lived in the core. Two routes were tried and both fail: a module MIRRORING the type is not assignable
|
|
162
|
+
* where the core expects its full one, and a module IMPORTING it loses the self-contained declaration the
|
|
163
|
+
* core needs to resolve through the @modules mapping. So it lives here, where both sides import from.
|
|
164
|
+
*/
|
|
165
|
+
export interface CommandProfile {
|
|
166
|
+
readonly kind: 'main' | 'persona';
|
|
167
|
+
readonly id: string;
|
|
168
|
+
readonly applicationId: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface CommandDefinitionLike {
|
|
172
|
+
readonly data: unknown;
|
|
173
|
+
readonly moduleId: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface CommandRegistryLike {
|
|
177
|
+
all(): readonly CommandDefinitionLike[];
|
|
178
|
+
getModuleTier(moduleId: string): string | undefined;
|
|
179
|
+
register(def: CommandDefinitionLike): void;
|
|
180
|
+
registerModule(moduleId: string, tier: string): void;
|
|
181
|
+
}
|
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
export const IS_COMPONENTS_V2 = 32768;
|
|
2
|
+
/** 1 << 6 — a message only the invoking user can see. Combinable with IS_COMPONENTS_V2. */
|
|
3
|
+
export const EPHEMERAL = 64;
|
|
4
|
+
|
|
5
|
+
export const ComponentType = {
|
|
6
|
+
ACTION_ROW: 1,
|
|
7
|
+
TEXT_DISPLAY: 10,
|
|
8
|
+
MEDIA_GALLERY: 12,
|
|
9
|
+
SEPARATOR: 14,
|
|
10
|
+
CONTAINER: 17,
|
|
11
|
+
STRING_SELECT: 3,
|
|
12
|
+
BUTTON: 2,
|
|
13
|
+
/** item 8 — a Section: text blocks beside an accessory (e.g. an inline button). */
|
|
14
|
+
SECTION: 9,
|
|
15
|
+
/** item 3 — a small image usable as a Section accessory (Discord type 11). */
|
|
16
|
+
THUMBNAIL: 11,
|
|
17
|
+
/** item 6 — the select-menu family: user / role / mentionable / channel (Discord types 5-8). */
|
|
18
|
+
USER_SELECT: 5,
|
|
19
|
+
ROLE_SELECT: 6,
|
|
20
|
+
MENTIONABLE_SELECT: 7,
|
|
21
|
+
CHANNEL_SELECT: 8,
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
export type ComponentTypeValue =
|
|
25
|
+
| typeof ComponentType.ACTION_ROW
|
|
26
|
+
| typeof ComponentType.TEXT_DISPLAY
|
|
27
|
+
| typeof ComponentType.MEDIA_GALLERY
|
|
28
|
+
| typeof ComponentType.SEPARATOR
|
|
29
|
+
| typeof ComponentType.CONTAINER
|
|
30
|
+
| typeof ComponentType.STRING_SELECT
|
|
31
|
+
| typeof ComponentType.BUTTON
|
|
32
|
+
| typeof ComponentType.SECTION
|
|
33
|
+
| typeof ComponentType.THUMBNAIL
|
|
34
|
+
| typeof ComponentType.USER_SELECT
|
|
35
|
+
| typeof ComponentType.ROLE_SELECT
|
|
36
|
+
| typeof ComponentType.MENTIONABLE_SELECT
|
|
37
|
+
| typeof ComponentType.CHANNEL_SELECT;
|
|
38
|
+
|
|
39
|
+
export interface ComponentBase {
|
|
40
|
+
type: ComponentTypeValue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface TextDisplayComponent extends ComponentBase {
|
|
44
|
+
type: typeof ComponentType.TEXT_DISPLAY;
|
|
45
|
+
content: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface MediaGalleryComponent extends ComponentBase {
|
|
49
|
+
type: typeof ComponentType.MEDIA_GALLERY;
|
|
50
|
+
items: Array<{
|
|
51
|
+
media: {
|
|
52
|
+
url: string;
|
|
53
|
+
};
|
|
54
|
+
description?: string;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface SeparatorComponent extends ComponentBase {
|
|
59
|
+
type: typeof ComponentType.SEPARATOR;
|
|
60
|
+
divider?: boolean;
|
|
61
|
+
spacing?: 1 | 2;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ContainerComponent extends ComponentBase {
|
|
65
|
+
type: typeof ComponentType.CONTAINER;
|
|
66
|
+
components: Component[];
|
|
67
|
+
accent_color?: number;
|
|
68
|
+
spoiler?: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface StringSelectComponent extends ComponentBase {
|
|
72
|
+
type: typeof ComponentType.STRING_SELECT;
|
|
73
|
+
custom_id: string;
|
|
74
|
+
placeholder?: string;
|
|
75
|
+
min_values?: number;
|
|
76
|
+
max_values?: number;
|
|
77
|
+
disabled?: boolean;
|
|
78
|
+
options: Array<{
|
|
79
|
+
label: string;
|
|
80
|
+
value: string;
|
|
81
|
+
description?: string;
|
|
82
|
+
emoji?: { name: string; id?: string; animated?: boolean };
|
|
83
|
+
default?: boolean;
|
|
84
|
+
}>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* item 6 — the select-menu family that is NOT the string select. Discord types 5-8 (user, role,
|
|
89
|
+
* mentionable, channel) share one shape: a minted customId, optional placeholder/min/max/disabled,
|
|
90
|
+
* and an optional `default_values` list. They carry no `options` array — the client enumerates the
|
|
91
|
+
* candidates (members, roles, channels) itself.
|
|
92
|
+
*/
|
|
93
|
+
export interface EntitySelectComponent extends ComponentBase {
|
|
94
|
+
type:
|
|
95
|
+
| typeof ComponentType.USER_SELECT
|
|
96
|
+
| typeof ComponentType.ROLE_SELECT
|
|
97
|
+
| typeof ComponentType.MENTIONABLE_SELECT
|
|
98
|
+
| typeof ComponentType.CHANNEL_SELECT;
|
|
99
|
+
custom_id: string;
|
|
100
|
+
placeholder?: string;
|
|
101
|
+
min_values?: number;
|
|
102
|
+
max_values?: number;
|
|
103
|
+
disabled?: boolean;
|
|
104
|
+
default_values?: Array<{ id: string; type: 'user' | 'role' | 'channel' }>;
|
|
105
|
+
/** Channel select only — restrict to these channel types (Discord channel type numbers). */
|
|
106
|
+
channel_types?: number[];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface ButtonComponent extends ComponentBase {
|
|
110
|
+
type: typeof ComponentType.BUTTON;
|
|
111
|
+
style: 1 | 2 | 3 | 4 | 5;
|
|
112
|
+
custom_id: string;
|
|
113
|
+
/** item 2 — omitted for an icon-only control (the Home button). */
|
|
114
|
+
label?: string;
|
|
115
|
+
disabled?: boolean;
|
|
116
|
+
emoji?: { name: string; id?: string; animated?: boolean };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface ActionRowComponent extends ComponentBase {
|
|
120
|
+
type: typeof ComponentType.ACTION_ROW;
|
|
121
|
+
components: Array<ButtonComponent | StringSelectComponent | EntitySelectComponent>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* item 3 — a small image (Discord type 11). Usable ONLY as a Section accessory, and (item 6) also
|
|
126
|
+
* usable as a standalone content element. Mirrors the embed thumbnail slot.
|
|
127
|
+
*/
|
|
128
|
+
export interface ThumbnailComponent extends ComponentBase {
|
|
129
|
+
type: typeof ComponentType.THUMBNAIL;
|
|
130
|
+
media: { url: string };
|
|
131
|
+
description?: string;
|
|
132
|
+
spoiler?: boolean;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* item 8 — a Section holds one or more Text Displays beside a single accessory, so a control can sit
|
|
137
|
+
* IN-LINE after its text rather than on a separate row. Discord allows exactly one accessory, and it
|
|
138
|
+
* is either a Button or a Thumbnail (item 3).
|
|
139
|
+
*/
|
|
140
|
+
export interface SectionComponent extends ComponentBase {
|
|
141
|
+
type: typeof ComponentType.SECTION;
|
|
142
|
+
components: TextDisplayComponent[];
|
|
143
|
+
accessory: ButtonComponent | ThumbnailComponent;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type Component =
|
|
147
|
+
| TextDisplayComponent
|
|
148
|
+
| MediaGalleryComponent
|
|
149
|
+
| SeparatorComponent
|
|
150
|
+
| ContainerComponent
|
|
151
|
+
| StringSelectComponent
|
|
152
|
+
| EntitySelectComponent
|
|
153
|
+
| ButtonComponent
|
|
154
|
+
| ActionRowComponent
|
|
155
|
+
| SectionComponent
|
|
156
|
+
| ThumbnailComponent;
|
|
157
|
+
|
|
158
|
+
export interface ComponentsV2Message {
|
|
159
|
+
components: Component[];
|
|
160
|
+
flags: number;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function textDisplay(content: string): TextDisplayComponent {
|
|
164
|
+
return {
|
|
165
|
+
type: ComponentType.TEXT_DISPLAY,
|
|
166
|
+
content,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function mediaGallery(url: string, description?: string): MediaGalleryComponent {
|
|
171
|
+
const item: { media: { url: string }; description?: string } = { media: { url } };
|
|
172
|
+
if (description !== undefined) {
|
|
173
|
+
item.description = description;
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
type: ComponentType.MEDIA_GALLERY,
|
|
177
|
+
items: [item],
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function separator(
|
|
182
|
+
dividerOrSpacing: boolean | 'small' | 'large' = true,
|
|
183
|
+
spacing: 'small' | 'large' = 'large',
|
|
184
|
+
): SeparatorComponent {
|
|
185
|
+
const divider = typeof dividerOrSpacing === 'boolean' ? dividerOrSpacing : true;
|
|
186
|
+
const size = typeof dividerOrSpacing === 'string' ? dividerOrSpacing : spacing;
|
|
187
|
+
return {
|
|
188
|
+
type: ComponentType.SEPARATOR,
|
|
189
|
+
divider,
|
|
190
|
+
spacing: size === 'small' ? 1 : 2,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function container(components: Component[], accentColor?: number): ContainerComponent {
|
|
195
|
+
const result: ContainerComponent = {
|
|
196
|
+
type: ComponentType.CONTAINER,
|
|
197
|
+
components,
|
|
198
|
+
};
|
|
199
|
+
if (accentColor !== undefined) {
|
|
200
|
+
result.accent_color = accentColor;
|
|
201
|
+
}
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function stringSelect(
|
|
206
|
+
customId: string,
|
|
207
|
+
options: Array<{
|
|
208
|
+
label: string;
|
|
209
|
+
value: string;
|
|
210
|
+
description?: string;
|
|
211
|
+
emoji?: string | { name: string; id?: string };
|
|
212
|
+
default?: boolean;
|
|
213
|
+
}>,
|
|
214
|
+
placeholder?: string,
|
|
215
|
+
disabled?: boolean,
|
|
216
|
+
): StringSelectComponent {
|
|
217
|
+
const result: StringSelectComponent = {
|
|
218
|
+
type: ComponentType.STRING_SELECT,
|
|
219
|
+
custom_id: customId,
|
|
220
|
+
min_values: 1,
|
|
221
|
+
max_values: 1,
|
|
222
|
+
options: options.map((opt) => {
|
|
223
|
+
const result: {
|
|
224
|
+
label: string;
|
|
225
|
+
value: string;
|
|
226
|
+
description?: string;
|
|
227
|
+
emoji?: { name: string; id?: string; animated?: boolean };
|
|
228
|
+
default?: boolean;
|
|
229
|
+
} = {
|
|
230
|
+
label: opt.label,
|
|
231
|
+
value: opt.value,
|
|
232
|
+
};
|
|
233
|
+
if (opt.description !== undefined) result.description = opt.description;
|
|
234
|
+
if (opt.emoji !== undefined)
|
|
235
|
+
result.emoji = typeof opt.emoji === 'string' ? { name: opt.emoji } : opt.emoji;
|
|
236
|
+
if (opt.default !== undefined) result.default = opt.default;
|
|
237
|
+
return result;
|
|
238
|
+
}),
|
|
239
|
+
};
|
|
240
|
+
if (placeholder !== undefined) {
|
|
241
|
+
result.placeholder = placeholder;
|
|
242
|
+
}
|
|
243
|
+
if (disabled !== undefined) {
|
|
244
|
+
result.disabled = disabled;
|
|
245
|
+
}
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** item 6 — the shared shape of the user/role/mentionable/channel select family. */
|
|
250
|
+
function entitySelect(
|
|
251
|
+
type: EntitySelectComponent['type'],
|
|
252
|
+
customId: string,
|
|
253
|
+
options: {
|
|
254
|
+
placeholder?: string;
|
|
255
|
+
minValues?: number;
|
|
256
|
+
maxValues?: number;
|
|
257
|
+
disabled?: boolean;
|
|
258
|
+
defaultValues?: Array<{ id: string; type: 'user' | 'role' | 'channel' }>;
|
|
259
|
+
channelTypes?: number[];
|
|
260
|
+
} = {},
|
|
261
|
+
): EntitySelectComponent {
|
|
262
|
+
const result: EntitySelectComponent = {
|
|
263
|
+
type,
|
|
264
|
+
custom_id: customId,
|
|
265
|
+
min_values: options.minValues ?? 1,
|
|
266
|
+
max_values: options.maxValues ?? 1,
|
|
267
|
+
};
|
|
268
|
+
if (options.placeholder !== undefined) result.placeholder = options.placeholder;
|
|
269
|
+
if (options.disabled !== undefined) result.disabled = options.disabled;
|
|
270
|
+
if (options.defaultValues !== undefined) result.default_values = options.defaultValues;
|
|
271
|
+
if (options.channelTypes !== undefined) result.channel_types = options.channelTypes;
|
|
272
|
+
return result;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** item 6 — a User Select menu (Discord type 5). */
|
|
276
|
+
export function userSelect(
|
|
277
|
+
customId: string,
|
|
278
|
+
options?: Parameters<typeof entitySelect>[2],
|
|
279
|
+
): EntitySelectComponent {
|
|
280
|
+
return entitySelect(ComponentType.USER_SELECT, customId, options);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** item 6 — a Role Select menu (Discord type 6). */
|
|
284
|
+
export function roleSelect(
|
|
285
|
+
customId: string,
|
|
286
|
+
options?: Parameters<typeof entitySelect>[2],
|
|
287
|
+
): EntitySelectComponent {
|
|
288
|
+
return entitySelect(ComponentType.ROLE_SELECT, customId, options);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** item 6 — a Mentionable Select menu (Discord type 7: users and roles). */
|
|
292
|
+
export function mentionableSelect(
|
|
293
|
+
customId: string,
|
|
294
|
+
options?: Parameters<typeof entitySelect>[2],
|
|
295
|
+
): EntitySelectComponent {
|
|
296
|
+
return entitySelect(ComponentType.MENTIONABLE_SELECT, customId, options);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** item 6 — a Channel Select menu (Discord type 8), optionally restricted to channel types. */
|
|
300
|
+
export function channelSelect(
|
|
301
|
+
customId: string,
|
|
302
|
+
options?: Parameters<typeof entitySelect>[2],
|
|
303
|
+
): EntitySelectComponent {
|
|
304
|
+
return entitySelect(ComponentType.CHANNEL_SELECT, customId, options);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function button(
|
|
308
|
+
customId: string,
|
|
309
|
+
label: string,
|
|
310
|
+
style: 1 | 2 | 3 | 4 | 5 = 2,
|
|
311
|
+
disabled = false,
|
|
312
|
+
emoji?: string | { name: string; id?: string },
|
|
313
|
+
): ButtonComponent {
|
|
314
|
+
const result: ButtonComponent = {
|
|
315
|
+
type: ComponentType.BUTTON,
|
|
316
|
+
style,
|
|
317
|
+
custom_id: customId,
|
|
318
|
+
disabled,
|
|
319
|
+
};
|
|
320
|
+
// item 2 — an icon-only control (the Home button) omits the label and carries a custom emoji.
|
|
321
|
+
if (label !== '') {
|
|
322
|
+
result.label = label;
|
|
323
|
+
}
|
|
324
|
+
if (emoji !== undefined) {
|
|
325
|
+
result.emoji = typeof emoji === 'string' ? { name: emoji } : emoji;
|
|
326
|
+
}
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* UR-20261012-029 — a LINK button (style 5). Discord requires a `url` in place of a `custom_id` on
|
|
332
|
+
* a link button, so it is built here rather than through `button()`.
|
|
333
|
+
*/
|
|
334
|
+
export function linkButton(
|
|
335
|
+
url: string,
|
|
336
|
+
label: string,
|
|
337
|
+
emoji?: string | { name: string; id?: string },
|
|
338
|
+
): ButtonComponent {
|
|
339
|
+
const result = {
|
|
340
|
+
type: ComponentType.BUTTON,
|
|
341
|
+
style: 5 as const,
|
|
342
|
+
custom_id: '',
|
|
343
|
+
url,
|
|
344
|
+
disabled: false,
|
|
345
|
+
} as unknown as ButtonComponent & { url: string };
|
|
346
|
+
if (label !== '') result.label = label;
|
|
347
|
+
if (emoji !== undefined) result.emoji = typeof emoji === 'string' ? { name: emoji } : emoji;
|
|
348
|
+
return result;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export function actionRow(
|
|
352
|
+
components: Array<ButtonComponent | StringSelectComponent | EntitySelectComponent>,
|
|
353
|
+
): ActionRowComponent {
|
|
354
|
+
return {
|
|
355
|
+
type: ComponentType.ACTION_ROW,
|
|
356
|
+
components,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* item 3 — a small image usable as a Section accessory (Discord type 11). Mirrors the embed
|
|
362
|
+
* thumbnail slot; Discord renders it right-aligned beside the section's text.
|
|
363
|
+
*/
|
|
364
|
+
export function thumbnail(
|
|
365
|
+
url: string,
|
|
366
|
+
description?: string,
|
|
367
|
+
spoiler?: boolean,
|
|
368
|
+
): ThumbnailComponent {
|
|
369
|
+
const result: ThumbnailComponent = {
|
|
370
|
+
type: ComponentType.THUMBNAIL,
|
|
371
|
+
media: { url },
|
|
372
|
+
};
|
|
373
|
+
if (description !== undefined) result.description = description;
|
|
374
|
+
if (spoiler !== undefined) result.spoiler = spoiler;
|
|
375
|
+
return result;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** item 8 — a Section: a text block with an accessory (button or thumbnail) rendered in-line. */
|
|
379
|
+
export function section(
|
|
380
|
+
content: string | TextDisplayComponent[],
|
|
381
|
+
accessory: ButtonComponent | ThumbnailComponent,
|
|
382
|
+
): SectionComponent {
|
|
383
|
+
const components = typeof content === 'string' ? [textDisplay(content)] : content;
|
|
384
|
+
return {
|
|
385
|
+
type: ComponentType.SECTION,
|
|
386
|
+
components,
|
|
387
|
+
accessory,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** item 5 — a modal text input (short, style 1) or paragraph (style 2). */
|
|
392
|
+
export interface ModalTextInput {
|
|
393
|
+
customId: string;
|
|
394
|
+
label: string;
|
|
395
|
+
placeholder?: string;
|
|
396
|
+
required?: boolean;
|
|
397
|
+
maxLength?: number;
|
|
398
|
+
/** item 6 — style 2 is a multi-line paragraph input. */
|
|
399
|
+
style?: 'short' | 'paragraph';
|
|
400
|
+
minLength?: number;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export interface ModalPayload {
|
|
404
|
+
custom_id: string;
|
|
405
|
+
title: string;
|
|
406
|
+
components: Array<{
|
|
407
|
+
type: typeof ComponentType.ACTION_ROW;
|
|
408
|
+
components: Array<{
|
|
409
|
+
type: 4;
|
|
410
|
+
custom_id: string;
|
|
411
|
+
label: string;
|
|
412
|
+
style: 1 | 2;
|
|
413
|
+
placeholder?: string;
|
|
414
|
+
required?: boolean;
|
|
415
|
+
max_length?: number;
|
|
416
|
+
min_length?: number;
|
|
417
|
+
}>;
|
|
418
|
+
}>;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function textInputRow(input: ModalTextInput): ModalPayload['components'][number] {
|
|
422
|
+
return {
|
|
423
|
+
type: ComponentType.ACTION_ROW,
|
|
424
|
+
components: [
|
|
425
|
+
{
|
|
426
|
+
type: 4,
|
|
427
|
+
custom_id: input.customId,
|
|
428
|
+
label: input.label,
|
|
429
|
+
style: input.style === 'paragraph' ? 2 : 1,
|
|
430
|
+
...(input.placeholder !== undefined ? { placeholder: input.placeholder } : {}),
|
|
431
|
+
...(input.required !== undefined ? { required: input.required } : {}),
|
|
432
|
+
...(input.maxLength !== undefined ? { max_length: input.maxLength } : {}),
|
|
433
|
+
...(input.minLength !== undefined ? { min_length: input.minLength } : {}),
|
|
434
|
+
},
|
|
435
|
+
],
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export function textInputModal(
|
|
440
|
+
customId: string,
|
|
441
|
+
title: string,
|
|
442
|
+
input: ModalTextInput,
|
|
443
|
+
): ModalPayload {
|
|
444
|
+
return {
|
|
445
|
+
custom_id: customId,
|
|
446
|
+
title,
|
|
447
|
+
components: [textInputRow(input)],
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** item 6 — a modal carrying several inputs (short inputs and/or paragraphs), one per action row. */
|
|
452
|
+
export function multiInputModal(
|
|
453
|
+
customId: string,
|
|
454
|
+
title: string,
|
|
455
|
+
inputs: readonly ModalTextInput[],
|
|
456
|
+
): ModalPayload {
|
|
457
|
+
return {
|
|
458
|
+
custom_id: customId,
|
|
459
|
+
title,
|
|
460
|
+
components: inputs.map(textInputRow),
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* item 5 — build a Components-v2 message. `ephemeral` adds the EPHEMERAL flag (1 << 6) alongside
|
|
466
|
+
* IS_COMPONENTS_V2, producing a message only the invoking user can see.
|
|
467
|
+
*/
|
|
468
|
+
export function buildComponentsV2(
|
|
469
|
+
components: Component[],
|
|
470
|
+
options: { ephemeral?: boolean } = {},
|
|
471
|
+
): ComponentsV2Message {
|
|
472
|
+
return {
|
|
473
|
+
components,
|
|
474
|
+
flags: options.ephemeral === true ? IS_COMPONENTS_V2 | EPHEMERAL : IS_COMPONENTS_V2,
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
export const DEFAULT_ACCENT_COLOR = 0xffca6d;
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* item 2 — the accent a Twill-registered persona falls back to when none is configured: a neutral
|
|
482
|
+
* gray. Distinct from the framework's amber default, so a persona with no declared identity is
|
|
483
|
+
* visibly its own surface rather than the framework's.
|
|
484
|
+
*/
|
|
485
|
+
export const DEFAULT_PERSONA_ACCENT = '#808080';
|
|
486
|
+
|
|
487
|
+
export function createBannerMediaGallery(bannerUrl: string): MediaGalleryComponent {
|
|
488
|
+
return mediaGallery(bannerUrl, 'Dumby banner');
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export function getDefaultBannerUrl(
|
|
492
|
+
moduleName: string,
|
|
493
|
+
accentColor = DEFAULT_ACCENT_COLOR,
|
|
494
|
+
): string {
|
|
495
|
+
const encoded = encodeURIComponent(moduleName);
|
|
496
|
+
return `https://api.dumby.dev/banner?module=${encoded}&color=${accentColor.toString(16).padStart(6, '0')}`;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* The identity band: `**<owner> | <page>**` over an attribution line.
|
|
501
|
+
*
|
|
502
|
+
* Both halves are arguments, because neither is constant across profiles. The resident bot is
|
|
503
|
+
* "Dumby Suite", "Developed by Quixotic Mnemonics"; a persona carries her OWN name as the owner and
|
|
504
|
+
* "Powered by Dumby Suite" as the attribution. The line is passed whole rather than assembled from a
|
|
505
|
+
* name, because the two profiles do not even use the same verb.
|
|
506
|
+
*/
|
|
507
|
+
export function createTitleBlock(
|
|
508
|
+
pageName: string,
|
|
509
|
+
developer = 'Quixotic Mnemonics',
|
|
510
|
+
options: { owner?: string; attributionLine?: string } = {},
|
|
511
|
+
): TextDisplayComponent {
|
|
512
|
+
// The second parameter stays the DEVELOPER NAME: changing its meaning would silently drop the
|
|
513
|
+
// "Developed by" verb at every call site that still passes a name.
|
|
514
|
+
const attribution = options.attributionLine ?? `Developed by ${developer}`;
|
|
515
|
+
return textDisplay(`**${options.owner ?? 'Dumby Suite'} | ${pageName}**\n-# ${attribution}`);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
export function createMarketplaceTitleBlock(
|
|
519
|
+
developer = 'Quixotic Mnemonics',
|
|
520
|
+
options: { owner?: string; attributionLine?: string } = {},
|
|
521
|
+
): TextDisplayComponent {
|
|
522
|
+
const attribution = options.attributionLine ?? `Developed by ${developer}`;
|
|
523
|
+
return textDisplay(`**${options.owner ?? 'Dumby Suite'} | Marketplace**\n-# ${attribution}`);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export function createSectionHeader(emoji: string, title: string): TextDisplayComponent {
|
|
527
|
+
return textDisplay(`━━ ${emoji} ${title} ━━`);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export function createKeyValueDisplay(pairs: Record<string, string>): TextDisplayComponent {
|
|
531
|
+
const lines = Object.entries(pairs).map(([key, value]) => `${key}: ${value}`);
|
|
532
|
+
return textDisplay(lines.join('\n'));
|
|
533
|
+
}
|