gralonium 0.4.1 → 0.5.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/lib/classes/Client.d.ts +7 -1
- package/lib/classes/Client.js +22 -0
- package/lib/classes/Context.js +68 -19
- package/lib/classes/Loader.d.ts +4 -2
- package/lib/classes/Loader.js +40 -0
- package/lib/classes/Utils.js +37 -7
- package/lib/classes/builders/ComponentsV2Builder.d.ts +48 -3
- package/lib/classes/builders/ComponentsV2Builder.js +391 -71
- package/lib/classes/builders/InteractionBuilder.d.ts +1 -0
- package/lib/classes/builders/InteractionBuilder.js +1 -0
- package/lib/classes/builders/components/helpers.d.ts +3 -0
- package/lib/classes/builders/components/helpers.js +56 -3
- package/lib/classes/builders/components/linter.d.ts +61 -0
- package/lib/classes/builders/components/linter.js +252 -0
- package/lib/classes/builders/components/overflow.d.ts +151 -0
- package/lib/classes/builders/components/overflow.js +534 -0
- package/lib/classes/views/V2Adaptive.d.ts +103 -0
- package/lib/classes/views/V2Adaptive.js +502 -0
- package/lib/classes/views/V2PersistentRouter.d.ts +124 -0
- package/lib/classes/views/V2PersistentRouter.js +511 -0
- package/lib/classes/views/V2View.d.ts +1 -0
- package/lib/classes/views/V2View.js +53 -15
- package/lib/experiments.d.ts +2 -0
- package/lib/experiments.js +2 -0
- package/lib/main.d.ts +4 -0
- package/lib/main.js +4 -0
- package/package.json +1 -1
|
@@ -14,6 +14,8 @@ exports.disableMessageComponents =
|
|
|
14
14
|
exports.validateSelectMenuOptions =
|
|
15
15
|
exports.validateButtonCount =
|
|
16
16
|
exports.validateTextContent =
|
|
17
|
+
exports.MENU_ACTION_ITEM_TYPE =
|
|
18
|
+
exports.OVERFLOW_MENU_TYPE =
|
|
17
19
|
exports.MAX_V2_TOP_LEVEL_COMPONENTS =
|
|
18
20
|
exports.MAX_V2_COMPONENTS =
|
|
19
21
|
exports.SAFE_V2_TEXT_LENGTH =
|
|
@@ -35,6 +37,12 @@ exports.MAX_V2_COMPONENTS = MAX_V2_COMPONENTS;
|
|
|
35
37
|
const MAX_V2_TOP_LEVEL_COMPONENTS = 10;
|
|
36
38
|
exports.MAX_V2_TOP_LEVEL_COMPONENTS = MAX_V2_TOP_LEVEL_COMPONENTS;
|
|
37
39
|
|
|
40
|
+
const OVERFLOW_MENU_TYPE = 25;
|
|
41
|
+
exports.OVERFLOW_MENU_TYPE = OVERFLOW_MENU_TYPE;
|
|
42
|
+
|
|
43
|
+
const MENU_ACTION_ITEM_TYPE = 26;
|
|
44
|
+
exports.MENU_ACTION_ITEM_TYPE = MENU_ACTION_ITEM_TYPE;
|
|
45
|
+
|
|
38
46
|
const COLOR_PRESETS = (() => {
|
|
39
47
|
const map = new Map();
|
|
40
48
|
if (discord_js_1.Colors && typeof discord_js_1.Colors === "object") {
|
|
@@ -61,6 +69,8 @@ const V2_COMPONENT_TYPES = new Set(
|
|
|
61
69
|
discord_js_1.ComponentType?.File ?? 13,
|
|
62
70
|
discord_js_1.ComponentType?.Separator ?? 14,
|
|
63
71
|
discord_js_1.ComponentType?.Container ?? 17,
|
|
72
|
+
discord_js_1.ComponentType?.OverflowMenu ?? OVERFLOW_MENU_TYPE,
|
|
73
|
+
discord_js_1.ComponentType?.MenuActionItem ?? MENU_ACTION_ITEM_TYPE,
|
|
64
74
|
].filter((v) => typeof v === "number")
|
|
65
75
|
);
|
|
66
76
|
|
|
@@ -326,9 +336,25 @@ function countComponentNode(node) {
|
|
|
326
336
|
total += countComponentNode(accessory);
|
|
327
337
|
}
|
|
328
338
|
|
|
329
|
-
const
|
|
330
|
-
if (Array.isArray(
|
|
331
|
-
|
|
339
|
+
const groups = node.groups ?? data.groups;
|
|
340
|
+
if (Array.isArray(groups)) {
|
|
341
|
+
for (const group of groups) {
|
|
342
|
+
if (!group || typeof group !== "object") continue;
|
|
343
|
+
total += 1;
|
|
344
|
+
const groupItems = group.items;
|
|
345
|
+
if (Array.isArray(groupItems)) {
|
|
346
|
+
for (const item of groupItems) {
|
|
347
|
+
total += item && typeof item === "object" ? countComponentNode(item) : 1;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
const items = node.items ?? data.items;
|
|
353
|
+
if (Array.isArray(items)) {
|
|
354
|
+
for (const item of items) {
|
|
355
|
+
total += item && typeof item === "object" ? countComponentNode(item) : 1;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
332
358
|
}
|
|
333
359
|
|
|
334
360
|
return total;
|
|
@@ -353,6 +379,7 @@ function disableNodeInPlace(node, options) {
|
|
|
353
379
|
const disableButtons = options?.disableButtons !== false;
|
|
354
380
|
const disableSelects = options?.disableSelects !== false;
|
|
355
381
|
const disableLinks = Boolean(options?.disableLinks);
|
|
382
|
+
const disableOverflow = options?.disableOverflow !== false;
|
|
356
383
|
|
|
357
384
|
if (node.type === (discord_js_1.ComponentType?.Button ?? 2)) {
|
|
358
385
|
if (disableButtons && (disableLinks || node.style !== discord_js_1.ButtonStyle.Link)) {
|
|
@@ -368,6 +395,32 @@ function disableNodeInPlace(node, options) {
|
|
|
368
395
|
return node;
|
|
369
396
|
}
|
|
370
397
|
|
|
398
|
+
if (node.type === (discord_js_1.ComponentType?.MenuActionItem ?? MENU_ACTION_ITEM_TYPE)) {
|
|
399
|
+
if (disableOverflow && (disableLinks || node.style !== 3)) {
|
|
400
|
+
node.disabled = true;
|
|
401
|
+
}
|
|
402
|
+
return node;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (node.type === (discord_js_1.ComponentType?.OverflowMenu ?? OVERFLOW_MENU_TYPE)) {
|
|
406
|
+
if (disableOverflow) {
|
|
407
|
+
node.disabled = true;
|
|
408
|
+
}
|
|
409
|
+
if (Array.isArray(node.groups)) {
|
|
410
|
+
node.groups = node.groups.map((group) => {
|
|
411
|
+
if (!group || typeof group !== "object") return group;
|
|
412
|
+
return {
|
|
413
|
+
...group,
|
|
414
|
+
items: Array.isArray(group.items) ? group.items.map((item) => disableNodeInPlace(item, options)) : [],
|
|
415
|
+
};
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
if (Array.isArray(node.items)) {
|
|
419
|
+
node.items = node.items.map((item) => disableNodeInPlace(item, options));
|
|
420
|
+
}
|
|
421
|
+
return node;
|
|
422
|
+
}
|
|
423
|
+
|
|
371
424
|
if (Array.isArray(node.components)) {
|
|
372
425
|
node.components = node.components.map((child) => disableNodeInPlace(child, options));
|
|
373
426
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type V2LintSeverity = "error" | "warning";
|
|
2
|
+
|
|
3
|
+
export type V2LintCode =
|
|
4
|
+
| "MAX_TOP_LEVEL_EXCEEDED"
|
|
5
|
+
| "MAX_COMPONENTS_EXCEEDED"
|
|
6
|
+
| "MAX_TEXT_LENGTH_EXCEEDED"
|
|
7
|
+
| "NEAR_TEXT_LENGTH_LIMIT"
|
|
8
|
+
| "EMPTY_CUSTOM_ID"
|
|
9
|
+
| "CUSTOM_ID_TOO_LONG"
|
|
10
|
+
| "DUPLICATE_CUSTOM_ID"
|
|
11
|
+
| "OVERFLOW_EMPTY"
|
|
12
|
+
| "OVERFLOW_GROUP_EMPTY"
|
|
13
|
+
| "OVERFLOW_TOO_MANY_ITEMS"
|
|
14
|
+
| "ANIMATED_EMOJI_ONLY_CONTROL"
|
|
15
|
+
| "ANIMATED_EMOJI_ONLY_TEXT";
|
|
16
|
+
|
|
17
|
+
export interface V2LintIssue {
|
|
18
|
+
severity: V2LintSeverity;
|
|
19
|
+
code: V2LintCode;
|
|
20
|
+
message: string;
|
|
21
|
+
path?: string;
|
|
22
|
+
customId?: string;
|
|
23
|
+
previousPath?: string;
|
|
24
|
+
length?: number;
|
|
25
|
+
totalItems?: number;
|
|
26
|
+
topLevelCount?: number;
|
|
27
|
+
maxTopLevel?: number;
|
|
28
|
+
componentCount?: number;
|
|
29
|
+
maxComponents?: number;
|
|
30
|
+
textLength?: number;
|
|
31
|
+
maxTextLength?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface V2LintOptions {
|
|
35
|
+
maxComponents?: number;
|
|
36
|
+
maxTopLevel?: number;
|
|
37
|
+
maxTextLength?: number;
|
|
38
|
+
warnNearTextLimit?: number;
|
|
39
|
+
strictGameMode?: boolean;
|
|
40
|
+
strict?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface V2LintStats {
|
|
44
|
+
componentCount: number;
|
|
45
|
+
topLevelCount: number;
|
|
46
|
+
textLength: number;
|
|
47
|
+
customIdCount: number;
|
|
48
|
+
animatedEmojiCount: number;
|
|
49
|
+
hasOverflowMenu: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface V2LintResult {
|
|
53
|
+
ok: boolean;
|
|
54
|
+
valid: boolean;
|
|
55
|
+
issues: V2LintIssue[];
|
|
56
|
+
errors: V2LintIssue[];
|
|
57
|
+
warnings: V2LintIssue[];
|
|
58
|
+
stats: V2LintStats;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export declare function lintComponents(target: unknown, options?: V2LintOptions): V2LintResult;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lintComponents = void 0;
|
|
4
|
+
|
|
5
|
+
const discord_js_1 = require("discord.js");
|
|
6
|
+
const helpers_js_1 = require("./helpers.js");
|
|
7
|
+
|
|
8
|
+
const ANIMATED_EMOJI_REGEX = /<a:[a-zA-Z0-9_~]+:\d{15,22}>/g;
|
|
9
|
+
const STRIP_MARKDOWN_AND_WHITESPACE_REGEX = /[#>*_`~\-\s|]/g;
|
|
10
|
+
|
|
11
|
+
function normalizeInputComponents(target) {
|
|
12
|
+
if (!target) return [];
|
|
13
|
+
if (typeof target.toJSON === "function") {
|
|
14
|
+
try {
|
|
15
|
+
const json = target.toJSON({ validate: false });
|
|
16
|
+
return Array.isArray(json) ? json : [json];
|
|
17
|
+
} catch {
|
|
18
|
+
const json = target.toJSON();
|
|
19
|
+
return Array.isArray(json) ? json : [json];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (Array.isArray(target.components)) {
|
|
23
|
+
return target.components.map((c) => (typeof c?.toJSON === "function" ? c.toJSON() : c));
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(target)) {
|
|
26
|
+
return target.map((c) => (typeof c?.toJSON === "function" ? c.toJSON() : c));
|
|
27
|
+
}
|
|
28
|
+
return [target];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Performs static diagnostics on Components V2 trees:
|
|
33
|
+
* - Component count <= 40 and top-level count <= 10
|
|
34
|
+
* - TextDisplay total characters <= 4,000 (warns near 3,950)
|
|
35
|
+
* - Duplicate, empty, or >100-char custom_id detection
|
|
36
|
+
* - OverflowMenu group/item hygiene
|
|
37
|
+
* - Game Mode 10 FPS check (animated-emoji-only controls/text without fallback text)
|
|
38
|
+
*/
|
|
39
|
+
function lintComponents(target, options = {}) {
|
|
40
|
+
const maxComponents = options.maxComponents ?? helpers_js_1.MAX_V2_COMPONENTS;
|
|
41
|
+
const maxTopLevel = options.maxTopLevel ?? helpers_js_1.MAX_V2_TOP_LEVEL_COMPONENTS;
|
|
42
|
+
const maxTextLength = options.maxTextLength ?? helpers_js_1.MAX_V2_TEXT_LENGTH;
|
|
43
|
+
const warnNearTextLimit = options.warnNearTextLimit ?? helpers_js_1.SAFE_V2_TEXT_LENGTH;
|
|
44
|
+
const strictGameMode = Boolean(options.strictGameMode);
|
|
45
|
+
const strict = Boolean(options.strict);
|
|
46
|
+
|
|
47
|
+
const tree = normalizeInputComponents(target);
|
|
48
|
+
const issues = [];
|
|
49
|
+
const seenCustomIds = new Map();
|
|
50
|
+
|
|
51
|
+
let animatedEmojiCount = 0;
|
|
52
|
+
let hasOverflowMenu = false;
|
|
53
|
+
|
|
54
|
+
const pushIssue = (severity, code, message, extra = {}) => {
|
|
55
|
+
issues.push({ severity, code, message, ...extra });
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const checkCustomId = (customId, path) => {
|
|
59
|
+
if (typeof customId !== "string" || customId.trim().length === 0) {
|
|
60
|
+
pushIssue("error", "EMPTY_CUSTOM_ID", `Interactive component at ${path} has an empty custom_id.`, { path });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (customId.length > 100) {
|
|
64
|
+
pushIssue(
|
|
65
|
+
"error",
|
|
66
|
+
"CUSTOM_ID_TOO_LONG",
|
|
67
|
+
`custom_id "${customId.slice(0, 24)}..." exceeds Discord's 100-char limit (${customId.length}).`,
|
|
68
|
+
{ path, customId, length: customId.length }
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
const prevPath = seenCustomIds.get(customId);
|
|
72
|
+
if (prevPath) {
|
|
73
|
+
pushIssue(
|
|
74
|
+
"error",
|
|
75
|
+
"DUPLICATE_CUSTOM_ID",
|
|
76
|
+
`Duplicate custom_id "${customId}" at ${path} (already used at ${prevPath}).`,
|
|
77
|
+
{ path, customId, previousPath: prevPath }
|
|
78
|
+
);
|
|
79
|
+
} else {
|
|
80
|
+
seenCustomIds.set(customId, path);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const checkGameModeControl = (label, emoji, path) => {
|
|
85
|
+
if (emoji && emoji.animated === true) {
|
|
86
|
+
animatedEmojiCount += 1;
|
|
87
|
+
if (!label || String(label).trim().length === 0) {
|
|
88
|
+
pushIssue(
|
|
89
|
+
strictGameMode ? "error" : "warning",
|
|
90
|
+
"ANIMATED_EMOJI_ONLY_CONTROL",
|
|
91
|
+
`Control at ${path} relies solely on an animated emoji without a text label (freezes at 10 FPS in Discord Game Mode).`,
|
|
92
|
+
{ path }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const walkNode = (node, path) => {
|
|
99
|
+
if (!node || typeof node !== "object") return;
|
|
100
|
+
const type = node.type;
|
|
101
|
+
|
|
102
|
+
if (type === (discord_js_1.ComponentType?.TextDisplay ?? 10) && typeof node.content === "string") {
|
|
103
|
+
const matches = node.content.match(ANIMATED_EMOJI_REGEX);
|
|
104
|
+
if (matches && matches.length > 0) {
|
|
105
|
+
animatedEmojiCount += matches.length;
|
|
106
|
+
const withoutAnimated = node.content.replace(ANIMATED_EMOJI_REGEX, "");
|
|
107
|
+
const remaining = withoutAnimated.replace(STRIP_MARKDOWN_AND_WHITESPACE_REGEX, "");
|
|
108
|
+
if (remaining.length === 0) {
|
|
109
|
+
pushIssue(
|
|
110
|
+
strictGameMode ? "error" : "warning",
|
|
111
|
+
"ANIMATED_EMOJI_ONLY_TEXT",
|
|
112
|
+
`TextDisplay at ${path} contains only animated emoji(s) without fallback text (freezes in Discord Game Mode).`,
|
|
113
|
+
{ path }
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (type === (discord_js_1.ComponentType?.Button ?? 2)) {
|
|
121
|
+
const isLink = node.style === discord_js_1.ButtonStyle.Link || node.style === 5;
|
|
122
|
+
const isPremium = node.style === discord_js_1.ButtonStyle.Premium || node.style === 6;
|
|
123
|
+
if (!isLink && !isPremium) {
|
|
124
|
+
checkCustomId(node.custom_id, path);
|
|
125
|
+
}
|
|
126
|
+
checkGameModeControl(node.label, node.emoji, path);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if ([3, 5, 6, 7, 8].includes(type)) {
|
|
131
|
+
checkCustomId(node.custom_id, path);
|
|
132
|
+
if (type === 3 && Array.isArray(node.options)) {
|
|
133
|
+
node.options.forEach((opt, idx) => {
|
|
134
|
+
checkGameModeControl(opt?.label, opt?.emoji, `${path}.options[${idx}]`);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (type === helpers_js_1.OVERFLOW_MENU_TYPE) {
|
|
141
|
+
hasOverflowMenu = true;
|
|
142
|
+
if (node.custom_id !== undefined) {
|
|
143
|
+
checkCustomId(node.custom_id, path);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const groups = Array.isArray(node.groups) ? node.groups : [];
|
|
147
|
+
let totalItems = 0;
|
|
148
|
+
|
|
149
|
+
groups.forEach((group, gIdx) => {
|
|
150
|
+
const items = Array.isArray(group?.items) ? group.items : [];
|
|
151
|
+
if (items.length === 0) {
|
|
152
|
+
pushIssue("error", "OVERFLOW_GROUP_EMPTY", `OverflowMenu group at ${path}.groups[${gIdx}] has no items.`, {
|
|
153
|
+
path: `${path}.groups[${gIdx}]`,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
items.forEach((item, iIdx) => {
|
|
157
|
+
totalItems += 1;
|
|
158
|
+
walkNode(item, `${path}.groups[${gIdx}].items[${iIdx}]`);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (groups.length === 0 || totalItems === 0) {
|
|
163
|
+
pushIssue("error", "OVERFLOW_EMPTY", `OverflowMenu at ${path} requires at least one action item.`, { path });
|
|
164
|
+
}
|
|
165
|
+
if (totalItems > 25) {
|
|
166
|
+
pushIssue(
|
|
167
|
+
"error",
|
|
168
|
+
"OVERFLOW_TOO_MANY_ITEMS",
|
|
169
|
+
`OverflowMenu at ${path} has ${totalItems} items (maximum 25).`,
|
|
170
|
+
{ path, totalItems }
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (type === helpers_js_1.MENU_ACTION_ITEM_TYPE) {
|
|
177
|
+
if (node.style !== 3) {
|
|
178
|
+
checkCustomId(node.custom_id, path);
|
|
179
|
+
}
|
|
180
|
+
checkGameModeControl(node.label, node.emoji, path);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (Array.isArray(node.components)) {
|
|
185
|
+
node.components.forEach((child, idx) => walkNode(child, `${path}.components[${idx}]`));
|
|
186
|
+
}
|
|
187
|
+
if (node.accessory && typeof node.accessory === "object") {
|
|
188
|
+
walkNode(node.accessory, `${path}.accessory`);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
tree.forEach((node, idx) => walkNode(node, `components[${idx}]`));
|
|
193
|
+
|
|
194
|
+
const topLevelCount = tree.length;
|
|
195
|
+
const componentCount = helpers_js_1.countComponents(tree);
|
|
196
|
+
const textLength = helpers_js_1.countTextLength(tree);
|
|
197
|
+
|
|
198
|
+
if (topLevelCount > maxTopLevel) {
|
|
199
|
+
pushIssue(
|
|
200
|
+
"error",
|
|
201
|
+
"MAX_TOP_LEVEL_EXCEEDED",
|
|
202
|
+
`Top-level component count ${topLevelCount} exceeds maximum ${maxTopLevel}.`,
|
|
203
|
+
{ topLevelCount, maxTopLevel }
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (componentCount > maxComponents) {
|
|
208
|
+
pushIssue(
|
|
209
|
+
"error",
|
|
210
|
+
"MAX_COMPONENTS_EXCEEDED",
|
|
211
|
+
`Total V2 component count ${componentCount} exceeds maximum ${maxComponents}.`,
|
|
212
|
+
{ componentCount, maxComponents }
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (textLength > maxTextLength) {
|
|
217
|
+
pushIssue(
|
|
218
|
+
"error",
|
|
219
|
+
"MAX_TEXT_LENGTH_EXCEEDED",
|
|
220
|
+
`Total TextDisplay character count ${textLength} exceeds maximum ${maxTextLength}.`,
|
|
221
|
+
{ textLength, maxTextLength }
|
|
222
|
+
);
|
|
223
|
+
} else if (warnNearTextLimit > 0 && textLength > warnNearTextLimit) {
|
|
224
|
+
pushIssue(
|
|
225
|
+
"warning",
|
|
226
|
+
"NEAR_TEXT_LENGTH_LIMIT",
|
|
227
|
+
`Total TextDisplay character count ${textLength} is close to the ${maxTextLength}-char limit.`,
|
|
228
|
+
{ textLength, maxTextLength }
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const errors = issues.filter((issue) => issue.severity === "error");
|
|
233
|
+
const warnings = issues.filter((issue) => issue.severity === "warning");
|
|
234
|
+
const valid = strict ? issues.length === 0 : errors.length === 0;
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
ok: valid,
|
|
238
|
+
valid,
|
|
239
|
+
issues,
|
|
240
|
+
errors,
|
|
241
|
+
warnings,
|
|
242
|
+
stats: {
|
|
243
|
+
componentCount,
|
|
244
|
+
topLevelCount,
|
|
245
|
+
textLength,
|
|
246
|
+
customIdCount: seenCustomIds.size,
|
|
247
|
+
animatedEmojiCount,
|
|
248
|
+
hasOverflowMenu,
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
exports.lintComponents = lintComponents;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { ActionRowBuilder, APIMessageComponentEmoji } from "discord.js";
|
|
2
|
+
import type { EmojiInput } from "./helpers.js";
|
|
3
|
+
import type { ComponentsV2Builder } from "../ComponentsV2Builder.js";
|
|
4
|
+
|
|
5
|
+
export declare const OVERFLOW_MENU_TYPE = 25;
|
|
6
|
+
export declare const MENU_ACTION_ITEM_TYPE = 26;
|
|
7
|
+
export declare const OVERFLOW_FALLBACK_SELECT_PREFIX = "__ovf_sel:";
|
|
8
|
+
|
|
9
|
+
export declare const MenuActionItemStyle: Readonly<{
|
|
10
|
+
Default: 1;
|
|
11
|
+
Danger: 2;
|
|
12
|
+
Link: 3;
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
export type MenuActionItemStyleName = "default" | "primary" | "secondary" | "danger" | "error" | "destructive" | "link" | "url";
|
|
16
|
+
export type MenuActionItemStyleInput = MenuActionItemStyleName | 1 | 2 | 3 | number;
|
|
17
|
+
|
|
18
|
+
export interface MenuActionItemOptions {
|
|
19
|
+
label?: string;
|
|
20
|
+
customId?: string;
|
|
21
|
+
id?: string;
|
|
22
|
+
style?: MenuActionItemStyleInput;
|
|
23
|
+
url?: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
emoji?: EmojiInput;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface APIMenuActionItemComponent {
|
|
30
|
+
type: 26;
|
|
31
|
+
style: 1 | 2 | 3;
|
|
32
|
+
label?: string;
|
|
33
|
+
custom_id?: string;
|
|
34
|
+
url?: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
emoji?: APIMessageComponentEmoji;
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface APIOverflowMenuGroup {
|
|
41
|
+
label?: string;
|
|
42
|
+
items: APIMenuActionItemComponent[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface APIOverflowMenuComponent {
|
|
46
|
+
type: 25;
|
|
47
|
+
custom_id?: string;
|
|
48
|
+
disabled?: boolean;
|
|
49
|
+
groups: APIOverflowMenuGroup[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface OverflowMenuGroupOptions {
|
|
53
|
+
label?: string;
|
|
54
|
+
title?: string;
|
|
55
|
+
items?: Array<MenuActionItemBuilder | MenuActionItemOptions | false | null | undefined>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface OverflowMenuFallbackOptions {
|
|
59
|
+
mode?: "select" | "buttons";
|
|
60
|
+
customId?: string;
|
|
61
|
+
placeholder?: string;
|
|
62
|
+
disabled?: boolean;
|
|
63
|
+
includeLinks?: boolean;
|
|
64
|
+
validate?: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface OverflowMenuOptions {
|
|
68
|
+
customId?: string;
|
|
69
|
+
id?: string;
|
|
70
|
+
disabled?: boolean;
|
|
71
|
+
placeholder?: string;
|
|
72
|
+
groups?: Array<OverflowMenuGroupBuilder | OverflowMenuGroupOptions | false | null | undefined>;
|
|
73
|
+
items?: Array<MenuActionItemBuilder | MenuActionItemOptions | false | null | undefined>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export declare function mapMenuActionItemStyle(style?: MenuActionItemStyleInput | null, hasUrl?: boolean): 1 | 2 | 3;
|
|
77
|
+
|
|
78
|
+
export declare class MenuActionItemBuilder {
|
|
79
|
+
label?: string;
|
|
80
|
+
customId?: string;
|
|
81
|
+
style?: MenuActionItemStyleInput;
|
|
82
|
+
url?: string;
|
|
83
|
+
description?: string;
|
|
84
|
+
emoji?: EmojiInput;
|
|
85
|
+
disabled?: boolean;
|
|
86
|
+
constructor(options?: MenuActionItemOptions);
|
|
87
|
+
setLabel(label: string): this;
|
|
88
|
+
setCustomId(customId: string): this;
|
|
89
|
+
setStyle(style: MenuActionItemStyleInput): this;
|
|
90
|
+
setURL(url: string): this;
|
|
91
|
+
setDescription(description?: string): this;
|
|
92
|
+
setEmoji(emoji?: EmojiInput): this;
|
|
93
|
+
setDisabled(disabled?: boolean): this;
|
|
94
|
+
toJSON(options?: { validate?: boolean }): APIMenuActionItemComponent;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export declare class OverflowMenuGroupBuilder {
|
|
98
|
+
label?: string;
|
|
99
|
+
items: MenuActionItemBuilder[];
|
|
100
|
+
constructor(labelOrOptions?: string | OverflowMenuGroupOptions);
|
|
101
|
+
setLabel(label?: string): this;
|
|
102
|
+
addItem(itemOrConfig: MenuActionItemBuilder | MenuActionItemOptions | false | null | undefined): this;
|
|
103
|
+
addItems(items: Array<MenuActionItemBuilder | MenuActionItemOptions | false | null | undefined>): this;
|
|
104
|
+
addLink(label: string, url: string, extra?: Partial<MenuActionItemOptions>): this;
|
|
105
|
+
addLink(config: MenuActionItemOptions & { url: string }): this;
|
|
106
|
+
toJSON(options?: { validate?: boolean }): APIOverflowMenuGroup;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export declare class OverflowMenuBuilder {
|
|
110
|
+
customId?: string;
|
|
111
|
+
disabled?: boolean;
|
|
112
|
+
placeholder: string;
|
|
113
|
+
groups: OverflowMenuGroupBuilder[];
|
|
114
|
+
constructor(options?: OverflowMenuOptions);
|
|
115
|
+
setCustomId(customId?: string): this;
|
|
116
|
+
setDisabled(disabled?: boolean): this;
|
|
117
|
+
setPlaceholder(placeholder: string): this;
|
|
118
|
+
addGroup(
|
|
119
|
+
labelOrOptions: string | OverflowMenuGroupBuilder | OverflowMenuGroupOptions,
|
|
120
|
+
callbackOrItems?:
|
|
121
|
+
| ((group: OverflowMenuGroupBuilder) => unknown)
|
|
122
|
+
| Array<MenuActionItemBuilder | MenuActionItemOptions | false | null | undefined>
|
|
123
|
+
): this;
|
|
124
|
+
addItem(itemOrConfig: MenuActionItemBuilder | MenuActionItemOptions | false | null | undefined): this;
|
|
125
|
+
addItems(items: Array<MenuActionItemBuilder | MenuActionItemOptions | false | null | undefined>): this;
|
|
126
|
+
addLink(label: string, url: string, extra?: Partial<MenuActionItemOptions>): this;
|
|
127
|
+
addLink(config: MenuActionItemOptions & { url: string }): this;
|
|
128
|
+
readonly itemCount: number;
|
|
129
|
+
toJSON(options?: { validate?: boolean }): APIOverflowMenuComponent;
|
|
130
|
+
toFallbackComponents(fallbackOptions?: OverflowMenuFallbackOptions): ActionRowBuilder<any>[];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export declare class OverflowMenuProxy {
|
|
134
|
+
constructor(parent: ComponentsV2Builder, menu: OverflowMenuBuilder);
|
|
135
|
+
setCustomId(customId?: string): this;
|
|
136
|
+
setDisabled(disabled?: boolean): this;
|
|
137
|
+
setPlaceholder(placeholder: string): this;
|
|
138
|
+
addGroup(
|
|
139
|
+
labelOrOptions: string | OverflowMenuGroupBuilder | OverflowMenuGroupOptions,
|
|
140
|
+
callbackOrItems?:
|
|
141
|
+
| ((group: OverflowMenuGroupBuilder) => unknown)
|
|
142
|
+
| Array<MenuActionItemBuilder | MenuActionItemOptions | false | null | undefined>
|
|
143
|
+
): this;
|
|
144
|
+
addItem(itemOrConfig: MenuActionItemBuilder | MenuActionItemOptions | false | null | undefined): this;
|
|
145
|
+
addItems(items: Array<MenuActionItemBuilder | MenuActionItemOptions | false | null | undefined>): this;
|
|
146
|
+
addLink(label: string, url: string, extra?: Partial<MenuActionItemOptions>): this;
|
|
147
|
+
addLink(config: MenuActionItemOptions & { url: string }): this;
|
|
148
|
+
toBuilder(): OverflowMenuBuilder;
|
|
149
|
+
toJSON(options?: { validate?: boolean }): APIOverflowMenuComponent;
|
|
150
|
+
end(): ComponentsV2Builder;
|
|
151
|
+
}
|