gralonium 0.4.0 → 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.
Files changed (40) hide show
  1. package/lib/classes/Client.d.ts +13 -3
  2. package/lib/classes/Client.js +23 -1
  3. package/lib/classes/Context.d.ts +2 -0
  4. package/lib/classes/Context.js +94 -21
  5. package/lib/classes/Cooldowns.d.ts +2 -0
  6. package/lib/classes/Cooldowns.js +28 -0
  7. package/lib/classes/Loader.d.ts +12 -3
  8. package/lib/classes/Loader.js +141 -19
  9. package/lib/classes/Plugins.js +3 -2
  10. package/lib/classes/Utils.d.ts +1 -1
  11. package/lib/classes/Utils.js +110 -20
  12. package/lib/classes/builders/CommandBuilder.d.ts +14 -0
  13. package/lib/classes/builders/CommandBuilder.js +50 -2
  14. package/lib/classes/builders/ComponentsV2Builder.d.ts +51 -3
  15. package/lib/classes/builders/ComponentsV2Builder.js +394 -72
  16. package/lib/classes/builders/GroupBuilder.d.ts +11 -0
  17. package/lib/classes/builders/GroupBuilder.js +21 -1
  18. package/lib/classes/builders/InteractionBuilder.d.ts +47 -0
  19. package/lib/classes/builders/InteractionBuilder.js +113 -2
  20. package/lib/classes/builders/ParamsBuilder.d.ts +118 -76
  21. package/lib/classes/builders/ParamsBuilder.js +167 -1
  22. package/lib/classes/builders/components/StyleMapper.d.ts +13 -1
  23. package/lib/classes/builders/components/StyleMapper.js +33 -8
  24. package/lib/classes/builders/components/helpers.d.ts +3 -0
  25. package/lib/classes/builders/components/helpers.js +56 -3
  26. package/lib/classes/builders/components/linter.d.ts +61 -0
  27. package/lib/classes/builders/components/linter.js +252 -0
  28. package/lib/classes/builders/components/overflow.d.ts +151 -0
  29. package/lib/classes/builders/components/overflow.js +534 -0
  30. package/lib/classes/views/V2Adaptive.d.ts +103 -0
  31. package/lib/classes/views/V2Adaptive.js +502 -0
  32. package/lib/classes/views/V2PersistentRouter.d.ts +124 -0
  33. package/lib/classes/views/V2PersistentRouter.js +511 -0
  34. package/lib/classes/views/V2View.d.ts +1 -0
  35. package/lib/classes/views/V2View.js +53 -15
  36. package/lib/experiments.d.ts +2 -0
  37. package/lib/experiments.js +2 -0
  38. package/lib/main.d.ts +4 -0
  39. package/lib/main.js +4 -0
  40. package/package.json +1 -1
@@ -3,8 +3,20 @@ import { ButtonStyle } from "discord.js";
3
3
  export type ButtonStyleName = "primary" | "secondary" | "success" | "danger" | "link" | "premium";
4
4
  export type ButtonStyleInput = ButtonStyleName | ButtonStyle;
5
5
 
6
+ /**
7
+ * Sets the default fallback button style used when no explicit style is provided.
8
+ */
9
+ export declare function setDefaultButtonStyle(style?: ButtonStyleInput | null): ButtonStyle;
10
+ export declare const setDefaultStyle: typeof setDefaultButtonStyle;
11
+
12
+ /**
13
+ * Returns the current default fallback button style.
14
+ */
15
+ export declare function getDefaultButtonStyle(): ButtonStyle;
16
+ export declare const getDefaultStyle: typeof getDefaultButtonStyle;
17
+
6
18
  /**
7
19
  * Maps a button style name (string) or ButtonStyle enum value to a ButtonStyle.
8
- * Defaults to Primary if the provided value is not recognized.
20
+ * Defaults to the configured default button style (Secondary by default) if not recognized.
9
21
  */
10
22
  export declare function mapButtonStyle(style?: ButtonStyleInput | null): ButtonStyle;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapButtonStyle = void 0;
3
+ exports.getDefaultStyle = exports.setDefaultStyle = exports.getDefaultButtonStyle = exports.setDefaultButtonStyle = exports.mapButtonStyle = void 0;
4
4
 
5
5
  const discord_js_1 = require("discord.js");
6
6
 
@@ -13,21 +13,46 @@ const STYLE_MAP = {
13
13
  ...(discord_js_1.ButtonStyle.Premium !== undefined ? { premium: discord_js_1.ButtonStyle.Premium } : {}),
14
14
  };
15
15
 
16
- /**
17
- * Maps a button style name (string) or ButtonStyle enum value to a ButtonStyle.
18
- * Defaults to Primary if the provided value is not recognized.
19
- */
20
- function mapButtonStyle(style) {
16
+ let defaultButtonStyle = discord_js_1.ButtonStyle.Secondary;
17
+
18
+ function resolveStyleValue(style, fallback = defaultButtonStyle) {
21
19
  if (style === undefined || style === null) {
22
- return discord_js_1.ButtonStyle.Primary;
20
+ return fallback;
23
21
  }
24
22
  if (typeof style === "number") {
25
23
  return style;
26
24
  }
27
25
  const mapped = STYLE_MAP[String(style).toLowerCase()];
28
26
  if (mapped === undefined) {
29
- return discord_js_1.ButtonStyle.Primary;
27
+ return fallback;
30
28
  }
31
29
  return mapped;
32
30
  }
31
+
32
+ /**
33
+ * Sets the default fallback button style used when no explicit style is provided.
34
+ */
35
+ function setDefaultButtonStyle(style) {
36
+ defaultButtonStyle = resolveStyleValue(style, discord_js_1.ButtonStyle.Secondary);
37
+ return defaultButtonStyle;
38
+ }
39
+ exports.setDefaultButtonStyle = setDefaultButtonStyle;
40
+ exports.setDefaultStyle = setDefaultButtonStyle;
41
+
42
+ /**
43
+ * Returns the current default fallback button style.
44
+ */
45
+ function getDefaultButtonStyle() {
46
+ return defaultButtonStyle;
47
+ }
48
+ exports.getDefaultButtonStyle = getDefaultButtonStyle;
49
+ exports.getDefaultStyle = getDefaultButtonStyle;
50
+
51
+ /**
52
+ * Maps a button style name (string) or ButtonStyle enum value to a ButtonStyle.
53
+ * Defaults to the configured default button style (Secondary by default) if not recognized.
54
+ */
55
+ function mapButtonStyle(style) {
56
+ return resolveStyleValue(style, defaultButtonStyle);
57
+ }
33
58
  exports.mapButtonStyle = mapButtonStyle;
@@ -4,6 +4,8 @@ export declare const MAX_V2_TEXT_LENGTH = 4000;
4
4
  export declare const SAFE_V2_TEXT_LENGTH = 3950;
5
5
  export declare const MAX_V2_COMPONENTS = 40;
6
6
  export declare const MAX_V2_TOP_LEVEL_COMPONENTS = 10;
7
+ export declare const OVERFLOW_MENU_TYPE = 25;
8
+ export declare const MENU_ACTION_ITEM_TYPE = 26;
7
9
 
8
10
  export type AccentColorInput = number | string | RGBTuple | null | undefined;
9
11
  export type EmojiInput = string | APIMessageComponentEmoji | null | undefined;
@@ -12,6 +14,7 @@ export interface DisableComponentsOptions {
12
14
  disableButtons?: boolean;
13
15
  disableSelects?: boolean;
14
16
  disableLinks?: boolean;
17
+ disableOverflow?: boolean;
15
18
  }
16
19
 
17
20
  /**
@@ -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 items = node.items ?? data.items;
330
- if (Array.isArray(items)) {
331
- total += items.length;
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
+ }