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,287 +1,1174 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ComponentsV2Builder = void 0;
|
|
3
|
+
exports.SelectMenuProxy = exports.ComponentsV2Builder = void 0;
|
|
4
4
|
|
|
5
|
+
const path_1 = require("path");
|
|
5
6
|
const discord_js_1 = require("discord.js");
|
|
6
|
-
const StyleMapper_js_1 = require("./components/StyleMapper.js");
|
|
7
7
|
const helpers_js_1 = require("./components/helpers.js");
|
|
8
|
+
const StyleMapper_js_1 = require("./components/StyleMapper.js");
|
|
9
|
+
const text_js_1 = require("./components/text.js");
|
|
10
|
+
const templates = require("./components/templates.js");
|
|
11
|
+
|
|
12
|
+
const SELECT_TYPE_MAP = {
|
|
13
|
+
string: "string",
|
|
14
|
+
user: "user",
|
|
15
|
+
role: "role",
|
|
16
|
+
channel: "channel",
|
|
17
|
+
mentionable: "mentionable",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function sanitizeAttachmentName(name, fallback = "file.bin") {
|
|
21
|
+
const raw = String(name || "").trim();
|
|
22
|
+
if (!raw) return fallback;
|
|
23
|
+
const base = path_1.basename(raw).replace(/\s+/g, "_");
|
|
24
|
+
return base || fallback;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function splitTextIntoChunks(text, maxChunkSize) {
|
|
28
|
+
const limit = Math.max(10, Number(maxChunkSize) || 1900);
|
|
29
|
+
const chunks = [];
|
|
30
|
+
let remaining = String(text ?? "");
|
|
31
|
+
|
|
32
|
+
while (remaining.length > limit) {
|
|
33
|
+
let sliceAt = remaining.lastIndexOf("\n", limit);
|
|
34
|
+
if (sliceAt < Math.floor(limit * 0.4)) {
|
|
35
|
+
sliceAt = remaining.lastIndexOf(" ", limit);
|
|
36
|
+
}
|
|
37
|
+
if (sliceAt < Math.floor(limit * 0.4)) {
|
|
38
|
+
sliceAt = limit;
|
|
39
|
+
}
|
|
40
|
+
const piece = remaining.slice(0, sliceAt).trimEnd();
|
|
41
|
+
if (piece.length > 0) chunks.push(piece);
|
|
42
|
+
remaining = remaining.slice(sliceAt).replace(/^\n+/, "");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (remaining.length > 0) {
|
|
46
|
+
chunks.push(remaining);
|
|
47
|
+
}
|
|
48
|
+
return chunks;
|
|
49
|
+
}
|
|
8
50
|
|
|
9
51
|
/**
|
|
10
|
-
*
|
|
11
|
-
* and
|
|
52
|
+
* Proxy for configuring a StringSelectMenuBuilder using chained `.addOption(...)`
|
|
53
|
+
* and returning to the parent ComponentsV2Builder with `.end()`.
|
|
12
54
|
*/
|
|
13
55
|
class SelectMenuProxy {
|
|
56
|
+
#parent;
|
|
57
|
+
#menu;
|
|
58
|
+
|
|
14
59
|
constructor(parent, menu) {
|
|
15
|
-
this
|
|
16
|
-
this
|
|
17
|
-
this._optionCount = 0;
|
|
60
|
+
this.#parent = parent;
|
|
61
|
+
this.#menu = menu;
|
|
18
62
|
}
|
|
19
63
|
|
|
20
64
|
/**
|
|
21
|
-
*
|
|
65
|
+
* Adds an option to the select menu.
|
|
66
|
+
* Supports positional args `(label, value, description?, emoji?, isDefault?)`
|
|
67
|
+
* or an option object `{ label, value, description, emoji, default }`.
|
|
22
68
|
*/
|
|
23
|
-
addOption(
|
|
24
|
-
this.
|
|
25
|
-
helpers_js_1.validateSelectMenuOptions(
|
|
69
|
+
addOption(labelOrOption, value, description, emoji, isDefault) {
|
|
70
|
+
const currentCount = this.#menu.options ? this.#menu.options.length : 0;
|
|
71
|
+
helpers_js_1.validateSelectMenuOptions(currentCount + 1);
|
|
72
|
+
|
|
73
|
+
let optionBuilder;
|
|
74
|
+
if (labelOrOption instanceof discord_js_1.StringSelectMenuOptionBuilder) {
|
|
75
|
+
optionBuilder = labelOrOption;
|
|
76
|
+
} else {
|
|
77
|
+
const cfg =
|
|
78
|
+
labelOrOption && typeof labelOrOption === "object"
|
|
79
|
+
? labelOrOption
|
|
80
|
+
: { label: labelOrOption, value, description, emoji, default: isDefault };
|
|
26
81
|
|
|
27
|
-
|
|
28
|
-
.
|
|
29
|
-
|
|
82
|
+
const optLabel = String(cfg.label ?? "").trim();
|
|
83
|
+
const optValue = String(cfg.value ?? optLabel);
|
|
84
|
+
if (!optLabel || !optValue) {
|
|
85
|
+
throw new Error("[ComponentsV2Builder] Select menu options require non-empty label and value.");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
optionBuilder = new discord_js_1.StringSelectMenuOptionBuilder().setLabel(optLabel).setValue(optValue);
|
|
30
89
|
|
|
31
|
-
|
|
32
|
-
|
|
90
|
+
if (cfg.description) {
|
|
91
|
+
optionBuilder.setDescription(String(cfg.description));
|
|
92
|
+
}
|
|
93
|
+
if (cfg.emoji) {
|
|
94
|
+
const parsedEmoji = helpers_js_1.parseEmoji(cfg.emoji);
|
|
95
|
+
if (parsedEmoji) optionBuilder.setEmoji(parsedEmoji);
|
|
96
|
+
}
|
|
97
|
+
if (cfg.default !== undefined) {
|
|
98
|
+
optionBuilder.setDefault(Boolean(cfg.default));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.#menu.addOptions(optionBuilder);
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Adds multiple options at once (objects, tuples `[label, value, description?, emoji?, default?]`, or builders).
|
|
108
|
+
*/
|
|
109
|
+
addOptions(options) {
|
|
110
|
+
if (!Array.isArray(options)) return this;
|
|
111
|
+
for (const item of options) {
|
|
112
|
+
if (!item) continue;
|
|
113
|
+
if (Array.isArray(item)) {
|
|
114
|
+
this.addOption(item[0], item[1], item[2], item[3], item[4]);
|
|
115
|
+
} else {
|
|
116
|
+
this.addOption(item);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
setPlaceholder(placeholder) {
|
|
123
|
+
this.#menu.setPlaceholder(String(placeholder));
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
setMinValues(min) {
|
|
128
|
+
this.#menu.setMinValues(Number(min));
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
setMaxValues(max) {
|
|
133
|
+
this.#menu.setMaxValues(Number(max));
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
33
136
|
|
|
34
|
-
|
|
137
|
+
setDisabled(disabled = true) {
|
|
138
|
+
this.#menu.setDisabled(Boolean(disabled));
|
|
35
139
|
return this;
|
|
36
140
|
}
|
|
37
141
|
|
|
38
142
|
/**
|
|
39
|
-
*
|
|
143
|
+
* Finishes configuring the select menu and returns to the parent ComponentsV2Builder.
|
|
40
144
|
*/
|
|
41
145
|
end() {
|
|
42
|
-
return this
|
|
146
|
+
return this.#parent;
|
|
43
147
|
}
|
|
44
148
|
}
|
|
149
|
+
exports.SelectMenuProxy = SelectMenuProxy;
|
|
45
150
|
|
|
46
151
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* and
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```js
|
|
53
|
-
* const { ComponentsV2Builder } = require("gralonium");
|
|
54
|
-
*
|
|
55
|
-
* const components = new ComponentsV2Builder()
|
|
56
|
-
* .addText("## Welcome!")
|
|
57
|
-
* .addSeparator("small")
|
|
58
|
-
* .addButton("Click Me", "btn_1", "primary")
|
|
59
|
-
* .addButton("Cancel", "btn_2", "secondary")
|
|
60
|
-
* .build();
|
|
61
|
-
*
|
|
62
|
-
* interaction.reply({ components });
|
|
63
|
-
* ```
|
|
152
|
+
* Fluent builder for Discord Components V2 messages with full support for
|
|
153
|
+
* Containers, Sections, MediaGalleries, Files/Attachments, typed SelectMenus,
|
|
154
|
+
* smart emojis, outside rows, limit guards, and ready-to-send payloads.
|
|
64
155
|
*/
|
|
65
156
|
class ComponentsV2Builder {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
157
|
+
#topLevel = [];
|
|
158
|
+
#activeContainerEntry;
|
|
159
|
+
#placement = "inside";
|
|
160
|
+
#currentRow = null;
|
|
161
|
+
#currentRowPlacement = null;
|
|
162
|
+
#files = [];
|
|
163
|
+
#defaultSafeMentions = true;
|
|
164
|
+
#lastKindByTarget = { inside: null, outside: null };
|
|
165
|
+
|
|
166
|
+
static flags = discord_js_1.MessageFlags.IsComponentsV2;
|
|
167
|
+
static MAX_TEXT_LENGTH = helpers_js_1.MAX_V2_TEXT_LENGTH;
|
|
168
|
+
static SAFE_TEXT_LENGTH = helpers_js_1.SAFE_V2_TEXT_LENGTH;
|
|
169
|
+
static MAX_COMPONENTS = helpers_js_1.MAX_V2_COMPONENTS;
|
|
170
|
+
static MAX_TOP_LEVEL_COMPONENTS = helpers_js_1.MAX_V2_TOP_LEVEL_COMPONENTS;
|
|
171
|
+
static text = text_js_1.V2Text;
|
|
172
|
+
static clipText = helpers_js_1.clipText;
|
|
173
|
+
static resolveColor = helpers_js_1.resolveAccentColor;
|
|
174
|
+
static parseEmoji = helpers_js_1.parseEmoji;
|
|
175
|
+
static isValidMediaUrl = helpers_js_1.isValidMediaUrl;
|
|
176
|
+
static isValidLinkUrl = helpers_js_1.isValidLinkUrl;
|
|
177
|
+
static disableComponents = helpers_js_1.disableComponents;
|
|
178
|
+
static disableMessageComponents = helpers_js_1.disableMessageComponents;
|
|
179
|
+
static countTextLength = helpers_js_1.countTextLength;
|
|
180
|
+
static countComponents = helpers_js_1.countComponents;
|
|
181
|
+
|
|
182
|
+
static isBuilder(value) {
|
|
183
|
+
return Boolean(
|
|
184
|
+
value &&
|
|
185
|
+
(value instanceof ComponentsV2Builder ||
|
|
186
|
+
(typeof value === "object" && typeof value.toPayload === "function" && typeof value.build === "function"))
|
|
187
|
+
);
|
|
70
188
|
}
|
|
71
189
|
|
|
72
|
-
|
|
190
|
+
constructor(options = {}) {
|
|
191
|
+
this.#defaultSafeMentions = options.safeMentions !== false;
|
|
192
|
+
this.#activeContainerEntry = this.#createContainerEntry(options);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
#createContainerEntry(options = {}) {
|
|
196
|
+
const container = new discord_js_1.ContainerBuilder();
|
|
197
|
+
const colorInput = options.color !== undefined ? options.color : options.accentColor;
|
|
198
|
+
if (colorInput !== undefined && colorInput !== null) {
|
|
199
|
+
const resolved = helpers_js_1.resolveAccentColor(colorInput);
|
|
200
|
+
if (resolved !== null) container.setAccentColor(resolved);
|
|
201
|
+
}
|
|
202
|
+
if (options.spoiler) {
|
|
203
|
+
container.setSpoiler(true);
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
kind: "container",
|
|
207
|
+
builder: container,
|
|
208
|
+
hasContent: false,
|
|
209
|
+
attached: false,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
#ensureContainerAttached(entry) {
|
|
214
|
+
if (!entry.attached) {
|
|
215
|
+
this.#topLevel.push(entry);
|
|
216
|
+
entry.attached = true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
#flushPendingRow() {
|
|
221
|
+
if (!this.#currentRow || !this.#currentRow.components?.length) {
|
|
222
|
+
this.#currentRow = null;
|
|
223
|
+
this.#currentRowPlacement = null;
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const row = this.#currentRow;
|
|
227
|
+
const placement = this.#currentRowPlacement || "inside";
|
|
228
|
+
this.#currentRow = null;
|
|
229
|
+
this.#currentRowPlacement = null;
|
|
230
|
+
this.#appendDirect(row, "actionRow", placement);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
#appendDirect(component, kind, placement = this.#placement) {
|
|
234
|
+
if (placement === "outside") {
|
|
235
|
+
this.#topLevel.push({ kind: "outside", component });
|
|
236
|
+
this.#lastKindByTarget.outside = kind;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const entry = this.#activeContainerEntry;
|
|
241
|
+
this.#ensureContainerAttached(entry);
|
|
242
|
+
entry.hasContent = true;
|
|
243
|
+
|
|
244
|
+
const c = entry.builder;
|
|
245
|
+
switch (kind) {
|
|
246
|
+
case "text":
|
|
247
|
+
c.addTextDisplayComponents(component);
|
|
248
|
+
break;
|
|
249
|
+
case "separator":
|
|
250
|
+
c.addSeparatorComponents(component);
|
|
251
|
+
break;
|
|
252
|
+
case "section":
|
|
253
|
+
c.addSectionComponents(component);
|
|
254
|
+
break;
|
|
255
|
+
case "gallery":
|
|
256
|
+
c.addMediaGalleryComponents(component);
|
|
257
|
+
break;
|
|
258
|
+
case "file":
|
|
259
|
+
c.addFileComponents(component);
|
|
260
|
+
break;
|
|
261
|
+
case "actionRow":
|
|
262
|
+
c.addActionRowComponents(component);
|
|
263
|
+
break;
|
|
264
|
+
default:
|
|
265
|
+
throw new TypeError(`[ComponentsV2Builder] Unsupported component kind: ${String(kind)}`);
|
|
266
|
+
}
|
|
267
|
+
this.#lastKindByTarget.inside = kind;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
#appendComponent(component, kind) {
|
|
271
|
+
this.#flushPendingRow();
|
|
272
|
+
this.#appendDirect(component, kind, this.#placement);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
#ensureActionRow() {
|
|
276
|
+
if (this.#currentRow && this.#currentRowPlacement !== this.#placement) {
|
|
277
|
+
this.#flushPendingRow();
|
|
278
|
+
}
|
|
279
|
+
if (!this.#currentRow || this.#currentRow.components.length >= 5) {
|
|
280
|
+
this.#flushPendingRow();
|
|
281
|
+
this.#currentRow = new discord_js_1.ActionRowBuilder();
|
|
282
|
+
this.#currentRowPlacement = this.#placement;
|
|
283
|
+
}
|
|
284
|
+
return this.#currentRow;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
#createButton(input, customIdArg, styleArg, urlArg, extraArg) {
|
|
288
|
+
if (input instanceof discord_js_1.ButtonBuilder) {
|
|
289
|
+
return input;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const cfg =
|
|
293
|
+
input && typeof input === "object"
|
|
294
|
+
? input
|
|
295
|
+
: {
|
|
296
|
+
label: input,
|
|
297
|
+
customId: customIdArg,
|
|
298
|
+
style: styleArg,
|
|
299
|
+
url: urlArg,
|
|
300
|
+
...(extraArg && typeof extraArg === "object" ? extraArg : {}),
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const button = new discord_js_1.ButtonBuilder();
|
|
304
|
+
const resolvedStyle =
|
|
305
|
+
cfg.style !== undefined && cfg.style !== null
|
|
306
|
+
? StyleMapper_js_1.mapButtonStyle(cfg.style)
|
|
307
|
+
: cfg.url
|
|
308
|
+
? discord_js_1.ButtonStyle.Link
|
|
309
|
+
: discord_js_1.ButtonStyle.Primary;
|
|
310
|
+
|
|
311
|
+
button.setStyle(resolvedStyle);
|
|
312
|
+
|
|
313
|
+
const parsedEmoji = cfg.emoji ? helpers_js_1.parseEmoji(cfg.emoji) : null;
|
|
314
|
+
const hasLabel = cfg.label !== undefined && cfg.label !== null && String(cfg.label) !== "";
|
|
315
|
+
|
|
316
|
+
if (hasLabel) {
|
|
317
|
+
button.setLabel(String(cfg.label));
|
|
318
|
+
}
|
|
319
|
+
if (parsedEmoji) {
|
|
320
|
+
button.setEmoji(parsedEmoji);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const isLink = resolvedStyle === discord_js_1.ButtonStyle.Link;
|
|
324
|
+
const isPremium = discord_js_1.ButtonStyle.Premium !== undefined && resolvedStyle === discord_js_1.ButtonStyle.Premium;
|
|
325
|
+
|
|
326
|
+
if (!hasLabel && !parsedEmoji && !isPremium) {
|
|
327
|
+
throw new Error("[ComponentsV2Builder] A button requires a label, an emoji, or Premium skuId.");
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (isLink) {
|
|
331
|
+
if (!helpers_js_1.isValidLinkUrl(cfg.url)) {
|
|
332
|
+
throw new Error(`[ComponentsV2Builder] Link buttons require a valid http(s)/discord URL (received: ${String(cfg.url)}).`);
|
|
333
|
+
}
|
|
334
|
+
button.setURL(String(cfg.url).trim());
|
|
335
|
+
} else if (isPremium) {
|
|
336
|
+
if (!cfg.skuId) {
|
|
337
|
+
throw new Error("[ComponentsV2Builder] Premium buttons require a valid skuId.");
|
|
338
|
+
}
|
|
339
|
+
button.setSKUId(String(cfg.skuId));
|
|
340
|
+
} else {
|
|
341
|
+
const id = cfg.customId ?? cfg.id ?? helpers_js_1.generateCustomId("btn");
|
|
342
|
+
button.setCustomId(String(id));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (cfg.disabled !== undefined) {
|
|
346
|
+
button.setDisabled(Boolean(cfg.disabled));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return button;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
#normalizeTextInput(content, options = {}) {
|
|
353
|
+
if (content instanceof discord_js_1.TextDisplayBuilder) {
|
|
354
|
+
return content.data?.content ?? "";
|
|
355
|
+
}
|
|
356
|
+
if (Array.isArray(content)) {
|
|
357
|
+
const lines = content
|
|
358
|
+
.filter((line) => line !== false && line !== null && line !== undefined)
|
|
359
|
+
.map((line) => (line instanceof discord_js_1.TextDisplayBuilder ? line.data?.content ?? "" : String(line)))
|
|
360
|
+
.filter((line) => line.trim().length > 0);
|
|
361
|
+
return lines.join(options.joinWith ?? "\n");
|
|
362
|
+
}
|
|
363
|
+
return content;
|
|
364
|
+
}
|
|
73
365
|
|
|
74
366
|
/**
|
|
75
|
-
*
|
|
367
|
+
* Sets or clears the accent color of the active container.
|
|
76
368
|
*/
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
369
|
+
setColor(color) {
|
|
370
|
+
if (color === null) {
|
|
371
|
+
this.#activeContainerEntry.builder.clearAccentColor();
|
|
372
|
+
return this;
|
|
373
|
+
}
|
|
374
|
+
const resolved = helpers_js_1.resolveAccentColor(color);
|
|
375
|
+
if (resolved !== null) {
|
|
376
|
+
this.#activeContainerEntry.builder.setAccentColor(resolved);
|
|
377
|
+
}
|
|
378
|
+
return this;
|
|
82
379
|
}
|
|
83
380
|
|
|
84
|
-
|
|
381
|
+
/**
|
|
382
|
+
* Alias of `setColor(color)`.
|
|
383
|
+
*/
|
|
384
|
+
setAccentColor(color) {
|
|
385
|
+
return this.setColor(color);
|
|
386
|
+
}
|
|
85
387
|
|
|
86
388
|
/**
|
|
87
|
-
*
|
|
389
|
+
* Sets whether the active container is marked as a spoiler.
|
|
88
390
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this._flushButtons();
|
|
92
|
-
this._container.addTextDisplayComponents(
|
|
93
|
-
new discord_js_1.TextDisplayBuilder().setContent(content)
|
|
94
|
-
);
|
|
391
|
+
setSpoiler(spoiler = true) {
|
|
392
|
+
this.#activeContainerEntry.builder.setSpoiler(Boolean(spoiler));
|
|
95
393
|
return this;
|
|
96
394
|
}
|
|
97
395
|
|
|
98
396
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* @param spacing - "small" | "large" (defaults to "small")
|
|
102
|
-
* @param divider - Whether to render a visual divider line (defaults to true)
|
|
397
|
+
* Starts a new ContainerBuilder (switching placement back to `"inside"`).
|
|
103
398
|
*/
|
|
104
|
-
|
|
105
|
-
this
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
399
|
+
addContainer(options = {}) {
|
|
400
|
+
this.#flushPendingRow();
|
|
401
|
+
const nextEntry = this.#createContainerEntry(options);
|
|
402
|
+
if (
|
|
403
|
+
!this.#activeContainerEntry.hasContent &&
|
|
404
|
+
!this.#activeContainerEntry.attached &&
|
|
405
|
+
this.#topLevel.length === 0
|
|
406
|
+
) {
|
|
407
|
+
this.#activeContainerEntry = nextEntry;
|
|
408
|
+
} else {
|
|
409
|
+
this.#activeContainerEntry = nextEntry;
|
|
410
|
+
this.#ensureContainerAttached(nextEntry);
|
|
411
|
+
}
|
|
412
|
+
this.#placement = "inside";
|
|
413
|
+
this.#lastKindByTarget.inside = null;
|
|
114
414
|
return this;
|
|
115
415
|
}
|
|
116
416
|
|
|
117
417
|
/**
|
|
118
|
-
*
|
|
119
|
-
* Buttons are batched and placed into ActionRows automatically (max 5 per row).
|
|
120
|
-
*
|
|
121
|
-
* @param label - Button label text
|
|
122
|
-
* @param customId - Custom ID (or URL for link buttons)
|
|
123
|
-
* @param style - "primary" | "secondary" | "success" | "danger" | "link"
|
|
124
|
-
* @param url - URL (only used when style is "link")
|
|
418
|
+
* Switches component placement outside the container (top-level message components).
|
|
125
419
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
420
|
+
outside() {
|
|
421
|
+
this.#flushPendingRow();
|
|
422
|
+
this.#placement = "outside";
|
|
423
|
+
return this;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Switches component placement back inside the active container (or creates one if `options.new` is true).
|
|
428
|
+
*/
|
|
429
|
+
inside(options = {}) {
|
|
430
|
+
this.#flushPendingRow();
|
|
431
|
+
if (options?.new || options?.newContainer) {
|
|
432
|
+
return this.addContainer(options);
|
|
433
|
+
}
|
|
434
|
+
this.#placement = "inside";
|
|
435
|
+
if (options && (options.color !== undefined || options.accentColor !== undefined)) {
|
|
436
|
+
this.setColor(options.color !== undefined ? options.color : options.accentColor);
|
|
437
|
+
}
|
|
438
|
+
if (options?.spoiler !== undefined) {
|
|
439
|
+
this.setSpoiler(options.spoiler);
|
|
440
|
+
}
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
128
443
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
444
|
+
/**
|
|
445
|
+
* Adds a TextDisplay component. Pass `{ ignoreEmpty: true }` to skip empty/whitespace text safely.
|
|
446
|
+
*/
|
|
447
|
+
addText(content, options = {}) {
|
|
448
|
+
if (content instanceof discord_js_1.TextDisplayBuilder) {
|
|
449
|
+
this.#appendComponent(content, "text");
|
|
450
|
+
return this;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const normalized = this.#normalizeTextInput(content, options);
|
|
454
|
+
if (!helpers_js_1.validateTextContent(normalized, options)) {
|
|
455
|
+
return this;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const finalText = options.maxLength ? helpers_js_1.clipText(normalized, options.maxLength) : String(normalized);
|
|
459
|
+
if (!helpers_js_1.validateTextContent(finalText, options)) {
|
|
460
|
+
return this;
|
|
132
461
|
}
|
|
133
462
|
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
463
|
+
const textComponent = new discord_js_1.TextDisplayBuilder().setContent(finalText);
|
|
464
|
+
this.#appendComponent(textComponent, "text");
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
137
467
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
468
|
+
/**
|
|
469
|
+
* Adds formatted key/value rows (`> **Label:** value`), filtering falsy/empty rows automatically.
|
|
470
|
+
*/
|
|
471
|
+
addFields(rows, options = {}) {
|
|
472
|
+
const formatted = text_js_1.V2Text.fields(rows, options);
|
|
473
|
+
if (!formatted && options.omitIfEmpty !== false) {
|
|
474
|
+
return this;
|
|
475
|
+
}
|
|
476
|
+
if (!formatted) return this;
|
|
477
|
+
return this.addText(formatted, options);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Adds an independent section block (`**Heading**\n> **Label:** value`) with optional divider before it.
|
|
482
|
+
*/
|
|
483
|
+
addSectionBlock(heading, rows, options = {}) {
|
|
484
|
+
const formatted = text_js_1.V2Text.sectionBlock(heading, rows, options);
|
|
485
|
+
if (!formatted) return this;
|
|
486
|
+
|
|
487
|
+
const targetHasContent =
|
|
488
|
+
this.#placement === "outside"
|
|
489
|
+
? this.#topLevel.some((e) => e.kind === "outside")
|
|
490
|
+
: this.#activeContainerEntry.hasContent;
|
|
491
|
+
|
|
492
|
+
const wantsSeparator = options.separator !== false;
|
|
493
|
+
const lastKind = this.#lastKindByTarget[this.#placement];
|
|
494
|
+
if (targetHasContent && wantsSeparator && lastKind !== "separator") {
|
|
495
|
+
const spacing = typeof options.separator === "string" ? options.separator : "small";
|
|
496
|
+
this.addSeparator(spacing, true);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
return this.addText(formatted, options);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Adds a blockquote TextDisplay block.
|
|
504
|
+
*/
|
|
505
|
+
addQuote(text, options = {}) {
|
|
506
|
+
if (options.ignoreEmpty && (text === undefined || text === null || String(text).trim() === "")) {
|
|
507
|
+
return this;
|
|
508
|
+
}
|
|
509
|
+
const quoted = text_js_1.V2Text.quote(text, options.maxLength, options.fallback);
|
|
510
|
+
if (!quoted) return this;
|
|
511
|
+
return this.addText(quoted, options);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Adds text while protecting against Discord V2 text length limits (`overflow: "file" | "clip" | "split"`).
|
|
516
|
+
*/
|
|
517
|
+
addSmartText(text, options = {}) {
|
|
518
|
+
const raw = String(text ?? "");
|
|
519
|
+
if (raw.trim().length === 0) {
|
|
520
|
+
if (options.ignoreEmpty) return this;
|
|
521
|
+
helpers_js_1.validateTextContent(raw, options);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const budgetLeft = this.remainingChars;
|
|
525
|
+
const hardLimit = options.maxLength ?? helpers_js_1.SAFE_V2_TEXT_LENGTH;
|
|
526
|
+
const effectiveLimit = Math.max(0, Math.min(hardLimit, budgetLeft));
|
|
527
|
+
|
|
528
|
+
if (raw.length <= effectiveLimit && effectiveLimit > 0) {
|
|
529
|
+
return this.addText(options.codeBlock ? `\`\`\`${options.codeBlock}\n${raw}\n\`\`\`` : raw);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const overflow = options.overflow || "file";
|
|
533
|
+
|
|
534
|
+
if (overflow === "clip") {
|
|
535
|
+
if (effectiveLimit <= 0) return this;
|
|
536
|
+
const clipped = helpers_js_1.clipText(raw, effectiveLimit);
|
|
537
|
+
return this.addText(clipped, { ignoreEmpty: true });
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
if (overflow === "split") {
|
|
541
|
+
const chunkSize = Math.min(options.chunkSize ?? 1900, helpers_js_1.SAFE_V2_TEXT_LENGTH);
|
|
542
|
+
const chunks = splitTextIntoChunks(raw, chunkSize);
|
|
543
|
+
const overflowChunks = [];
|
|
544
|
+
|
|
545
|
+
for (const chunk of chunks) {
|
|
546
|
+
const canFitChars = this.remainingChars;
|
|
547
|
+
const canFitComponents = this.remainingComponents;
|
|
548
|
+
if (chunk.length <= canFitChars && canFitComponents >= 2) {
|
|
549
|
+
this.addText(chunk);
|
|
550
|
+
} else {
|
|
551
|
+
overflowChunks.push(chunk);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
if (overflowChunks.length > 0) {
|
|
556
|
+
const leftover = overflowChunks.join("\n\n");
|
|
557
|
+
if (options.fallbackToFile !== false) {
|
|
558
|
+
this.addFile(Buffer.from(raw, "utf8"), {
|
|
559
|
+
name: options.filename || "output.txt",
|
|
560
|
+
description: options.fileDescription,
|
|
561
|
+
spoiler: options.spoiler,
|
|
562
|
+
});
|
|
563
|
+
} else if (this.remainingChars > 10) {
|
|
564
|
+
this.addText(helpers_js_1.clipText(leftover, this.remainingChars), { ignoreEmpty: true });
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return this;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// overflow === "file"
|
|
571
|
+
const filename = options.filename || "output.txt";
|
|
572
|
+
const notice = options.overflowNotice ?? `-# Contenido completo adjunto en \`${sanitizeAttachmentName(filename, "output.txt")}\`.`;
|
|
573
|
+
|
|
574
|
+
if (options.preview !== false) {
|
|
575
|
+
const codePrefix = options.codeBlock ? `\`\`\`${options.codeBlock}\n` : "";
|
|
576
|
+
const codeSuffix = options.codeBlock ? "\n```" : "";
|
|
577
|
+
const overhead = codePrefix.length + codeSuffix.length + (notice ? notice.length + 2 : 0);
|
|
578
|
+
const maxPreviewLen = Math.min(options.previewLimit ?? 600, Math.max(0, effectiveLimit - overhead));
|
|
579
|
+
|
|
580
|
+
if (maxPreviewLen >= 40) {
|
|
581
|
+
const clippedPreview = helpers_js_1.clipText(raw, maxPreviewLen);
|
|
582
|
+
const body = `${codePrefix}${clippedPreview}${codeSuffix}${notice ? `\n${notice}` : ""}`;
|
|
583
|
+
this.addText(body, { ignoreEmpty: true });
|
|
584
|
+
} else if (notice && notice.length <= effectiveLimit) {
|
|
585
|
+
this.addText(notice, { ignoreEmpty: true });
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return this.addFile(Buffer.from(raw, "utf8"), {
|
|
590
|
+
name: filename,
|
|
591
|
+
description: options.fileDescription,
|
|
592
|
+
spoiler: options.spoiler,
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Adds a Section (1-3 TextDisplay components paired with a Thumbnail or Button accessory).
|
|
598
|
+
* Falls back to `addText` automatically when no valid accessory is supplied (unless `fallbackToText: false`).
|
|
599
|
+
*/
|
|
600
|
+
addSection(texts, accessoryOrOptions = {}) {
|
|
601
|
+
let options = {};
|
|
602
|
+
let thumbnailAccessory = null;
|
|
603
|
+
let buttonAccessory = null;
|
|
604
|
+
|
|
605
|
+
if (accessoryOrOptions instanceof discord_js_1.ThumbnailBuilder) {
|
|
606
|
+
thumbnailAccessory = accessoryOrOptions;
|
|
607
|
+
} else if (accessoryOrOptions instanceof discord_js_1.ButtonBuilder) {
|
|
608
|
+
buttonAccessory = accessoryOrOptions;
|
|
609
|
+
} else if (accessoryOrOptions && typeof accessoryOrOptions === "object") {
|
|
610
|
+
options = accessoryOrOptions;
|
|
611
|
+
if (options.thumbnail instanceof discord_js_1.ThumbnailBuilder) {
|
|
612
|
+
thumbnailAccessory = options.thumbnail;
|
|
613
|
+
} else if (options.thumbnail) {
|
|
614
|
+
const thumbCfg = typeof options.thumbnail === "string" ? { url: options.thumbnail } : options.thumbnail;
|
|
615
|
+
if (thumbCfg && helpers_js_1.isValidMediaUrl(thumbCfg.url)) {
|
|
616
|
+
thumbnailAccessory = new discord_js_1.ThumbnailBuilder().setURL(thumbCfg.url.trim());
|
|
617
|
+
const desc = thumbCfg.description ?? options.thumbnailDescription;
|
|
618
|
+
if (desc) thumbnailAccessory.setDescription(String(desc));
|
|
619
|
+
const spoiler = thumbCfg.spoiler ?? options.thumbnailSpoiler;
|
|
620
|
+
if (spoiler !== undefined) thumbnailAccessory.setSpoiler(Boolean(spoiler));
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
if (!thumbnailAccessory && options.button) {
|
|
625
|
+
buttonAccessory = this.#createButton(options.button);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
const textBuilders = [];
|
|
630
|
+
if (Array.isArray(texts) && texts.some((item) => item instanceof discord_js_1.TextDisplayBuilder)) {
|
|
631
|
+
for (const item of texts) {
|
|
632
|
+
if (!item) continue;
|
|
633
|
+
if (item instanceof discord_js_1.TextDisplayBuilder) {
|
|
634
|
+
textBuilders.push(item);
|
|
635
|
+
} else {
|
|
636
|
+
const str = String(item).trim();
|
|
637
|
+
if (str) textBuilders.push(new discord_js_1.TextDisplayBuilder().setContent(str));
|
|
638
|
+
}
|
|
142
639
|
}
|
|
143
|
-
btn.setURL(url);
|
|
144
640
|
} else {
|
|
145
|
-
|
|
641
|
+
const normalized = this.#normalizeTextInput(texts, options);
|
|
642
|
+
if (!helpers_js_1.validateTextContent(normalized, options)) {
|
|
643
|
+
return this;
|
|
644
|
+
}
|
|
645
|
+
const finalText = options.maxLength ? helpers_js_1.clipText(normalized, options.maxLength) : String(normalized);
|
|
646
|
+
textBuilders.push(new discord_js_1.TextDisplayBuilder().setContent(finalText));
|
|
146
647
|
}
|
|
147
648
|
|
|
148
|
-
|
|
649
|
+
if (textBuilders.length === 0) {
|
|
650
|
+
if (options.ignoreEmpty) return this;
|
|
651
|
+
throw new Error("[ComponentsV2Builder] Section requires at least one non-empty text display.");
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
if (!thumbnailAccessory && !buttonAccessory) {
|
|
655
|
+
if (options.fallbackToText !== false) {
|
|
656
|
+
for (const tb of textBuilders) {
|
|
657
|
+
this.#appendComponent(tb, "text");
|
|
658
|
+
}
|
|
659
|
+
return this;
|
|
660
|
+
}
|
|
661
|
+
throw new Error("[ComponentsV2Builder] Section requires a valid thumbnail URL or button accessory.");
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
if (textBuilders.length > 3) {
|
|
665
|
+
const merged = textBuilders.map((tb) => tb.data?.content || "").filter(Boolean).join("\n");
|
|
666
|
+
textBuilders.length = 0;
|
|
667
|
+
textBuilders.push(new discord_js_1.TextDisplayBuilder().setContent(merged));
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const section = new discord_js_1.SectionBuilder().addTextDisplayComponents(...textBuilders);
|
|
671
|
+
if (thumbnailAccessory) {
|
|
672
|
+
section.setThumbnailAccessory(thumbnailAccessory);
|
|
673
|
+
} else if (buttonAccessory) {
|
|
674
|
+
section.setButtonAccessory(buttonAccessory);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
this.#appendComponent(section, "section");
|
|
149
678
|
return this;
|
|
150
679
|
}
|
|
151
680
|
|
|
152
681
|
/**
|
|
153
|
-
*
|
|
154
|
-
* They are batched into ActionRows automatically (max 5 per row).
|
|
682
|
+
* Adds a MediaGallery component (`http://`, `https://`, or `attachment://` URLs).
|
|
155
683
|
*/
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
684
|
+
addGallery(itemsOrUrl, options = {}) {
|
|
685
|
+
if (itemsOrUrl instanceof discord_js_1.MediaGalleryBuilder) {
|
|
686
|
+
this.#appendComponent(itemsOrUrl, "gallery");
|
|
687
|
+
return this;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
const rawList = Array.isArray(itemsOrUrl) ? itemsOrUrl : [itemsOrUrl];
|
|
691
|
+
const validItems = [];
|
|
692
|
+
|
|
693
|
+
for (const entry of rawList) {
|
|
694
|
+
if (!entry) {
|
|
695
|
+
if (options.ignoreEmpty || options.ignoreInvalid) continue;
|
|
696
|
+
if (!Array.isArray(itemsOrUrl)) {
|
|
697
|
+
throw new Error("[ComponentsV2Builder] Invalid or empty media URL for MediaGallery.");
|
|
698
|
+
}
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
if (entry instanceof discord_js_1.MediaGalleryItemBuilder) {
|
|
703
|
+
validItems.push(entry);
|
|
704
|
+
continue;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
const cfg = typeof entry === "string" ? { url: entry } : entry;
|
|
708
|
+
const url = cfg?.url;
|
|
709
|
+
if (!helpers_js_1.isValidMediaUrl(url)) {
|
|
710
|
+
if (options.ignoreInvalid) continue;
|
|
711
|
+
throw new Error(`[ComponentsV2Builder] Invalid media URL for MediaGallery: ${String(url)}`);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
const item = new discord_js_1.MediaGalleryItemBuilder().setURL(url.trim());
|
|
715
|
+
const desc = cfg.description ?? options.description;
|
|
716
|
+
if (desc) item.setDescription(String(desc));
|
|
717
|
+
const spoiler = cfg.spoiler ?? options.spoiler;
|
|
718
|
+
if (spoiler !== undefined) item.setSpoiler(Boolean(spoiler));
|
|
719
|
+
validItems.push(item);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
if (validItems.length === 0) {
|
|
723
|
+
if (options.ignoreEmpty || options.ignoreInvalid) return this;
|
|
724
|
+
throw new Error("[ComponentsV2Builder] MediaGallery requires at least one valid media item.");
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (validItems.length > 10 && !options.autoSplit) {
|
|
728
|
+
throw new Error("[ComponentsV2Builder] A MediaGallery cannot contain more than 10 items.");
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
for (let i = 0; i < validItems.length; i += 10) {
|
|
732
|
+
const slice = validItems.slice(i, i + 10);
|
|
733
|
+
const gallery = new discord_js_1.MediaGalleryBuilder().addItems(...slice);
|
|
734
|
+
this.#appendComponent(gallery, "gallery");
|
|
735
|
+
}
|
|
736
|
+
return this;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Attaches an AttachmentBuilder without emitting a File component (useful for `attachment://` galleries/thumbnails).
|
|
741
|
+
*/
|
|
742
|
+
addAttachment(source, options = {}) {
|
|
743
|
+
if (source instanceof discord_js_1.AttachmentBuilder) {
|
|
744
|
+
if (options.name) source.setName(sanitizeAttachmentName(options.name));
|
|
745
|
+
if (options.description) source.setDescription(String(options.description));
|
|
746
|
+
this.#files.push(source);
|
|
747
|
+
return this;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const defaultName = typeof source === "string" ? path_1.basename(source) : "file.bin";
|
|
751
|
+
const filename = sanitizeAttachmentName(options.name || defaultName);
|
|
752
|
+
const attachmentOptions = { name: filename };
|
|
753
|
+
if (options.description) attachmentOptions.description = String(options.description);
|
|
754
|
+
|
|
755
|
+
const attachment = new discord_js_1.AttachmentBuilder(source, attachmentOptions);
|
|
756
|
+
this.#files.push(attachment);
|
|
757
|
+
return this;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Adds a File component and automatically registers its AttachmentBuilder in `files`.
|
|
762
|
+
* If `source` is already an `attachment://...` URL, adds only the File component.
|
|
763
|
+
*/
|
|
764
|
+
addFile(source, options = {}) {
|
|
765
|
+
if (source instanceof discord_js_1.FileBuilder) {
|
|
766
|
+
this.#appendComponent(source, "file");
|
|
767
|
+
return this;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
let attachmentUrl;
|
|
771
|
+
if (typeof source === "string" && /^attachment:\/\/[^\s/]+$/i.test(source.trim())) {
|
|
772
|
+
attachmentUrl = source.trim();
|
|
773
|
+
if (options.attachment) {
|
|
774
|
+
this.addAttachment(options.attachment, options);
|
|
775
|
+
}
|
|
776
|
+
} else if (source instanceof discord_js_1.AttachmentBuilder) {
|
|
777
|
+
const name = sanitizeAttachmentName(options.name || source.name || "file.bin");
|
|
778
|
+
if (!source.name) source.setName(name);
|
|
779
|
+
this.addAttachment(source, { ...options, name });
|
|
780
|
+
attachmentUrl = `attachment://${source.name}`;
|
|
781
|
+
} else {
|
|
782
|
+
const defaultName = typeof source === "string" ? path_1.basename(source) : "file.bin";
|
|
783
|
+
const name = sanitizeAttachmentName(options.name || defaultName);
|
|
784
|
+
this.addAttachment(source, { ...options, name });
|
|
785
|
+
attachmentUrl = `attachment://${name}`;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
const fileBuilder = new discord_js_1.FileBuilder().setURL(attachmentUrl);
|
|
789
|
+
if (options.spoiler !== undefined) {
|
|
790
|
+
fileBuilder.setSpoiler(Boolean(options.spoiler));
|
|
791
|
+
}
|
|
792
|
+
this.#appendComponent(fileBuilder, "file");
|
|
793
|
+
return this;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Adds a visual separator or empty spacer (`divider: false`).
|
|
798
|
+
*/
|
|
799
|
+
addSeparator(spacing = "small", divider = true) {
|
|
800
|
+
let spacingArg = spacing;
|
|
801
|
+
let dividerArg = divider;
|
|
802
|
+
|
|
803
|
+
if (spacing && typeof spacing === "object") {
|
|
804
|
+
spacingArg = spacing.spacing ?? "small";
|
|
805
|
+
dividerArg = spacing.divider !== undefined ? Boolean(spacing.divider) : true;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
const size =
|
|
809
|
+
spacingArg === "large" || spacingArg === discord_js_1.SeparatorSpacingSize.Large
|
|
810
|
+
? discord_js_1.SeparatorSpacingSize.Large
|
|
811
|
+
: discord_js_1.SeparatorSpacingSize.Small;
|
|
812
|
+
|
|
813
|
+
const separator = new discord_js_1.SeparatorBuilder().setSpacing(size).setDivider(Boolean(dividerArg));
|
|
814
|
+
this.#appendComponent(separator, "separator");
|
|
815
|
+
return this;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* Shorthand for an invisible vertical spacer (`addSeparator(spacing, false)`).
|
|
820
|
+
*/
|
|
821
|
+
addSpacer(spacing = "small") {
|
|
822
|
+
return this.addSeparator(spacing, false);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Adds a button to the current button ActionRow (creating a new row automatically at 5 buttons).
|
|
827
|
+
* Supports both an options object `{ label, customId, id, style, url, emoji, disabled }`
|
|
828
|
+
* and legacy positional args `(label, customId, style, url)`.
|
|
829
|
+
*/
|
|
830
|
+
addButton(labelOrConfig, customId, style, url, extraOptions) {
|
|
831
|
+
const button = this.#createButton(labelOrConfig, customId, style, url, extraOptions);
|
|
832
|
+
this.#ensureActionRow().addComponents(button);
|
|
833
|
+
return this;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Adds a dedicated ActionRow containing up to 5 buttons (flushes any previous open button row).
|
|
838
|
+
*/
|
|
839
|
+
addButtons(buttons, options = {}) {
|
|
840
|
+
this.#flushPendingRow();
|
|
841
|
+
const list = (Array.isArray(buttons) ? buttons : []).filter(Boolean);
|
|
842
|
+
if (list.length === 0) return this;
|
|
843
|
+
|
|
844
|
+
if (!options.autoWrap) {
|
|
845
|
+
helpers_js_1.validateButtonCount(list.length);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
for (let i = 0; i < list.length; i += 5) {
|
|
849
|
+
const chunk = list.slice(i, i + 5);
|
|
850
|
+
const row = new discord_js_1.ActionRowBuilder();
|
|
851
|
+
for (const item of chunk) {
|
|
852
|
+
if (Array.isArray(item)) {
|
|
853
|
+
row.addComponents(this.#createButton(item[0], item[1], item[2], item[3], item[4]));
|
|
854
|
+
} else {
|
|
855
|
+
row.addComponents(this.#createButton(item));
|
|
856
|
+
}
|
|
160
857
|
}
|
|
161
|
-
this
|
|
858
|
+
this.#appendDirect(row, "actionRow", this.#placement);
|
|
162
859
|
}
|
|
860
|
+
|
|
163
861
|
return this;
|
|
164
862
|
}
|
|
165
863
|
|
|
166
864
|
/**
|
|
167
|
-
*
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
865
|
+
* Alias of `addButtons(buttons, options)` for explicit ActionRow ergonomics.
|
|
866
|
+
*/
|
|
867
|
+
addButtonsRow(buttons, options = {}) {
|
|
868
|
+
return this.addButtons(buttons, options);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* Starts a legacy chained StringSelectMenu (`SelectMenuProxy`) OR adds a full select menu
|
|
873
|
+
* when passed an options object `{ customId, type, placeholder, options, ... }`.
|
|
173
874
|
*/
|
|
174
|
-
addSelectMenu(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
875
|
+
addSelectMenu(customIdOrConfig, placeholder = "Select an option") {
|
|
876
|
+
if (customIdOrConfig && typeof customIdOrConfig === "object") {
|
|
877
|
+
return this.addSelectRow(customIdOrConfig);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
this.#flushPendingRow();
|
|
881
|
+
const select = new discord_js_1.StringSelectMenuBuilder()
|
|
882
|
+
.setCustomId(String(customIdOrConfig || helpers_js_1.generateCustomId("select")))
|
|
883
|
+
.setPlaceholder(String(placeholder));
|
|
884
|
+
|
|
885
|
+
const row = new discord_js_1.ActionRowBuilder().addComponents(select);
|
|
886
|
+
this.#appendDirect(row, "actionRow", this.#placement);
|
|
887
|
+
return new SelectMenuProxy(this, select);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Adds an ActionRow containing any Discord select menu (`string`, `user`, `role`, `channel`, `mentionable`).
|
|
892
|
+
*/
|
|
893
|
+
addSelectRow(config = {}) {
|
|
894
|
+
this.#flushPendingRow();
|
|
895
|
+
const type = SELECT_TYPE_MAP[String(config.type || "string").toLowerCase()] || "string";
|
|
896
|
+
const customId = String(config.customId ?? config.id ?? helpers_js_1.generateCustomId("select"));
|
|
897
|
+
|
|
898
|
+
let menu;
|
|
899
|
+
switch (type) {
|
|
900
|
+
case "user":
|
|
901
|
+
menu = new discord_js_1.UserSelectMenuBuilder();
|
|
902
|
+
if (Array.isArray(config.defaultUsers) && config.defaultUsers.length > 0) {
|
|
903
|
+
menu.setDefaultUsers(config.defaultUsers);
|
|
904
|
+
} else if (Array.isArray(config.defaultValues) && config.defaultValues.length > 0) {
|
|
905
|
+
menu.setDefaultUsers(config.defaultValues);
|
|
906
|
+
}
|
|
907
|
+
break;
|
|
908
|
+
|
|
909
|
+
case "role":
|
|
910
|
+
menu = new discord_js_1.RoleSelectMenuBuilder();
|
|
911
|
+
if (Array.isArray(config.defaultRoles) && config.defaultRoles.length > 0) {
|
|
912
|
+
menu.setDefaultRoles(config.defaultRoles);
|
|
913
|
+
} else if (Array.isArray(config.defaultValues) && config.defaultValues.length > 0) {
|
|
914
|
+
menu.setDefaultRoles(config.defaultValues);
|
|
915
|
+
}
|
|
916
|
+
break;
|
|
917
|
+
|
|
918
|
+
case "channel":
|
|
919
|
+
menu = new discord_js_1.ChannelSelectMenuBuilder();
|
|
920
|
+
if (Array.isArray(config.channelTypes) && config.channelTypes.length > 0) {
|
|
921
|
+
menu.setChannelTypes(config.channelTypes);
|
|
922
|
+
}
|
|
923
|
+
if (Array.isArray(config.defaultChannels) && config.defaultChannels.length > 0) {
|
|
924
|
+
menu.setDefaultChannels(config.defaultChannels);
|
|
925
|
+
} else if (Array.isArray(config.defaultValues) && config.defaultValues.length > 0) {
|
|
926
|
+
menu.setDefaultChannels(config.defaultValues);
|
|
927
|
+
}
|
|
928
|
+
break;
|
|
929
|
+
|
|
930
|
+
case "mentionable":
|
|
931
|
+
menu = new discord_js_1.MentionableSelectMenuBuilder();
|
|
932
|
+
if (Array.isArray(config.defaultValues) && config.defaultValues.length > 0) {
|
|
933
|
+
menu.setDefaultValues(config.defaultValues);
|
|
934
|
+
} else {
|
|
935
|
+
if (Array.isArray(config.defaultUsers) && config.defaultUsers.length > 0) {
|
|
936
|
+
menu.addDefaultUsers(config.defaultUsers);
|
|
937
|
+
}
|
|
938
|
+
if (Array.isArray(config.defaultRoles) && config.defaultRoles.length > 0) {
|
|
939
|
+
menu.addDefaultRoles(config.defaultRoles);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
break;
|
|
943
|
+
|
|
944
|
+
case "string":
|
|
945
|
+
default: {
|
|
946
|
+
menu = new discord_js_1.StringSelectMenuBuilder();
|
|
947
|
+
const proxy = new SelectMenuProxy(this, menu);
|
|
948
|
+
if (Array.isArray(config.options) && config.options.length > 0) {
|
|
949
|
+
proxy.addOptions(config.options);
|
|
950
|
+
}
|
|
951
|
+
break;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
menu.setCustomId(customId);
|
|
956
|
+
if (config.placeholder) menu.setPlaceholder(String(config.placeholder));
|
|
957
|
+
if (config.minValues !== undefined) menu.setMinValues(Number(config.minValues));
|
|
958
|
+
if (config.maxValues !== undefined) menu.setMaxValues(Number(config.maxValues));
|
|
959
|
+
if (config.disabled !== undefined) menu.setDisabled(Boolean(config.disabled));
|
|
179
960
|
|
|
180
|
-
// We need to add the row after options are configured; the proxy returns
|
|
181
|
-
// to us via `.end()` which flushes remaining buttons and adds the row.
|
|
182
|
-
// To support immediate chaining, we attach the row now — options get added
|
|
183
|
-
// by the proxy in-place (discord.js builders are mutable).
|
|
184
961
|
const row = new discord_js_1.ActionRowBuilder().addComponents(menu);
|
|
185
|
-
this
|
|
186
|
-
return
|
|
962
|
+
this.#appendDirect(row, "actionRow", this.#placement);
|
|
963
|
+
return this;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
addUserSelectMenu(configOrCustomId, options = {}) {
|
|
967
|
+
const cfg = typeof configOrCustomId === "string" ? { ...options, customId: configOrCustomId } : { ...configOrCustomId };
|
|
968
|
+
return this.addSelectRow({ ...cfg, type: "user" });
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
addRoleSelectMenu(configOrCustomId, options = {}) {
|
|
972
|
+
const cfg = typeof configOrCustomId === "string" ? { ...options, customId: configOrCustomId } : { ...configOrCustomId };
|
|
973
|
+
return this.addSelectRow({ ...cfg, type: "role" });
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
addChannelSelectMenu(configOrCustomId, options = {}) {
|
|
977
|
+
const cfg = typeof configOrCustomId === "string" ? { ...options, customId: configOrCustomId } : { ...configOrCustomId };
|
|
978
|
+
return this.addSelectRow({ ...cfg, type: "channel" });
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
addMentionableSelectMenu(configOrCustomId, options = {}) {
|
|
982
|
+
const cfg = typeof configOrCustomId === "string" ? { ...options, customId: configOrCustomId } : { ...configOrCustomId };
|
|
983
|
+
return this.addSelectRow({ ...cfg, type: "mentionable" });
|
|
187
984
|
}
|
|
188
985
|
|
|
189
986
|
/**
|
|
190
|
-
*
|
|
987
|
+
* Adds a raw discord.js component builder respecting the current container/outside placement.
|
|
191
988
|
*/
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
this
|
|
989
|
+
addComponent(component) {
|
|
990
|
+
if (!component) return this;
|
|
991
|
+
this.#flushPendingRow();
|
|
992
|
+
|
|
993
|
+
if (component instanceof discord_js_1.ContainerBuilder) {
|
|
994
|
+
this.#topLevel.push({ kind: "container", builder: component, hasContent: true, attached: true });
|
|
995
|
+
return this;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
const type = component?.data?.type;
|
|
999
|
+
if (component instanceof discord_js_1.TextDisplayBuilder || type === (discord_js_1.ComponentType?.TextDisplay ?? 10)) {
|
|
1000
|
+
this.#appendDirect(component, "text", this.#placement);
|
|
1001
|
+
} else if (component instanceof discord_js_1.SeparatorBuilder || type === (discord_js_1.ComponentType?.Separator ?? 14)) {
|
|
1002
|
+
this.#appendDirect(component, "separator", this.#placement);
|
|
1003
|
+
} else if (component instanceof discord_js_1.SectionBuilder || type === (discord_js_1.ComponentType?.Section ?? 9)) {
|
|
1004
|
+
this.#appendDirect(component, "section", this.#placement);
|
|
1005
|
+
} else if (component instanceof discord_js_1.MediaGalleryBuilder || type === (discord_js_1.ComponentType?.MediaGallery ?? 12)) {
|
|
1006
|
+
this.#appendDirect(component, "gallery", this.#placement);
|
|
1007
|
+
} else if (component instanceof discord_js_1.FileBuilder || type === (discord_js_1.ComponentType?.File ?? 13)) {
|
|
1008
|
+
this.#appendDirect(component, "file", this.#placement);
|
|
1009
|
+
} else if (component instanceof discord_js_1.ActionRowBuilder || type === (discord_js_1.ComponentType?.ActionRow ?? 1)) {
|
|
1010
|
+
this.#appendDirect(component, "actionRow", this.#placement);
|
|
1011
|
+
} else {
|
|
1012
|
+
this.#topLevel.push({ kind: "outside", component });
|
|
1013
|
+
}
|
|
195
1014
|
return this;
|
|
196
1015
|
}
|
|
197
1016
|
|
|
198
1017
|
/**
|
|
199
|
-
*
|
|
200
|
-
* `interaction.reply({ components })`.
|
|
201
|
-
*
|
|
202
|
-
* The `MessageFlags.IsComponentsV2` flag is **not** added here because it
|
|
203
|
-
* must be set on the reply options object itself, not inside the components
|
|
204
|
-
* array. Use the helper `ComponentsV2Builder.flags` constant when replying:
|
|
205
|
-
*
|
|
206
|
-
* ```js
|
|
207
|
-
* interaction.reply({ components: builder.build(), flags: ComponentsV2Builder.flags });
|
|
208
|
-
* ```
|
|
1018
|
+
* Total character count across all TextDisplay components added so far.
|
|
209
1019
|
*/
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
return [this._container];
|
|
1020
|
+
get textLength() {
|
|
1021
|
+
return helpers_js_1.countTextLength(this.#snapshotComponents());
|
|
213
1022
|
}
|
|
214
1023
|
|
|
215
|
-
|
|
1024
|
+
/**
|
|
1025
|
+
* Remaining characters before reaching Discord's 4,000-char V2 text display limit.
|
|
1026
|
+
*/
|
|
1027
|
+
get remainingChars() {
|
|
1028
|
+
return Math.max(0, helpers_js_1.MAX_V2_TEXT_LENGTH - this.textLength);
|
|
1029
|
+
}
|
|
216
1030
|
|
|
217
1031
|
/**
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* ```js
|
|
221
|
-
* interaction.reply({ components: builder.build(), flags: ComponentsV2Builder.flags });
|
|
222
|
-
* ```
|
|
1032
|
+
* Total component count (including nested Container, Section, ActionRow, and MediaGallery items).
|
|
223
1033
|
*/
|
|
224
|
-
|
|
225
|
-
return
|
|
1034
|
+
get componentCount() {
|
|
1035
|
+
return helpers_js_1.countComponents(this.#snapshotComponents());
|
|
226
1036
|
}
|
|
227
1037
|
|
|
228
|
-
|
|
1038
|
+
/**
|
|
1039
|
+
* Remaining component budget before reaching Discord's 40-component V2 limit.
|
|
1040
|
+
*/
|
|
1041
|
+
get remainingComponents() {
|
|
1042
|
+
return Math.max(0, helpers_js_1.MAX_V2_COMPONENTS - this.componentCount);
|
|
1043
|
+
}
|
|
229
1044
|
|
|
230
1045
|
/**
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* @param confirmId - Custom ID for the confirm button (default: "cv2_confirm")
|
|
234
|
-
* @param cancelId - Custom ID for the cancel button (default: "cv2_cancel")
|
|
1046
|
+
* Shallow copy of all AttachmentBuilders registered via `.addFile()` or `.addAttachment()`.
|
|
235
1047
|
*/
|
|
236
|
-
|
|
237
|
-
return
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
1048
|
+
get files() {
|
|
1049
|
+
return [...this.#files];
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
#snapshotComponents() {
|
|
1053
|
+
const out = [];
|
|
1054
|
+
for (const entry of this.#topLevel) {
|
|
1055
|
+
if (entry.kind === "container") {
|
|
1056
|
+
if (entry.hasContent) out.push(entry.builder);
|
|
1057
|
+
} else {
|
|
1058
|
+
out.push(entry.component);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
if (this.#currentRow && this.#currentRow.components?.length) {
|
|
1062
|
+
out.push(this.#currentRow);
|
|
1063
|
+
}
|
|
1064
|
+
return out;
|
|
242
1065
|
}
|
|
243
1066
|
|
|
244
1067
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
* @param customId - Custom ID for the select menu (default: "cv2_ticket_menu")
|
|
1068
|
+
* Builds and returns the array of top-level discord.js V2 component builders.
|
|
248
1069
|
*/
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
.
|
|
254
|
-
.
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
1070
|
+
build() {
|
|
1071
|
+
this.#flushPendingRow();
|
|
1072
|
+
const result = [];
|
|
1073
|
+
for (const entry of this.#topLevel) {
|
|
1074
|
+
if (entry.kind === "container") {
|
|
1075
|
+
if (entry.hasContent) {
|
|
1076
|
+
result.push(entry.builder);
|
|
1077
|
+
}
|
|
1078
|
+
} else {
|
|
1079
|
+
result.push(entry.component);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
if (result.length === 0 && this.#topLevel.length === 0) {
|
|
1084
|
+
return [this.#activeContainerEntry.builder];
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
return result;
|
|
258
1088
|
}
|
|
259
1089
|
|
|
260
1090
|
/**
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* @param customId - Custom ID for the select menu (default: "cv2_plan_menu")
|
|
1091
|
+
* Serializes the built top-level components into plain JSON objects.
|
|
264
1092
|
*/
|
|
265
|
-
|
|
266
|
-
return
|
|
267
|
-
.addText("## Welcome!\nPlease select the plan you want to join!")
|
|
268
|
-
.addSeparator("small")
|
|
269
|
-
.addButton("Discord Bot Hosting", "plan_bot", "primary")
|
|
270
|
-
.addButton("Game Hosting", "plan_game", "success")
|
|
271
|
-
.addButton("Web Hosting", "plan_web", "danger");
|
|
1093
|
+
toJSON() {
|
|
1094
|
+
return this.build().map((comp) => (typeof comp?.toJSON === "function" ? comp.toJSON() : comp));
|
|
272
1095
|
}
|
|
273
1096
|
|
|
274
1097
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* @param customId - Custom ID for the select menu (default: "cv2_role_menu")
|
|
1098
|
+
* Builds a ready-to-send Discord message/interaction payload with `IsComponentsV2` flag,
|
|
1099
|
+
* optional ephemeral/notification flags, attached files, and safe `allowedMentions`.
|
|
278
1100
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
1101
|
+
toPayload(options = {}) {
|
|
1102
|
+
const components = this.build();
|
|
1103
|
+
let flags = discord_js_1.MessageFlags.IsComponentsV2;
|
|
1104
|
+
|
|
1105
|
+
if (options.ephemeral) {
|
|
1106
|
+
flags |= discord_js_1.MessageFlags.Ephemeral;
|
|
1107
|
+
}
|
|
1108
|
+
if (options.suppressNotifications && discord_js_1.MessageFlags.SuppressNotifications !== undefined) {
|
|
1109
|
+
flags |= discord_js_1.MessageFlags.SuppressNotifications;
|
|
1110
|
+
}
|
|
1111
|
+
if (typeof options.flags === "number" && Number.isFinite(options.flags)) {
|
|
1112
|
+
flags |= options.flags;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
const extraFiles = Array.isArray(options.files) ? options.files.filter(Boolean) : [];
|
|
1116
|
+
const mergedFiles = [...this.#files, ...extraFiles];
|
|
1117
|
+
|
|
1118
|
+
const payload = {
|
|
1119
|
+
components,
|
|
1120
|
+
flags,
|
|
1121
|
+
};
|
|
1122
|
+
|
|
1123
|
+
if (mergedFiles.length > 0) {
|
|
1124
|
+
payload.files = mergedFiles;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
const useSafeMentions = options.safeMentions !== undefined ? options.safeMentions : this.#defaultSafeMentions;
|
|
1128
|
+
if (options.allowedMentions !== undefined) {
|
|
1129
|
+
payload.allowedMentions = options.allowedMentions;
|
|
1130
|
+
} else if (useSafeMentions) {
|
|
1131
|
+
payload.allowedMentions = { parse: [], repliedUser: false };
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
return payload;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
// =========================================================================
|
|
1138
|
+
// Agnostic & legacy static template factories
|
|
1139
|
+
// =========================================================================
|
|
1140
|
+
|
|
1141
|
+
static card(options) {
|
|
1142
|
+
return templates.createCard(options);
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
static imageView(options) {
|
|
1146
|
+
return templates.createImageView(options);
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
static list(options) {
|
|
1150
|
+
return templates.createList(options);
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
static confirm(confirmIdOrOptions, cancelId, title, message) {
|
|
1154
|
+
return templates.createConfirm(confirmIdOrOptions, cancelId, title, message);
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
static createConfirm(confirmIdOrOptions, cancelId, title, message) {
|
|
1158
|
+
return templates.createConfirm(confirmIdOrOptions, cancelId, title, message);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
static createTicketMenu(customId, title, description) {
|
|
1162
|
+
return templates.createTicketMenu(customId, title, description);
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
static createPlanSelector(customId, title, description) {
|
|
1166
|
+
return templates.createPlanSelector(customId, title, description);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
static createRoleMenu(customId, title, description) {
|
|
1170
|
+
return templates.createRoleMenu(customId, title, description);
|
|
285
1171
|
}
|
|
286
1172
|
}
|
|
1173
|
+
|
|
287
1174
|
exports.ComponentsV2Builder = ComponentsV2Builder;
|