lunibee 0.1.1 → 0.1.3
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/LICENSE +21 -0
- package/README.md +234 -11
- package/dist/builders/attachment.d.ts +20 -0
- package/dist/builders/commands.d.ts +118 -0
- package/dist/builders/components.d.ts +151 -0
- package/dist/builders/embed.d.ts +59 -0
- package/dist/builders/index.d.ts +5 -0
- package/dist/builders/index.js +828 -0
- package/dist/builders/index.js.map +13 -0
- package/dist/collection/cache.d.ts +37 -0
- package/dist/collection/index.d.ts +47 -0
- package/dist/collection/index.js +214 -0
- package/dist/collection/index.js.map +11 -0
- package/dist/core/client-state.d.ts +10 -0
- package/dist/core/collector.d.ts +27 -0
- package/dist/core/events.d.ts +5 -0
- package/dist/core/index.d.ts +111 -0
- package/dist/core/index.js +3188 -0
- package/dist/core/index.js.map +29 -0
- package/dist/core/permissions.d.ts +293 -0
- package/dist/formatters/index.d.ts +10 -0
- package/dist/formatters/index.js +43 -0
- package/dist/formatters/index.js.map +10 -0
- package/dist/handlers/index.d.ts +16 -0
- package/dist/handlers/index.js +37 -0
- package/dist/handlers/index.js.map +10 -0
- package/{src/index.ts → dist/index.d.ts} +2 -29
- package/dist/index.js +4182 -0
- package/dist/index.js.map +41 -0
- package/dist/managers/application.d.ts +28 -0
- package/dist/managers/base.d.ts +28 -0
- package/dist/managers/index.d.ts +96 -0
- package/dist/managers/index.js +947 -0
- package/dist/managers/index.js.map +22 -0
- package/dist/managers/member.d.ts +35 -0
- package/dist/managers/message.d.ts +25 -0
- package/dist/managers/role.d.ts +34 -0
- package/dist/managers/thread.d.ts +14 -0
- package/dist/rest/index.d.ts +49 -0
- package/dist/rest/index.js +344 -0
- package/dist/rest/index.js.map +12 -0
- package/dist/rest/routes.d.ts +44 -0
- package/dist/rest/types.d.ts +26 -0
- package/dist/rest/webhook.d.ts +40 -0
- package/dist/sharding/bus.d.ts +22 -0
- package/dist/sharding/index.d.ts +34 -0
- package/dist/sharding/index.js +732 -0
- package/dist/sharding/index.js.map +13 -0
- package/dist/structures/base.d.ts +75 -0
- package/dist/structures/index.d.ts +39 -0
- package/dist/structures/index.js +571 -0
- package/dist/structures/index.js.map +14 -0
- package/dist/structures/interactions.d.ts +136 -0
- package/dist/structures/permissions.d.ts +73 -0
- package/dist/structures/resources.d.ts +64 -0
- package/dist/types/index.d.ts +535 -0
- package/dist/types/index.js +132 -0
- package/dist/types/index.js.map +10 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/index.js.map +10 -0
- package/dist/voice/index.d.ts +97 -0
- package/dist/voice/index.js +161 -0
- package/dist/voice/index.js.map +10 -0
- package/dist/ws/index.d.ts +76 -0
- package/dist/ws/index.js +582 -0
- package/dist/ws/index.js.map +11 -0
- package/package.json +113 -28
|
@@ -0,0 +1,828 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/builders/src/embed.ts
|
|
3
|
+
class EmbedBuilder {
|
|
4
|
+
#data = {};
|
|
5
|
+
setTitle(value) {
|
|
6
|
+
this.#data.title = validate(value, 256, "Embed title");
|
|
7
|
+
return this;
|
|
8
|
+
}
|
|
9
|
+
setDescription(value) {
|
|
10
|
+
this.#data.description = validate(value, 4096, "Embed description");
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
setURL(value) {
|
|
14
|
+
this.#data.url = url(value, "Embed URL");
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
setColor(value) {
|
|
18
|
+
if (!Number.isInteger(value) || value < 0 || value > 16777215)
|
|
19
|
+
throw new RangeError("Embed color must be an integer between 0 and 16777215.");
|
|
20
|
+
this.#data.color = value;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
setTimestamp(value = new Date) {
|
|
24
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
25
|
+
if (Number.isNaN(date.getTime()))
|
|
26
|
+
throw new RangeError("Embed timestamp must be a valid date.");
|
|
27
|
+
this.#data.timestamp = date.toISOString();
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
setFooter(value) {
|
|
31
|
+
this.#data.footer = {
|
|
32
|
+
text: validate(value.text, 2048, "Footer text"),
|
|
33
|
+
...value.icon_url ? { icon_url: url(value.icon_url, "Footer icon URL") } : {}
|
|
34
|
+
};
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
setAuthor(value) {
|
|
38
|
+
this.#data.author = {
|
|
39
|
+
name: validate(value.name, 256, "Author name"),
|
|
40
|
+
...value.url ? { url: url(value.url, "Author URL") } : {},
|
|
41
|
+
...value.icon_url ? { icon_url: url(value.icon_url, "Author icon URL") } : {}
|
|
42
|
+
};
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
setThumbnail(value) {
|
|
46
|
+
const valueURL = typeof value === "string" ? value : value.url;
|
|
47
|
+
this.#data.thumbnail = { url: url(valueURL, "Thumbnail URL") };
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
setImage(value) {
|
|
51
|
+
const valueURL = typeof value === "string" ? value : value.url;
|
|
52
|
+
this.#data.image = { url: url(valueURL, "Image URL") };
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
addFields(...fields) {
|
|
56
|
+
if (!fields.length)
|
|
57
|
+
throw new TypeError("At least one embed field is required.");
|
|
58
|
+
const current = this.#data.fields ?? [];
|
|
59
|
+
if (current.length + fields.length > 25)
|
|
60
|
+
throw new RangeError("An embed cannot contain more than 25 fields.");
|
|
61
|
+
for (const field of fields) {
|
|
62
|
+
validate(field.name, 256, "Embed field name");
|
|
63
|
+
validate(field.value, 1024, "Embed field value");
|
|
64
|
+
}
|
|
65
|
+
this.#data.fields = [...current, ...fields.map((field) => ({ ...field }))];
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
setFields(fields) {
|
|
69
|
+
this.#data.fields = [];
|
|
70
|
+
return this.addFields(...fields);
|
|
71
|
+
}
|
|
72
|
+
spliceFields(index, deleteCount, ...fields) {
|
|
73
|
+
const current = [...this.#data.fields ?? []];
|
|
74
|
+
if (!Number.isInteger(index) || !Number.isInteger(deleteCount) || index < 0 || deleteCount < 0)
|
|
75
|
+
throw new RangeError("Field index and delete count must be non-negative integers.");
|
|
76
|
+
current.splice(index, deleteCount, ...fields);
|
|
77
|
+
if (current.length > 25)
|
|
78
|
+
throw new RangeError("An embed cannot contain more than 25 fields.");
|
|
79
|
+
this.#data.fields = current;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
clearFields() {
|
|
83
|
+
delete this.#data.fields;
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
clearTitle() {
|
|
87
|
+
delete this.#data.title;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
clearDescription() {
|
|
91
|
+
delete this.#data.description;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
get data() {
|
|
95
|
+
return this.toJSON();
|
|
96
|
+
}
|
|
97
|
+
toJSON() {
|
|
98
|
+
return structuredClone(this.#data);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function validate(value, max, field) {
|
|
102
|
+
if (typeof value !== "string" || value.length === 0 || value.length > max)
|
|
103
|
+
throw new RangeError(`${field} must contain 1-${max} characters.`);
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
function url(value, field) {
|
|
107
|
+
try {
|
|
108
|
+
return new URL(value).toString();
|
|
109
|
+
} catch (error) {
|
|
110
|
+
throw new TypeError(`${field} must be a valid URL.`, { cause: error });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// packages/builders/src/components.ts
|
|
114
|
+
var ComponentType = {
|
|
115
|
+
ActionRow: 1,
|
|
116
|
+
Button: 2,
|
|
117
|
+
StringSelect: 3,
|
|
118
|
+
TextInput: 4,
|
|
119
|
+
UserSelect: 5,
|
|
120
|
+
RoleSelect: 6,
|
|
121
|
+
MentionableSelect: 7,
|
|
122
|
+
ChannelSelect: 8
|
|
123
|
+
};
|
|
124
|
+
var ButtonStyle = {
|
|
125
|
+
Primary: 1,
|
|
126
|
+
Secondary: 2,
|
|
127
|
+
Success: 3,
|
|
128
|
+
Danger: 4,
|
|
129
|
+
Link: 5
|
|
130
|
+
};
|
|
131
|
+
var TextInputStyle = { Short: 1, Paragraph: 2 };
|
|
132
|
+
|
|
133
|
+
class ActionRowBuilder {
|
|
134
|
+
#components = [];
|
|
135
|
+
addComponents(...components) {
|
|
136
|
+
if (!components.length)
|
|
137
|
+
throw new TypeError("At least one component is required.");
|
|
138
|
+
if (this.#components.length + components.length > 5)
|
|
139
|
+
throw new RangeError("An action row cannot contain more than 5 components.");
|
|
140
|
+
this.#components.push(...components);
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
clearComponents() {
|
|
144
|
+
this.#components.length = 0;
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
toJSON() {
|
|
148
|
+
return {
|
|
149
|
+
type: ComponentType.ActionRow,
|
|
150
|
+
components: this.#components.map((component) => component.toJSON())
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
class StringSelectBuilder {
|
|
156
|
+
#data = {
|
|
157
|
+
type: ComponentType.StringSelect
|
|
158
|
+
};
|
|
159
|
+
setCustomId(value) {
|
|
160
|
+
validateText(value, 100, "Component custom ID");
|
|
161
|
+
this.#data.custom_id = value;
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
setPlaceholder(value) {
|
|
165
|
+
validateText(value, 150, "Component placeholder");
|
|
166
|
+
this.#data.placeholder = value;
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
setMinValues(value) {
|
|
170
|
+
validateCount(value, "min_values", 0);
|
|
171
|
+
this.#data.min_values = value;
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
setMaxValues(value) {
|
|
175
|
+
validateCount(value, "max_values", 1);
|
|
176
|
+
this.#data.max_values = value;
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
setRequired(value = true) {
|
|
180
|
+
this.#data.required = value;
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
setDisabled(value = true) {
|
|
184
|
+
this.#data.disabled = value;
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
addOptions(...options) {
|
|
188
|
+
if (!options.length)
|
|
189
|
+
throw new TypeError("At least one select option is required.");
|
|
190
|
+
const current = this.#data.options ?? [];
|
|
191
|
+
if (current.length + options.length > 25)
|
|
192
|
+
throw new RangeError("A string select cannot contain more than 25 options.");
|
|
193
|
+
for (const option of options) {
|
|
194
|
+
validateText(option.label, 100, "Select option label");
|
|
195
|
+
validateText(option.value, 100, "Select option value");
|
|
196
|
+
if (option.description)
|
|
197
|
+
validateText(option.description, 100, "Select option description");
|
|
198
|
+
}
|
|
199
|
+
this.#data.options = [
|
|
200
|
+
...current,
|
|
201
|
+
...options.map((option) => ({ ...option }))
|
|
202
|
+
];
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
toJSON() {
|
|
206
|
+
return structuredClone(this.#data);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
class ButtonBuilder {
|
|
211
|
+
#data = {
|
|
212
|
+
type: ComponentType.Button,
|
|
213
|
+
style: ButtonStyle.Secondary
|
|
214
|
+
};
|
|
215
|
+
setStyle(style) {
|
|
216
|
+
this.#data.style = style;
|
|
217
|
+
if (style === ButtonStyle.Link)
|
|
218
|
+
delete this.#data.custom_id;
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
setCustomId(value) {
|
|
222
|
+
validateText(value, 100, "Button custom ID");
|
|
223
|
+
if (this.#data.style === ButtonStyle.Link)
|
|
224
|
+
throw new TypeError("Link buttons cannot use custom IDs.");
|
|
225
|
+
this.#data.custom_id = value;
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
setLabel(value) {
|
|
229
|
+
validateText(value, 80, "Button label");
|
|
230
|
+
this.#data.label = value;
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
setURL(value) {
|
|
234
|
+
validateText(value, 512, "Button URL");
|
|
235
|
+
let url2;
|
|
236
|
+
try {
|
|
237
|
+
url2 = new URL(value);
|
|
238
|
+
} catch (error) {
|
|
239
|
+
throw new TypeError("Button URL must be a valid URL.", { cause: error });
|
|
240
|
+
}
|
|
241
|
+
this.#data.style = ButtonStyle.Link;
|
|
242
|
+
delete this.#data.custom_id;
|
|
243
|
+
this.#data.url = url2.toString();
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
setEmoji(emoji) {
|
|
247
|
+
this.#data.emoji = typeof emoji === "string" ? { name: emoji } : { ...emoji };
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
setDisabled(value = true) {
|
|
251
|
+
this.#data.disabled = value;
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
toJSON() {
|
|
255
|
+
return structuredClone(this.#data);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
class EntitySelectBuilder {
|
|
260
|
+
#data;
|
|
261
|
+
constructor(type) {
|
|
262
|
+
if (type !== ComponentType.UserSelect && type !== ComponentType.RoleSelect && type !== ComponentType.MentionableSelect && type !== ComponentType.ChannelSelect)
|
|
263
|
+
throw new TypeError("Invalid select component type.");
|
|
264
|
+
this.#data = { type };
|
|
265
|
+
}
|
|
266
|
+
setCustomId(value) {
|
|
267
|
+
validateText(value, 100, "Component custom ID");
|
|
268
|
+
this.#data.custom_id = value;
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
setPlaceholder(value) {
|
|
272
|
+
validateText(value, 150, "Component placeholder");
|
|
273
|
+
this.#data.placeholder = value;
|
|
274
|
+
return this;
|
|
275
|
+
}
|
|
276
|
+
setMinValues(value) {
|
|
277
|
+
validateCount(value, "min_values", 0);
|
|
278
|
+
this.#data.min_values = value;
|
|
279
|
+
return this;
|
|
280
|
+
}
|
|
281
|
+
setMaxValues(value) {
|
|
282
|
+
validateCount(value, "max_values", 1);
|
|
283
|
+
this.#data.max_values = value;
|
|
284
|
+
return this;
|
|
285
|
+
}
|
|
286
|
+
setRequired(value = true) {
|
|
287
|
+
this.#data.required = value;
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
setDisabled(value = true) {
|
|
291
|
+
this.#data.disabled = value;
|
|
292
|
+
return this;
|
|
293
|
+
}
|
|
294
|
+
setDefaultValues(...values) {
|
|
295
|
+
this.#data.default_values = values;
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
toJSON() {
|
|
299
|
+
return structuredClone(this.#data);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
class ModalBuilder {
|
|
304
|
+
#components = [];
|
|
305
|
+
#custom_id;
|
|
306
|
+
#title;
|
|
307
|
+
setCustomId(value) {
|
|
308
|
+
validateText(value, 100, "Modal custom ID");
|
|
309
|
+
this.#custom_id = value;
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
setTitle(value) {
|
|
313
|
+
validateText(value, 45, "Modal title");
|
|
314
|
+
this.#title = value;
|
|
315
|
+
return this;
|
|
316
|
+
}
|
|
317
|
+
addComponents(...components) {
|
|
318
|
+
if (!components.length)
|
|
319
|
+
throw new TypeError("At least one modal component is required.");
|
|
320
|
+
if (this.#components.length + components.length > 5)
|
|
321
|
+
throw new RangeError("A modal cannot contain more than 5 action rows.");
|
|
322
|
+
this.#components.push(...components);
|
|
323
|
+
return this;
|
|
324
|
+
}
|
|
325
|
+
toJSON() {
|
|
326
|
+
return {
|
|
327
|
+
type: 9,
|
|
328
|
+
...this.#custom_id ? { custom_id: this.#custom_id } : {},
|
|
329
|
+
...this.#title ? { title: this.#title } : {},
|
|
330
|
+
components: this.#components.map((component) => component.toJSON())
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
class TextInputBuilder {
|
|
336
|
+
#data = {
|
|
337
|
+
type: ComponentType.TextInput,
|
|
338
|
+
style: TextInputStyle.Short
|
|
339
|
+
};
|
|
340
|
+
setStyle(style) {
|
|
341
|
+
this.#data.style = style;
|
|
342
|
+
return this;
|
|
343
|
+
}
|
|
344
|
+
setCustomId(value) {
|
|
345
|
+
validateText(value, 100, "Text input custom ID");
|
|
346
|
+
this.#data.custom_id = value;
|
|
347
|
+
return this;
|
|
348
|
+
}
|
|
349
|
+
setLabel(value) {
|
|
350
|
+
validateText(value, 45, "Text input label");
|
|
351
|
+
this.#data.label = value;
|
|
352
|
+
return this;
|
|
353
|
+
}
|
|
354
|
+
setPlaceholder(value) {
|
|
355
|
+
validateText(value, 100, "Text input placeholder");
|
|
356
|
+
this.#data.placeholder = value;
|
|
357
|
+
return this;
|
|
358
|
+
}
|
|
359
|
+
setMinLength(value) {
|
|
360
|
+
validateLength(value, "min_length", 4000);
|
|
361
|
+
this.#data.min_length = value;
|
|
362
|
+
return this;
|
|
363
|
+
}
|
|
364
|
+
setMaxLength(value) {
|
|
365
|
+
validateLength(value, "max_length", 4000);
|
|
366
|
+
this.#data.max_length = value;
|
|
367
|
+
return this;
|
|
368
|
+
}
|
|
369
|
+
setRequired(value = true) {
|
|
370
|
+
this.#data.required = value;
|
|
371
|
+
return this;
|
|
372
|
+
}
|
|
373
|
+
setValue(value) {
|
|
374
|
+
validateText(value, 4000, "Text input value");
|
|
375
|
+
this.#data.value = value;
|
|
376
|
+
return this;
|
|
377
|
+
}
|
|
378
|
+
toJSON() {
|
|
379
|
+
return structuredClone(this.#data);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function validateText(value, max, field) {
|
|
383
|
+
if (typeof value !== "string")
|
|
384
|
+
throw new TypeError(`${field} must be a string.`);
|
|
385
|
+
if (!value.trim())
|
|
386
|
+
throw new RangeError(`${field} must be a non-empty string.`);
|
|
387
|
+
if (value.length > max)
|
|
388
|
+
throw new RangeError(`${field} cannot exceed ${max} characters.`);
|
|
389
|
+
}
|
|
390
|
+
function validateCount(value, field, min, max = 25) {
|
|
391
|
+
if (!Number.isInteger(value) || value < min || value > max)
|
|
392
|
+
throw new RangeError(`${field} must be an integer between ${min} and ${max}.`);
|
|
393
|
+
}
|
|
394
|
+
function validateLength(value, field, max = 4000) {
|
|
395
|
+
if (!Number.isInteger(value) || value < 0 || value > max)
|
|
396
|
+
throw new RangeError(`${field} must be an integer between 0 and ${max}.`);
|
|
397
|
+
}
|
|
398
|
+
// packages/builders/src/commands.ts
|
|
399
|
+
var ApplicationCommandOptionType = {
|
|
400
|
+
Subcommand: 1,
|
|
401
|
+
SubcommandGroup: 2,
|
|
402
|
+
String: 3,
|
|
403
|
+
Integer: 4,
|
|
404
|
+
Boolean: 5,
|
|
405
|
+
User: 6,
|
|
406
|
+
Channel: 7,
|
|
407
|
+
Role: 8,
|
|
408
|
+
Mentionable: 9,
|
|
409
|
+
Number: 10,
|
|
410
|
+
Attachment: 11
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
class SlashCommandBuilder {
|
|
414
|
+
#data = { type: 1 };
|
|
415
|
+
setName(name) {
|
|
416
|
+
validateName(name, "Command name");
|
|
417
|
+
this.#data.name = name;
|
|
418
|
+
return this;
|
|
419
|
+
}
|
|
420
|
+
setDescription(description) {
|
|
421
|
+
validateText2(description, "Command description", 100);
|
|
422
|
+
this.#data.description = description;
|
|
423
|
+
return this;
|
|
424
|
+
}
|
|
425
|
+
setDMPermission(enabled) {
|
|
426
|
+
this.#data.dm_permission = enabled;
|
|
427
|
+
return this;
|
|
428
|
+
}
|
|
429
|
+
setNSFW(nsfw = true) {
|
|
430
|
+
this.#data.nsfw = nsfw;
|
|
431
|
+
return this;
|
|
432
|
+
}
|
|
433
|
+
setNsfw(nsfw = true) {
|
|
434
|
+
return this.setNSFW(nsfw);
|
|
435
|
+
}
|
|
436
|
+
setDefaultMemberPermissions(permissions) {
|
|
437
|
+
this.#data.default_member_permissions = permissions === null ? null : BigInt(permissions).toString();
|
|
438
|
+
return this;
|
|
439
|
+
}
|
|
440
|
+
setIntegrationTypes(...types) {
|
|
441
|
+
this.#data.integration_types = [...types];
|
|
442
|
+
return this;
|
|
443
|
+
}
|
|
444
|
+
addStringOption(configure) {
|
|
445
|
+
return this.addOption(configure(new StringOptionBuilder));
|
|
446
|
+
}
|
|
447
|
+
addIntegerOption(configure) {
|
|
448
|
+
return this.addOption(configure(new IntegerOptionBuilder));
|
|
449
|
+
}
|
|
450
|
+
addNumberOption(configure) {
|
|
451
|
+
return this.addOption(configure(new NumberOptionBuilder));
|
|
452
|
+
}
|
|
453
|
+
addBooleanOption(configure) {
|
|
454
|
+
return this.addOption(configure(new BooleanOptionBuilder));
|
|
455
|
+
}
|
|
456
|
+
addUserOption(configure) {
|
|
457
|
+
return this.addOption(configure(new UserOptionBuilder));
|
|
458
|
+
}
|
|
459
|
+
addChannelOption(configure) {
|
|
460
|
+
return this.addOption(configure(new ChannelOptionBuilder));
|
|
461
|
+
}
|
|
462
|
+
addRoleOption(configure) {
|
|
463
|
+
return this.addOption(configure(new RoleOptionBuilder));
|
|
464
|
+
}
|
|
465
|
+
addMentionableOption(configure) {
|
|
466
|
+
return this.addOption(configure(new MentionableOptionBuilder));
|
|
467
|
+
}
|
|
468
|
+
addAttachmentOption(configure) {
|
|
469
|
+
return this.addOption(configure(new AttachmentOptionBuilder));
|
|
470
|
+
}
|
|
471
|
+
addSubcommand(configure) {
|
|
472
|
+
return this.addOption(configure(new SubcommandBuilder));
|
|
473
|
+
}
|
|
474
|
+
addSubcommandGroup(configure) {
|
|
475
|
+
return this.addOption(configure(new SubcommandGroupBuilder));
|
|
476
|
+
}
|
|
477
|
+
toJSON() {
|
|
478
|
+
return structuredClone(this.#data);
|
|
479
|
+
}
|
|
480
|
+
addOption(option) {
|
|
481
|
+
const options = this.#data.options ?? [];
|
|
482
|
+
if (options.length >= 25)
|
|
483
|
+
throw new RangeError("An application command cannot contain more than 25 options.");
|
|
484
|
+
const payload = option.toJSON();
|
|
485
|
+
if (options.some((existing) => existing.name === payload.name))
|
|
486
|
+
throw new RangeError(`Duplicate option name: ${String(payload.name)}.`);
|
|
487
|
+
if (payload.required === true && options.some((existing) => existing.required !== true))
|
|
488
|
+
throw new RangeError("Required application command options must be placed before optional options.");
|
|
489
|
+
options.push(payload);
|
|
490
|
+
this.#data.options = options;
|
|
491
|
+
return this;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
class CommandOptionBuilder {
|
|
496
|
+
data;
|
|
497
|
+
constructor(type) {
|
|
498
|
+
this.data = { type };
|
|
499
|
+
}
|
|
500
|
+
setName(name) {
|
|
501
|
+
validateName(name, "Option name");
|
|
502
|
+
this.data.name = name;
|
|
503
|
+
return this;
|
|
504
|
+
}
|
|
505
|
+
setDescription(description) {
|
|
506
|
+
validateText2(description, "Option description", 100);
|
|
507
|
+
this.data.description = description;
|
|
508
|
+
return this;
|
|
509
|
+
}
|
|
510
|
+
setRequired(required = true) {
|
|
511
|
+
this.data.required = required;
|
|
512
|
+
return this;
|
|
513
|
+
}
|
|
514
|
+
setAutocomplete(enabled = true) {
|
|
515
|
+
this.data.autocomplete = enabled;
|
|
516
|
+
return this;
|
|
517
|
+
}
|
|
518
|
+
toJSON() {
|
|
519
|
+
return structuredClone(this.data);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
class StringOptionBuilder extends CommandOptionBuilder {
|
|
524
|
+
constructor() {
|
|
525
|
+
super(ApplicationCommandOptionType.String);
|
|
526
|
+
}
|
|
527
|
+
addChoices(...choices) {
|
|
528
|
+
const current = this.data.choices ?? [];
|
|
529
|
+
if (!choices.length)
|
|
530
|
+
throw new TypeError("At least one choice is required.");
|
|
531
|
+
if (this.data.autocomplete === true)
|
|
532
|
+
throw new RangeError("Autocomplete options cannot define choices.");
|
|
533
|
+
if (current.length + choices.length > 25)
|
|
534
|
+
throw new RangeError("An option cannot contain more than 25 choices.");
|
|
535
|
+
for (const choice of choices) {
|
|
536
|
+
validateText2(choice.name, "Choice name", 100);
|
|
537
|
+
validateText2(choice.value, "Choice value", 100);
|
|
538
|
+
}
|
|
539
|
+
this.data.choices = [
|
|
540
|
+
...current,
|
|
541
|
+
...choices.map((choice) => ({ ...choice }))
|
|
542
|
+
];
|
|
543
|
+
return this;
|
|
544
|
+
}
|
|
545
|
+
setMinLength(value) {
|
|
546
|
+
validateIntegerRange(value, 0, 6000, "min_length");
|
|
547
|
+
this.data.min_length = value;
|
|
548
|
+
return this;
|
|
549
|
+
}
|
|
550
|
+
setMaxLength(value) {
|
|
551
|
+
validateIntegerRange(value, 1, 6000, "max_length");
|
|
552
|
+
if (this.data.min_length !== undefined && this.data.min_length > value)
|
|
553
|
+
throw new RangeError("min_length cannot exceed max_length.");
|
|
554
|
+
this.data.max_length = value;
|
|
555
|
+
return this;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
class IntegerOptionBuilder extends CommandOptionBuilder {
|
|
560
|
+
constructor() {
|
|
561
|
+
super(ApplicationCommandOptionType.Integer);
|
|
562
|
+
}
|
|
563
|
+
setMinValue(value) {
|
|
564
|
+
validateNumberRange(value, -9007199254740991, 9007199254740991, "min_value", true);
|
|
565
|
+
this.data.min_value = value;
|
|
566
|
+
return this;
|
|
567
|
+
}
|
|
568
|
+
setMaxValue(value) {
|
|
569
|
+
validateNumberRange(value, -9007199254740991, 9007199254740991, "max_value", true);
|
|
570
|
+
if (this.data.min_value !== undefined && this.data.min_value > value)
|
|
571
|
+
throw new RangeError("min_value cannot exceed max_value.");
|
|
572
|
+
this.data.max_value = value;
|
|
573
|
+
return this;
|
|
574
|
+
}
|
|
575
|
+
setAutocomplete(enabled = true) {
|
|
576
|
+
if (enabled && Array.isArray(this.data.choices) && this.data.choices.length)
|
|
577
|
+
throw new RangeError("Autocomplete options cannot define choices.");
|
|
578
|
+
this.data.autocomplete = enabled;
|
|
579
|
+
return this;
|
|
580
|
+
}
|
|
581
|
+
addChoices(...choices) {
|
|
582
|
+
const current = this.data.choices ?? [];
|
|
583
|
+
if (!choices.length)
|
|
584
|
+
throw new TypeError("At least one choice is required.");
|
|
585
|
+
if (this.data.autocomplete === true)
|
|
586
|
+
throw new RangeError("Autocomplete options cannot define choices.");
|
|
587
|
+
if (current.length + choices.length > 25)
|
|
588
|
+
throw new RangeError("An option cannot contain more than 25 choices.");
|
|
589
|
+
this.data.choices = [...current, ...choices];
|
|
590
|
+
return this;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
class NumberOptionBuilder extends CommandOptionBuilder {
|
|
595
|
+
constructor() {
|
|
596
|
+
super(ApplicationCommandOptionType.Number);
|
|
597
|
+
}
|
|
598
|
+
setMinValue(value) {
|
|
599
|
+
validateNumberRange(value, -9007199254740991, 9007199254740991, "min_value", false);
|
|
600
|
+
this.data.min_value = value;
|
|
601
|
+
return this;
|
|
602
|
+
}
|
|
603
|
+
setMaxValue(value) {
|
|
604
|
+
validateNumberRange(value, -9007199254740991, 9007199254740991, "max_value", false);
|
|
605
|
+
if (this.data.min_value !== undefined && this.data.min_value > value)
|
|
606
|
+
throw new RangeError("min_value cannot exceed max_value.");
|
|
607
|
+
this.data.max_value = value;
|
|
608
|
+
return this;
|
|
609
|
+
}
|
|
610
|
+
setAutocomplete(enabled = true) {
|
|
611
|
+
if (enabled && Array.isArray(this.data.choices) && this.data.choices.length)
|
|
612
|
+
throw new RangeError("Autocomplete options cannot define choices.");
|
|
613
|
+
this.data.autocomplete = enabled;
|
|
614
|
+
return this;
|
|
615
|
+
}
|
|
616
|
+
addChoices(...choices) {
|
|
617
|
+
const current = this.data.choices ?? [];
|
|
618
|
+
if (!choices.length)
|
|
619
|
+
throw new TypeError("At least one choice is required.");
|
|
620
|
+
if (this.data.autocomplete === true)
|
|
621
|
+
throw new RangeError("Autocomplete options cannot define choices.");
|
|
622
|
+
if (current.length + choices.length > 25)
|
|
623
|
+
throw new RangeError("An option cannot contain more than 25 choices.");
|
|
624
|
+
this.data.choices = [...current, ...choices];
|
|
625
|
+
return this;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
class BooleanOptionBuilder extends CommandOptionBuilder {
|
|
630
|
+
constructor() {
|
|
631
|
+
super(ApplicationCommandOptionType.Boolean);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
class UserOptionBuilder extends CommandOptionBuilder {
|
|
636
|
+
constructor() {
|
|
637
|
+
super(ApplicationCommandOptionType.User);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
class RoleOptionBuilder extends CommandOptionBuilder {
|
|
642
|
+
constructor() {
|
|
643
|
+
super(ApplicationCommandOptionType.Role);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
class MentionableOptionBuilder extends CommandOptionBuilder {
|
|
648
|
+
constructor() {
|
|
649
|
+
super(ApplicationCommandOptionType.Mentionable);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
class AttachmentOptionBuilder extends CommandOptionBuilder {
|
|
654
|
+
constructor() {
|
|
655
|
+
super(ApplicationCommandOptionType.Attachment);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
class ChannelOptionBuilder extends CommandOptionBuilder {
|
|
660
|
+
constructor() {
|
|
661
|
+
super(ApplicationCommandOptionType.Channel);
|
|
662
|
+
}
|
|
663
|
+
addChannelTypes(...types) {
|
|
664
|
+
if (types.some((type) => !Number.isInteger(type) || type < 0))
|
|
665
|
+
throw new RangeError("Channel types must be non-negative integers.");
|
|
666
|
+
this.data.channel_types = [...new Set(types)];
|
|
667
|
+
return this;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
class SubcommandBuilder extends CommandOptionBuilder {
|
|
672
|
+
constructor() {
|
|
673
|
+
super(ApplicationCommandOptionType.Subcommand);
|
|
674
|
+
}
|
|
675
|
+
addStringOption(configure) {
|
|
676
|
+
return this.addChildOption(configure(new StringOptionBuilder));
|
|
677
|
+
}
|
|
678
|
+
addIntegerOption(configure) {
|
|
679
|
+
return this.addChildOption(configure(new IntegerOptionBuilder));
|
|
680
|
+
}
|
|
681
|
+
addNumberOption(configure) {
|
|
682
|
+
return this.addChildOption(configure(new NumberOptionBuilder));
|
|
683
|
+
}
|
|
684
|
+
addBooleanOption(configure) {
|
|
685
|
+
return this.addChildOption(configure(new BooleanOptionBuilder));
|
|
686
|
+
}
|
|
687
|
+
addUserOption(configure) {
|
|
688
|
+
return this.addChildOption(configure(new UserOptionBuilder));
|
|
689
|
+
}
|
|
690
|
+
addChannelOption(configure) {
|
|
691
|
+
return this.addChildOption(configure(new ChannelOptionBuilder));
|
|
692
|
+
}
|
|
693
|
+
addRoleOption(configure) {
|
|
694
|
+
return this.addChildOption(configure(new RoleOptionBuilder));
|
|
695
|
+
}
|
|
696
|
+
addMentionableOption(configure) {
|
|
697
|
+
return this.addChildOption(configure(new MentionableOptionBuilder));
|
|
698
|
+
}
|
|
699
|
+
addAttachmentOption(configure) {
|
|
700
|
+
return this.addChildOption(configure(new AttachmentOptionBuilder));
|
|
701
|
+
}
|
|
702
|
+
addChildOption(option) {
|
|
703
|
+
const options = this.data.options ?? [];
|
|
704
|
+
if (options.length >= 25)
|
|
705
|
+
throw new RangeError("A subcommand cannot contain more than 25 options.");
|
|
706
|
+
const payload = option.toJSON();
|
|
707
|
+
if (options.some((existing) => existing.name === payload.name))
|
|
708
|
+
throw new RangeError(`Duplicate option name: ${String(payload.name)}.`);
|
|
709
|
+
if (payload.required === true && options.some((existing) => existing.required !== true))
|
|
710
|
+
throw new RangeError("Required subcommand options must be placed before optional options.");
|
|
711
|
+
if (options.some((existing) => existing.type === ApplicationCommandOptionType.Subcommand))
|
|
712
|
+
throw new RangeError("Subcommands cannot contain nested subcommands.");
|
|
713
|
+
options.push(payload);
|
|
714
|
+
this.data.options = options;
|
|
715
|
+
return this;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
class SubcommandGroupBuilder extends CommandOptionBuilder {
|
|
720
|
+
constructor() {
|
|
721
|
+
super(ApplicationCommandOptionType.SubcommandGroup);
|
|
722
|
+
}
|
|
723
|
+
addSubcommand(configure) {
|
|
724
|
+
const options = this.data.options ?? [];
|
|
725
|
+
if (options.length >= 25)
|
|
726
|
+
throw new RangeError("A subcommand group cannot contain more than 25 subcommands.");
|
|
727
|
+
const payload = configure(new SubcommandBuilder).toJSON();
|
|
728
|
+
if (options.some((existing) => existing.name === payload.name))
|
|
729
|
+
throw new RangeError(`Duplicate subcommand name: ${String(payload.name)}.`);
|
|
730
|
+
if (payload.type !== ApplicationCommandOptionType.Subcommand)
|
|
731
|
+
throw new TypeError("Subcommand group children must be subcommands.");
|
|
732
|
+
options.push(payload);
|
|
733
|
+
this.data.options = options;
|
|
734
|
+
return this;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
function validateName(value, field) {
|
|
738
|
+
if (!/^[\p{L}\p{N}_-]{1,32}$/u.test(value) || value !== value.toLowerCase())
|
|
739
|
+
throw new RangeError(`${field} must contain 1-32 lowercase letters, numbers, underscores, or hyphens.`);
|
|
740
|
+
}
|
|
741
|
+
function validateText2(value, field, max) {
|
|
742
|
+
if (typeof value !== "string" || !value.trim() || value.length > max)
|
|
743
|
+
throw new RangeError(`${field} must contain 1-${max} characters.`);
|
|
744
|
+
}
|
|
745
|
+
function validateIntegerRange(value, minimum, maximum, field) {
|
|
746
|
+
if (!Number.isInteger(value) || value < minimum || value > maximum)
|
|
747
|
+
throw new RangeError(`${field} must be an integer between ${minimum} and ${maximum}.`);
|
|
748
|
+
}
|
|
749
|
+
function validateNumberRange(value, minimum, maximum, field, integerOnly = true) {
|
|
750
|
+
if (!Number.isFinite(value) || integerOnly && !Number.isInteger(value) || value < minimum || value > maximum)
|
|
751
|
+
throw new RangeError(`${field} must be ${integerOnly ? "an integer" : "a number"} between ${minimum} and ${maximum}.`);
|
|
752
|
+
}
|
|
753
|
+
// packages/builders/src/attachment.ts
|
|
754
|
+
import { readFile } from "fs/promises";
|
|
755
|
+
import { basename } from "path";
|
|
756
|
+
|
|
757
|
+
class AttachmentBuilder {
|
|
758
|
+
name;
|
|
759
|
+
description;
|
|
760
|
+
file;
|
|
761
|
+
constructor(file, data) {
|
|
762
|
+
this.file = file;
|
|
763
|
+
if (typeof data === "string") {
|
|
764
|
+
this.name = data;
|
|
765
|
+
} else {
|
|
766
|
+
this.name = data?.name ?? (typeof file === "string" ? basename(file) : "file.bin");
|
|
767
|
+
this.description = data?.description;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
setName(name) {
|
|
771
|
+
this.name = name;
|
|
772
|
+
return this;
|
|
773
|
+
}
|
|
774
|
+
setDescription(description) {
|
|
775
|
+
this.description = description;
|
|
776
|
+
return this;
|
|
777
|
+
}
|
|
778
|
+
setFile(file) {
|
|
779
|
+
this.file = file;
|
|
780
|
+
return this;
|
|
781
|
+
}
|
|
782
|
+
async toBuffer() {
|
|
783
|
+
if (typeof this.file === "string") {
|
|
784
|
+
const buffer = await readFile(this.file);
|
|
785
|
+
return new Uint8Array(buffer);
|
|
786
|
+
}
|
|
787
|
+
if (this.file instanceof Uint8Array)
|
|
788
|
+
return this.file;
|
|
789
|
+
if (this.file instanceof ArrayBuffer)
|
|
790
|
+
return new Uint8Array(this.file);
|
|
791
|
+
if (this.file instanceof Blob) {
|
|
792
|
+
const buf = await this.file.arrayBuffer();
|
|
793
|
+
return new Uint8Array(buf);
|
|
794
|
+
}
|
|
795
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(this.file)) {
|
|
796
|
+
return new Uint8Array(this.file);
|
|
797
|
+
}
|
|
798
|
+
return new Uint8Array;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
export {
|
|
802
|
+
ActionRowBuilder,
|
|
803
|
+
ApplicationCommandOptionType,
|
|
804
|
+
AttachmentBuilder,
|
|
805
|
+
AttachmentOptionBuilder,
|
|
806
|
+
BooleanOptionBuilder,
|
|
807
|
+
ButtonBuilder,
|
|
808
|
+
ButtonStyle,
|
|
809
|
+
ChannelOptionBuilder,
|
|
810
|
+
ComponentType,
|
|
811
|
+
EmbedBuilder,
|
|
812
|
+
EntitySelectBuilder,
|
|
813
|
+
IntegerOptionBuilder,
|
|
814
|
+
MentionableOptionBuilder,
|
|
815
|
+
ModalBuilder,
|
|
816
|
+
NumberOptionBuilder,
|
|
817
|
+
RoleOptionBuilder,
|
|
818
|
+
SlashCommandBuilder,
|
|
819
|
+
StringOptionBuilder,
|
|
820
|
+
StringSelectBuilder,
|
|
821
|
+
SubcommandBuilder,
|
|
822
|
+
SubcommandGroupBuilder,
|
|
823
|
+
TextInputBuilder,
|
|
824
|
+
TextInputStyle,
|
|
825
|
+
UserOptionBuilder
|
|
826
|
+
};
|
|
827
|
+
|
|
828
|
+
//# debugId=2D9849BFEE96124664756E2164756E21
|