djs-builder 0.7.0 → 0.7.1-8.1

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.
@@ -4,10 +4,27 @@ const {
4
4
  RoleSelectMenuBuilder,
5
5
  UserSelectMenuBuilder,
6
6
  ActionRowBuilder,
7
+ SelectMenuDefaultValueTypes,
7
8
  ButtonBuilder,
8
9
  } = require("discord.js");
9
10
 
10
- const axios = require("axios");
11
+ const {
12
+ ModalBuilder,
13
+ TextInputBuilder,
14
+ LabelBuilder,
15
+ FileUploadBuilder,
16
+ } = require("discord.js");
17
+
18
+ const {
19
+ TextDisplayBuilder,
20
+ ContainerBuilder,
21
+ SectionBuilder,
22
+ FileBuilder,
23
+ SeparatorBuilder,
24
+ MediaGalleryBuilder,
25
+ ThumbnailBuilder,
26
+ MediaGalleryItemBuilder,
27
+ } = require("discord.js");
11
28
 
12
29
  //////////////////////////////////* Bar 🔄
13
30
 
@@ -136,12 +153,12 @@ async function Wait({
136
153
 
137
154
  //////////////////////////////////* Row creat 🔩
138
155
 
139
- function CreateRow(components) {
156
+ function CreateRow(components, rowOnly = false) {
140
157
  if (!Array.isArray(components)) {
141
158
  throw new Error("Components should be an array.");
142
159
  }
143
160
 
144
- const actionRows = [];
161
+ let actionRows = [];
145
162
 
146
163
  components.forEach((component) => {
147
164
  if (!component.type) {
@@ -192,6 +209,7 @@ function CreateRow(components) {
192
209
 
193
210
  selectMenu.setCustomId(id);
194
211
  selectMenu.setPlaceholder(placeholder);
212
+ selectMenu.setRequired(options.required || false);
195
213
 
196
214
  if (min) {
197
215
  selectMenu.setMinValues(Math.min(min, data.length));
@@ -208,24 +226,37 @@ function CreateRow(components) {
208
226
  description: item[description]?.slice(0, 100) || undefined,
209
227
  emoji: item[emoji] || undefined,
210
228
  value: item[value] || `${index}`,
211
- default: item.default || false, // جديد
229
+ default: item.default || false,
212
230
  }));
213
231
  selectMenu.addOptions(selectOptions);
214
232
  }
215
233
 
216
234
  if (type === "channel" && Array.isArray(channelTypes)) {
217
- selectMenu.setChannelTypes(channelTypes); // جديد
235
+ selectMenu.setChannelTypes(channelTypes);
218
236
  }
219
237
 
220
238
  if (defaultValues && Array.isArray(defaultValues)) {
221
- selectMenu.setDefaultValues(defaultValues); // جديد
239
+ let ty,
240
+ all = [];
241
+ if (type === "user") ty = selectMenu.setDefaultUsers(...defaultValues);
242
+ else if (type === "role")
243
+ ty = selectMenu.setDefaultRoles(...defaultValues);
244
+ else if (type === "channel")
245
+ ty = selectMenu.setDefaultChannels(...defaultValues);
246
+ for (const val of defaultValues) {
247
+ all.push({ type: ty, id: val });
248
+ }
222
249
  }
223
250
 
224
251
  if (options.hasOwnProperty("disabled")) {
225
252
  selectMenu.setDisabled(options.disabled);
226
253
  }
227
254
 
228
- actionRows.push(new ActionRowBuilder().addComponents(selectMenu));
255
+ if (rowOnly) {
256
+ actionRows = selectMenu;
257
+ } else {
258
+ actionRows.push(new ActionRowBuilder().addComponents(selectMenu));
259
+ }
229
260
  } else {
230
261
  throw new Error("Invalid component format");
231
262
  }
@@ -234,6 +265,215 @@ function CreateRow(components) {
234
265
  return actionRows;
235
266
  }
236
267
 
268
+ //////////////////////////////////* MODAL creat 🔩
269
+
270
+ async function CreateModal(options) {
271
+ const { id, title, components } = options;
272
+ const modal = new ModalBuilder().setCustomId(id).setTitle(title);
273
+
274
+ components.forEach(async (com) => {
275
+ if (com.type === "textInput") {
276
+ com.components.forEach((component) => {
277
+ const {
278
+ label,
279
+ description,
280
+ id,
281
+ style,
282
+ placeholder,
283
+ minLength,
284
+ maxLength,
285
+ required,
286
+ value,
287
+ } = component;
288
+ const input = new TextInputBuilder().setCustomId(id).setStyle(style);
289
+ if (placeholder) input.setPlaceholder(placeholder);
290
+ if (required !== undefined) input.setRequired(required);
291
+ if (minLength) input.setMinLength(minLength);
292
+ if (maxLength) input.setMaxLength(maxLength);
293
+ if (value) input.setValue(value);
294
+ const actionRow = new LabelBuilder()
295
+ .setLabel(label)
296
+ .setTextInputComponent(input);
297
+ if (description) actionRow.setDescription(description);
298
+
299
+ modal.addLabelComponents(actionRow);
300
+ });
301
+ } else if (com.type === "menu") {
302
+ const { type, options } = com.components;
303
+
304
+ const selectMenu = await CreateRow(
305
+ [
306
+ {
307
+ type: type,
308
+ options: options,
309
+ },
310
+ ],
311
+ true,
312
+ );
313
+
314
+
315
+ const menu = new LabelBuilder().setLabel(
316
+ options.mine_label || "Select an option",
317
+ );
318
+ if (type === "string") {
319
+ menu.setStringSelectMenuComponent(selectMenu);
320
+ } else if (type === "user") {
321
+ menu.setUserSelectMenuComponent(selectMenu);
322
+ } else if (type === "role") {
323
+ menu.setRoleSelectMenuComponent(selectMenu);
324
+ } else if (type === "channel") {
325
+ menu.setChannelSelectMenuComponent(selectMenu);
326
+ }
327
+ if (options.mine_description)
328
+ menu.setDescription(options.mine_description);
329
+
330
+
331
+
332
+
333
+ modal.addLabelComponents(menu);
334
+ } else if (com.type === "file") {
335
+ const { id, label, description, required } = com.components;
336
+
337
+ const fileUpload = new LabelBuilder().setLabel(label);
338
+ if (description) fileUpload.setDescription(description);
339
+
340
+ fileUpload.setFileUploadComponent(
341
+ new FileUploadBuilder().setCustomId(id).setRequired(required === undefined ? false : required)
342
+ );
343
+
344
+ modal.addLabelComponents(fileUpload);
345
+ } else if (com.type === "text") {
346
+ const { content } = com.components;
347
+ const text = new TextDisplayBuilder().setContent(content);
348
+
349
+ modal.addTextDisplayComponents(text);
350
+ }
351
+ });
352
+ return modal;
353
+ }
354
+
355
+ //////////////////////////////////* components creat 🔩
356
+
357
+ async function CreateComponents(container, components) {
358
+ let result;
359
+ if (container === true) {
360
+ result = new ContainerBuilder();
361
+ } else {
362
+ result = [];
363
+ }
364
+
365
+ components.forEach(async (item) => {
366
+ if (item.type === "text") {
367
+ const text = new TextDisplayBuilder().setContent(item.content);
368
+
369
+ if (container !== true) {
370
+ result.push(text);
371
+ } else {
372
+ result.addTextDisplayComponents(text);
373
+ }
374
+ } else if (item.type === "separator") {
375
+ const separator = new SeparatorBuilder().setDivider(
376
+ item.divider || false,
377
+ );
378
+ if (item.spacing) separator.setSpacing(item.spacing);
379
+
380
+ if (container === true) {
381
+ result.addSeparatorComponents(separator);
382
+ } else {
383
+ result.push(separator);
384
+ }
385
+ } else if (item.type === "media") {
386
+ let items = [];
387
+ item.links.forEach((link) => {
388
+ if (typeof link === "string") {
389
+ items.push(new MediaGalleryItemBuilder().setURL(link));
390
+ } else {
391
+ const mediaItem = new MediaGalleryItemBuilder().setURL(link.url);
392
+ if (link.description) mediaItem.setDescription(link.description);
393
+ if (link.spoiler) mediaItem.setSpoiler(true);
394
+ items.push(mediaItem);
395
+ }
396
+ });
397
+ const media = new MediaGalleryBuilder().addItems(items);
398
+ if (container === true) {
399
+ result.addMediaGalleryComponents(media);
400
+ } else {
401
+ result.push(media);
402
+ }
403
+ } else if (item.type === "file") {
404
+ const file = new FileBuilder().setURL(item.url);
405
+ if (item.spoiler) file.setSpoiler(true);
406
+ if (container === true) {
407
+ result.addFileComponents(file);
408
+ } else {
409
+ result.push(file);
410
+ }
411
+ } else if (item.type === "button") {
412
+ const but = await CreateRow([item.components]);
413
+ if (container === true) {
414
+ result.addActionRowComponents(but);
415
+ } else {
416
+ result.push(but);
417
+ }
418
+ } else if (item.type === "menu") {
419
+ const menu_type = item.components.type;
420
+ const options = item.components.options;
421
+
422
+ const menu = await CreateRow([
423
+ {
424
+ type: menu_type,
425
+ options: options,
426
+ },
427
+ ]);
428
+ if (container === true) {
429
+ result.addActionRowComponents(menu);
430
+ } else {
431
+ result.push(menu);
432
+ }
433
+ } else if (item.type === "section") {
434
+ const section = new SectionBuilder();
435
+
436
+ if (item.content) {
437
+ section.addTextDisplayComponents(
438
+ new TextDisplayBuilder().setContent(item.content),
439
+ );
440
+ }
441
+
442
+ if (item.accessory) {
443
+ if (item.accessory.type === "button") {
444
+ const btn = new ButtonBuilder().setStyle(item.accessory.style || 2);
445
+ if (item.accessory.label) btn.setLabel(item.accessory.label);
446
+ if (item.accessory.emoji) btn.setEmoji(item.accessory.emoji);
447
+ if (item.accessory.style !== 5) {
448
+ btn.setCustomId(item.accessory.id);
449
+ } else if (item.accessory.url) {
450
+ btn.setURL(item.accessory.url);
451
+ }
452
+
453
+ section.setButtonAccessory(btn);
454
+ } else if (item.accessory.type === "thumbnail") {
455
+ const thumb = new ThumbnailBuilder().setURL(item.accessory.url);
456
+ if (item.accessory.description)
457
+ thumb.setDescription(item.accessory.description);
458
+ section.setThumbnailAccessory(thumb);
459
+ }
460
+ }
461
+
462
+ if (container === true) {
463
+ result.addSectionComponents(section);
464
+ } else {
465
+ result.push(section);
466
+ }
467
+ }
468
+ });
469
+
470
+ if (container === true) {
471
+ return [result];
472
+ } else {
473
+ return [...result];
474
+ }
475
+ }
476
+
237
477
  //////////////////////////////////* Get User 👀
238
478
 
239
479
  async function GetUser(message) {
@@ -267,4 +507,11 @@ async function GetUser(message) {
267
507
  };
268
508
  }
269
509
 
270
- module.exports = { Wait, CreateBar, CreateRow, GetUser };
510
+ module.exports = {
511
+ Wait,
512
+ CreateBar,
513
+ CreateRow,
514
+ GetUser,
515
+ CreateModal,
516
+ CreateComponents,
517
+ };