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.
- package/lib/classes/Client.d.ts +13 -3
- package/lib/classes/Client.js +23 -1
- package/lib/classes/Context.d.ts +2 -0
- package/lib/classes/Context.js +94 -21
- package/lib/classes/Cooldowns.d.ts +2 -0
- package/lib/classes/Cooldowns.js +28 -0
- package/lib/classes/Loader.d.ts +12 -3
- package/lib/classes/Loader.js +141 -19
- package/lib/classes/Plugins.js +3 -2
- package/lib/classes/Utils.d.ts +1 -1
- package/lib/classes/Utils.js +110 -20
- package/lib/classes/builders/CommandBuilder.d.ts +14 -0
- package/lib/classes/builders/CommandBuilder.js +50 -2
- package/lib/classes/builders/ComponentsV2Builder.d.ts +51 -3
- package/lib/classes/builders/ComponentsV2Builder.js +394 -72
- package/lib/classes/builders/GroupBuilder.d.ts +11 -0
- package/lib/classes/builders/GroupBuilder.js +21 -1
- package/lib/classes/builders/InteractionBuilder.d.ts +47 -0
- package/lib/classes/builders/InteractionBuilder.js +113 -2
- package/lib/classes/builders/ParamsBuilder.d.ts +118 -76
- package/lib/classes/builders/ParamsBuilder.js +167 -1
- package/lib/classes/builders/components/StyleMapper.d.ts +13 -1
- package/lib/classes/builders/components/StyleMapper.js +33 -8
- 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
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OverflowMenuProxy =
|
|
4
|
+
exports.OverflowMenuBuilder =
|
|
5
|
+
exports.OverflowMenuGroupBuilder =
|
|
6
|
+
exports.MenuActionItemBuilder =
|
|
7
|
+
exports.mapMenuActionItemStyle =
|
|
8
|
+
exports.MenuActionItemStyle =
|
|
9
|
+
exports.OVERFLOW_FALLBACK_SELECT_PREFIX =
|
|
10
|
+
exports.MENU_ACTION_ITEM_TYPE =
|
|
11
|
+
exports.OVERFLOW_MENU_TYPE =
|
|
12
|
+
void 0;
|
|
13
|
+
|
|
14
|
+
const crypto_1 = require("crypto");
|
|
15
|
+
const discord_js_1 = require("discord.js");
|
|
16
|
+
const helpers_js_1 = require("./helpers.js");
|
|
17
|
+
|
|
18
|
+
const OVERFLOW_MENU_TYPE = 25;
|
|
19
|
+
exports.OVERFLOW_MENU_TYPE = OVERFLOW_MENU_TYPE;
|
|
20
|
+
|
|
21
|
+
const MENU_ACTION_ITEM_TYPE = 26;
|
|
22
|
+
exports.MENU_ACTION_ITEM_TYPE = MENU_ACTION_ITEM_TYPE;
|
|
23
|
+
|
|
24
|
+
const OVERFLOW_FALLBACK_SELECT_PREFIX = "__ovf_sel:";
|
|
25
|
+
exports.OVERFLOW_FALLBACK_SELECT_PREFIX = OVERFLOW_FALLBACK_SELECT_PREFIX;
|
|
26
|
+
|
|
27
|
+
const MenuActionItemStyle = Object.freeze({
|
|
28
|
+
Default: 1,
|
|
29
|
+
Danger: 2,
|
|
30
|
+
Link: 3,
|
|
31
|
+
});
|
|
32
|
+
exports.MenuActionItemStyle = MenuActionItemStyle;
|
|
33
|
+
|
|
34
|
+
function shortToken() {
|
|
35
|
+
if (typeof crypto_1.randomBytes === "function") {
|
|
36
|
+
return crypto_1.randomBytes(4).toString("hex");
|
|
37
|
+
}
|
|
38
|
+
return Math.random().toString(36).slice(2, 10);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Maps string or numeric action item styles to Discord's MenuActionItem style enum (`1 | 2 | 3`).
|
|
43
|
+
*/
|
|
44
|
+
function mapMenuActionItemStyle(style, hasUrl = false) {
|
|
45
|
+
if (style === undefined || style === null) {
|
|
46
|
+
return hasUrl ? MenuActionItemStyle.Link : MenuActionItemStyle.Default;
|
|
47
|
+
}
|
|
48
|
+
if (typeof style === "number") {
|
|
49
|
+
if (style === MenuActionItemStyle.Danger) return MenuActionItemStyle.Danger;
|
|
50
|
+
if (style === MenuActionItemStyle.Link) return MenuActionItemStyle.Link;
|
|
51
|
+
return MenuActionItemStyle.Default;
|
|
52
|
+
}
|
|
53
|
+
const normalized = String(style).trim().toLowerCase();
|
|
54
|
+
if (normalized === "danger" || normalized === "error" || normalized === "destructive") {
|
|
55
|
+
return MenuActionItemStyle.Danger;
|
|
56
|
+
}
|
|
57
|
+
if (normalized === "link" || normalized === "url") {
|
|
58
|
+
return MenuActionItemStyle.Link;
|
|
59
|
+
}
|
|
60
|
+
return MenuActionItemStyle.Default;
|
|
61
|
+
}
|
|
62
|
+
exports.mapMenuActionItemStyle = mapMenuActionItemStyle;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Builder for Discord MenuActionItem (`type: 26`) entries inside an OverflowMenu group.
|
|
66
|
+
*/
|
|
67
|
+
class MenuActionItemBuilder {
|
|
68
|
+
label;
|
|
69
|
+
customId;
|
|
70
|
+
style;
|
|
71
|
+
url;
|
|
72
|
+
description;
|
|
73
|
+
emoji;
|
|
74
|
+
disabled;
|
|
75
|
+
|
|
76
|
+
constructor(options = {}) {
|
|
77
|
+
if (options && typeof options === "object") {
|
|
78
|
+
if (options.label !== undefined) this.label = options.label;
|
|
79
|
+
if (options.customId !== undefined || options.id !== undefined) {
|
|
80
|
+
this.customId = options.customId ?? options.id;
|
|
81
|
+
}
|
|
82
|
+
if (options.style !== undefined) this.style = options.style;
|
|
83
|
+
if (options.url !== undefined) this.url = options.url;
|
|
84
|
+
if (options.description !== undefined) this.description = options.description;
|
|
85
|
+
if (options.emoji !== undefined) this.emoji = options.emoji;
|
|
86
|
+
if (options.disabled !== undefined) this.disabled = Boolean(options.disabled);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
setLabel(label) {
|
|
91
|
+
this.label = label;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
setCustomId(customId) {
|
|
96
|
+
this.customId = customId;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
setStyle(style) {
|
|
101
|
+
this.style = style;
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
setURL(url) {
|
|
106
|
+
this.url = url;
|
|
107
|
+
if (this.style === undefined) {
|
|
108
|
+
this.style = MenuActionItemStyle.Link;
|
|
109
|
+
}
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
setDescription(description) {
|
|
114
|
+
this.description = description;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
setEmoji(emoji) {
|
|
119
|
+
this.emoji = emoji;
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
setDisabled(disabled = true) {
|
|
124
|
+
this.disabled = Boolean(disabled);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
toJSON(options = {}) {
|
|
129
|
+
const validate = options?.validate !== false;
|
|
130
|
+
const parsedEmoji = this.emoji ? helpers_js_1.parseEmoji(this.emoji) : null;
|
|
131
|
+
const rawLabel = this.label !== undefined && this.label !== null ? String(this.label).trim() : "";
|
|
132
|
+
const hasLabel = rawLabel.length > 0;
|
|
133
|
+
|
|
134
|
+
if (validate && !hasLabel && !parsedEmoji) {
|
|
135
|
+
throw new Error("[OverflowMenuBuilder] MenuActionItem requires a non-empty label or emoji.");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const resolvedStyle = mapMenuActionItemStyle(this.style, Boolean(this.url));
|
|
139
|
+
const payload = {
|
|
140
|
+
type: MENU_ACTION_ITEM_TYPE,
|
|
141
|
+
style: resolvedStyle,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
if (hasLabel) {
|
|
145
|
+
payload.label = helpers_js_1.clipText(rawLabel, 100);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (resolvedStyle === MenuActionItemStyle.Link) {
|
|
149
|
+
if (validate && !helpers_js_1.isValidLinkUrl(this.url)) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
`[OverflowMenuBuilder] Link MenuActionItem requires a valid http(s)/discord URL (received: ${String(this.url)}).`
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
if (this.url !== undefined && this.url !== null) {
|
|
155
|
+
payload.url = String(this.url).trim();
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
const id =
|
|
159
|
+
this.customId !== undefined && this.customId !== null
|
|
160
|
+
? String(this.customId)
|
|
161
|
+
: helpers_js_1.generateCustomId("ovf");
|
|
162
|
+
payload.custom_id = id;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (this.description !== undefined && this.description !== null && String(this.description).trim() !== "") {
|
|
166
|
+
payload.description = helpers_js_1.clipText(this.description, 100);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (parsedEmoji) {
|
|
170
|
+
payload.emoji = parsedEmoji;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (this.disabled !== undefined) {
|
|
174
|
+
payload.disabled = Boolean(this.disabled);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return payload;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.MenuActionItemBuilder = MenuActionItemBuilder;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Builder for an item group inside an OverflowMenu (`type: 25`).
|
|
184
|
+
*/
|
|
185
|
+
class OverflowMenuGroupBuilder {
|
|
186
|
+
label;
|
|
187
|
+
items = [];
|
|
188
|
+
|
|
189
|
+
constructor(labelOrOptions = {}) {
|
|
190
|
+
if (typeof labelOrOptions === "string") {
|
|
191
|
+
this.label = labelOrOptions;
|
|
192
|
+
} else if (labelOrOptions && typeof labelOrOptions === "object") {
|
|
193
|
+
this.label = labelOrOptions.label ?? labelOrOptions.title;
|
|
194
|
+
if (Array.isArray(labelOrOptions.items)) {
|
|
195
|
+
this.addItems(labelOrOptions.items);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
setLabel(label) {
|
|
201
|
+
this.label = label;
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
addItem(itemOrConfig) {
|
|
206
|
+
if (!itemOrConfig) return this;
|
|
207
|
+
const item =
|
|
208
|
+
itemOrConfig instanceof MenuActionItemBuilder
|
|
209
|
+
? itemOrConfig
|
|
210
|
+
: new MenuActionItemBuilder(itemOrConfig);
|
|
211
|
+
this.items.push(item);
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
addItems(items) {
|
|
216
|
+
if (!Array.isArray(items)) return this;
|
|
217
|
+
for (const item of items) {
|
|
218
|
+
if (!item) continue;
|
|
219
|
+
this.addItem(item);
|
|
220
|
+
}
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
addLink(labelOrConfig, url, extra) {
|
|
225
|
+
const cfg =
|
|
226
|
+
typeof labelOrConfig === "string"
|
|
227
|
+
? { ...(extra && typeof extra === "object" ? extra : {}), label: labelOrConfig, url, style: MenuActionItemStyle.Link }
|
|
228
|
+
: { ...labelOrConfig, style: MenuActionItemStyle.Link };
|
|
229
|
+
return this.addItem(cfg);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
toJSON(options = {}) {
|
|
233
|
+
const hasLabel = this.label !== undefined && this.label !== null && String(this.label).trim().length > 0;
|
|
234
|
+
return {
|
|
235
|
+
...(hasLabel ? { label: helpers_js_1.clipText(this.label, 100) } : {}),
|
|
236
|
+
items: this.items.map((item) => item.toJSON(options)),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.OverflowMenuGroupBuilder = OverflowMenuGroupBuilder;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Builder for Discord Components V2 OverflowMenu (`type: 25`) section accessory
|
|
244
|
+
* with automatic conversion to Select/Link-Button fallback rows when needed.
|
|
245
|
+
*/
|
|
246
|
+
class OverflowMenuBuilder {
|
|
247
|
+
customId;
|
|
248
|
+
disabled;
|
|
249
|
+
placeholder = "⋯ Más acciones";
|
|
250
|
+
groups = [];
|
|
251
|
+
|
|
252
|
+
constructor(options = {}) {
|
|
253
|
+
if (options && typeof options === "object") {
|
|
254
|
+
if (options.customId !== undefined || options.id !== undefined) {
|
|
255
|
+
this.customId = options.customId ?? options.id;
|
|
256
|
+
}
|
|
257
|
+
if (options.disabled !== undefined) {
|
|
258
|
+
this.disabled = Boolean(options.disabled);
|
|
259
|
+
}
|
|
260
|
+
if (options.placeholder !== undefined) {
|
|
261
|
+
this.placeholder = String(options.placeholder);
|
|
262
|
+
}
|
|
263
|
+
if (Array.isArray(options.groups)) {
|
|
264
|
+
for (const group of options.groups) {
|
|
265
|
+
if (!group) continue;
|
|
266
|
+
if (group instanceof OverflowMenuGroupBuilder) {
|
|
267
|
+
this.groups.push(group);
|
|
268
|
+
} else {
|
|
269
|
+
this.addGroup(group);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (Array.isArray(options.items)) {
|
|
274
|
+
this.addItems(options.items);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
setCustomId(customId) {
|
|
280
|
+
this.customId = customId;
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
setDisabled(disabled = true) {
|
|
285
|
+
this.disabled = Boolean(disabled);
|
|
286
|
+
return this;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
setPlaceholder(placeholder) {
|
|
290
|
+
this.placeholder = String(placeholder || "⋯ Más acciones");
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
#ensureDefaultGroup() {
|
|
295
|
+
const last = this.groups[this.groups.length - 1];
|
|
296
|
+
if (last && !last.label) return last;
|
|
297
|
+
const group = new OverflowMenuGroupBuilder();
|
|
298
|
+
this.groups.push(group);
|
|
299
|
+
return group;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
addGroup(labelOrOptions, callbackOrItems) {
|
|
303
|
+
const group =
|
|
304
|
+
labelOrOptions instanceof OverflowMenuGroupBuilder
|
|
305
|
+
? labelOrOptions
|
|
306
|
+
: new OverflowMenuGroupBuilder(labelOrOptions);
|
|
307
|
+
|
|
308
|
+
if (typeof callbackOrItems === "function") {
|
|
309
|
+
callbackOrItems(group);
|
|
310
|
+
} else if (Array.isArray(callbackOrItems)) {
|
|
311
|
+
group.addItems(callbackOrItems);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
this.groups.push(group);
|
|
315
|
+
return this;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
addItem(itemOrConfig) {
|
|
319
|
+
if (!itemOrConfig) return this;
|
|
320
|
+
this.#ensureDefaultGroup().addItem(itemOrConfig);
|
|
321
|
+
return this;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
addItems(items) {
|
|
325
|
+
if (!Array.isArray(items)) return this;
|
|
326
|
+
for (const item of items) {
|
|
327
|
+
if (!item) continue;
|
|
328
|
+
this.addItem(item);
|
|
329
|
+
}
|
|
330
|
+
return this;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
addLink(labelOrConfig, url, extra) {
|
|
334
|
+
this.#ensureDefaultGroup().addLink(labelOrConfig, url, extra);
|
|
335
|
+
return this;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
get itemCount() {
|
|
339
|
+
let total = 0;
|
|
340
|
+
for (const group of this.groups) {
|
|
341
|
+
total += group.items.length;
|
|
342
|
+
}
|
|
343
|
+
return total;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
toJSON(options = {}) {
|
|
347
|
+
const validate = options?.validate !== false;
|
|
348
|
+
const total = this.itemCount;
|
|
349
|
+
|
|
350
|
+
if (validate) {
|
|
351
|
+
if (total === 0) {
|
|
352
|
+
throw new Error("[OverflowMenuBuilder] OverflowMenu requires at least one item.");
|
|
353
|
+
}
|
|
354
|
+
if (total > 25) {
|
|
355
|
+
throw new Error(`[OverflowMenuBuilder] OverflowMenu cannot contain more than 25 items (got ${total}).`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
type: OVERFLOW_MENU_TYPE,
|
|
361
|
+
...(this.customId !== undefined && this.customId !== null ? { custom_id: String(this.customId) } : {}),
|
|
362
|
+
...(this.disabled !== undefined ? { disabled: Boolean(this.disabled) } : {}),
|
|
363
|
+
groups: this.groups.map((group) => group.toJSON({ validate })),
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Builds standard discord.js ActionRows (`"select"` + link buttons, or `"buttons"`)
|
|
369
|
+
* used when degrading gracefully via `V2Adaptive` or explicit fallback options.
|
|
370
|
+
*/
|
|
371
|
+
toFallbackComponents(fallbackOptions = {}) {
|
|
372
|
+
const mode = String(fallbackOptions.mode || "select").toLowerCase();
|
|
373
|
+
const raw = this.toJSON({ validate: fallbackOptions.validate !== false });
|
|
374
|
+
|
|
375
|
+
if (mode === "buttons") {
|
|
376
|
+
const buttons = [];
|
|
377
|
+
for (const group of raw.groups) {
|
|
378
|
+
for (const item of group.items) {
|
|
379
|
+
const btn = new discord_js_1.ButtonBuilder();
|
|
380
|
+
if (item.label) btn.setLabel(item.label);
|
|
381
|
+
if (item.emoji) btn.setEmoji(item.emoji);
|
|
382
|
+
if (item.disabled || raw.disabled || fallbackOptions.disabled) {
|
|
383
|
+
btn.setDisabled(true);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (item.style === MenuActionItemStyle.Link) {
|
|
387
|
+
btn.setStyle(discord_js_1.ButtonStyle.Link).setURL(item.url);
|
|
388
|
+
} else {
|
|
389
|
+
btn
|
|
390
|
+
.setStyle(
|
|
391
|
+
item.style === MenuActionItemStyle.Danger
|
|
392
|
+
? discord_js_1.ButtonStyle.Danger
|
|
393
|
+
: discord_js_1.ButtonStyle.Secondary
|
|
394
|
+
)
|
|
395
|
+
.setCustomId(item.custom_id);
|
|
396
|
+
}
|
|
397
|
+
buttons.push(btn);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const rows = [];
|
|
402
|
+
for (let i = 0; i < buttons.length; i += 5) {
|
|
403
|
+
rows.push(new discord_js_1.ActionRowBuilder().addComponents(...buttons.slice(i, i + 5)));
|
|
404
|
+
}
|
|
405
|
+
return rows;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const selectOptions = [];
|
|
409
|
+
const linkButtons = [];
|
|
410
|
+
|
|
411
|
+
for (const group of raw.groups) {
|
|
412
|
+
const groupLabel = group.label ? String(group.label).trim() : "";
|
|
413
|
+
for (const item of group.items) {
|
|
414
|
+
if (item.style === MenuActionItemStyle.Link) {
|
|
415
|
+
if (fallbackOptions.includeLinks !== false) {
|
|
416
|
+
const btn = new discord_js_1.ButtonBuilder()
|
|
417
|
+
.setStyle(discord_js_1.ButtonStyle.Link)
|
|
418
|
+
.setURL(item.url);
|
|
419
|
+
if (item.label) btn.setLabel(item.label);
|
|
420
|
+
if (item.emoji) btn.setEmoji(item.emoji);
|
|
421
|
+
if (item.disabled || raw.disabled || fallbackOptions.disabled) {
|
|
422
|
+
btn.setDisabled(true);
|
|
423
|
+
}
|
|
424
|
+
linkButtons.push(btn);
|
|
425
|
+
}
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (selectOptions.length >= 25) continue;
|
|
430
|
+
|
|
431
|
+
const label = item.label || item.custom_id || "Acción";
|
|
432
|
+
const option = new discord_js_1.StringSelectMenuOptionBuilder()
|
|
433
|
+
.setLabel(helpers_js_1.clipText(label, 100))
|
|
434
|
+
.setValue(String(item.custom_id));
|
|
435
|
+
|
|
436
|
+
const desc =
|
|
437
|
+
groupLabel && item.description
|
|
438
|
+
? `${groupLabel} · ${item.description}`
|
|
439
|
+
: item.description || groupLabel;
|
|
440
|
+
if (desc) {
|
|
441
|
+
option.setDescription(helpers_js_1.clipText(desc, 100));
|
|
442
|
+
}
|
|
443
|
+
if (item.emoji) {
|
|
444
|
+
option.setEmoji(item.emoji);
|
|
445
|
+
}
|
|
446
|
+
selectOptions.push(option);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const rows = [];
|
|
451
|
+
if (selectOptions.length > 0) {
|
|
452
|
+
const selectCustomId =
|
|
453
|
+
fallbackOptions.customId || `${OVERFLOW_FALLBACK_SELECT_PREFIX}${raw.custom_id || shortToken()}`;
|
|
454
|
+
const select = new discord_js_1.StringSelectMenuBuilder()
|
|
455
|
+
.setCustomId(String(selectCustomId).slice(0, 100))
|
|
456
|
+
.setPlaceholder(helpers_js_1.clipText(fallbackOptions.placeholder || this.placeholder || "⋯ Más acciones", 150))
|
|
457
|
+
.addOptions(...selectOptions);
|
|
458
|
+
|
|
459
|
+
if (raw.disabled || fallbackOptions.disabled) {
|
|
460
|
+
select.setDisabled(true);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
rows.push(new discord_js_1.ActionRowBuilder().addComponents(select));
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
for (let i = 0; i < linkButtons.length; i += 5) {
|
|
467
|
+
rows.push(new discord_js_1.ActionRowBuilder().addComponents(...linkButtons.slice(i, i + 5)));
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
return rows;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
exports.OverflowMenuBuilder = OverflowMenuBuilder;
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Fluent proxy returned by `ComponentsV2Builder#addOverflowSection(...)` or `addSection` callbacks.
|
|
477
|
+
*/
|
|
478
|
+
class OverflowMenuProxy {
|
|
479
|
+
#parent;
|
|
480
|
+
#menu;
|
|
481
|
+
|
|
482
|
+
constructor(parent, menu) {
|
|
483
|
+
this.#parent = parent;
|
|
484
|
+
this.#menu = menu;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
setCustomId(customId) {
|
|
488
|
+
this.#menu.setCustomId(customId);
|
|
489
|
+
return this;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
setDisabled(disabled = true) {
|
|
493
|
+
this.#menu.setDisabled(disabled);
|
|
494
|
+
return this;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
setPlaceholder(placeholder) {
|
|
498
|
+
this.#menu.setPlaceholder(placeholder);
|
|
499
|
+
return this;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
addGroup(labelOrOptions, callbackOrItems) {
|
|
503
|
+
this.#menu.addGroup(labelOrOptions, callbackOrItems);
|
|
504
|
+
return this;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
addItem(itemOrConfig) {
|
|
508
|
+
this.#menu.addItem(itemOrConfig);
|
|
509
|
+
return this;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
addItems(items) {
|
|
513
|
+
this.#menu.addItems(items);
|
|
514
|
+
return this;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
addLink(labelOrConfig, url, extra) {
|
|
518
|
+
this.#menu.addLink(labelOrConfig, url, extra);
|
|
519
|
+
return this;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
toBuilder() {
|
|
523
|
+
return this.#menu;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
toJSON(options) {
|
|
527
|
+
return this.#menu.toJSON(options);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
end() {
|
|
531
|
+
return this.#parent;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
exports.OverflowMenuProxy = OverflowMenuProxy;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { BaseInteraction, Client, Message, TextBasedChannel } from "discord.js";
|
|
2
|
+
import type { ComponentsV2Builder, V2BuiltPayload, V2PayloadOptions } from "../builders/ComponentsV2Builder.js";
|
|
3
|
+
import type { Context, ContextSendOptions } from "../Context.js";
|
|
4
|
+
|
|
5
|
+
export declare const OVERFLOW_SOURCE_SYMBOL: unique symbol;
|
|
6
|
+
|
|
7
|
+
export interface V2AdaptiveStatus {
|
|
8
|
+
overflowAvailable: boolean;
|
|
9
|
+
disabledUntil: number;
|
|
10
|
+
ttlMs: number;
|
|
11
|
+
forceMode: "native" | "fallback" | null;
|
|
12
|
+
fallbackCount: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface V2AdaptiveConfigureOptions {
|
|
16
|
+
ttlMs?: number;
|
|
17
|
+
forceMode?: "native" | "fallback" | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare function unwrapOverflowFallbackInteraction<T = BaseInteraction>(interaction: T): T;
|
|
21
|
+
|
|
22
|
+
export declare function ensureOverflowInteractionBridge(client: Client | Record<string, any>): boolean;
|
|
23
|
+
|
|
24
|
+
export declare class OverflowMenuInteraction {
|
|
25
|
+
client: Client | any;
|
|
26
|
+
id: string;
|
|
27
|
+
applicationId: string | null;
|
|
28
|
+
type: number;
|
|
29
|
+
token: string | null;
|
|
30
|
+
version: number;
|
|
31
|
+
componentType: number;
|
|
32
|
+
customId: string;
|
|
33
|
+
values: string[];
|
|
34
|
+
channelId: string | null;
|
|
35
|
+
guildId: string | null;
|
|
36
|
+
guild: any;
|
|
37
|
+
channel: any;
|
|
38
|
+
user: any;
|
|
39
|
+
member: any;
|
|
40
|
+
message: any;
|
|
41
|
+
locale: string | null;
|
|
42
|
+
guildLocale: string | null;
|
|
43
|
+
deferred: boolean;
|
|
44
|
+
replied: boolean;
|
|
45
|
+
ephemeral: boolean | null;
|
|
46
|
+
rawData: Record<string, any>;
|
|
47
|
+
|
|
48
|
+
constructor(client: Client | any, rawPacketData: Record<string, any>);
|
|
49
|
+
isOverflowMenu(): boolean;
|
|
50
|
+
isMessageComponent(): boolean;
|
|
51
|
+
isChatInputCommand(): boolean;
|
|
52
|
+
isAutocomplete(): boolean;
|
|
53
|
+
isButton(): boolean;
|
|
54
|
+
isModalSubmit(): boolean;
|
|
55
|
+
isMessageContextMenuCommand(): boolean;
|
|
56
|
+
isUserContextMenuCommand(): boolean;
|
|
57
|
+
isChannelSelectMenu(): boolean;
|
|
58
|
+
isMentionableSelectMenu(): boolean;
|
|
59
|
+
isRoleSelectMenu(): boolean;
|
|
60
|
+
isStringSelectMenu(): boolean;
|
|
61
|
+
isUserSelectMenu(): boolean;
|
|
62
|
+
reply(payload: string | Record<string, any>): Promise<any>;
|
|
63
|
+
deferReply(options?: { flags?: number }): Promise<any>;
|
|
64
|
+
deferUpdate(): Promise<any>;
|
|
65
|
+
update(payload: string | Record<string, any>): Promise<any>;
|
|
66
|
+
editReply(payload: string | Record<string, any>): Promise<any>;
|
|
67
|
+
followUp(payload: string | Record<string, any>): Promise<any>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export declare class V2Adaptive {
|
|
71
|
+
static configure(options?: V2AdaptiveConfigureOptions): V2AdaptiveStatus;
|
|
72
|
+
static isOverflowAvailable(now?: number): boolean;
|
|
73
|
+
static markOverflowUnavailable(customTtlMs?: number, now?: number): V2AdaptiveStatus;
|
|
74
|
+
static markOverflowAvailable(): V2AdaptiveStatus;
|
|
75
|
+
static reset(): void;
|
|
76
|
+
static getStatus(now?: number): V2AdaptiveStatus;
|
|
77
|
+
static isOverflowRejectionError(error: unknown): boolean;
|
|
78
|
+
static extractOverflowSource(payloadOrBuilder: unknown): {
|
|
79
|
+
builder: ComponentsV2Builder;
|
|
80
|
+
options?: V2PayloadOptions;
|
|
81
|
+
usedNativeOverflow: boolean;
|
|
82
|
+
canFallback: boolean;
|
|
83
|
+
} | null;
|
|
84
|
+
static attachOverflowSource<T extends Record<string, any>>(
|
|
85
|
+
payload: T,
|
|
86
|
+
sourceMeta: {
|
|
87
|
+
builder: ComponentsV2Builder;
|
|
88
|
+
options?: V2PayloadOptions;
|
|
89
|
+
usedNativeOverflow: boolean;
|
|
90
|
+
canFallback: boolean;
|
|
91
|
+
}
|
|
92
|
+
): T;
|
|
93
|
+
static executeWithFallback<T = any>(
|
|
94
|
+
payloadOrBuilder: ComponentsV2Builder | V2BuiltPayload | Record<string, any>,
|
|
95
|
+
executorFn: (payload: V2BuiltPayload | Record<string, any>) => Promise<T>,
|
|
96
|
+
payloadOptions?: V2PayloadOptions
|
|
97
|
+
): Promise<T>;
|
|
98
|
+
static send<T = Message<boolean> | any>(
|
|
99
|
+
target: Context | TextBasedChannel | BaseInteraction | ((payload: V2BuiltPayload | Record<string, any>) => Promise<T>),
|
|
100
|
+
builderOrPayload: ComponentsV2Builder | V2BuiltPayload | Record<string, any>,
|
|
101
|
+
options?: V2PayloadOptions & ContextSendOptions & { followUp?: boolean }
|
|
102
|
+
): Promise<T>;
|
|
103
|
+
}
|