gralonium 0.2.0 → 0.4.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 +9 -11
- package/lib/classes/Client.js +10 -13
- package/lib/classes/Context.d.ts +43 -4
- package/lib/classes/Context.js +251 -12
- package/lib/classes/Cooldowns.d.ts +3 -3
- package/lib/classes/Cooldowns.js +3 -8
- package/lib/classes/HelpCommand.d.ts +55 -13
- package/lib/classes/HelpCommand.js +319 -1
- package/lib/classes/Loader.d.ts +17 -11
- package/lib/classes/Loader.js +43 -42
- package/lib/classes/Utils.d.ts +4 -5
- package/lib/classes/Utils.js +32 -21
- package/lib/classes/builders/CommandBuilder.d.ts +10 -0
- package/lib/classes/builders/CommandBuilder.js +16 -0
- package/lib/classes/builders/ComponentsV2Builder.d.ts +285 -113
- package/lib/classes/builders/ComponentsV2Builder.js +1069 -182
- package/lib/classes/builders/GroupBuilder.d.ts +9 -0
- package/lib/classes/builders/GroupBuilder.js +16 -0
- package/lib/classes/builders/InteractionBuilder.d.ts +40 -25
- package/lib/classes/builders/InteractionBuilder.js +102 -1
- package/lib/classes/builders/components/StyleMapper.d.ts +1 -1
- package/lib/classes/builders/components/StyleMapper.js +2 -1
- package/lib/classes/builders/components/helpers.d.ts +68 -4
- package/lib/classes/builders/components/helpers.js +366 -7
- package/lib/classes/builders/components/templates.d.ts +151 -9
- package/lib/classes/builders/components/templates.js +376 -17
- package/lib/classes/builders/components/text.d.ts +24 -0
- package/lib/classes/builders/components/text.js +91 -0
- package/lib/classes/experiments/Confirmator.d.ts +45 -50
- package/lib/classes/experiments/Confirmator.js +37 -21
- package/lib/classes/experiments/Paginator.d.ts +49 -56
- package/lib/classes/experiments/Paginator.js +48 -19
- package/lib/classes/views/V2Paginator.d.ts +91 -0
- package/lib/classes/views/V2Paginator.js +268 -0
- package/lib/classes/views/V2View.d.ts +113 -0
- package/lib/classes/views/V2View.js +438 -0
- package/lib/experiments.d.ts +2 -0
- package/lib/experiments.js +9 -1
- package/lib/main.d.ts +3 -3
- package/lib/main.js +5 -5
- package/package.json +6 -15
- package/lib/events/interactionCreate.d.ts +0 -4
- package/lib/events/interactionCreate.js +0 -17
- package/lib/events/messageCreate.d.ts +0 -4
- package/lib/events/messageCreate.js +0 -17
- package/lib/events/messageUpdate.d.ts +0 -4
- package/lib/events/messageUpdate.js +0 -17
|
@@ -1,21 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.disableMessageComponents =
|
|
4
|
+
exports.disableComponents =
|
|
5
|
+
exports.countComponents =
|
|
6
|
+
exports.countTextLength =
|
|
7
|
+
exports.isV2ComponentType =
|
|
8
|
+
exports.clipText =
|
|
9
|
+
exports.parseEmoji =
|
|
10
|
+
exports.isValidLinkUrl =
|
|
11
|
+
exports.isValidMediaUrl =
|
|
12
|
+
exports.resolveAccentColor =
|
|
13
|
+
exports.generateCustomId =
|
|
14
|
+
exports.validateSelectMenuOptions =
|
|
15
|
+
exports.validateButtonCount =
|
|
16
|
+
exports.validateTextContent =
|
|
17
|
+
exports.MAX_V2_TOP_LEVEL_COMPONENTS =
|
|
18
|
+
exports.MAX_V2_COMPONENTS =
|
|
19
|
+
exports.SAFE_V2_TEXT_LENGTH =
|
|
20
|
+
exports.MAX_V2_TEXT_LENGTH =
|
|
21
|
+
void 0;
|
|
22
|
+
|
|
23
|
+
const discord_js_1 = require("discord.js");
|
|
24
|
+
const crypto_1 = require("crypto");
|
|
25
|
+
|
|
26
|
+
const MAX_V2_TEXT_LENGTH = 4000;
|
|
27
|
+
exports.MAX_V2_TEXT_LENGTH = MAX_V2_TEXT_LENGTH;
|
|
28
|
+
|
|
29
|
+
const SAFE_V2_TEXT_LENGTH = 3950;
|
|
30
|
+
exports.SAFE_V2_TEXT_LENGTH = SAFE_V2_TEXT_LENGTH;
|
|
31
|
+
|
|
32
|
+
const MAX_V2_COMPONENTS = 40;
|
|
33
|
+
exports.MAX_V2_COMPONENTS = MAX_V2_COMPONENTS;
|
|
34
|
+
|
|
35
|
+
const MAX_V2_TOP_LEVEL_COMPONENTS = 10;
|
|
36
|
+
exports.MAX_V2_TOP_LEVEL_COMPONENTS = MAX_V2_TOP_LEVEL_COMPONENTS;
|
|
37
|
+
|
|
38
|
+
const COLOR_PRESETS = (() => {
|
|
39
|
+
const map = new Map();
|
|
40
|
+
if (discord_js_1.Colors && typeof discord_js_1.Colors === "object") {
|
|
41
|
+
for (const [key, val] of Object.entries(discord_js_1.Colors)) {
|
|
42
|
+
if (typeof val === "number") map.set(key.toLowerCase(), val);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
map.set("primary", 0x5865f2);
|
|
46
|
+
map.set("info", 0x5865f2);
|
|
47
|
+
map.set("success", 0x57f287);
|
|
48
|
+
map.set("warning", 0xfee75c);
|
|
49
|
+
map.set("danger", 0xed4245);
|
|
50
|
+
map.set("error", 0xed4245);
|
|
51
|
+
map.set("dark", 0x2b2d31);
|
|
52
|
+
return map;
|
|
53
|
+
})();
|
|
54
|
+
|
|
55
|
+
const V2_COMPONENT_TYPES = new Set(
|
|
56
|
+
[
|
|
57
|
+
discord_js_1.ComponentType?.Section ?? 9,
|
|
58
|
+
discord_js_1.ComponentType?.TextDisplay ?? 10,
|
|
59
|
+
discord_js_1.ComponentType?.Thumbnail ?? 11,
|
|
60
|
+
discord_js_1.ComponentType?.MediaGallery ?? 12,
|
|
61
|
+
discord_js_1.ComponentType?.File ?? 13,
|
|
62
|
+
discord_js_1.ComponentType?.Separator ?? 14,
|
|
63
|
+
discord_js_1.ComponentType?.Container ?? 17,
|
|
64
|
+
].filter((v) => typeof v === "number")
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const SELECT_COMPONENT_TYPES = new Set(
|
|
68
|
+
[
|
|
69
|
+
discord_js_1.ComponentType?.StringSelect ?? 3,
|
|
70
|
+
discord_js_1.ComponentType?.UserSelect ?? 5,
|
|
71
|
+
discord_js_1.ComponentType?.RoleSelect ?? 6,
|
|
72
|
+
discord_js_1.ComponentType?.MentionableSelect ?? 7,
|
|
73
|
+
discord_js_1.ComponentType?.ChannelSelect ?? 8,
|
|
74
|
+
].filter((v) => typeof v === "number")
|
|
75
|
+
);
|
|
4
76
|
|
|
5
77
|
/**
|
|
6
78
|
* Validates that text content is non-empty.
|
|
7
79
|
* Throws a descriptive error if validation fails.
|
|
8
80
|
*/
|
|
9
|
-
function validateTextContent(content) {
|
|
81
|
+
function validateTextContent(content, options) {
|
|
82
|
+
if (options?.ignoreEmpty && (content === undefined || content === null || (typeof content === "string" && content.trim().length === 0))) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
10
85
|
if (typeof content !== "string" || content.trim().length === 0) {
|
|
11
86
|
throw new Error("[ComponentsV2Builder] Text content must be a non-empty string.");
|
|
12
87
|
}
|
|
88
|
+
return true;
|
|
13
89
|
}
|
|
14
90
|
exports.validateTextContent = validateTextContent;
|
|
15
91
|
|
|
16
92
|
/**
|
|
17
93
|
* Validates that a button row does not exceed 5 buttons.
|
|
18
|
-
* Throws a descriptive error if validation fails.
|
|
19
94
|
*/
|
|
20
95
|
function validateButtonCount(count) {
|
|
21
96
|
if (count > 5) {
|
|
@@ -26,7 +101,6 @@ exports.validateButtonCount = validateButtonCount;
|
|
|
26
101
|
|
|
27
102
|
/**
|
|
28
103
|
* Validates that a select menu does not exceed 25 options.
|
|
29
|
-
* Throws a descriptive error if validation fails.
|
|
30
104
|
*/
|
|
31
105
|
function validateSelectMenuOptions(count) {
|
|
32
106
|
if (count > 25) {
|
|
@@ -37,15 +111,300 @@ exports.validateSelectMenuOptions = validateSelectMenuOptions;
|
|
|
37
111
|
|
|
38
112
|
/**
|
|
39
113
|
* Generates a unique custom ID with an optional prefix.
|
|
40
|
-
* Uses crypto.randomUUID when available, otherwise falls back to a
|
|
41
|
-
* timestamp + random number combination to avoid collisions in clustered
|
|
42
|
-
* or multi-process environments.
|
|
43
114
|
*/
|
|
44
115
|
function generateCustomId(prefix) {
|
|
45
116
|
const base = prefix ? `${prefix}_` : "cv2_";
|
|
117
|
+
if (typeof crypto_1.randomUUID === "function") {
|
|
118
|
+
return `${base}${crypto_1.randomUUID()}`;
|
|
119
|
+
}
|
|
46
120
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
47
121
|
return `${base}${crypto.randomUUID()}`;
|
|
48
122
|
}
|
|
49
123
|
return `${base}${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
50
124
|
}
|
|
51
125
|
exports.generateCustomId = generateCustomId;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Resolves a color input (hex string, RGB tuple, integer, or preset name) to a 24-bit RGB integer.
|
|
129
|
+
*/
|
|
130
|
+
function resolveAccentColor(color, fallback) {
|
|
131
|
+
if (color === undefined || color === null || color === "") {
|
|
132
|
+
return fallback !== undefined && fallback !== null ? resolveAccentColor(fallback) : null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (typeof color === "number") {
|
|
136
|
+
if (Number.isInteger(color) && color >= 0 && color <= 0xffffff) {
|
|
137
|
+
return color;
|
|
138
|
+
}
|
|
139
|
+
if (fallback !== undefined && fallback !== null) return resolveAccentColor(fallback);
|
|
140
|
+
throw new RangeError(`[ComponentsV2Builder] Accent color integer must be between 0x000000 and 0xffffff (received ${color}).`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (Array.isArray(color) && color.length === 3) {
|
|
144
|
+
const [r, g, b] = color.map(Number);
|
|
145
|
+
if ([r, g, b].every((n) => Number.isInteger(n) && n >= 0 && n <= 255)) {
|
|
146
|
+
return (r << 16) + (g << 8) + b;
|
|
147
|
+
}
|
|
148
|
+
if (fallback !== undefined && fallback !== null) return resolveAccentColor(fallback);
|
|
149
|
+
throw new RangeError("[ComponentsV2Builder] RGB tuple must contain 3 integers between 0 and 255.");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (typeof color === "string") {
|
|
153
|
+
const trimmed = color.trim();
|
|
154
|
+
const preset = COLOR_PRESETS.get(trimmed.toLowerCase());
|
|
155
|
+
if (preset !== undefined) return preset;
|
|
156
|
+
|
|
157
|
+
const hex = trimmed.replace(/^(?:#|0x)/i, "");
|
|
158
|
+
if (/^[0-9a-f]{6}$/i.test(hex)) {
|
|
159
|
+
return Number.parseInt(hex, 16);
|
|
160
|
+
}
|
|
161
|
+
if (/^[0-9a-f]{3}$/i.test(hex)) {
|
|
162
|
+
const expanded = hex
|
|
163
|
+
.split("")
|
|
164
|
+
.map((c) => c + c)
|
|
165
|
+
.join("");
|
|
166
|
+
return Number.parseInt(expanded, 16);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (fallback !== undefined && fallback !== null) {
|
|
171
|
+
return resolveAccentColor(fallback);
|
|
172
|
+
}
|
|
173
|
+
throw new TypeError(`[ComponentsV2Builder] Invalid accent color: ${String(color)}`);
|
|
174
|
+
}
|
|
175
|
+
exports.resolveAccentColor = resolveAccentColor;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Checks whether a URL is valid for Discord media components (http://, https://, attachment://).
|
|
179
|
+
*/
|
|
180
|
+
function isValidMediaUrl(url) {
|
|
181
|
+
if (typeof url !== "string") return false;
|
|
182
|
+
const trimmed = url.trim();
|
|
183
|
+
if (!trimmed || /\s/.test(trimmed)) return false;
|
|
184
|
+
if (/^attachment:\/\/[^\s/]+$/i.test(trimmed)) return true;
|
|
185
|
+
if (!/^https?:\/\//i.test(trimmed)) return false;
|
|
186
|
+
try {
|
|
187
|
+
const parsed = new URL(trimmed);
|
|
188
|
+
return (parsed.protocol === "http:" || parsed.protocol === "https:") && Boolean(parsed.hostname);
|
|
189
|
+
} catch {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.isValidMediaUrl = isValidMediaUrl;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Checks whether a URL is valid for Discord link buttons (http://, https://, discord://).
|
|
197
|
+
*/
|
|
198
|
+
function isValidLinkUrl(url) {
|
|
199
|
+
if (typeof url !== "string") return false;
|
|
200
|
+
const trimmed = url.trim();
|
|
201
|
+
if (!trimmed || /\s/.test(trimmed)) return false;
|
|
202
|
+
if (!/^(https?|discord):\/\//i.test(trimmed)) return false;
|
|
203
|
+
try {
|
|
204
|
+
const parsed = new URL(trimmed);
|
|
205
|
+
return ["http:", "https:", "discord:"].includes(parsed.protocol);
|
|
206
|
+
} catch {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.isValidLinkUrl = isValidLinkUrl;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Parses an emoji input (unicode string, custom Discord markup `<:name:id>` / `<a:name:id>`,
|
|
214
|
+
* snowflake ID, `name:id`, or `{ id, name, animated }`) into APIMessageComponentEmoji.
|
|
215
|
+
*/
|
|
216
|
+
function parseEmoji(emoji) {
|
|
217
|
+
if (!emoji) return null;
|
|
218
|
+
|
|
219
|
+
if (typeof emoji === "object") {
|
|
220
|
+
const parsed = {};
|
|
221
|
+
if (emoji.id) parsed.id = String(emoji.id);
|
|
222
|
+
if (emoji.name) parsed.name = String(emoji.name);
|
|
223
|
+
if (emoji.animated !== undefined) parsed.animated = Boolean(emoji.animated);
|
|
224
|
+
return parsed.id || parsed.name ? parsed : null;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const raw = String(emoji).trim();
|
|
228
|
+
if (!raw) return null;
|
|
229
|
+
|
|
230
|
+
const markupMatch = raw.match(/^<(a)?:([a-zA-Z0-9_~]+):(\d{15,22})>$/);
|
|
231
|
+
if (markupMatch) {
|
|
232
|
+
return {
|
|
233
|
+
animated: Boolean(markupMatch[1]),
|
|
234
|
+
name: markupMatch[2],
|
|
235
|
+
id: markupMatch[3],
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const colonMatch = raw.match(/^(?:(a):)?([a-zA-Z0-9_~]+):(\d{15,22})$/);
|
|
240
|
+
if (colonMatch) {
|
|
241
|
+
return {
|
|
242
|
+
animated: Boolean(colonMatch[1]),
|
|
243
|
+
name: colonMatch[2],
|
|
244
|
+
id: colonMatch[3],
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (/^\d{15,22}$/.test(raw)) {
|
|
249
|
+
return { id: raw };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return { name: raw };
|
|
253
|
+
}
|
|
254
|
+
exports.parseEmoji = parseEmoji;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Clips text to a maximum length, appending an ellipsis when truncated.
|
|
258
|
+
*/
|
|
259
|
+
function clipText(text, maxLen = SAFE_V2_TEXT_LENGTH, fallback = "") {
|
|
260
|
+
const str = String(text ?? "").trim();
|
|
261
|
+
if (!str) return fallback;
|
|
262
|
+
if (!Number.isFinite(maxLen) || maxLen <= 0) return "";
|
|
263
|
+
if (str.length <= maxLen) return str;
|
|
264
|
+
if (maxLen <= 1) return str.slice(0, maxLen);
|
|
265
|
+
return `${str.slice(0, maxLen - 1)}…`;
|
|
266
|
+
}
|
|
267
|
+
exports.clipText = clipText;
|
|
268
|
+
|
|
269
|
+
function toPlainComponent(component) {
|
|
270
|
+
if (!component || typeof component !== "object") return component;
|
|
271
|
+
if (typeof component.toJSON === "function") return component.toJSON();
|
|
272
|
+
return JSON.parse(JSON.stringify(component));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function isV2ComponentType(type) {
|
|
276
|
+
return V2_COMPONENT_TYPES.has(type);
|
|
277
|
+
}
|
|
278
|
+
exports.isV2ComponentType = isV2ComponentType;
|
|
279
|
+
|
|
280
|
+
function sumTextNode(node) {
|
|
281
|
+
if (!node || typeof node !== "object") return 0;
|
|
282
|
+
const data = typeof node.toJSON === "function" ? node.toJSON() : node.data ?? node;
|
|
283
|
+
let total = 0;
|
|
284
|
+
|
|
285
|
+
if (data.type === (discord_js_1.ComponentType?.TextDisplay ?? 10) && typeof data.content === "string") {
|
|
286
|
+
total += data.content.length;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const children = node.components ?? data.components;
|
|
290
|
+
if (Array.isArray(children)) {
|
|
291
|
+
for (const child of children) {
|
|
292
|
+
total += sumTextNode(child);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return total;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Counts total characters across all TextDisplay components in a component list.
|
|
301
|
+
*/
|
|
302
|
+
function countTextLength(components) {
|
|
303
|
+
if (!Array.isArray(components)) return 0;
|
|
304
|
+
let total = 0;
|
|
305
|
+
for (const comp of components) {
|
|
306
|
+
total += sumTextNode(comp);
|
|
307
|
+
}
|
|
308
|
+
return total;
|
|
309
|
+
}
|
|
310
|
+
exports.countTextLength = countTextLength;
|
|
311
|
+
|
|
312
|
+
function countComponentNode(node) {
|
|
313
|
+
if (!node || typeof node !== "object") return 0;
|
|
314
|
+
const data = typeof node.toJSON === "function" ? node.toJSON() : node.data ?? node;
|
|
315
|
+
let total = 1;
|
|
316
|
+
|
|
317
|
+
const children = node.components ?? data.components;
|
|
318
|
+
if (Array.isArray(children)) {
|
|
319
|
+
for (const child of children) {
|
|
320
|
+
total += countComponentNode(child);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const accessory = node.accessory ?? data.accessory;
|
|
325
|
+
if (accessory && typeof accessory === "object") {
|
|
326
|
+
total += countComponentNode(accessory);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const items = node.items ?? data.items;
|
|
330
|
+
if (Array.isArray(items)) {
|
|
331
|
+
total += items.length;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return total;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Counts total component nodes (including nested Container, Section, ActionRow, and MediaGallery items).
|
|
339
|
+
*/
|
|
340
|
+
function countComponents(components) {
|
|
341
|
+
if (!Array.isArray(components)) return 0;
|
|
342
|
+
let total = 0;
|
|
343
|
+
for (const comp of components) {
|
|
344
|
+
total += countComponentNode(comp);
|
|
345
|
+
}
|
|
346
|
+
return total;
|
|
347
|
+
}
|
|
348
|
+
exports.countComponents = countComponents;
|
|
349
|
+
|
|
350
|
+
function disableNodeInPlace(node, options) {
|
|
351
|
+
if (!node || typeof node !== "object") return node;
|
|
352
|
+
|
|
353
|
+
const disableButtons = options?.disableButtons !== false;
|
|
354
|
+
const disableSelects = options?.disableSelects !== false;
|
|
355
|
+
const disableLinks = Boolean(options?.disableLinks);
|
|
356
|
+
|
|
357
|
+
if (node.type === (discord_js_1.ComponentType?.Button ?? 2)) {
|
|
358
|
+
if (disableButtons && (disableLinks || node.style !== discord_js_1.ButtonStyle.Link)) {
|
|
359
|
+
node.disabled = true;
|
|
360
|
+
}
|
|
361
|
+
return node;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (SELECT_COMPONENT_TYPES.has(node.type)) {
|
|
365
|
+
if (disableSelects) {
|
|
366
|
+
node.disabled = true;
|
|
367
|
+
}
|
|
368
|
+
return node;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (Array.isArray(node.components)) {
|
|
372
|
+
node.components = node.components.map((child) => disableNodeInPlace(child, options));
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (node.accessory && typeof node.accessory === "object") {
|
|
376
|
+
node.accessory = disableNodeInPlace(node.accessory, options);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return node;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Recursively clones and disables buttons/selects in both V1 ActionRows and V2 Containers/Sections.
|
|
384
|
+
*/
|
|
385
|
+
function disableComponents(components, options = {}) {
|
|
386
|
+
if (!Array.isArray(components) || !components.length) return [];
|
|
387
|
+
return components.map((comp) => disableNodeInPlace(toPlainComponent(comp), options));
|
|
388
|
+
}
|
|
389
|
+
exports.disableComponents = disableComponents;
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Edits a Discord message to disable all interactive components (V1 or V2) recursively.
|
|
393
|
+
*/
|
|
394
|
+
async function disableMessageComponents(message, options = {}) {
|
|
395
|
+
if (!message?.editable || !message.components?.length) return null;
|
|
396
|
+
|
|
397
|
+
const components = disableComponents(message.components, options);
|
|
398
|
+
const isV2 = Boolean(
|
|
399
|
+
message.flags?.has?.(discord_js_1.MessageFlags?.IsComponentsV2) ||
|
|
400
|
+
components.some((c) => isV2ComponentType(c?.type))
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
const editPayload = { components };
|
|
404
|
+
if (isV2 && discord_js_1.MessageFlags?.IsComponentsV2 !== undefined) {
|
|
405
|
+
editPayload.flags = discord_js_1.MessageFlags.IsComponentsV2;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return message.edit(editPayload).catch(() => null);
|
|
409
|
+
}
|
|
410
|
+
exports.disableMessageComponents = disableMessageComponents;
|
|
@@ -1,13 +1,155 @@
|
|
|
1
|
-
import { ComponentsV2Builder } from "../ComponentsV2Builder
|
|
1
|
+
import type { ColorResolvable, ComponentsV2Builder, V2ButtonInput, V2FileInput, V2GalleryInput, V2SectionFieldRow } from "../ComponentsV2Builder";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export interface V2CardSectionConfig {
|
|
4
|
+
heading?: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
rows?: Array<V2SectionFieldRow | false | null | undefined>;
|
|
7
|
+
fields?: Array<V2SectionFieldRow | false | null | undefined>;
|
|
8
|
+
text?: string;
|
|
9
|
+
separator?: boolean | "small" | "large";
|
|
10
|
+
omitIfEmpty?: boolean;
|
|
11
|
+
fallback?: string;
|
|
12
|
+
}
|
|
5
13
|
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
export interface V2CardOptions {
|
|
15
|
+
color?: ColorResolvable;
|
|
16
|
+
accentColor?: ColorResolvable;
|
|
17
|
+
spoiler?: boolean;
|
|
18
|
+
safeMentions?: boolean;
|
|
19
|
+
title?: string;
|
|
20
|
+
subtitle?: string;
|
|
21
|
+
headingLevel?: 1 | 2 | 3;
|
|
22
|
+
thumbnail?: string | null;
|
|
23
|
+
thumbnailDescription?: string;
|
|
24
|
+
thumbnailSpoiler?: boolean;
|
|
25
|
+
headerButton?: V2ButtonInput;
|
|
26
|
+
headerSeparator?: boolean;
|
|
27
|
+
description?: string;
|
|
28
|
+
overflow?: "file" | "clip" | "split";
|
|
29
|
+
overflowFilename?: string;
|
|
30
|
+
maxDescriptionLength?: number;
|
|
31
|
+
fields?: Array<V2SectionFieldRow | false | null | undefined>;
|
|
32
|
+
fieldsSeparator?: boolean;
|
|
33
|
+
omitEmptyFields?: boolean;
|
|
34
|
+
fieldFallback?: string;
|
|
35
|
+
sections?: Array<V2CardSectionConfig | false | null | undefined>;
|
|
36
|
+
gallery?: V2GalleryInput;
|
|
37
|
+
image?: V2GalleryInput;
|
|
38
|
+
gallerySeparator?: boolean;
|
|
39
|
+
ignoreInvalidMedia?: boolean;
|
|
40
|
+
separatorSpacing?: "small" | "large";
|
|
41
|
+
files?: Array<V2FileInput | Buffer | string | false | null | undefined>;
|
|
42
|
+
footer?: string;
|
|
43
|
+
footerSeparator?: boolean;
|
|
44
|
+
buttons?: Array<V2ButtonInput | false | null | undefined>;
|
|
45
|
+
buttonSpacer?: boolean;
|
|
46
|
+
outsideButtons?: Array<V2ButtonInput | false | null | undefined>;
|
|
47
|
+
}
|
|
8
48
|
|
|
9
|
-
|
|
10
|
-
|
|
49
|
+
export interface V2ImageViewLink {
|
|
50
|
+
label?: string;
|
|
51
|
+
url: string;
|
|
52
|
+
style?: "link" | "primary" | "secondary" | "success" | "danger";
|
|
53
|
+
emoji?: string | { id?: string; name?: string; animated?: boolean };
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
}
|
|
11
56
|
|
|
12
|
-
|
|
13
|
-
|
|
57
|
+
export interface V2ImageViewOptions {
|
|
58
|
+
color?: ColorResolvable;
|
|
59
|
+
accentColor?: ColorResolvable;
|
|
60
|
+
spoiler?: boolean;
|
|
61
|
+
safeMentions?: boolean;
|
|
62
|
+
title?: string;
|
|
63
|
+
subtitle?: string;
|
|
64
|
+
headingLevel?: 1 | 2 | 3;
|
|
65
|
+
description?: string;
|
|
66
|
+
image?: V2GalleryInput;
|
|
67
|
+
images?: V2GalleryInput;
|
|
68
|
+
gallery?: V2GalleryInput;
|
|
69
|
+
url?: string | null;
|
|
70
|
+
imageDescription?: string;
|
|
71
|
+
imageSpoiler?: boolean;
|
|
72
|
+
ignoreInvalidMedia?: boolean;
|
|
73
|
+
links?: V2ImageViewLink[];
|
|
74
|
+
buttons?: Array<V2ButtonInput | false | null | undefined>;
|
|
75
|
+
outsideButtons?: Array<V2ButtonInput | false | null | undefined>;
|
|
76
|
+
footer?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface V2ListOptions<T = unknown> {
|
|
80
|
+
color?: ColorResolvable;
|
|
81
|
+
accentColor?: ColorResolvable;
|
|
82
|
+
spoiler?: boolean;
|
|
83
|
+
safeMentions?: boolean;
|
|
84
|
+
title?: string;
|
|
85
|
+
subtitle?: string;
|
|
86
|
+
headingLevel?: 1 | 2 | 3;
|
|
87
|
+
thumbnail?: string | null;
|
|
88
|
+
items?: T[];
|
|
89
|
+
renderItem?: (item: T, index: number) => string;
|
|
90
|
+
numbered?: boolean;
|
|
91
|
+
startIndex?: number;
|
|
92
|
+
itemSeparator?: string;
|
|
93
|
+
emptyText?: string;
|
|
94
|
+
overflow?: "file" | "clip" | "split";
|
|
95
|
+
overflowFilename?: string;
|
|
96
|
+
page?: number;
|
|
97
|
+
totalPages?: number;
|
|
98
|
+
totalItems?: number;
|
|
99
|
+
pageFormatter?: (page: number, totalPages: number, totalItems?: number) => string;
|
|
100
|
+
footer?: string;
|
|
101
|
+
buttons?: Array<V2ButtonInput | false | null | undefined>;
|
|
102
|
+
outsideButtons?: Array<V2ButtonInput | false | null | undefined>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface V2ConfirmOptions {
|
|
106
|
+
color?: ColorResolvable;
|
|
107
|
+
accentColor?: ColorResolvable;
|
|
108
|
+
spoiler?: boolean;
|
|
109
|
+
safeMentions?: boolean;
|
|
110
|
+
title?: string;
|
|
111
|
+
headingLevel?: 1 | 2 | 3;
|
|
112
|
+
message?: string;
|
|
113
|
+
description?: string;
|
|
114
|
+
warning?: string;
|
|
115
|
+
confirmId?: string;
|
|
116
|
+
cancelId?: string;
|
|
117
|
+
confirmLabel?: string;
|
|
118
|
+
cancelLabel?: string;
|
|
119
|
+
confirmStyle?: "primary" | "secondary" | "success" | "danger" | number;
|
|
120
|
+
cancelStyle?: "primary" | "secondary" | "success" | "danger" | number;
|
|
121
|
+
confirmEmoji?: string | { id?: string; name?: string; animated?: boolean };
|
|
122
|
+
cancelEmoji?: string | { id?: string; name?: string; animated?: boolean };
|
|
123
|
+
disabled?: boolean;
|
|
124
|
+
outsideButtons?: Array<V2ButtonInput | false | null | undefined>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export declare function createCard(options?: V2CardOptions): ComponentsV2Builder;
|
|
128
|
+
export declare function createImageView(options?: V2ImageViewOptions): ComponentsV2Builder;
|
|
129
|
+
export declare function createList<T = unknown>(options?: V2ListOptions<T>): ComponentsV2Builder;
|
|
130
|
+
export declare function createConfirm(options: V2ConfirmOptions): ComponentsV2Builder;
|
|
131
|
+
export declare function createConfirm(confirmId: string, cancelId: string, title?: string, message?: string): ComponentsV2Builder;
|
|
132
|
+
export declare function createTicketMenu(
|
|
133
|
+
customId: string,
|
|
134
|
+
title?: string,
|
|
135
|
+
description?: string
|
|
136
|
+
): {
|
|
137
|
+
builder: ComponentsV2Builder;
|
|
138
|
+
select: ReturnType<ComponentsV2Builder["addSelectMenu"]>;
|
|
139
|
+
};
|
|
140
|
+
export declare function createPlanSelector(
|
|
141
|
+
customId: string,
|
|
142
|
+
title?: string,
|
|
143
|
+
description?: string
|
|
144
|
+
): {
|
|
145
|
+
builder: ComponentsV2Builder;
|
|
146
|
+
select: ReturnType<ComponentsV2Builder["addSelectMenu"]>;
|
|
147
|
+
};
|
|
148
|
+
export declare function createRoleMenu(
|
|
149
|
+
customId: string,
|
|
150
|
+
title?: string,
|
|
151
|
+
description?: string
|
|
152
|
+
): {
|
|
153
|
+
builder: ComponentsV2Builder;
|
|
154
|
+
select: ReturnType<ComponentsV2Builder["addSelectMenu"]>;
|
|
155
|
+
};
|