@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
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
export declare const IS_COMPONENTS_V2 = 32768;
|
|
2
|
+
/** 1 << 6 — a message only the invoking user can see. Combinable with IS_COMPONENTS_V2. */
|
|
3
|
+
export declare const EPHEMERAL = 64;
|
|
4
|
+
export declare const ComponentType: {
|
|
5
|
+
readonly ACTION_ROW: 1;
|
|
6
|
+
readonly TEXT_DISPLAY: 10;
|
|
7
|
+
readonly MEDIA_GALLERY: 12;
|
|
8
|
+
readonly SEPARATOR: 14;
|
|
9
|
+
readonly CONTAINER: 17;
|
|
10
|
+
readonly STRING_SELECT: 3;
|
|
11
|
+
readonly BUTTON: 2;
|
|
12
|
+
/** item 8 — a Section: text blocks beside an accessory (e.g. an inline button). */
|
|
13
|
+
readonly SECTION: 9;
|
|
14
|
+
/** item 3 — a small image usable as a Section accessory (Discord type 11). */
|
|
15
|
+
readonly THUMBNAIL: 11;
|
|
16
|
+
/** item 6 — the select-menu family: user / role / mentionable / channel (Discord types 5-8). */
|
|
17
|
+
readonly USER_SELECT: 5;
|
|
18
|
+
readonly ROLE_SELECT: 6;
|
|
19
|
+
readonly MENTIONABLE_SELECT: 7;
|
|
20
|
+
readonly CHANNEL_SELECT: 8;
|
|
21
|
+
};
|
|
22
|
+
export type ComponentTypeValue = typeof ComponentType.ACTION_ROW | typeof ComponentType.TEXT_DISPLAY | typeof ComponentType.MEDIA_GALLERY | typeof ComponentType.SEPARATOR | typeof ComponentType.CONTAINER | typeof ComponentType.STRING_SELECT | typeof ComponentType.BUTTON | typeof ComponentType.SECTION | typeof ComponentType.THUMBNAIL | typeof ComponentType.USER_SELECT | typeof ComponentType.ROLE_SELECT | typeof ComponentType.MENTIONABLE_SELECT | typeof ComponentType.CHANNEL_SELECT;
|
|
23
|
+
export interface ComponentBase {
|
|
24
|
+
type: ComponentTypeValue;
|
|
25
|
+
}
|
|
26
|
+
export interface TextDisplayComponent extends ComponentBase {
|
|
27
|
+
type: typeof ComponentType.TEXT_DISPLAY;
|
|
28
|
+
content: string;
|
|
29
|
+
}
|
|
30
|
+
export interface MediaGalleryComponent extends ComponentBase {
|
|
31
|
+
type: typeof ComponentType.MEDIA_GALLERY;
|
|
32
|
+
items: Array<{
|
|
33
|
+
media: {
|
|
34
|
+
url: string;
|
|
35
|
+
};
|
|
36
|
+
description?: string;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
export interface SeparatorComponent extends ComponentBase {
|
|
40
|
+
type: typeof ComponentType.SEPARATOR;
|
|
41
|
+
divider?: boolean;
|
|
42
|
+
spacing?: 1 | 2;
|
|
43
|
+
}
|
|
44
|
+
export interface ContainerComponent extends ComponentBase {
|
|
45
|
+
type: typeof ComponentType.CONTAINER;
|
|
46
|
+
components: Component[];
|
|
47
|
+
accent_color?: number;
|
|
48
|
+
spoiler?: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface StringSelectComponent extends ComponentBase {
|
|
51
|
+
type: typeof ComponentType.STRING_SELECT;
|
|
52
|
+
custom_id: string;
|
|
53
|
+
placeholder?: string;
|
|
54
|
+
min_values?: number;
|
|
55
|
+
max_values?: number;
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
options: Array<{
|
|
58
|
+
label: string;
|
|
59
|
+
value: string;
|
|
60
|
+
description?: string;
|
|
61
|
+
emoji?: {
|
|
62
|
+
name: string;
|
|
63
|
+
id?: string;
|
|
64
|
+
animated?: boolean;
|
|
65
|
+
};
|
|
66
|
+
default?: boolean;
|
|
67
|
+
}>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* item 6 — the select-menu family that is NOT the string select. Discord types 5-8 (user, role,
|
|
71
|
+
* mentionable, channel) share one shape: a minted customId, optional placeholder/min/max/disabled,
|
|
72
|
+
* and an optional `default_values` list. They carry no `options` array — the client enumerates the
|
|
73
|
+
* candidates (members, roles, channels) itself.
|
|
74
|
+
*/
|
|
75
|
+
export interface EntitySelectComponent extends ComponentBase {
|
|
76
|
+
type: typeof ComponentType.USER_SELECT | typeof ComponentType.ROLE_SELECT | typeof ComponentType.MENTIONABLE_SELECT | typeof ComponentType.CHANNEL_SELECT;
|
|
77
|
+
custom_id: string;
|
|
78
|
+
placeholder?: string;
|
|
79
|
+
min_values?: number;
|
|
80
|
+
max_values?: number;
|
|
81
|
+
disabled?: boolean;
|
|
82
|
+
default_values?: Array<{
|
|
83
|
+
id: string;
|
|
84
|
+
type: 'user' | 'role' | 'channel';
|
|
85
|
+
}>;
|
|
86
|
+
/** Channel select only — restrict to these channel types (Discord channel type numbers). */
|
|
87
|
+
channel_types?: number[];
|
|
88
|
+
}
|
|
89
|
+
export interface ButtonComponent extends ComponentBase {
|
|
90
|
+
type: typeof ComponentType.BUTTON;
|
|
91
|
+
style: 1 | 2 | 3 | 4 | 5;
|
|
92
|
+
custom_id: string;
|
|
93
|
+
/** item 2 — omitted for an icon-only control (the Home button). */
|
|
94
|
+
label?: string;
|
|
95
|
+
disabled?: boolean;
|
|
96
|
+
emoji?: {
|
|
97
|
+
name: string;
|
|
98
|
+
id?: string;
|
|
99
|
+
animated?: boolean;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export interface ActionRowComponent extends ComponentBase {
|
|
103
|
+
type: typeof ComponentType.ACTION_ROW;
|
|
104
|
+
components: Array<ButtonComponent | StringSelectComponent | EntitySelectComponent>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* item 3 — a small image (Discord type 11). Usable ONLY as a Section accessory, and (item 6) also
|
|
108
|
+
* usable as a standalone content element. Mirrors the embed thumbnail slot.
|
|
109
|
+
*/
|
|
110
|
+
export interface ThumbnailComponent extends ComponentBase {
|
|
111
|
+
type: typeof ComponentType.THUMBNAIL;
|
|
112
|
+
media: {
|
|
113
|
+
url: string;
|
|
114
|
+
};
|
|
115
|
+
description?: string;
|
|
116
|
+
spoiler?: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* item 8 — a Section holds one or more Text Displays beside a single accessory, so a control can sit
|
|
120
|
+
* IN-LINE after its text rather than on a separate row. Discord allows exactly one accessory, and it
|
|
121
|
+
* is either a Button or a Thumbnail (item 3).
|
|
122
|
+
*/
|
|
123
|
+
export interface SectionComponent extends ComponentBase {
|
|
124
|
+
type: typeof ComponentType.SECTION;
|
|
125
|
+
components: TextDisplayComponent[];
|
|
126
|
+
accessory: ButtonComponent | ThumbnailComponent;
|
|
127
|
+
}
|
|
128
|
+
export type Component = TextDisplayComponent | MediaGalleryComponent | SeparatorComponent | ContainerComponent | StringSelectComponent | EntitySelectComponent | ButtonComponent | ActionRowComponent | SectionComponent | ThumbnailComponent;
|
|
129
|
+
export interface ComponentsV2Message {
|
|
130
|
+
components: Component[];
|
|
131
|
+
flags: number;
|
|
132
|
+
}
|
|
133
|
+
export declare function textDisplay(content: string): TextDisplayComponent;
|
|
134
|
+
export declare function mediaGallery(url: string, description?: string): MediaGalleryComponent;
|
|
135
|
+
export declare function separator(dividerOrSpacing?: boolean | 'small' | 'large', spacing?: 'small' | 'large'): SeparatorComponent;
|
|
136
|
+
export declare function container(components: Component[], accentColor?: number): ContainerComponent;
|
|
137
|
+
export declare function stringSelect(customId: string, options: Array<{
|
|
138
|
+
label: string;
|
|
139
|
+
value: string;
|
|
140
|
+
description?: string;
|
|
141
|
+
emoji?: string | {
|
|
142
|
+
name: string;
|
|
143
|
+
id?: string;
|
|
144
|
+
};
|
|
145
|
+
default?: boolean;
|
|
146
|
+
}>, placeholder?: string, disabled?: boolean): StringSelectComponent;
|
|
147
|
+
/** item 6 — the shared shape of the user/role/mentionable/channel select family. */
|
|
148
|
+
declare function entitySelect(type: EntitySelectComponent['type'], customId: string, options?: {
|
|
149
|
+
placeholder?: string;
|
|
150
|
+
minValues?: number;
|
|
151
|
+
maxValues?: number;
|
|
152
|
+
disabled?: boolean;
|
|
153
|
+
defaultValues?: Array<{
|
|
154
|
+
id: string;
|
|
155
|
+
type: 'user' | 'role' | 'channel';
|
|
156
|
+
}>;
|
|
157
|
+
channelTypes?: number[];
|
|
158
|
+
}): EntitySelectComponent;
|
|
159
|
+
/** item 6 — a User Select menu (Discord type 5). */
|
|
160
|
+
export declare function userSelect(customId: string, options?: Parameters<typeof entitySelect>[2]): EntitySelectComponent;
|
|
161
|
+
/** item 6 — a Role Select menu (Discord type 6). */
|
|
162
|
+
export declare function roleSelect(customId: string, options?: Parameters<typeof entitySelect>[2]): EntitySelectComponent;
|
|
163
|
+
/** item 6 — a Mentionable Select menu (Discord type 7: users and roles). */
|
|
164
|
+
export declare function mentionableSelect(customId: string, options?: Parameters<typeof entitySelect>[2]): EntitySelectComponent;
|
|
165
|
+
/** item 6 — a Channel Select menu (Discord type 8), optionally restricted to channel types. */
|
|
166
|
+
export declare function channelSelect(customId: string, options?: Parameters<typeof entitySelect>[2]): EntitySelectComponent;
|
|
167
|
+
export declare function button(customId: string, label: string, style?: 1 | 2 | 3 | 4 | 5, disabled?: boolean, emoji?: string | {
|
|
168
|
+
name: string;
|
|
169
|
+
id?: string;
|
|
170
|
+
}): ButtonComponent;
|
|
171
|
+
/**
|
|
172
|
+
* UR-20261012-029 — a LINK button (style 5). Discord requires a `url` in place of a `custom_id` on
|
|
173
|
+
* a link button, so it is built here rather than through `button()`.
|
|
174
|
+
*/
|
|
175
|
+
export declare function linkButton(url: string, label: string, emoji?: string | {
|
|
176
|
+
name: string;
|
|
177
|
+
id?: string;
|
|
178
|
+
}): ButtonComponent;
|
|
179
|
+
export declare function actionRow(components: Array<ButtonComponent | StringSelectComponent | EntitySelectComponent>): ActionRowComponent;
|
|
180
|
+
/**
|
|
181
|
+
* item 3 — a small image usable as a Section accessory (Discord type 11). Mirrors the embed
|
|
182
|
+
* thumbnail slot; Discord renders it right-aligned beside the section's text.
|
|
183
|
+
*/
|
|
184
|
+
export declare function thumbnail(url: string, description?: string, spoiler?: boolean): ThumbnailComponent;
|
|
185
|
+
/** item 8 — a Section: a text block with an accessory (button or thumbnail) rendered in-line. */
|
|
186
|
+
export declare function section(content: string | TextDisplayComponent[], accessory: ButtonComponent | ThumbnailComponent): SectionComponent;
|
|
187
|
+
/** item 5 — a modal text input (short, style 1) or paragraph (style 2). */
|
|
188
|
+
export interface ModalTextInput {
|
|
189
|
+
customId: string;
|
|
190
|
+
label: string;
|
|
191
|
+
placeholder?: string;
|
|
192
|
+
required?: boolean;
|
|
193
|
+
maxLength?: number;
|
|
194
|
+
/** item 6 — style 2 is a multi-line paragraph input. */
|
|
195
|
+
style?: 'short' | 'paragraph';
|
|
196
|
+
minLength?: number;
|
|
197
|
+
}
|
|
198
|
+
export interface ModalPayload {
|
|
199
|
+
custom_id: string;
|
|
200
|
+
title: string;
|
|
201
|
+
components: Array<{
|
|
202
|
+
type: typeof ComponentType.ACTION_ROW;
|
|
203
|
+
components: Array<{
|
|
204
|
+
type: 4;
|
|
205
|
+
custom_id: string;
|
|
206
|
+
label: string;
|
|
207
|
+
style: 1 | 2;
|
|
208
|
+
placeholder?: string;
|
|
209
|
+
required?: boolean;
|
|
210
|
+
max_length?: number;
|
|
211
|
+
min_length?: number;
|
|
212
|
+
}>;
|
|
213
|
+
}>;
|
|
214
|
+
}
|
|
215
|
+
export declare function textInputModal(customId: string, title: string, input: ModalTextInput): ModalPayload;
|
|
216
|
+
/** item 6 — a modal carrying several inputs (short inputs and/or paragraphs), one per action row. */
|
|
217
|
+
export declare function multiInputModal(customId: string, title: string, inputs: readonly ModalTextInput[]): ModalPayload;
|
|
218
|
+
/**
|
|
219
|
+
* item 5 — build a Components-v2 message. `ephemeral` adds the EPHEMERAL flag (1 << 6) alongside
|
|
220
|
+
* IS_COMPONENTS_V2, producing a message only the invoking user can see.
|
|
221
|
+
*/
|
|
222
|
+
export declare function buildComponentsV2(components: Component[], options?: {
|
|
223
|
+
ephemeral?: boolean;
|
|
224
|
+
}): ComponentsV2Message;
|
|
225
|
+
export declare const DEFAULT_ACCENT_COLOR = 16763501;
|
|
226
|
+
/**
|
|
227
|
+
* item 2 — the accent a Twill-registered persona falls back to when none is configured: a neutral
|
|
228
|
+
* gray. Distinct from the framework's amber default, so a persona with no declared identity is
|
|
229
|
+
* visibly its own surface rather than the framework's.
|
|
230
|
+
*/
|
|
231
|
+
export declare const DEFAULT_PERSONA_ACCENT = "#808080";
|
|
232
|
+
export declare function createBannerMediaGallery(bannerUrl: string): MediaGalleryComponent;
|
|
233
|
+
export declare function getDefaultBannerUrl(moduleName: string, accentColor?: number): string;
|
|
234
|
+
/**
|
|
235
|
+
* The identity band: `**<owner> | <page>**` over an attribution line.
|
|
236
|
+
*
|
|
237
|
+
* Both halves are arguments, because neither is constant across profiles. The resident bot is
|
|
238
|
+
* "Dumby Suite", "Developed by Quixotic Mnemonics"; a persona carries her OWN name as the owner and
|
|
239
|
+
* "Powered by Dumby Suite" as the attribution. The line is passed whole rather than assembled from a
|
|
240
|
+
* name, because the two profiles do not even use the same verb.
|
|
241
|
+
*/
|
|
242
|
+
export declare function createTitleBlock(pageName: string, developer?: string, options?: {
|
|
243
|
+
owner?: string;
|
|
244
|
+
attributionLine?: string;
|
|
245
|
+
}): TextDisplayComponent;
|
|
246
|
+
export declare function createMarketplaceTitleBlock(developer?: string, options?: {
|
|
247
|
+
owner?: string;
|
|
248
|
+
attributionLine?: string;
|
|
249
|
+
}): TextDisplayComponent;
|
|
250
|
+
export declare function createSectionHeader(emoji: string, title: string): TextDisplayComponent;
|
|
251
|
+
export declare function createKeyValueDisplay(pairs: Record<string, string>): TextDisplayComponent;
|
|
252
|
+
export {};
|
|
@@ -0,0 +1,263 @@
|
|
|
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
|
+
export const ComponentType = {
|
|
5
|
+
ACTION_ROW: 1,
|
|
6
|
+
TEXT_DISPLAY: 10,
|
|
7
|
+
MEDIA_GALLERY: 12,
|
|
8
|
+
SEPARATOR: 14,
|
|
9
|
+
CONTAINER: 17,
|
|
10
|
+
STRING_SELECT: 3,
|
|
11
|
+
BUTTON: 2,
|
|
12
|
+
/** item 8 — a Section: text blocks beside an accessory (e.g. an inline button). */
|
|
13
|
+
SECTION: 9,
|
|
14
|
+
/** item 3 — a small image usable as a Section accessory (Discord type 11). */
|
|
15
|
+
THUMBNAIL: 11,
|
|
16
|
+
/** item 6 — the select-menu family: user / role / mentionable / channel (Discord types 5-8). */
|
|
17
|
+
USER_SELECT: 5,
|
|
18
|
+
ROLE_SELECT: 6,
|
|
19
|
+
MENTIONABLE_SELECT: 7,
|
|
20
|
+
CHANNEL_SELECT: 8,
|
|
21
|
+
};
|
|
22
|
+
export function textDisplay(content) {
|
|
23
|
+
return {
|
|
24
|
+
type: ComponentType.TEXT_DISPLAY,
|
|
25
|
+
content,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function mediaGallery(url, description) {
|
|
29
|
+
const item = { media: { url } };
|
|
30
|
+
if (description !== undefined) {
|
|
31
|
+
item.description = description;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
type: ComponentType.MEDIA_GALLERY,
|
|
35
|
+
items: [item],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function separator(dividerOrSpacing = true, spacing = 'large') {
|
|
39
|
+
const divider = typeof dividerOrSpacing === 'boolean' ? dividerOrSpacing : true;
|
|
40
|
+
const size = typeof dividerOrSpacing === 'string' ? dividerOrSpacing : spacing;
|
|
41
|
+
return {
|
|
42
|
+
type: ComponentType.SEPARATOR,
|
|
43
|
+
divider,
|
|
44
|
+
spacing: size === 'small' ? 1 : 2,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export function container(components, accentColor) {
|
|
48
|
+
const result = {
|
|
49
|
+
type: ComponentType.CONTAINER,
|
|
50
|
+
components,
|
|
51
|
+
};
|
|
52
|
+
if (accentColor !== undefined) {
|
|
53
|
+
result.accent_color = accentColor;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
export function stringSelect(customId, options, placeholder, disabled) {
|
|
58
|
+
const result = {
|
|
59
|
+
type: ComponentType.STRING_SELECT,
|
|
60
|
+
custom_id: customId,
|
|
61
|
+
min_values: 1,
|
|
62
|
+
max_values: 1,
|
|
63
|
+
options: options.map((opt) => {
|
|
64
|
+
const result = {
|
|
65
|
+
label: opt.label,
|
|
66
|
+
value: opt.value,
|
|
67
|
+
};
|
|
68
|
+
if (opt.description !== undefined)
|
|
69
|
+
result.description = opt.description;
|
|
70
|
+
if (opt.emoji !== undefined)
|
|
71
|
+
result.emoji = typeof opt.emoji === 'string' ? { name: opt.emoji } : opt.emoji;
|
|
72
|
+
if (opt.default !== undefined)
|
|
73
|
+
result.default = opt.default;
|
|
74
|
+
return result;
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
if (placeholder !== undefined) {
|
|
78
|
+
result.placeholder = placeholder;
|
|
79
|
+
}
|
|
80
|
+
if (disabled !== undefined) {
|
|
81
|
+
result.disabled = disabled;
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
/** item 6 — the shared shape of the user/role/mentionable/channel select family. */
|
|
86
|
+
function entitySelect(type, customId, options = {}) {
|
|
87
|
+
const result = {
|
|
88
|
+
type,
|
|
89
|
+
custom_id: customId,
|
|
90
|
+
min_values: options.minValues ?? 1,
|
|
91
|
+
max_values: options.maxValues ?? 1,
|
|
92
|
+
};
|
|
93
|
+
if (options.placeholder !== undefined)
|
|
94
|
+
result.placeholder = options.placeholder;
|
|
95
|
+
if (options.disabled !== undefined)
|
|
96
|
+
result.disabled = options.disabled;
|
|
97
|
+
if (options.defaultValues !== undefined)
|
|
98
|
+
result.default_values = options.defaultValues;
|
|
99
|
+
if (options.channelTypes !== undefined)
|
|
100
|
+
result.channel_types = options.channelTypes;
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
/** item 6 — a User Select menu (Discord type 5). */
|
|
104
|
+
export function userSelect(customId, options) {
|
|
105
|
+
return entitySelect(ComponentType.USER_SELECT, customId, options);
|
|
106
|
+
}
|
|
107
|
+
/** item 6 — a Role Select menu (Discord type 6). */
|
|
108
|
+
export function roleSelect(customId, options) {
|
|
109
|
+
return entitySelect(ComponentType.ROLE_SELECT, customId, options);
|
|
110
|
+
}
|
|
111
|
+
/** item 6 — a Mentionable Select menu (Discord type 7: users and roles). */
|
|
112
|
+
export function mentionableSelect(customId, options) {
|
|
113
|
+
return entitySelect(ComponentType.MENTIONABLE_SELECT, customId, options);
|
|
114
|
+
}
|
|
115
|
+
/** item 6 — a Channel Select menu (Discord type 8), optionally restricted to channel types. */
|
|
116
|
+
export function channelSelect(customId, options) {
|
|
117
|
+
return entitySelect(ComponentType.CHANNEL_SELECT, customId, options);
|
|
118
|
+
}
|
|
119
|
+
export function button(customId, label, style = 2, disabled = false, emoji) {
|
|
120
|
+
const result = {
|
|
121
|
+
type: ComponentType.BUTTON,
|
|
122
|
+
style,
|
|
123
|
+
custom_id: customId,
|
|
124
|
+
disabled,
|
|
125
|
+
};
|
|
126
|
+
// item 2 — an icon-only control (the Home button) omits the label and carries a custom emoji.
|
|
127
|
+
if (label !== '') {
|
|
128
|
+
result.label = label;
|
|
129
|
+
}
|
|
130
|
+
if (emoji !== undefined) {
|
|
131
|
+
result.emoji = typeof emoji === 'string' ? { name: emoji } : emoji;
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* UR-20261012-029 — a LINK button (style 5). Discord requires a `url` in place of a `custom_id` on
|
|
137
|
+
* a link button, so it is built here rather than through `button()`.
|
|
138
|
+
*/
|
|
139
|
+
export function linkButton(url, label, emoji) {
|
|
140
|
+
const result = {
|
|
141
|
+
type: ComponentType.BUTTON,
|
|
142
|
+
style: 5,
|
|
143
|
+
custom_id: '',
|
|
144
|
+
url,
|
|
145
|
+
disabled: false,
|
|
146
|
+
};
|
|
147
|
+
if (label !== '')
|
|
148
|
+
result.label = label;
|
|
149
|
+
if (emoji !== undefined)
|
|
150
|
+
result.emoji = typeof emoji === 'string' ? { name: emoji } : emoji;
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
export function actionRow(components) {
|
|
154
|
+
return {
|
|
155
|
+
type: ComponentType.ACTION_ROW,
|
|
156
|
+
components,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* item 3 — a small image usable as a Section accessory (Discord type 11). Mirrors the embed
|
|
161
|
+
* thumbnail slot; Discord renders it right-aligned beside the section's text.
|
|
162
|
+
*/
|
|
163
|
+
export function thumbnail(url, description, spoiler) {
|
|
164
|
+
const result = {
|
|
165
|
+
type: ComponentType.THUMBNAIL,
|
|
166
|
+
media: { url },
|
|
167
|
+
};
|
|
168
|
+
if (description !== undefined)
|
|
169
|
+
result.description = description;
|
|
170
|
+
if (spoiler !== undefined)
|
|
171
|
+
result.spoiler = spoiler;
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
/** item 8 — a Section: a text block with an accessory (button or thumbnail) rendered in-line. */
|
|
175
|
+
export function section(content, accessory) {
|
|
176
|
+
const components = typeof content === 'string' ? [textDisplay(content)] : content;
|
|
177
|
+
return {
|
|
178
|
+
type: ComponentType.SECTION,
|
|
179
|
+
components,
|
|
180
|
+
accessory,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function textInputRow(input) {
|
|
184
|
+
return {
|
|
185
|
+
type: ComponentType.ACTION_ROW,
|
|
186
|
+
components: [
|
|
187
|
+
{
|
|
188
|
+
type: 4,
|
|
189
|
+
custom_id: input.customId,
|
|
190
|
+
label: input.label,
|
|
191
|
+
style: input.style === 'paragraph' ? 2 : 1,
|
|
192
|
+
...(input.placeholder !== undefined ? { placeholder: input.placeholder } : {}),
|
|
193
|
+
...(input.required !== undefined ? { required: input.required } : {}),
|
|
194
|
+
...(input.maxLength !== undefined ? { max_length: input.maxLength } : {}),
|
|
195
|
+
...(input.minLength !== undefined ? { min_length: input.minLength } : {}),
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
export function textInputModal(customId, title, input) {
|
|
201
|
+
return {
|
|
202
|
+
custom_id: customId,
|
|
203
|
+
title,
|
|
204
|
+
components: [textInputRow(input)],
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/** item 6 — a modal carrying several inputs (short inputs and/or paragraphs), one per action row. */
|
|
208
|
+
export function multiInputModal(customId, title, inputs) {
|
|
209
|
+
return {
|
|
210
|
+
custom_id: customId,
|
|
211
|
+
title,
|
|
212
|
+
components: inputs.map(textInputRow),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* item 5 — build a Components-v2 message. `ephemeral` adds the EPHEMERAL flag (1 << 6) alongside
|
|
217
|
+
* IS_COMPONENTS_V2, producing a message only the invoking user can see.
|
|
218
|
+
*/
|
|
219
|
+
export function buildComponentsV2(components, options = {}) {
|
|
220
|
+
return {
|
|
221
|
+
components,
|
|
222
|
+
flags: options.ephemeral === true ? IS_COMPONENTS_V2 | EPHEMERAL : IS_COMPONENTS_V2,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
export const DEFAULT_ACCENT_COLOR = 0xffca6d;
|
|
226
|
+
/**
|
|
227
|
+
* item 2 — the accent a Twill-registered persona falls back to when none is configured: a neutral
|
|
228
|
+
* gray. Distinct from the framework's amber default, so a persona with no declared identity is
|
|
229
|
+
* visibly its own surface rather than the framework's.
|
|
230
|
+
*/
|
|
231
|
+
export const DEFAULT_PERSONA_ACCENT = '#808080';
|
|
232
|
+
export function createBannerMediaGallery(bannerUrl) {
|
|
233
|
+
return mediaGallery(bannerUrl, 'Dumby banner');
|
|
234
|
+
}
|
|
235
|
+
export function getDefaultBannerUrl(moduleName, accentColor = DEFAULT_ACCENT_COLOR) {
|
|
236
|
+
const encoded = encodeURIComponent(moduleName);
|
|
237
|
+
return `https://api.dumby.dev/banner?module=${encoded}&color=${accentColor.toString(16).padStart(6, '0')}`;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The identity band: `**<owner> | <page>**` over an attribution line.
|
|
241
|
+
*
|
|
242
|
+
* Both halves are arguments, because neither is constant across profiles. The resident bot is
|
|
243
|
+
* "Dumby Suite", "Developed by Quixotic Mnemonics"; a persona carries her OWN name as the owner and
|
|
244
|
+
* "Powered by Dumby Suite" as the attribution. The line is passed whole rather than assembled from a
|
|
245
|
+
* name, because the two profiles do not even use the same verb.
|
|
246
|
+
*/
|
|
247
|
+
export function createTitleBlock(pageName, developer = 'Quixotic Mnemonics', options = {}) {
|
|
248
|
+
// The second parameter stays the DEVELOPER NAME: changing its meaning would silently drop the
|
|
249
|
+
// "Developed by" verb at every call site that still passes a name.
|
|
250
|
+
const attribution = options.attributionLine ?? `Developed by ${developer}`;
|
|
251
|
+
return textDisplay(`**${options.owner ?? 'Dumby Suite'} | ${pageName}**\n-# ${attribution}`);
|
|
252
|
+
}
|
|
253
|
+
export function createMarketplaceTitleBlock(developer = 'Quixotic Mnemonics', options = {}) {
|
|
254
|
+
const attribution = options.attributionLine ?? `Developed by ${developer}`;
|
|
255
|
+
return textDisplay(`**${options.owner ?? 'Dumby Suite'} | Marketplace**\n-# ${attribution}`);
|
|
256
|
+
}
|
|
257
|
+
export function createSectionHeader(emoji, title) {
|
|
258
|
+
return textDisplay(`━━ ${emoji} ${title} ━━`);
|
|
259
|
+
}
|
|
260
|
+
export function createKeyValueDisplay(pairs) {
|
|
261
|
+
const lines = Object.entries(pairs).map(([key, value]) => `${key}: ${value}`);
|
|
262
|
+
return textDisplay(lines.join('\n'));
|
|
263
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { ComponentsV2Message, ModalPayload } from './components-v2.js';
|
|
2
|
+
/**
|
|
3
|
+
* UR-20261116-132 \u2014 the COMPONENT surface: a module owns the control AND the answer to it.
|
|
4
|
+
*
|
|
5
|
+
* The gap this closes. `UR-20261031-120` gave modules the Components V2 vocabulary so that a
|
|
6
|
+
* module-specific card \u2014 the persona OAuth redirect guide \u2014 could leave the core. It moved the
|
|
7
|
+
* vocabulary and stopped there, because the card was not the whole problem: the CONTROL that opens it
|
|
8
|
+
* (`dumby:persona-setup:<invoker>:<applicationId>`) is built by the persona module's blocks, while the
|
|
9
|
+
* handler for that prefix was registered by core in `interactions/core-frame.handlers.ts`. So core still
|
|
10
|
+
* carried a persona-shaped branch \u2014 the prefix string and the callback that built the card \u2014 which is
|
|
11
|
+
* what `SPEC-01-FOUNDATIONS-0001` \u00a71.2's consequence check forbids: "an admin command implemented as
|
|
12
|
+
* inline framework code instead of a module".
|
|
13
|
+
*
|
|
14
|
+
* The contract now has a fifth entry point. A module declares the prefixes it owns in its manifest and
|
|
15
|
+
* exports the handlers; the loader registers them with the interaction registry, exactly as it already
|
|
16
|
+
* registers `pages`. Core stops knowing any module's customId.
|
|
17
|
+
*
|
|
18
|
+
* WHAT THE HOST DOES, AND WHY THAT IS NOT A LEAK. The module returns a MESSAGE; the host performs the
|
|
19
|
+
* acknowledgement and the `editReply`. Acknowledgement is a property of the interaction, not of the
|
|
20
|
+
* module's intent \u2014 Discord requires it within three seconds and the mode (update, ephemeral, none)
|
|
21
|
+
* decides whether the page is replaced, a private card is opened, or nothing is sent. A module that had
|
|
22
|
+
* to acknowledge would need the raw interaction object, which is a core type; a module that returns a
|
|
23
|
+
* message and declares its `ack` does not.
|
|
24
|
+
*/
|
|
25
|
+
export interface ComponentInvocation {
|
|
26
|
+
/** The full customId, as Discord sent it. */
|
|
27
|
+
readonly customId: string;
|
|
28
|
+
/** The segments AFTER the declared prefix \u2014 `dumby:persona-setup:u1:999` gives `['u1', '999']`. */
|
|
29
|
+
readonly params: readonly string[];
|
|
30
|
+
/** The invoker, when the customId carries one. */
|
|
31
|
+
readonly invokerId?: string;
|
|
32
|
+
/** The profile whose control this was, when the interaction reports one. */
|
|
33
|
+
readonly applicationId?: string;
|
|
34
|
+
/** The guild the interaction happened in. */
|
|
35
|
+
readonly guildId?: string;
|
|
36
|
+
/**
|
|
37
|
+
* UR-20261120-153 — the chosen values, when the control was a SELECT MENU.
|
|
38
|
+
*
|
|
39
|
+
* `params` come from the customId, which a select does not change: its choice arrives in `values`. Without
|
|
40
|
+
* this a module could render a menu and never learn what was picked, which is why the permit console could
|
|
41
|
+
* not have been built on selects alone.
|
|
42
|
+
*/
|
|
43
|
+
readonly values?: readonly string[];
|
|
44
|
+
/**
|
|
45
|
+
* UR-20261123-190 (P3b) — the fields a MODAL SUBMISSION carried, keyed by the input's `custom_id`.
|
|
46
|
+
*
|
|
47
|
+
* A modal answers through `fields.getTextInputValue(name)`, which is not `values`: `values` is a select
|
|
48
|
+
* menu's choice and arrives with the component interaction, while these arrive only on submit. Without them
|
|
49
|
+
* a module could open a text input and never learn what was typed — which is why the framework's one modal
|
|
50
|
+
* (`/browse`'s Discover) had to be special-cased in core, by name, field and module.
|
|
51
|
+
*/
|
|
52
|
+
readonly fields?: Readonly<Record<string, string>>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* How the host should acknowledge before the module's answer is sent.
|
|
56
|
+
*
|
|
57
|
+
* - `update` (default) \u2014 the component's own message is edited in place; the page stays where it is.
|
|
58
|
+
* - `ephemeral` \u2014 a PRIVATE message. Used for anything that shows an operator a credential, a URL or a
|
|
59
|
+
* refusal: the interaction's response is private, so the answer is too.
|
|
60
|
+
* - `none` \u2014 nothing is acknowledged here; the module's answer opens a modal or is sent by other means.
|
|
61
|
+
*/
|
|
62
|
+
export type ComponentAck = 'update' | 'ephemeral' | 'none';
|
|
63
|
+
/** The rank vocabulary a control uses — the same names a command's `permissions.rbac` accepts. */
|
|
64
|
+
export type ComponentRbacRequirement = 'RESTRICTED' | 'MEMBER' | 'HELPER' | 'MOD' | 'ADMIN' | 'OWNER';
|
|
65
|
+
export interface ComponentHandlerDefinition {
|
|
66
|
+
/**
|
|
67
|
+
* The customId prefix this handler owns, e.g. `dumby:persona-setup:`.
|
|
68
|
+
*
|
|
69
|
+
* It MUST also be declared in the manifest's `components`, and the loader refuses a handler whose
|
|
70
|
+
* prefix is not declared \u2014 the manifest is the complete table of contents, and a control a module
|
|
71
|
+
* answers but does not declare is exactly the kind of hidden surface the contract exists to prevent.
|
|
72
|
+
*/
|
|
73
|
+
readonly customIdPrefix: string;
|
|
74
|
+
/** Defaults to `update`. */
|
|
75
|
+
readonly ack?: ComponentAck;
|
|
76
|
+
/**
|
|
77
|
+
* UR-20261119-147 — the rank a member must hold to USE this control.
|
|
78
|
+
*
|
|
79
|
+
* A command's requirement gates the command; this gates one action inside it. `/browse` may be open to
|
|
80
|
+
* everyone while its install control is not — which is the distinction the backend did not have: every
|
|
81
|
+
* control was open because `ComponentHandlerDefinition` carried no requirement at all.
|
|
82
|
+
*
|
|
83
|
+
* The same rank names a command uses, so an author has one vocabulary:
|
|
84
|
+
* `RESTRICTED | MEMBER | HELPER | MOD | ADMIN | OWNER`. Absent means the control inherits the command's
|
|
85
|
+
* posture, which is today's behaviour and therefore no regression.
|
|
86
|
+
*/
|
|
87
|
+
readonly permissions?: {
|
|
88
|
+
readonly rbac?: ComponentRbacRequirement;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* The reason shown when a member who fails `permissions` sees this control.
|
|
92
|
+
*
|
|
93
|
+
* Rendered by the card itself, so the member is told what the control needs instead of discovering it by
|
|
94
|
+
* clicking. Optional: absent, the card decides, and the control is refused at dispatch with the standard
|
|
95
|
+
* one-line denial.
|
|
96
|
+
*/
|
|
97
|
+
readonly deniedReason?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Build the answer.
|
|
100
|
+
*
|
|
101
|
+
* Returning `undefined` means "acknowledged, nothing to say" \u2014 a legitimate outcome for an `update`
|
|
102
|
+
* that changes nothing. The host sends nothing in that case.
|
|
103
|
+
*/
|
|
104
|
+
readonly build: (invocation: ComponentInvocation) => Promise<ModalPayload | BlockPayload | NoticePayload | undefined> | ComponentsV2Message | ModalPayload | BlockPayload | undefined;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* UR-20261124-203 — A HANDLER MAY ANSWER WITH BLOCKS INSTEAD OF A MESSAGE.
|
|
108
|
+
*
|
|
109
|
+
* A message returned from here goes straight to `editReply`, so the framework's chrome — banner, accent, title
|
|
110
|
+
* row, footer — is never applied, and a re-render comes out as a bare notice while the first render, which went
|
|
111
|
+
* through the page path, is framed. That is the inconsistency reported on /permit on 2026-11-24.
|
|
112
|
+
*
|
|
113
|
+
* A `BlockPayload` is routed through `renderer.render()` by the adapter, exactly as a page's blocks are, so the
|
|
114
|
+
* chrome is applied on every render and the first and the thousandth look the same. The module declares blocks;
|
|
115
|
+
* the framework frames them.
|
|
116
|
+
*
|
|
117
|
+
* Structurally typed rather than importing the renderer's `RenderBlock`, because a module may not reach into
|
|
118
|
+
* `apps/main` — the adapter validates the shape before it renders.
|
|
119
|
+
*/
|
|
120
|
+
/**
|
|
121
|
+
* UR-20261126-241 — A NOTICE IS ITS OWN SIGNAL, NOT A BLOCK.
|
|
122
|
+
*
|
|
123
|
+
* The owner's rule: enforcement follows the FINAL STATE of the signal. A private ephemeral answer and a public
|
|
124
|
+
* page are two grammars with their own templates — standard (banner, band, accent, footer) and notice (compact,
|
|
125
|
+
* none of them). A module states WHICH; the renderer decides HOW.
|
|
126
|
+
*
|
|
127
|
+
* Returning blocks for a notice was wrong for exactly that reason: it went through `render()` and came back
|
|
128
|
+
* wearing the standard grammar on an ephemeral message.
|
|
129
|
+
*/
|
|
130
|
+
export interface NoticePayload {
|
|
131
|
+
/** The one line the member is told. The renderer supplies the rest of the notice grammar. */
|
|
132
|
+
readonly notice: string;
|
|
133
|
+
}
|
|
134
|
+
export interface BlockPayload {
|
|
135
|
+
readonly blocks: readonly Readonly<Record<string, unknown>>[];
|
|
136
|
+
}
|
|
137
|
+
/** A module's declared component surface, as exported from its entry point. */
|
|
138
|
+
export type ComponentHandlers = readonly ComponentHandlerDefinition[];
|
|
139
|
+
/**
|
|
140
|
+
* Read the segments after a prefix. Exported so a module can test its own `parse` without the host.
|
|
141
|
+
*/
|
|
142
|
+
export declare function componentParams(customId: string, prefix: string): readonly string[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the segments after a prefix. Exported so a module can test its own `parse` without the host.
|
|
3
|
+
*/
|
|
4
|
+
export function componentParams(customId, prefix) {
|
|
5
|
+
if (!customId.startsWith(prefix))
|
|
6
|
+
return [];
|
|
7
|
+
return customId
|
|
8
|
+
.slice(prefix.length)
|
|
9
|
+
.split(':')
|
|
10
|
+
.filter((part) => part !== '');
|
|
11
|
+
}
|