@open-discord-bots/framework 0.0.1 → 0.0.2

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.
Files changed (103) hide show
  1. package/LICENSE.md +713 -0
  2. package/README.md +104 -0
  3. package/dist/api/api.d.ts +26 -0
  4. package/dist/api/api.js +44 -0
  5. package/dist/api/main.d.ts +133 -0
  6. package/dist/api/main.js +87 -0
  7. package/dist/api/modules/action.d.ts +34 -0
  8. package/dist/api/modules/action.js +58 -0
  9. package/dist/api/modules/base.d.ts +329 -0
  10. package/dist/api/modules/base.js +804 -0
  11. package/dist/api/modules/builder.d.ts +647 -0
  12. package/dist/api/modules/builder.js +1441 -0
  13. package/dist/api/modules/checker.d.ts +648 -0
  14. package/dist/api/modules/checker.js +1324 -0
  15. package/dist/api/modules/client.d.ts +768 -0
  16. package/dist/api/modules/client.js +1859 -0
  17. package/dist/api/modules/code.d.ts +33 -0
  18. package/dist/api/modules/code.js +57 -0
  19. package/dist/api/modules/config.d.ts +70 -0
  20. package/dist/api/modules/config.js +206 -0
  21. package/dist/api/modules/console.d.ts +305 -0
  22. package/dist/api/modules/console.js +598 -0
  23. package/dist/api/modules/cooldown.d.ts +138 -0
  24. package/dist/api/modules/cooldown.js +359 -0
  25. package/dist/api/modules/database.d.ts +135 -0
  26. package/dist/api/modules/database.js +271 -0
  27. package/dist/api/modules/event.d.ts +43 -0
  28. package/dist/api/modules/event.js +100 -0
  29. package/dist/api/modules/flag.d.ts +40 -0
  30. package/dist/api/modules/flag.js +72 -0
  31. package/dist/api/modules/fuse.d.ts +218 -0
  32. package/dist/api/modules/fuse.js +123 -0
  33. package/dist/api/modules/helpmenu.d.ts +106 -0
  34. package/dist/api/modules/helpmenu.js +167 -0
  35. package/dist/api/modules/language.d.ts +85 -0
  36. package/dist/api/modules/language.js +195 -0
  37. package/dist/api/modules/permission.d.ts +121 -0
  38. package/dist/api/modules/permission.js +314 -0
  39. package/dist/api/modules/plugin.d.ts +128 -0
  40. package/dist/api/modules/plugin.js +168 -0
  41. package/dist/api/modules/post.d.ts +44 -0
  42. package/dist/api/modules/post.js +92 -0
  43. package/dist/api/modules/progressbar.d.ts +108 -0
  44. package/dist/api/modules/progressbar.js +233 -0
  45. package/dist/api/modules/responder.d.ts +506 -0
  46. package/dist/api/modules/responder.js +1468 -0
  47. package/dist/api/modules/session.d.ts +58 -0
  48. package/dist/api/modules/session.js +171 -0
  49. package/dist/api/modules/startscreen.d.ts +165 -0
  50. package/dist/api/modules/startscreen.js +293 -0
  51. package/dist/api/modules/stat.d.ts +142 -0
  52. package/dist/api/modules/stat.js +293 -0
  53. package/dist/api/modules/verifybar.d.ts +54 -0
  54. package/dist/api/modules/verifybar.js +60 -0
  55. package/dist/api/modules/worker.d.ts +41 -0
  56. package/dist/api/modules/worker.js +93 -0
  57. package/dist/api/utils.d.ts +61 -0
  58. package/dist/api/utils.js +254 -0
  59. package/dist/index.d.ts +4 -1
  60. package/dist/index.js +40 -0
  61. package/dist/startup/dump.d.ts +14 -0
  62. package/dist/startup/dump.js +79 -0
  63. package/dist/startup/errorHandling.d.ts +2 -0
  64. package/dist/startup/errorHandling.js +43 -0
  65. package/dist/startup/pluginLauncher.d.ts +2 -0
  66. package/dist/startup/pluginLauncher.js +202 -0
  67. package/package.json +9 -3
  68. package/src/api/api.ts +29 -0
  69. package/src/api/main.ts +189 -0
  70. package/src/api/modules/action.ts +58 -0
  71. package/src/api/modules/base.ts +811 -0
  72. package/src/api/modules/builder.ts +1554 -0
  73. package/src/api/modules/checker.ts +1549 -0
  74. package/src/api/modules/client.ts +2247 -0
  75. package/src/api/modules/code.ts +58 -0
  76. package/src/api/modules/config.ts +159 -0
  77. package/src/api/modules/console.ts +665 -0
  78. package/src/api/modules/cooldown.ts +348 -0
  79. package/src/api/modules/database.ts +278 -0
  80. package/src/api/modules/event.ts +99 -0
  81. package/src/api/modules/flag.ts +73 -0
  82. package/src/api/modules/fuse.ts +348 -0
  83. package/src/api/modules/helpmenu.ts +216 -0
  84. package/src/api/modules/language.ts +201 -0
  85. package/src/api/modules/permission.ts +340 -0
  86. package/src/api/modules/plugin.ts +242 -0
  87. package/src/api/modules/post.ts +90 -0
  88. package/src/api/modules/progressbar.ts +232 -0
  89. package/src/api/modules/responder.ts +1420 -0
  90. package/src/api/modules/session.ts +155 -0
  91. package/src/api/modules/startscreen.ts +320 -0
  92. package/src/api/modules/stat.ts +313 -0
  93. package/src/api/modules/verifybar.ts +61 -0
  94. package/src/api/modules/worker.ts +93 -0
  95. package/src/api/utils.ts +206 -0
  96. package/src/cli/cli.ts +151 -0
  97. package/src/cli/editConfig.ts +943 -0
  98. package/src/index.ts +6 -1
  99. package/src/startup/compilation.ts +186 -0
  100. package/src/startup/dump.ts +45 -0
  101. package/src/startup/errorHandling.ts +38 -0
  102. package/src/startup/pluginLauncher.ts +261 -0
  103. package/LICENSE +0 -21
@@ -0,0 +1,1441 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ODModal = exports.ODModalInstance = exports.ODModalManager = exports.ODQuickMessage = exports.ODMessage = exports.ODMessageInstance = exports.ODMessageManager = exports.ODQuickEmbed = exports.ODEmbed = exports.ODEmbedInstance = exports.ODEmbedManager = exports.ODQuickFile = exports.ODFile = exports.ODFileInstance = exports.ODFileManager = exports.ODQuickDropdown = exports.ODDropdown = exports.ODDropdownInstance = exports.ODDropdownManager = exports.ODQuickButton = exports.ODButton = exports.ODButtonInstance = exports.ODButtonManager = exports.ODBuilderManager = exports.ODBuilderImplementation = void 0;
37
+ ///////////////////////////////////////
38
+ //BUILDER MODULE
39
+ ///////////////////////////////////////
40
+ const base_1 = require("./base");
41
+ const discord = __importStar(require("discord.js"));
42
+ const worker_1 = require("./worker");
43
+ /**## ODBuilderImplementation `class`
44
+ * This is an Open Discord builder implementation.
45
+ *
46
+ * It is a basic implementation of the `ODWorkerManager` used by all `ODBuilder` classes.
47
+ *
48
+ * This class can't be used stand-alone & needs to be extended from!
49
+ */
50
+ class ODBuilderImplementation extends base_1.ODManagerData {
51
+ /**The manager that has all workers of this implementation */
52
+ workers;
53
+ /**Cache a build or create it every time from scratch when this.build() gets executed. */
54
+ allowCache = false;
55
+ /**Did the build already got created/cached? */
56
+ didCache = false;
57
+ /**The cache of this build. */
58
+ cache = null;
59
+ constructor(id, callback, priority, callbackId) {
60
+ super(id);
61
+ this.workers = new worker_1.ODWorkerManager("ascending");
62
+ if (callback)
63
+ this.workers.add(new worker_1.ODWorker(callbackId ? callbackId : id, priority ?? 0, callback));
64
+ }
65
+ /**Set if caching is allowed */
66
+ setCacheMode(allowed) {
67
+ this.allowCache = allowed;
68
+ this.resetCache();
69
+ return this;
70
+ }
71
+ /**Reset the current cache */
72
+ resetCache() {
73
+ this.cache = null;
74
+ this.didCache = false;
75
+ return this;
76
+ }
77
+ /**Execute all workers & return the result. */
78
+ async build(source, params) {
79
+ throw new base_1.ODSystemError("Tried to build an unimplemented ODBuilderImplementation");
80
+ }
81
+ }
82
+ exports.ODBuilderImplementation = ODBuilderImplementation;
83
+ /**## ODBuilderManager `class`
84
+ * This is an Open Discord builder manager.
85
+ *
86
+ * It contains all Open Discord builders. You can find messages, embeds, files & dropdowns, buttons & modals all here!
87
+ *
88
+ * Using the Open Discord builder system has a few advantages compared to vanilla discord.js:
89
+ * - plugins can extend/edit messages
90
+ * - automatically reply on error
91
+ * - independent workers (with priority)
92
+ * - fail-safe design using try-catch
93
+ * - cache frequently used objects
94
+ * - get to know the source of the build request for a specific message, button, etc
95
+ * - And so much more!
96
+ */
97
+ class ODBuilderManager {
98
+ /**The manager for all button builders */
99
+ buttons;
100
+ /**The manager for all dropdown builders */
101
+ dropdowns;
102
+ /**The manager for all file/attachment builders */
103
+ files;
104
+ /**The manager for all embed builders */
105
+ embeds;
106
+ /**The manager for all message builders */
107
+ messages;
108
+ /**The manager for all modal builders */
109
+ modals;
110
+ constructor(debug) {
111
+ this.buttons = new ODButtonManager(debug);
112
+ this.dropdowns = new ODDropdownManager(debug);
113
+ this.files = new ODFileManager(debug);
114
+ this.embeds = new ODEmbedManager(debug);
115
+ this.messages = new ODMessageManager(debug);
116
+ this.modals = new ODModalManager(debug);
117
+ }
118
+ }
119
+ exports.ODBuilderManager = ODBuilderManager;
120
+ /**## ODButtonManager `class`
121
+ * This is an Open Discord button manager.
122
+ *
123
+ * It contains all Open Discord button builders. Here, you can add your own buttons or edit existing ones!
124
+ *
125
+ * It's recommended to use this system in combination with all the other Open Discord builders!
126
+ */
127
+ class ODButtonManager extends base_1.ODManagerWithSafety {
128
+ constructor(debug) {
129
+ super(() => {
130
+ return new ODButton("opendiscord:unknown-button", (instance, params, source, cancel) => {
131
+ instance.setCustomId("od:unknown-button");
132
+ instance.setMode("button");
133
+ instance.setColor("red");
134
+ instance.setLabel("<ODError:Unknown Button>");
135
+ instance.setEmoji("✖");
136
+ instance.setDisabled(true);
137
+ cancel();
138
+ });
139
+ }, debug, "button");
140
+ }
141
+ /**Get a newline component for buttons & dropdowns! */
142
+ getNewLine(id) {
143
+ return {
144
+ id: new base_1.ODId(id),
145
+ component: "\n"
146
+ };
147
+ }
148
+ }
149
+ exports.ODButtonManager = ODButtonManager;
150
+ /**## ODButtonInstance `class`
151
+ * This is an Open Discord button instance.
152
+ *
153
+ * It contains all properties & functions to build a button!
154
+ */
155
+ class ODButtonInstance {
156
+ /**The current data of this button */
157
+ data = {
158
+ customId: "",
159
+ mode: "button",
160
+ url: null,
161
+ color: null,
162
+ label: null,
163
+ emoji: null,
164
+ disabled: false
165
+ };
166
+ /**Set the custom id of this button */
167
+ setCustomId(id) {
168
+ this.data.customId = id;
169
+ return this;
170
+ }
171
+ /**Set the mode of this button */
172
+ setMode(mode) {
173
+ this.data.mode = mode;
174
+ return this;
175
+ }
176
+ /**Set the url of this button */
177
+ setUrl(url) {
178
+ this.data.url = url;
179
+ return this;
180
+ }
181
+ /**Set the color of this button */
182
+ setColor(color) {
183
+ this.data.color = color;
184
+ return this;
185
+ }
186
+ /**Set the label of this button */
187
+ setLabel(label) {
188
+ this.data.label = label;
189
+ return this;
190
+ }
191
+ /**Set the emoji of this button */
192
+ setEmoji(emoji) {
193
+ this.data.emoji = emoji;
194
+ return this;
195
+ }
196
+ /**Disable this button */
197
+ setDisabled(disabled) {
198
+ this.data.disabled = disabled;
199
+ return this;
200
+ }
201
+ }
202
+ exports.ODButtonInstance = ODButtonInstance;
203
+ /**## ODButton `class`
204
+ * This is an Open Discord button builder.
205
+ *
206
+ * With this class, you can create a button to use in a message.
207
+ * The only difference with normal buttons is that this one can be edited by Open Discord plugins!
208
+ *
209
+ * This is possible by using "workers" or multiple functions that will be executed in priority order!
210
+ */
211
+ class ODButton extends ODBuilderImplementation {
212
+ /**Build this button & compile it for discord.js */
213
+ async build(source, params) {
214
+ if (this.didCache && this.cache && this.allowCache)
215
+ return this.cache;
216
+ try {
217
+ //create instance
218
+ const instance = new ODButtonInstance();
219
+ //wait for workers to finish
220
+ await this.workers.executeWorkers(instance, source, params);
221
+ //create the discord.js button
222
+ const button = new discord.ButtonBuilder();
223
+ if (instance.data.mode == "button")
224
+ button.setCustomId(instance.data.customId);
225
+ if (instance.data.mode == "url")
226
+ button.setStyle(discord.ButtonStyle.Link);
227
+ else if (instance.data.color == "gray")
228
+ button.setStyle(discord.ButtonStyle.Secondary);
229
+ else if (instance.data.color == "blue")
230
+ button.setStyle(discord.ButtonStyle.Primary);
231
+ else if (instance.data.color == "green")
232
+ button.setStyle(discord.ButtonStyle.Success);
233
+ else if (instance.data.color == "red")
234
+ button.setStyle(discord.ButtonStyle.Danger);
235
+ if (instance.data.url)
236
+ button.setURL(instance.data.url);
237
+ if (instance.data.label)
238
+ button.setLabel(instance.data.label);
239
+ if (instance.data.emoji)
240
+ button.setEmoji(instance.data.emoji);
241
+ if (instance.data.disabled)
242
+ button.setDisabled(instance.data.disabled);
243
+ if (!instance.data.emoji && !instance.data.label)
244
+ button.setLabel(instance.data.customId);
245
+ this.cache = { id: this.id, component: button };
246
+ this.didCache = true;
247
+ return { id: this.id, component: button };
248
+ }
249
+ catch (err) {
250
+ process.emit("uncaughtException", new base_1.ODSystemError("ODButton:build(\"" + this.id.value + "\") => Major Error (see next error)"));
251
+ process.emit("uncaughtException", err);
252
+ return { id: this.id, component: null };
253
+ }
254
+ }
255
+ }
256
+ exports.ODButton = ODButton;
257
+ /**## ODQuickButton `class`
258
+ * This is an Open Discord quick button builder.
259
+ *
260
+ * With this class, you can quickly create a button to use in a message.
261
+ * This quick button can be used by Open Discord plugins instead of the normal builders to speed up the process!
262
+ *
263
+ * Because of the quick functionality, these buttons are less customisable by other plugins.
264
+ */
265
+ class ODQuickButton {
266
+ /**The id of this button. */
267
+ id;
268
+ /**The current data of this button */
269
+ data;
270
+ constructor(id, data) {
271
+ this.id = new base_1.ODId(id);
272
+ this.data = data;
273
+ }
274
+ /**Build this button & compile it for discord.js */
275
+ async build() {
276
+ try {
277
+ //create the discord.js button
278
+ const button = new discord.ButtonBuilder();
279
+ if (this.data.mode == "button" || (!this.data.mode && this.data.customId))
280
+ button.setCustomId(this.data.customId ?? "od:unknown-button");
281
+ if (this.data.mode == "url")
282
+ button.setStyle(discord.ButtonStyle.Link);
283
+ else if (this.data.color == "gray")
284
+ button.setStyle(discord.ButtonStyle.Secondary);
285
+ else if (this.data.color == "blue")
286
+ button.setStyle(discord.ButtonStyle.Primary);
287
+ else if (this.data.color == "green")
288
+ button.setStyle(discord.ButtonStyle.Success);
289
+ else if (this.data.color == "red")
290
+ button.setStyle(discord.ButtonStyle.Danger);
291
+ else
292
+ button.setStyle(discord.ButtonStyle.Secondary);
293
+ if (this.data.url)
294
+ button.setURL(this.data.url);
295
+ if (this.data.label)
296
+ button.setLabel(this.data.label);
297
+ if (this.data.emoji)
298
+ button.setEmoji(this.data.emoji);
299
+ if (this.data.disabled)
300
+ button.setDisabled(this.data.disabled);
301
+ if (!this.data.emoji && !this.data.label)
302
+ button.setLabel(this.data.customId ?? "od:unknown-button");
303
+ return { id: this.id, component: button };
304
+ }
305
+ catch (err) {
306
+ process.emit("uncaughtException", new base_1.ODSystemError("ODQuickButton:build(\"" + this.id.value + "\") => Major Error (see next error)"));
307
+ process.emit("uncaughtException", err);
308
+ return { id: this.id, component: null };
309
+ }
310
+ }
311
+ }
312
+ exports.ODQuickButton = ODQuickButton;
313
+ /**## ODDropdownManager `class`
314
+ * This is an Open Discord dropdown manager.
315
+ *
316
+ * It contains all Open Discord dropdown builders. Here, you can add your own dropdowns or edit existing ones!
317
+ *
318
+ * It's recommended to use this system in combination with all the other Open Discord builders!
319
+ */
320
+ class ODDropdownManager extends base_1.ODManagerWithSafety {
321
+ constructor(debug) {
322
+ super(() => {
323
+ return new ODDropdown("opendiscord:unknown-dropdown", (instance, params, source, cancel) => {
324
+ instance.setCustomId("od:unknown-dropdown");
325
+ instance.setType("string");
326
+ instance.setPlaceholder("❌ <ODError:Unknown Dropdown>");
327
+ instance.setDisabled(true);
328
+ instance.setOptions([
329
+ { emoji: "❌", label: "<ODError:Unknown Dropdown>", value: "error" }
330
+ ]);
331
+ cancel();
332
+ });
333
+ }, debug, "dropdown");
334
+ }
335
+ /**Get a newline component for buttons & dropdowns! */
336
+ getNewLine(id) {
337
+ return {
338
+ id: new base_1.ODId(id),
339
+ component: "\n"
340
+ };
341
+ }
342
+ }
343
+ exports.ODDropdownManager = ODDropdownManager;
344
+ /**## ODDropdownInstance `class`
345
+ * This is an Open Discord dropdown instance.
346
+ *
347
+ * It contains all properties & functions to build a dropdown!
348
+ */
349
+ class ODDropdownInstance {
350
+ /**The current data of this dropdown */
351
+ data = {
352
+ customId: "",
353
+ type: "string",
354
+ placeholder: null,
355
+ minValues: null,
356
+ maxValues: null,
357
+ disabled: false,
358
+ channelTypes: [],
359
+ options: [],
360
+ users: [],
361
+ roles: [],
362
+ channels: [],
363
+ mentionables: []
364
+ };
365
+ /**Set the custom id of this dropdown */
366
+ setCustomId(id) {
367
+ this.data.customId = id;
368
+ return this;
369
+ }
370
+ /**Set the type of this dropdown */
371
+ setType(type) {
372
+ this.data.type = type;
373
+ return this;
374
+ }
375
+ /**Set the placeholder of this dropdown */
376
+ setPlaceholder(placeholder) {
377
+ this.data.placeholder = placeholder;
378
+ return this;
379
+ }
380
+ /**Set the minimum amount of values in this dropdown */
381
+ setMinValues(minValues) {
382
+ this.data.minValues = minValues;
383
+ return this;
384
+ }
385
+ /**Set the maximum amount of values ax this dropdown */
386
+ setMaxValues(maxValues) {
387
+ this.data.maxValues = maxValues;
388
+ return this;
389
+ }
390
+ /**Set the disabled of this dropdown */
391
+ setDisabled(disabled) {
392
+ this.data.disabled = disabled;
393
+ return this;
394
+ }
395
+ /**Set the channel types of this dropdown */
396
+ setChannelTypes(channelTypes) {
397
+ this.data.channelTypes = channelTypes;
398
+ return this;
399
+ }
400
+ /**Set the options of this dropdown (when `type == "string"`) */
401
+ setOptions(options) {
402
+ this.data.options = options;
403
+ return this;
404
+ }
405
+ /**Set the users of this dropdown (when `type == "user"`) */
406
+ setUsers(users) {
407
+ this.data.users = users;
408
+ return this;
409
+ }
410
+ /**Set the roles of this dropdown (when `type == "role"`) */
411
+ setRoles(roles) {
412
+ this.data.roles = roles;
413
+ return this;
414
+ }
415
+ /**Set the channels of this dropdown (when `type == "channel"`) */
416
+ setChannels(channels) {
417
+ this.data.channels = channels;
418
+ return this;
419
+ }
420
+ /**Set the mentionables of this dropdown (when `type == "mentionable"`) */
421
+ setMentionables(mentionables) {
422
+ this.data.mentionables = mentionables;
423
+ return this;
424
+ }
425
+ }
426
+ exports.ODDropdownInstance = ODDropdownInstance;
427
+ /**## ODDropdown `class`
428
+ * This is an Open Discord dropdown builder.
429
+ *
430
+ * With this class, you can create a dropdown to use in a message.
431
+ * The only difference with normal dropdowns is that this one can be edited by Open Discord plugins!
432
+ *
433
+ * This is possible by using "workers" or multiple functions that will be executed in priority order!
434
+ */
435
+ class ODDropdown extends ODBuilderImplementation {
436
+ /**Build this dropdown & compile it for discord.js */
437
+ async build(source, params) {
438
+ if (this.didCache && this.cache && this.allowCache)
439
+ return this.cache;
440
+ try {
441
+ //create instance
442
+ const instance = new ODDropdownInstance();
443
+ //wait for workers to finish
444
+ await this.workers.executeWorkers(instance, source, params);
445
+ //create the discord.js dropdown
446
+ if (instance.data.type == "string") {
447
+ const dropdown = new discord.StringSelectMenuBuilder();
448
+ dropdown.setCustomId(instance.data.customId);
449
+ dropdown.setOptions(...instance.data.options);
450
+ if (instance.data.placeholder)
451
+ dropdown.setPlaceholder(instance.data.placeholder);
452
+ if (instance.data.minValues)
453
+ dropdown.setMinValues(instance.data.minValues);
454
+ if (instance.data.maxValues)
455
+ dropdown.setMaxValues(instance.data.maxValues);
456
+ if (instance.data.disabled)
457
+ dropdown.setDisabled(instance.data.disabled);
458
+ this.cache = { id: this.id, component: dropdown };
459
+ this.didCache = true;
460
+ return { id: this.id, component: dropdown };
461
+ }
462
+ else if (instance.data.type == "user") {
463
+ const dropdown = new discord.UserSelectMenuBuilder();
464
+ dropdown.setCustomId(instance.data.customId);
465
+ if (instance.data.users.length > 0)
466
+ dropdown.setDefaultUsers(...instance.data.users.map((u) => u.id));
467
+ if (instance.data.placeholder)
468
+ dropdown.setPlaceholder(instance.data.placeholder);
469
+ if (instance.data.minValues)
470
+ dropdown.setMinValues(instance.data.minValues);
471
+ if (instance.data.maxValues)
472
+ dropdown.setMaxValues(instance.data.maxValues);
473
+ if (instance.data.disabled)
474
+ dropdown.setDisabled(instance.data.disabled);
475
+ this.cache = { id: this.id, component: dropdown };
476
+ this.didCache = true;
477
+ return { id: this.id, component: dropdown };
478
+ }
479
+ else if (instance.data.type == "role") {
480
+ const dropdown = new discord.RoleSelectMenuBuilder();
481
+ dropdown.setCustomId(instance.data.customId);
482
+ if (instance.data.roles.length > 0)
483
+ dropdown.setDefaultRoles(...instance.data.roles.map((r) => r.id));
484
+ if (instance.data.placeholder)
485
+ dropdown.setPlaceholder(instance.data.placeholder);
486
+ if (instance.data.minValues)
487
+ dropdown.setMinValues(instance.data.minValues);
488
+ if (instance.data.maxValues)
489
+ dropdown.setMaxValues(instance.data.maxValues);
490
+ if (instance.data.disabled)
491
+ dropdown.setDisabled(instance.data.disabled);
492
+ this.cache = { id: this.id, component: dropdown };
493
+ this.didCache = true;
494
+ return { id: this.id, component: dropdown };
495
+ }
496
+ else if (instance.data.type == "channel") {
497
+ const dropdown = new discord.ChannelSelectMenuBuilder();
498
+ dropdown.setCustomId(instance.data.customId);
499
+ if (instance.data.channels.length > 0)
500
+ dropdown.setDefaultChannels(...instance.data.channels.map((c) => c.id));
501
+ if (instance.data.placeholder)
502
+ dropdown.setPlaceholder(instance.data.placeholder);
503
+ if (instance.data.minValues)
504
+ dropdown.setMinValues(instance.data.minValues);
505
+ if (instance.data.maxValues)
506
+ dropdown.setMaxValues(instance.data.maxValues);
507
+ if (instance.data.disabled)
508
+ dropdown.setDisabled(instance.data.disabled);
509
+ this.cache = { id: this.id, component: dropdown };
510
+ this.didCache = true;
511
+ return { id: this.id, component: dropdown };
512
+ }
513
+ else if (instance.data.type == "mentionable") {
514
+ const dropdown = new discord.MentionableSelectMenuBuilder();
515
+ const values = [];
516
+ instance.data.mentionables.forEach((m) => {
517
+ if (m instanceof discord.User) {
518
+ values.push({ type: discord.SelectMenuDefaultValueType.User, id: m.id });
519
+ }
520
+ else {
521
+ values.push({ type: discord.SelectMenuDefaultValueType.Role, id: m.id });
522
+ }
523
+ });
524
+ dropdown.setCustomId(instance.data.customId);
525
+ if (instance.data.mentionables.length > 0)
526
+ dropdown.setDefaultValues(...values);
527
+ if (instance.data.placeholder)
528
+ dropdown.setPlaceholder(instance.data.placeholder);
529
+ if (instance.data.minValues)
530
+ dropdown.setMinValues(instance.data.minValues);
531
+ if (instance.data.maxValues)
532
+ dropdown.setMaxValues(instance.data.maxValues);
533
+ if (instance.data.disabled)
534
+ dropdown.setDisabled(instance.data.disabled);
535
+ this.cache = { id: this.id, component: dropdown };
536
+ this.didCache = true;
537
+ return { id: this.id, component: dropdown };
538
+ }
539
+ else {
540
+ throw new Error("Tried to build an ODDropdown with unknown type!");
541
+ }
542
+ }
543
+ catch (err) {
544
+ process.emit("uncaughtException", new base_1.ODSystemError("ODDropdown:build(\"" + this.id.value + "\") => Major Error (see next error)"));
545
+ process.emit("uncaughtException", err);
546
+ return { id: this.id, component: null };
547
+ }
548
+ }
549
+ }
550
+ exports.ODDropdown = ODDropdown;
551
+ /**## ODQuickDropdown `class`
552
+ * This is an Open Discord quick dropdown builder.
553
+ *
554
+ * With this class, you can quickly create a dropdown to use in a message.
555
+ * This quick dropdown can be used by Open Discord plugins instead of the normal builders to speed up the process!
556
+ *
557
+ * Because of the quick functionality, these dropdowns are less customisable by other plugins.
558
+ */
559
+ class ODQuickDropdown {
560
+ /**The id of this dropdown. */
561
+ id;
562
+ /**The current data of this dropdown */
563
+ data;
564
+ constructor(id, data) {
565
+ this.id = new base_1.ODId(id);
566
+ this.data = data;
567
+ }
568
+ /**Build this dropdown & compile it for discord.js */
569
+ async build() {
570
+ try {
571
+ //create the discord.js dropdown
572
+ if (this.data.type == "string") {
573
+ if (!this.data.options)
574
+ throw new base_1.ODSystemError("ODQuickDropdown:build(): " + this.id.value + " => Dropdown requires at least 1 option to be present.");
575
+ const dropdown = new discord.StringSelectMenuBuilder();
576
+ dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown");
577
+ dropdown.setOptions(...this.data.options);
578
+ if (this.data.placeholder)
579
+ dropdown.setPlaceholder(this.data.placeholder);
580
+ if (this.data.minValues)
581
+ dropdown.setMinValues(this.data.minValues);
582
+ if (this.data.maxValues)
583
+ dropdown.setMaxValues(this.data.maxValues);
584
+ if (this.data.disabled)
585
+ dropdown.setDisabled(this.data.disabled);
586
+ return { id: this.id, component: dropdown };
587
+ }
588
+ else if (this.data.type == "user") {
589
+ if (!this.data.users)
590
+ throw new base_1.ODSystemError("ODQuickDropdown:build(): " + this.id.value + " => Dropdown requires at least 1 user option to be present.");
591
+ const dropdown = new discord.UserSelectMenuBuilder();
592
+ dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown");
593
+ if (this.data.users.length > 0)
594
+ dropdown.setDefaultUsers(...this.data.users.map((u) => u.id));
595
+ if (this.data.placeholder)
596
+ dropdown.setPlaceholder(this.data.placeholder);
597
+ if (this.data.minValues)
598
+ dropdown.setMinValues(this.data.minValues);
599
+ if (this.data.maxValues)
600
+ dropdown.setMaxValues(this.data.maxValues);
601
+ if (this.data.disabled)
602
+ dropdown.setDisabled(this.data.disabled);
603
+ return { id: this.id, component: dropdown };
604
+ }
605
+ else if (this.data.type == "role") {
606
+ if (!this.data.roles)
607
+ throw new base_1.ODSystemError("ODQuickDropdown:build(): " + this.id.value + " => Dropdown requires at least 1 role option to be present.");
608
+ const dropdown = new discord.RoleSelectMenuBuilder();
609
+ dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown");
610
+ if (this.data.roles.length > 0)
611
+ dropdown.setDefaultRoles(...this.data.roles.map((r) => r.id));
612
+ if (this.data.placeholder)
613
+ dropdown.setPlaceholder(this.data.placeholder);
614
+ if (this.data.minValues)
615
+ dropdown.setMinValues(this.data.minValues);
616
+ if (this.data.maxValues)
617
+ dropdown.setMaxValues(this.data.maxValues);
618
+ if (this.data.disabled)
619
+ dropdown.setDisabled(this.data.disabled);
620
+ return { id: this.id, component: dropdown };
621
+ }
622
+ else if (this.data.type == "channel") {
623
+ if (!this.data.channels)
624
+ throw new base_1.ODSystemError("ODQuickDropdown:build(): " + this.id.value + " => Dropdown requires at least 1 channel option to be present.");
625
+ const dropdown = new discord.ChannelSelectMenuBuilder();
626
+ dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown");
627
+ if (this.data.channels.length > 0)
628
+ dropdown.setDefaultChannels(...this.data.channels.map((c) => c.id));
629
+ if (this.data.placeholder)
630
+ dropdown.setPlaceholder(this.data.placeholder);
631
+ if (this.data.minValues)
632
+ dropdown.setMinValues(this.data.minValues);
633
+ if (this.data.maxValues)
634
+ dropdown.setMaxValues(this.data.maxValues);
635
+ if (this.data.disabled)
636
+ dropdown.setDisabled(this.data.disabled);
637
+ return { id: this.id, component: dropdown };
638
+ }
639
+ else if (this.data.type == "mentionable") {
640
+ if (!this.data.mentionables)
641
+ throw new base_1.ODSystemError("ODQuickDropdown:build(): " + this.id.value + " => Dropdown requires at least 1 mentionable option to be present.");
642
+ const dropdown = new discord.MentionableSelectMenuBuilder();
643
+ const values = [];
644
+ this.data.mentionables.forEach((m) => {
645
+ if (m instanceof discord.User) {
646
+ values.push({ type: discord.SelectMenuDefaultValueType.User, id: m.id });
647
+ }
648
+ else {
649
+ values.push({ type: discord.SelectMenuDefaultValueType.Role, id: m.id });
650
+ }
651
+ });
652
+ dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown");
653
+ if (this.data.mentionables.length > 0)
654
+ dropdown.setDefaultValues(...values);
655
+ if (this.data.placeholder)
656
+ dropdown.setPlaceholder(this.data.placeholder);
657
+ if (this.data.minValues)
658
+ dropdown.setMinValues(this.data.minValues);
659
+ if (this.data.maxValues)
660
+ dropdown.setMaxValues(this.data.maxValues);
661
+ if (this.data.disabled)
662
+ dropdown.setDisabled(this.data.disabled);
663
+ return { id: this.id, component: dropdown };
664
+ }
665
+ else {
666
+ throw new Error("Tried to build an ODQuickDropdown with unknown type!");
667
+ }
668
+ }
669
+ catch (err) {
670
+ process.emit("uncaughtException", new base_1.ODSystemError("ODQuickDropdown:build(\"" + this.id.value + "\") => Major Error (see next error)"));
671
+ process.emit("uncaughtException", err);
672
+ return { id: this.id, component: null };
673
+ }
674
+ }
675
+ }
676
+ exports.ODQuickDropdown = ODQuickDropdown;
677
+ /**## ODFileManager `class`
678
+ * This is an Open Discord file manager.
679
+ *
680
+ * It contains all Open Discord file builders. Here, you can add your own files or edit existing ones!
681
+ *
682
+ * It's recommended to use this system in combination with all the other Open Discord builders!
683
+ */
684
+ class ODFileManager extends base_1.ODManagerWithSafety {
685
+ constructor(debug) {
686
+ super(() => {
687
+ return new ODFile("opendiscord:unknown-file", (instance, params, source, cancel) => {
688
+ instance.setName("opendiscord_unknown-file.txt");
689
+ instance.setDescription("❌ <ODError:Unknown File>");
690
+ instance.setContents("Couldn't find file in registery `opendiscord.builders.files`");
691
+ cancel();
692
+ });
693
+ }, debug, "file");
694
+ }
695
+ }
696
+ exports.ODFileManager = ODFileManager;
697
+ /**## ODFileInstance `class`
698
+ * This is an Open Discord file instance.
699
+ *
700
+ * It contains all properties & functions to build a file!
701
+ */
702
+ class ODFileInstance {
703
+ /**The current data of this file */
704
+ data = {
705
+ file: "",
706
+ name: "file.txt",
707
+ description: null,
708
+ spoiler: false
709
+ };
710
+ /**Set the file path of this attachment */
711
+ setFile(file) {
712
+ this.data.file = file;
713
+ return this;
714
+ }
715
+ /**Set the file contents of this attachment */
716
+ setContents(contents) {
717
+ this.data.file = (typeof contents == "string") ? Buffer.from(contents) : contents;
718
+ return this;
719
+ }
720
+ /**Set the name of this attachment */
721
+ setName(name) {
722
+ this.data.name = name;
723
+ return this;
724
+ }
725
+ /**Set the description of this attachment */
726
+ setDescription(description) {
727
+ this.data.description = description;
728
+ return this;
729
+ }
730
+ /**Set this attachment to show as a spoiler */
731
+ setSpoiler(spoiler) {
732
+ this.data.spoiler = spoiler;
733
+ return this;
734
+ }
735
+ }
736
+ exports.ODFileInstance = ODFileInstance;
737
+ /**## ODFile `class`
738
+ * This is an Open Discord file builder.
739
+ *
740
+ * With this class, you can create a file to use in a message.
741
+ * The only difference with normal files is that this one can be edited by Open Discord plugins!
742
+ *
743
+ * This is possible by using "workers" or multiple functions that will be executed in priority order!
744
+ */
745
+ class ODFile extends ODBuilderImplementation {
746
+ /**Build this attachment & compile it for discord.js */
747
+ async build(source, params) {
748
+ if (this.didCache && this.cache && this.allowCache)
749
+ return this.cache;
750
+ try {
751
+ //create instance
752
+ const instance = new ODFileInstance();
753
+ //wait for workers to finish
754
+ await this.workers.executeWorkers(instance, source, params);
755
+ //create the discord.js attachment
756
+ const file = new discord.AttachmentBuilder(instance.data.file);
757
+ file.setName(instance.data.name ? instance.data.name : "file.txt");
758
+ if (instance.data.description)
759
+ file.setDescription(instance.data.description);
760
+ if (instance.data.spoiler)
761
+ file.setSpoiler(instance.data.spoiler);
762
+ this.cache = { id: this.id, file };
763
+ this.didCache = true;
764
+ return { id: this.id, file };
765
+ }
766
+ catch (err) {
767
+ process.emit("uncaughtException", new base_1.ODSystemError("ODFile:build(\"" + this.id.value + "\") => Major Error (see next error)"));
768
+ process.emit("uncaughtException", err);
769
+ return { id: this.id, file: null };
770
+ }
771
+ }
772
+ }
773
+ exports.ODFile = ODFile;
774
+ /**## ODQuickFile `class`
775
+ * This is an Open Discord quick file builder.
776
+ *
777
+ * With this class, you can quickly create a file to use in a message.
778
+ * This quick file can be used by Open Discord plugins instead of the normal builders to speed up the process!
779
+ *
780
+ * Because of the quick functionality, these files are less customisable by other plugins.
781
+ */
782
+ class ODQuickFile {
783
+ /**The id of this file. */
784
+ id;
785
+ /**The current data of this file */
786
+ data;
787
+ constructor(id, data) {
788
+ this.id = new base_1.ODId(id);
789
+ this.data = data;
790
+ }
791
+ /**Build this attachment & compile it for discord.js */
792
+ async build() {
793
+ try {
794
+ //create the discord.js attachment
795
+ const file = new discord.AttachmentBuilder(this.data.file ?? "<empty-file>");
796
+ file.setName(this.data.name ? this.data.name : "file.txt");
797
+ if (this.data.description)
798
+ file.setDescription(this.data.description);
799
+ if (this.data.spoiler)
800
+ file.setSpoiler(this.data.spoiler);
801
+ return { id: this.id, file };
802
+ }
803
+ catch (err) {
804
+ process.emit("uncaughtException", new base_1.ODSystemError("ODQuickFile:build(\"" + this.id.value + "\") => Major Error (see next error)"));
805
+ process.emit("uncaughtException", err);
806
+ return { id: this.id, file: null };
807
+ }
808
+ }
809
+ }
810
+ exports.ODQuickFile = ODQuickFile;
811
+ /**## ODEmbedManager `class`
812
+ * This is an Open Discord embed manager.
813
+ *
814
+ * It contains all Open Discord embed builders. Here, you can add your own embeds or edit existing ones!
815
+ *
816
+ * It's recommended to use this system in combination with all the other Open Discord builders!
817
+ */
818
+ class ODEmbedManager extends base_1.ODManagerWithSafety {
819
+ constructor(debug) {
820
+ super(() => {
821
+ return new ODEmbed("opendiscord:unknown-embed", (instance, params, source, cancel) => {
822
+ instance.setFooter("opendiscord:unknown-embed");
823
+ instance.setColor("#ff0000");
824
+ instance.setTitle("❌ <ODError:Unknown Embed>");
825
+ instance.setDescription("Couldn't find embed in registery `opendiscord.builders.embeds`");
826
+ cancel();
827
+ });
828
+ }, debug, "embed");
829
+ }
830
+ }
831
+ exports.ODEmbedManager = ODEmbedManager;
832
+ /**## ODEmbedInstance `class`
833
+ * This is an Open Discord embed instance.
834
+ *
835
+ * It contains all properties & functions to build an embed!
836
+ */
837
+ class ODEmbedInstance {
838
+ /**The current data of this embed */
839
+ data = {
840
+ title: null,
841
+ color: null,
842
+ url: null,
843
+ description: null,
844
+ authorText: null,
845
+ authorImage: null,
846
+ authorUrl: null,
847
+ footerText: null,
848
+ footerImage: null,
849
+ image: null,
850
+ thumbnail: null,
851
+ fields: [],
852
+ timestamp: null
853
+ };
854
+ /**Set the title of this embed */
855
+ setTitle(title) {
856
+ this.data.title = title;
857
+ return this;
858
+ }
859
+ /**Set the color of this embed */
860
+ setColor(color) {
861
+ this.data.color = color;
862
+ return this;
863
+ }
864
+ /**Set the url of this embed */
865
+ setUrl(url) {
866
+ this.data.url = url;
867
+ return this;
868
+ }
869
+ /**Set the description of this embed */
870
+ setDescription(description) {
871
+ this.data.description = description;
872
+ return this;
873
+ }
874
+ /**Set the author of this embed */
875
+ setAuthor(text, image, url) {
876
+ this.data.authorText = text;
877
+ this.data.authorImage = image ?? null;
878
+ this.data.authorUrl = url ?? null;
879
+ return this;
880
+ }
881
+ /**Set the footer of this embed */
882
+ setFooter(text, image) {
883
+ this.data.footerText = text;
884
+ this.data.footerImage = image ?? null;
885
+ return this;
886
+ }
887
+ /**Set the image of this embed */
888
+ setImage(image) {
889
+ this.data.image = image;
890
+ return this;
891
+ }
892
+ /**Set the thumbnail of this embed */
893
+ setThumbnail(thumbnail) {
894
+ this.data.thumbnail = thumbnail;
895
+ return this;
896
+ }
897
+ /**Set the fields of this embed */
898
+ setFields(fields) {
899
+ //TEMP CHECKS
900
+ fields.forEach((field, index) => {
901
+ if (field.value.length >= 1024)
902
+ throw new base_1.ODSystemError("ODEmbed:setFields() => field " + index + " reached 1024 character limit!");
903
+ if (field.name.length >= 256)
904
+ throw new base_1.ODSystemError("ODEmbed:setFields() => field " + index + " reached 256 name character limit!");
905
+ });
906
+ this.data.fields = fields;
907
+ return this;
908
+ }
909
+ /**Add fields to this embed */
910
+ addFields(...fields) {
911
+ //TEMP CHECKS
912
+ fields.forEach((field, index) => {
913
+ if (field.value.length >= 1024)
914
+ throw new base_1.ODSystemError("ODEmbed:addFields() => field " + index + " reached 1024 character limit!");
915
+ if (field.name.length >= 256)
916
+ throw new base_1.ODSystemError("ODEmbed:addFields() => field " + index + " reached 256 name character limit!");
917
+ });
918
+ this.data.fields.push(...fields);
919
+ return this;
920
+ }
921
+ /**Clear all fields from this embed */
922
+ clearFields() {
923
+ this.data.fields = [];
924
+ return this;
925
+ }
926
+ /**Set the timestamp of this embed */
927
+ setTimestamp(timestamp) {
928
+ this.data.timestamp = timestamp;
929
+ return this;
930
+ }
931
+ }
932
+ exports.ODEmbedInstance = ODEmbedInstance;
933
+ /**## ODEmbed `class`
934
+ * This is an Open Discord embed builder.
935
+ *
936
+ * With this class, you can create a embed to use in a message.
937
+ * The only difference with normal embeds is that this one can be edited by Open Discord plugins!
938
+ *
939
+ * This is possible by using "workers" or multiple functions that will be executed in priority order!
940
+ */
941
+ class ODEmbed extends ODBuilderImplementation {
942
+ /**Build this embed & compile it for discord.js */
943
+ async build(source, params) {
944
+ if (this.didCache && this.cache && this.allowCache)
945
+ return this.cache;
946
+ try {
947
+ //create instance
948
+ const instance = new ODEmbedInstance();
949
+ //wait for workers to finish
950
+ await this.workers.executeWorkers(instance, source, params);
951
+ //create the discord.js embed
952
+ const embed = new discord.EmbedBuilder();
953
+ if (instance.data.title)
954
+ embed.setTitle(instance.data.title);
955
+ if (instance.data.color)
956
+ embed.setColor(instance.data.color);
957
+ if (instance.data.url)
958
+ embed.setURL(instance.data.url);
959
+ if (instance.data.description)
960
+ embed.setDescription(instance.data.description);
961
+ if (instance.data.authorText)
962
+ embed.setAuthor({
963
+ name: instance.data.authorText,
964
+ iconURL: instance.data.authorImage ?? undefined,
965
+ url: instance.data.authorUrl ?? undefined
966
+ });
967
+ if (instance.data.footerText)
968
+ embed.setFooter({
969
+ text: instance.data.footerText,
970
+ iconURL: instance.data.footerImage ?? undefined,
971
+ });
972
+ if (instance.data.image)
973
+ embed.setImage(instance.data.image);
974
+ if (instance.data.thumbnail)
975
+ embed.setThumbnail(instance.data.thumbnail);
976
+ if (instance.data.timestamp)
977
+ embed.setTimestamp(instance.data.timestamp);
978
+ if (instance.data.fields.length > 0)
979
+ embed.setFields(instance.data.fields);
980
+ this.cache = { id: this.id, embed };
981
+ this.didCache = true;
982
+ return { id: this.id, embed };
983
+ }
984
+ catch (err) {
985
+ process.emit("uncaughtException", new base_1.ODSystemError("ODEmbed:build(\"" + this.id.value + "\") => Major Error (see next error)"));
986
+ process.emit("uncaughtException", err);
987
+ return { id: this.id, embed: null };
988
+ }
989
+ }
990
+ }
991
+ exports.ODEmbed = ODEmbed;
992
+ /**## ODQuickEmbed `class`
993
+ * This is an Open Discord quick embed builder.
994
+ *
995
+ * With this class, you can quickly create a embed to use in a message.
996
+ * This quick embed can be used by Open Discord plugins instead of the normal builders to speed up the process!
997
+ *
998
+ * Because of the quick functionality, these embeds are less customisable by other plugins.
999
+ */
1000
+ class ODQuickEmbed {
1001
+ /**The id of this embed. */
1002
+ id;
1003
+ /**The current data of this embed */
1004
+ data;
1005
+ constructor(id, data) {
1006
+ this.id = new base_1.ODId(id);
1007
+ this.data = data;
1008
+ }
1009
+ /**Build this embed & compile it for discord.js */
1010
+ async build() {
1011
+ try {
1012
+ //create the discord.js embed
1013
+ const embed = new discord.EmbedBuilder();
1014
+ if (this.data.title)
1015
+ embed.setTitle(this.data.title);
1016
+ if (this.data.color)
1017
+ embed.setColor(this.data.color);
1018
+ if (this.data.url)
1019
+ embed.setURL(this.data.url);
1020
+ if (this.data.description)
1021
+ embed.setDescription(this.data.description);
1022
+ if (this.data.authorText)
1023
+ embed.setAuthor({
1024
+ name: this.data.authorText,
1025
+ iconURL: this.data.authorImage ?? undefined,
1026
+ url: this.data.authorUrl ?? undefined
1027
+ });
1028
+ if (this.data.footerText)
1029
+ embed.setFooter({
1030
+ text: this.data.footerText,
1031
+ iconURL: this.data.footerImage ?? undefined,
1032
+ });
1033
+ if (this.data.image)
1034
+ embed.setImage(this.data.image);
1035
+ if (this.data.thumbnail)
1036
+ embed.setThumbnail(this.data.thumbnail);
1037
+ if (this.data.timestamp)
1038
+ embed.setTimestamp(this.data.timestamp);
1039
+ if (this.data.fields && this.data.fields.length > 0)
1040
+ embed.setFields(this.data.fields);
1041
+ return { id: this.id, embed };
1042
+ }
1043
+ catch (err) {
1044
+ process.emit("uncaughtException", new base_1.ODSystemError("ODQuickEmbed:build(\"" + this.id.value + "\") => Major Error (see next error)"));
1045
+ process.emit("uncaughtException", err);
1046
+ return { id: this.id, embed: null };
1047
+ }
1048
+ }
1049
+ }
1050
+ exports.ODQuickEmbed = ODQuickEmbed;
1051
+ /**## ODMessageManager `class`
1052
+ * This is an Open Discord message manager.
1053
+ *
1054
+ * It contains all Open Discord message builders. Here, you can add your own messages or edit existing ones!
1055
+ *
1056
+ * It's recommended to use this system in combination with all the other Open Discord builders!
1057
+ */
1058
+ class ODMessageManager extends base_1.ODManagerWithSafety {
1059
+ constructor(debug) {
1060
+ super(() => {
1061
+ return new ODMessage("opendiscord:unknown-message", (instance, params, source, cancel) => {
1062
+ instance.setContent("**❌ <ODError:Unknown Message>**\nCouldn't find message in registery `opendiscord.builders.messages`");
1063
+ cancel();
1064
+ });
1065
+ }, debug, "message");
1066
+ }
1067
+ }
1068
+ exports.ODMessageManager = ODMessageManager;
1069
+ /**## ODMessageInstance `class`
1070
+ * This is an Open Discord message instance.
1071
+ *
1072
+ * It contains all properties & functions to build a message!
1073
+ */
1074
+ class ODMessageInstance {
1075
+ /**The current data of this message */
1076
+ data = {
1077
+ content: null,
1078
+ poll: null,
1079
+ ephemeral: false,
1080
+ embeds: [],
1081
+ components: [],
1082
+ files: [],
1083
+ additionalOptions: {}
1084
+ };
1085
+ /**Set the content of this message */
1086
+ setContent(content) {
1087
+ this.data.content = content;
1088
+ return this;
1089
+ }
1090
+ /**Set the poll of this message */
1091
+ setPoll(poll) {
1092
+ this.data.poll = poll;
1093
+ return this;
1094
+ }
1095
+ /**Make this message ephemeral when possible */
1096
+ setEphemeral(ephemeral) {
1097
+ this.data.ephemeral = ephemeral;
1098
+ return this;
1099
+ }
1100
+ /**Set the embeds of this message */
1101
+ setEmbeds(...embeds) {
1102
+ this.data.embeds = embeds;
1103
+ return this;
1104
+ }
1105
+ /**Add an embed to this message! */
1106
+ addEmbed(embed) {
1107
+ this.data.embeds.push(embed);
1108
+ return this;
1109
+ }
1110
+ /**Remove an embed from this message */
1111
+ removeEmbed(id) {
1112
+ const index = this.data.embeds.findIndex((embed) => embed.id.value === new base_1.ODId(id).value);
1113
+ if (index > -1)
1114
+ this.data.embeds.splice(index, 1);
1115
+ return this;
1116
+ }
1117
+ /**Get an embed from this message */
1118
+ getEmbed(id) {
1119
+ const embed = this.data.embeds.find((embed) => embed.id.value === new base_1.ODId(id).value);
1120
+ if (embed)
1121
+ return embed.embed;
1122
+ else
1123
+ return null;
1124
+ }
1125
+ /**Set the components of this message */
1126
+ setComponents(...components) {
1127
+ this.data.components = components;
1128
+ return this;
1129
+ }
1130
+ /**Add a component to this message! */
1131
+ addComponent(component) {
1132
+ this.data.components.push(component);
1133
+ return this;
1134
+ }
1135
+ /**Remove a component from this message */
1136
+ removeComponent(id) {
1137
+ const index = this.data.components.findIndex((component) => component.id.value === new base_1.ODId(id).value);
1138
+ if (index > -1)
1139
+ this.data.components.splice(index, 1);
1140
+ return this;
1141
+ }
1142
+ /**Get a component from this message */
1143
+ getComponent(id) {
1144
+ const component = this.data.components.find((component) => component.id.value === new base_1.ODId(id).value);
1145
+ if (component)
1146
+ return component.component;
1147
+ else
1148
+ return null;
1149
+ }
1150
+ /**Set the files of this message */
1151
+ setFiles(...files) {
1152
+ this.data.files = files;
1153
+ return this;
1154
+ }
1155
+ /**Add a file to this message! */
1156
+ addFile(file) {
1157
+ this.data.files.push(file);
1158
+ return this;
1159
+ }
1160
+ /**Remove a file from this message */
1161
+ removeFile(id) {
1162
+ const index = this.data.files.findIndex((file) => file.id.value === new base_1.ODId(id).value);
1163
+ if (index > -1)
1164
+ this.data.files.splice(index, 1);
1165
+ return this;
1166
+ }
1167
+ /**Get a file from this message */
1168
+ getFile(id) {
1169
+ const file = this.data.files.find((file) => file.id.value === new base_1.ODId(id).value);
1170
+ if (file)
1171
+ return file.file;
1172
+ else
1173
+ return null;
1174
+ }
1175
+ }
1176
+ exports.ODMessageInstance = ODMessageInstance;
1177
+ /**## ODMessage `class`
1178
+ * This is an Open Discord message builder.
1179
+ *
1180
+ * With this class, you can create a message to send in a discord channel.
1181
+ * The only difference with normal messages is that this one can be edited by Open Discord plugins!
1182
+ *
1183
+ * This is possible by using "workers" or multiple functions that will be executed in priority order!
1184
+ */
1185
+ class ODMessage extends ODBuilderImplementation {
1186
+ /**Build this message & compile it for discord.js */
1187
+ async build(source, params) {
1188
+ if (this.didCache && this.cache && this.allowCache)
1189
+ return this.cache;
1190
+ //create instance
1191
+ const instance = new ODMessageInstance();
1192
+ //wait for workers to finish
1193
+ await this.workers.executeWorkers(instance, source, params);
1194
+ //create the discord.js message
1195
+ const componentArray = [];
1196
+ let currentRow = new discord.ActionRowBuilder();
1197
+ instance.data.components.forEach((c) => {
1198
+ //return when component crashed
1199
+ if (c.component == null)
1200
+ return;
1201
+ else if (c.component == "\n") {
1202
+ //create new current row when required
1203
+ if (currentRow.components.length > 0) {
1204
+ componentArray.push(currentRow);
1205
+ currentRow = new discord.ActionRowBuilder();
1206
+ }
1207
+ }
1208
+ else if (c.component instanceof discord.BaseSelectMenuBuilder) {
1209
+ //push current row when not empty
1210
+ if (currentRow.components.length > 0) {
1211
+ componentArray.push(currentRow);
1212
+ currentRow = new discord.ActionRowBuilder();
1213
+ }
1214
+ currentRow.addComponents(c.component);
1215
+ //create new current row after dropdown
1216
+ componentArray.push(currentRow);
1217
+ currentRow = new discord.ActionRowBuilder();
1218
+ }
1219
+ else {
1220
+ //push button to current row
1221
+ currentRow.addComponents(c.component);
1222
+ }
1223
+ //create new row when 5 rows in length
1224
+ if (currentRow.components.length == 5) {
1225
+ componentArray.push(currentRow);
1226
+ currentRow = new discord.ActionRowBuilder();
1227
+ }
1228
+ });
1229
+ //push final row to array
1230
+ if (currentRow.components.length > 0)
1231
+ componentArray.push(currentRow);
1232
+ const filteredEmbeds = instance.data.embeds.map((e) => e.embed).filter((e) => e instanceof discord.EmbedBuilder);
1233
+ const filteredFiles = instance.data.files.map((f) => f.file).filter((f) => f instanceof discord.AttachmentBuilder);
1234
+ const message = {
1235
+ content: instance.data.content ?? "",
1236
+ poll: instance.data.poll ?? undefined,
1237
+ embeds: filteredEmbeds,
1238
+ components: componentArray,
1239
+ files: filteredFiles
1240
+ };
1241
+ let result = { id: this.id, message, ephemeral: instance.data.ephemeral };
1242
+ Object.assign(result.message, instance.data.additionalOptions);
1243
+ this.cache = result;
1244
+ this.didCache = true;
1245
+ return result;
1246
+ }
1247
+ }
1248
+ exports.ODMessage = ODMessage;
1249
+ /**## ODQuickMessage `class`
1250
+ * This is an Open Discord quick message builder.
1251
+ *
1252
+ * With this class, you can quickly create a message to send in a discord channel.
1253
+ * This quick message can be used by Open Discord plugins instead of the normal builders to speed up the process!
1254
+ *
1255
+ * Because of the quick functionality, these messages are less customisable by other plugins.
1256
+ */
1257
+ class ODQuickMessage {
1258
+ /**The id of this message. */
1259
+ id;
1260
+ /**The current data of this message. */
1261
+ data;
1262
+ constructor(id, data) {
1263
+ this.id = new base_1.ODId(id);
1264
+ this.data = data;
1265
+ }
1266
+ /**Build this message & compile it for discord.js */
1267
+ async build() {
1268
+ //create the discord.js message
1269
+ const componentArray = [];
1270
+ let currentRow = new discord.ActionRowBuilder();
1271
+ this.data.components?.forEach((c) => {
1272
+ //return when component crashed
1273
+ if (c.component == null)
1274
+ return;
1275
+ else if (c.component == "\n") {
1276
+ //create new current row when required
1277
+ if (currentRow.components.length > 0) {
1278
+ componentArray.push(currentRow);
1279
+ currentRow = new discord.ActionRowBuilder();
1280
+ }
1281
+ }
1282
+ else if (c.component instanceof discord.BaseSelectMenuBuilder) {
1283
+ //push current row when not empty
1284
+ if (currentRow.components.length > 0) {
1285
+ componentArray.push(currentRow);
1286
+ currentRow = new discord.ActionRowBuilder();
1287
+ }
1288
+ currentRow.addComponents(c.component);
1289
+ //create new current row after dropdown
1290
+ componentArray.push(currentRow);
1291
+ currentRow = new discord.ActionRowBuilder();
1292
+ }
1293
+ else {
1294
+ //push button to current row
1295
+ currentRow.addComponents(c.component);
1296
+ }
1297
+ //create new row when 5 rows in length
1298
+ if (currentRow.components.length == 5) {
1299
+ componentArray.push(currentRow);
1300
+ currentRow = new discord.ActionRowBuilder();
1301
+ }
1302
+ });
1303
+ //push final row to array
1304
+ if (currentRow.components.length > 0)
1305
+ componentArray.push(currentRow);
1306
+ const filteredEmbeds = this.data.embeds?.map((e) => e.embed).filter((e) => e instanceof discord.EmbedBuilder) ?? [];
1307
+ const filteredFiles = this.data.files?.map((f) => f.file).filter((f) => f instanceof discord.AttachmentBuilder) ?? [];
1308
+ const message = {
1309
+ content: this.data.content ?? "",
1310
+ poll: this.data.poll ?? undefined,
1311
+ embeds: filteredEmbeds,
1312
+ components: componentArray,
1313
+ files: filteredFiles
1314
+ };
1315
+ let result = { id: this.id, message, ephemeral: this.data.ephemeral ?? false };
1316
+ Object.assign(result.message, this.data.additionalOptions);
1317
+ return result;
1318
+ }
1319
+ }
1320
+ exports.ODQuickMessage = ODQuickMessage;
1321
+ /**## ODModalManager `class`
1322
+ * This is an Open Discord modal manager.
1323
+ *
1324
+ * It contains all Open Discord modal builders. Here, you can add your own modals or edit existing ones!
1325
+ *
1326
+ * It's recommended to use this system in combination with all the other Open Discord builders!
1327
+ */
1328
+ class ODModalManager extends base_1.ODManagerWithSafety {
1329
+ constructor(debug) {
1330
+ super(() => {
1331
+ return new ODModal("opendiscord:unknown-modal", (instance, params, source, cancel) => {
1332
+ instance.setCustomId("od:unknown-modal");
1333
+ instance.setTitle("❌ <ODError:Unknown Modal>");
1334
+ instance.setQuestions({
1335
+ style: "short",
1336
+ customId: "error",
1337
+ label: "error",
1338
+ placeholder: "Contact the bot creator for more info!"
1339
+ });
1340
+ cancel();
1341
+ });
1342
+ }, debug, "modal");
1343
+ }
1344
+ }
1345
+ exports.ODModalManager = ODModalManager;
1346
+ /**## ODModalInstance `class`
1347
+ * This is an Open Discord modal instance.
1348
+ *
1349
+ * It contains all properties & functions to build a modal!
1350
+ */
1351
+ class ODModalInstance {
1352
+ /**The current data of this modal */
1353
+ data = {
1354
+ customId: "",
1355
+ title: null,
1356
+ questions: []
1357
+ };
1358
+ /**Set the custom id of this modal */
1359
+ setCustomId(customId) {
1360
+ this.data.customId = customId;
1361
+ return this;
1362
+ }
1363
+ /**Set the title of this modal */
1364
+ setTitle(title) {
1365
+ this.data.title = title;
1366
+ return this;
1367
+ }
1368
+ /**Set the questions of this modal */
1369
+ setQuestions(...questions) {
1370
+ this.data.questions = questions;
1371
+ return this;
1372
+ }
1373
+ /**Add a question to this modal! */
1374
+ addQuestion(question) {
1375
+ this.data.questions.push(question);
1376
+ return this;
1377
+ }
1378
+ /**Remove a question from this modal */
1379
+ removeQuestion(customId) {
1380
+ const index = this.data.questions.findIndex((question) => question.customId === customId);
1381
+ if (index > -1)
1382
+ this.data.questions.splice(index, 1);
1383
+ return this;
1384
+ }
1385
+ /**Get a question from this modal */
1386
+ getQuestion(customId) {
1387
+ const question = this.data.questions.find((question) => question.customId === customId);
1388
+ if (question)
1389
+ return question;
1390
+ else
1391
+ return null;
1392
+ }
1393
+ }
1394
+ exports.ODModalInstance = ODModalInstance;
1395
+ /**## ODModal `class`
1396
+ * This is an Open Discord modal builder.
1397
+ *
1398
+ * With this class, you can create a modal to use as response in interactions.
1399
+ * The only difference with normal modals is that this one can be edited by Open Discord plugins!
1400
+ *
1401
+ * This is possible by using "workers" or multiple functions that will be executed in priority order!
1402
+ */
1403
+ class ODModal extends ODBuilderImplementation {
1404
+ /**Build this modal & compile it for discord.js */
1405
+ async build(source, params) {
1406
+ if (this.didCache && this.cache && this.allowCache)
1407
+ return this.cache;
1408
+ //create instance
1409
+ const instance = new ODModalInstance();
1410
+ //wait for workers to finish
1411
+ await this.workers.executeWorkers(instance, source, params);
1412
+ //create the discord.js modal
1413
+ const modal = new discord.ModalBuilder();
1414
+ modal.setCustomId(instance.data.customId);
1415
+ if (instance.data.title)
1416
+ modal.setTitle(instance.data.title);
1417
+ else
1418
+ modal.setTitle(instance.data.customId);
1419
+ instance.data.questions.forEach((question) => {
1420
+ const input = new discord.TextInputBuilder()
1421
+ .setStyle(question.style == "paragraph" ? discord.TextInputStyle.Paragraph : discord.TextInputStyle.Short)
1422
+ .setCustomId(question.customId)
1423
+ .setLabel(question.label ? question.label : question.customId)
1424
+ .setRequired(question.required ? true : false);
1425
+ if (question.minLength)
1426
+ input.setMinLength(question.minLength);
1427
+ if (question.maxLength)
1428
+ input.setMaxLength(question.maxLength);
1429
+ if (question.value)
1430
+ input.setValue(question.value);
1431
+ if (question.placeholder)
1432
+ input.setPlaceholder(question.placeholder);
1433
+ modal.addComponents(new discord.ActionRowBuilder()
1434
+ .addComponents(input));
1435
+ });
1436
+ this.cache = { id: this.id, modal };
1437
+ this.didCache = true;
1438
+ return { id: this.id, modal };
1439
+ }
1440
+ }
1441
+ exports.ODModal = ODModal;