@open-discord-bots/framework 0.3.0 → 0.3.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.
Files changed (61) hide show
  1. package/dist/api/main.js +1 -1
  2. package/dist/api/modules/base.d.ts +27 -9
  3. package/dist/api/modules/base.js +78 -80
  4. package/dist/api/modules/builder.d.ts +0 -9
  5. package/dist/api/modules/checker.d.ts +26 -5
  6. package/dist/api/modules/checker.js +31 -31
  7. package/dist/api/modules/client.d.ts +66 -14
  8. package/dist/api/modules/client.js +146 -132
  9. package/dist/api/modules/component.d.ts +8 -2
  10. package/dist/api/modules/component.js +8 -6
  11. package/dist/api/modules/config.d.ts +0 -1
  12. package/dist/api/modules/config.js +9 -7
  13. package/dist/api/modules/console.d.ts +16 -4
  14. package/dist/api/modules/console.js +25 -25
  15. package/dist/api/modules/event.d.ts +4 -2
  16. package/dist/api/modules/event.js +8 -10
  17. package/dist/api/modules/fuse.d.ts +1 -1
  18. package/dist/api/modules/helpmenu.d.ts +2 -2
  19. package/dist/api/modules/helpmenu.js +4 -7
  20. package/dist/api/modules/language.d.ts +2 -1
  21. package/dist/api/modules/language.js +6 -9
  22. package/dist/api/modules/permission.d.ts +10 -1
  23. package/dist/api/modules/permission.js +17 -20
  24. package/dist/api/modules/plugin.d.ts +2 -1
  25. package/dist/api/modules/plugin.js +2 -2
  26. package/dist/api/modules/post.d.ts +12 -4
  27. package/dist/api/modules/post.js +36 -10
  28. package/dist/api/modules/progressbar.d.ts +16 -5
  29. package/dist/api/modules/progressbar.js +34 -34
  30. package/dist/api/modules/responder.d.ts +95 -26
  31. package/dist/api/modules/responder.js +213 -172
  32. package/dist/api/modules/session.d.ts +10 -1
  33. package/dist/api/modules/session.js +15 -15
  34. package/dist/api/modules/startscreen.d.ts +0 -1
  35. package/dist/api/modules/startscreen.js +3 -6
  36. package/dist/api/modules/statistic.d.ts +2 -1
  37. package/dist/api/modules/statistic.js +4 -7
  38. package/dist/api/modules/worker.d.ts +2 -1
  39. package/dist/api/modules/worker.js +3 -3
  40. package/package.json +1 -1
  41. package/src/api/main.ts +1 -1
  42. package/src/api/modules/base.ts +75 -77
  43. package/src/api/modules/builder.ts +0 -10
  44. package/src/api/modules/checker.ts +31 -31
  45. package/src/api/modules/client.ts +144 -136
  46. package/src/api/modules/component.ts +11 -7
  47. package/src/api/modules/config.ts +8 -6
  48. package/src/api/modules/console.ts +25 -25
  49. package/src/api/modules/event.ts +6 -10
  50. package/src/api/modules/fuse.ts +1 -1
  51. package/src/api/modules/helpmenu.ts +4 -7
  52. package/src/api/modules/language.ts +6 -9
  53. package/src/api/modules/permission.ts +17 -20
  54. package/src/api/modules/plugin.ts +2 -2
  55. package/src/api/modules/post.ts +31 -10
  56. package/src/api/modules/progressbar.ts +34 -34
  57. package/src/api/modules/responder.ts +232 -181
  58. package/src/api/modules/session.ts +14 -14
  59. package/src/api/modules/startscreen.ts +3 -6
  60. package/src/api/modules/statistic.ts +4 -7
  61. package/src/api/modules/worker.ts +3 -3
@@ -3,7 +3,8 @@ import * as discord from "discord.js";
3
3
  import { ODWorkerManager, ODWorkerCallback } from "./worker.js";
4
4
  import { ODDebugger } from "./console.js";
5
5
  import { ODClientManager, ODContextMenu, ODSlashCommand, ODTextCommand, ODTextCommandInteractionOption } from "./client.js";
6
- import { ODDropdownData, ODMessageBuildResult, ODMessageBuildSentResult, ODModalBuildResult } from "./builder.js";
6
+ import { ODDropdownData, ODMessageBuildResult, ODModalBuildResult } from "./builder.js";
7
+ import { ODMessageComponentBuildResult } from "./component.js";
7
8
  /**## ODResponderImplementation `class`
8
9
  * This is an Open Discord responder implementation.
9
10
  *
@@ -23,7 +24,21 @@ export declare abstract class ODResponderImplementation<Instance, Origin extends
23
24
  /**## ODResponderTimeoutErrorCallback `type`
24
25
  * This is the callback for the responder timeout function. It will be executed when something went wrong or the action takes too much time.
25
26
  */
26
- export type ODResponderTimeoutErrorCallback<Instance, Origin extends "slash" | "text" | "button" | "dropdown" | "modal" | "other" | "context-menu" | "autocomplete"> = (instance: Instance, origin: Origin) => void | Promise<void>;
27
+ export type ODResponderTimeoutErrorCallback<Instance, Origin extends "slash" | "text" | "button" | "dropdown" | "modal" | "other" | "context-menu" | "autocomplete"> = (instance: Instance, origin: Origin) => ODResponderSendResult<boolean> | Promise<ODResponderSendResult<boolean>>;
28
+ /**## ODResponderSendResult `type`
29
+ * The result from a sent message using responders. Can be used to edit, view & save the message that got created.
30
+ */
31
+ export type ODResponderSendResult<InGuild extends boolean> = {
32
+ /**Did the message get sent successfully? */
33
+ success: true;
34
+ /**The message that got sent. */
35
+ message: discord.Message<InGuild>;
36
+ } | {
37
+ /**Did the message get sent successfully? */
38
+ success: boolean;
39
+ /**The message that got sent. */
40
+ message: null;
41
+ };
27
42
  /**## ODResponderManager `class`
28
43
  * This is an Open Discord responder manager.
29
44
  *
@@ -53,6 +68,15 @@ export declare class ODResponderManager<CommandIdList extends ODCommandResponder
53
68
  autocomplete: ODAutocompleteResponderManager<AutocompleteIdList>;
54
69
  constructor(debug: ODDebugger, client: ODClientManager);
55
70
  }
71
+ /**## ODBaseResponderInstance `class`
72
+ * A base class for creating responder instances.
73
+ */
74
+ export declare abstract class ODBaseResponderInstance {
75
+ /**Get the final `messageCreateOptions` from a returned build result from builders/components. */
76
+ protected getMessageFromBuildResult(build: ODMessageBuildResult | ODMessageComponentBuildResult, type: "interaction" | "message"): discord.MessageCreateOptions & {
77
+ flags: number[];
78
+ };
79
+ }
56
80
  /**## ODCommandResponderManagerIdConstraint `type`
57
81
  * The constraint/layout for id mappings/interfaces of the `ODCommandResponderManager` class.
58
82
  */
@@ -76,7 +100,12 @@ export type ODCommandResponderManagerIdConstraint = Record<string, {
76
100
  * - And so much more!
77
101
  */
78
102
  export declare class ODCommandResponderManager<IdList extends ODCommandResponderManagerIdConstraint = ODCommandResponderManagerIdConstraint> extends ODManager<ODCommandResponder<"slash" | "text", any>> {
79
- #private;
103
+ /**An alias to the Open Discord client manager. */
104
+ private client;
105
+ /**The callback executed when the default workers take too much time to reply. */
106
+ private timeoutErrorCallback;
107
+ /**The amount of milliseconds before the timeout error callback is executed. */
108
+ private timeoutMs;
80
109
  constructor(debug: ODDebugger, debugname: string, client: ODClientManager);
81
110
  /**Set the message to send when the response times out! */
82
111
  setTimeoutErrorCallback(callback: ODResponderTimeoutErrorCallback<ODCommandResponderInstance, "slash" | "text"> | null, ms: number | null): void;
@@ -94,7 +123,12 @@ export declare class ODCommandResponderManager<IdList extends ODCommandResponder
94
123
  * This class will manage all options & subcommands from slash & text commands.
95
124
  */
96
125
  export declare class ODCommandResponderInstanceOptions {
97
- #private;
126
+ /**The interaction to get data from. */
127
+ private interaction;
128
+ /**The command which is related to the interaction. */
129
+ private cmd;
130
+ /**A list of options which have been parsed by the text command parser. */
131
+ private options;
98
132
  constructor(interaction: discord.ChatInputCommandInteraction | discord.Message, cmd: ODSlashCommand | ODTextCommand, options?: ODTextCommandInteractionOption[]);
99
133
  /**Get a string option. */
100
134
  getString(name: string, required: true): string;
@@ -130,7 +164,7 @@ export declare class ODCommandResponderInstanceOptions {
130
164
  *
131
165
  * An instance is an active slash interaction or used text command. You can reply to the command using `reply()` for both slash & text commands.
132
166
  */
133
- export declare class ODCommandResponderInstance {
167
+ export declare class ODCommandResponderInstance extends ODBaseResponderInstance {
134
168
  /**The interaction which is the source of this instance. */
135
169
  interaction: discord.ChatInputCommandInteraction | discord.Message;
136
170
  /**The command wich is the source of this instance. */
@@ -151,7 +185,7 @@ export declare class ODCommandResponderInstance {
151
185
  channel: discord.TextBasedChannel;
152
186
  constructor(interaction: discord.ChatInputCommandInteraction | discord.Message, cmd: ODSlashCommand | ODTextCommand, errorCallback: ODResponderTimeoutErrorCallback<ODCommandResponderInstance, "slash" | "text"> | null, timeoutMs: number | null, options?: ODTextCommandInteractionOption[]);
153
187
  /**Reply to this command. */
154
- reply(msg: ODMessageBuildResult): Promise<ODMessageBuildSentResult<boolean>>;
188
+ reply(build: ODMessageBuildResult | ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>>;
155
189
  /**Defer this command. */
156
190
  defer(ephemeral: boolean): Promise<boolean>;
157
191
  /**Show a modal as reply to this command. */
@@ -191,7 +225,14 @@ export type ODButtonResponderManagerIdConstraint = Record<string, {
191
225
  * - And so much more!
192
226
  */
193
227
  export declare class ODButtonResponderManager<IdList extends ODButtonResponderManagerIdConstraint = ODButtonResponderManagerIdConstraint> extends ODManager<ODButtonResponder<"button", any>> {
194
- #private;
228
+ /**An alias to the Open Discord client manager. */
229
+ private client;
230
+ /**The callback executed when the default workers take too much time to reply. */
231
+ private timeoutErrorCallback;
232
+ /**The amount of milliseconds before the timeout error callback is executed. */
233
+ private timeoutMs;
234
+ /**A list of listeners which will listen to the raw interactionCreate event from discord.js */
235
+ private listeners;
195
236
  constructor(debug: ODDebugger, debugname: string, client: ODClientManager);
196
237
  /**Set the message to send when the response times out! */
197
238
  setTimeoutErrorCallback(callback: ODResponderTimeoutErrorCallback<ODButtonResponderInstance, "button"> | null, ms: number | null): void;
@@ -208,7 +249,7 @@ export declare class ODButtonResponderManager<IdList extends ODButtonResponderMa
208
249
  *
209
250
  * An instance is an active button interaction. You can reply to the button using `reply()`.
210
251
  */
211
- export declare class ODButtonResponderInstance {
252
+ export declare class ODButtonResponderInstance extends ODBaseResponderInstance {
212
253
  /**The interaction which is the source of this instance. */
213
254
  interaction: discord.ButtonInteraction;
214
255
  /**Did a worker already reply to this instance/interaction? */
@@ -225,9 +266,9 @@ export declare class ODButtonResponderInstance {
225
266
  message: discord.Message;
226
267
  constructor(interaction: discord.ButtonInteraction, errorCallback: ODResponderTimeoutErrorCallback<ODButtonResponderInstance, "button"> | null, timeoutMs: number | null);
227
268
  /**Reply to this button. */
228
- reply(msg: ODMessageBuildResult): Promise<ODMessageBuildSentResult<boolean>>;
269
+ reply(build: ODMessageBuildResult | ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>>;
229
270
  /**Update the message of this button. */
230
- update(msg: ODMessageBuildResult): Promise<ODMessageBuildSentResult<boolean>>;
271
+ update(build: ODMessageBuildResult | ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>>;
231
272
  /**Defer this button. */
232
273
  defer(type: "reply" | "update", ephemeral: boolean): Promise<boolean>;
233
274
  /**Show a modal as reply to this button. */
@@ -273,7 +314,14 @@ export type ODDropdownResponderManagerIdConstraint = Record<string, {
273
314
  * - And so much more!
274
315
  */
275
316
  export declare class ODDropdownResponderManager<IdList extends ODDropdownResponderManagerIdConstraint = ODDropdownResponderManagerIdConstraint> extends ODManager<ODDropdownResponder<"dropdown", any>> {
276
- #private;
317
+ /**An alias to the Open Discord client manager. */
318
+ private client;
319
+ /**The callback executed when the default workers take too much time to reply. */
320
+ private timeoutErrorCallback;
321
+ /**The amount of milliseconds before the timeout error callback is executed. */
322
+ private timeoutMs;
323
+ /**A list of listeners which will listen to the raw interactionCreate event from discord.js */
324
+ private listeners;
277
325
  constructor(debug: ODDebugger, debugname: string, client: ODClientManager);
278
326
  /**Set the message to send when the response times out! */
279
327
  setTimeoutErrorCallback(callback: ODResponderTimeoutErrorCallback<ODDropdownResponderInstance, "dropdown"> | null, ms: number | null): void;
@@ -291,7 +339,10 @@ export declare class ODDropdownResponderManager<IdList extends ODDropdownRespond
291
339
  * This class will manage all values from the dropdowns & select menus.
292
340
  */
293
341
  export declare class ODDropdownResponderInstanceValues {
294
- #private;
342
+ /**The interaction to get data from. */
343
+ private interaction;
344
+ /**The type of this dropdown. */
345
+ private type;
295
346
  constructor(interaction: discord.AnySelectMenuInteraction, type: ODDropdownData["type"]);
296
347
  /**Get the selected values. */
297
348
  getStringValues(): string[];
@@ -307,7 +358,7 @@ export declare class ODDropdownResponderInstanceValues {
307
358
  *
308
359
  * An instance is an active dropdown interaction. You can reply to the dropdown using `reply()`.
309
360
  */
310
- export declare class ODDropdownResponderInstance {
361
+ export declare class ODDropdownResponderInstance extends ODBaseResponderInstance {
311
362
  /**The interaction which is the source of this instance. */
312
363
  interaction: discord.AnySelectMenuInteraction;
313
364
  /**Did a worker already reply to this instance/interaction? */
@@ -328,9 +379,9 @@ export declare class ODDropdownResponderInstance {
328
379
  message: discord.Message;
329
380
  constructor(interaction: discord.AnySelectMenuInteraction, errorCallback: ODResponderTimeoutErrorCallback<ODDropdownResponderInstance, "dropdown"> | null, timeoutMs: number | null);
330
381
  /**Reply to this dropdown. */
331
- reply(msg: ODMessageBuildResult): Promise<ODMessageBuildSentResult<boolean>>;
382
+ reply(build: ODMessageBuildResult | ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>>;
332
383
  /**Update the message of this dropdown. */
333
- update(msg: ODMessageBuildResult): Promise<ODMessageBuildSentResult<boolean>>;
384
+ update(build: ODMessageBuildResult | ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>>;
334
385
  /**Defer this dropdown. */
335
386
  defer(type: "reply" | "update", ephemeral: boolean): Promise<boolean>;
336
387
  /**Show a modal as reply to this dropdown. */
@@ -376,7 +427,14 @@ export type ODModalResponderManagerIdConstraint = Record<string, {
376
427
  * - And so much more!
377
428
  */
378
429
  export declare class ODModalResponderManager<IdList extends ODModalResponderManagerIdConstraint = ODModalResponderManagerIdConstraint> extends ODManager<ODModalResponder<"modal", any>> {
379
- #private;
430
+ /**An alias to the Open Discord client manager. */
431
+ private client;
432
+ /**The callback executed when the default workers take too much time to reply. */
433
+ private timeoutErrorCallback;
434
+ /**The amount of milliseconds before the timeout error callback is executed. */
435
+ private timeoutMs;
436
+ /**A list of listeners which will listen to the raw interactionCreate event from discord.js */
437
+ private listeners;
380
438
  constructor(debug: ODDebugger, debugname: string, client: ODClientManager);
381
439
  /**Set the message to send when the response times out! */
382
440
  setTimeoutErrorCallback(callback: ODResponderTimeoutErrorCallback<ODModalResponderInstance, "modal"> | null, ms: number | null): void;
@@ -394,7 +452,8 @@ export declare class ODModalResponderManager<IdList extends ODModalResponderMana
394
452
  * This class will manage all fields from the modals.
395
453
  */
396
454
  export declare class ODModalResponderInstanceValues {
397
- #private;
455
+ /**The interaction to get data from. */
456
+ private interaction;
398
457
  constructor(interaction: discord.ModalSubmitInteraction);
399
458
  /**Get the value of a text field. */
400
459
  getTextField(name: string, required: true): string;
@@ -405,7 +464,7 @@ export declare class ODModalResponderInstanceValues {
405
464
  *
406
465
  * An instance is an active modal interaction. You can reply to the modal using `reply()`.
407
466
  */
408
- export declare class ODModalResponderInstance {
467
+ export declare class ODModalResponderInstance extends ODBaseResponderInstance {
409
468
  /**The interaction which is the source of this instance. */
410
469
  interaction: discord.ModalSubmitInteraction;
411
470
  /**Did a worker already reply to this instance/interaction? */
@@ -422,9 +481,9 @@ export declare class ODModalResponderInstance {
422
481
  channel: discord.TextBasedChannel | null;
423
482
  constructor(interaction: discord.ModalSubmitInteraction, errorCallback: ODResponderTimeoutErrorCallback<ODModalResponderInstance, "modal"> | null, timeoutMs: number | null);
424
483
  /**Reply to this modal. */
425
- reply(msg: ODMessageBuildResult): Promise<ODMessageBuildSentResult<boolean>>;
484
+ reply(build: ODMessageBuildResult | ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>>;
426
485
  /**Update the message of this modal. */
427
- update(msg: ODMessageBuildResult): Promise<ODMessageBuildSentResult<boolean>>;
486
+ update(build: ODMessageBuildResult | ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>>;
428
487
  /**Defer this modal. */
429
488
  defer(type: "reply" | "update", ephemeral: boolean): Promise<boolean>;
430
489
  }
@@ -459,7 +518,12 @@ export type ODContextMenuResponderManagerIdConstraint = Record<string, {
459
518
  * - And so much more!
460
519
  */
461
520
  export declare class ODContextMenuResponderManager<IdList extends ODContextMenuResponderManagerIdConstraint = ODContextMenuResponderManagerIdConstraint> extends ODManager<ODContextMenuResponder<"context-menu", any>> {
462
- #private;
521
+ /**An alias to the Open Discord client manager. */
522
+ private client;
523
+ /**The callback executed when the default workers take too much time to reply. */
524
+ private timeoutErrorCallback;
525
+ /**The amount of milliseconds before the timeout error callback is executed. */
526
+ private timeoutMs;
463
527
  constructor(debug: ODDebugger, debugname: string, client: ODClientManager);
464
528
  /**Set the message to send when the response times out! */
465
529
  setTimeoutErrorCallback(callback: ODResponderTimeoutErrorCallback<ODContextMenuResponderInstance, "context-menu"> | null, ms: number | null): void;
@@ -476,7 +540,7 @@ export declare class ODContextMenuResponderManager<IdList extends ODContextMenuR
476
540
  *
477
541
  * An instance is an active context menu interaction. You can reply to the context menu using `reply()`.
478
542
  */
479
- export declare class ODContextMenuResponderInstance {
543
+ export declare class ODContextMenuResponderInstance extends ODBaseResponderInstance {
480
544
  /**The interaction which is the source of this instance. */
481
545
  interaction: discord.ContextMenuCommandInteraction;
482
546
  /**Did a worker already reply to this instance/interaction? */
@@ -495,9 +559,9 @@ export declare class ODContextMenuResponderInstance {
495
559
  target: discord.Message | discord.User;
496
560
  constructor(interaction: discord.ContextMenuCommandInteraction, menu: ODContextMenu, errorCallback: ODResponderTimeoutErrorCallback<ODContextMenuResponderInstance, "context-menu"> | null, timeoutMs: number | null);
497
561
  /**Reply to this context menu. */
498
- reply(msg: ODMessageBuildResult): Promise<ODMessageBuildSentResult<boolean>>;
562
+ reply(build: ODMessageBuildResult | ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>>;
499
563
  /**Update the message of this context menu. */
500
- update(msg: ODMessageBuildResult): Promise<ODMessageBuildSentResult<boolean>>;
564
+ update(build: ODMessageBuildResult | ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>>;
501
565
  /**Defer this context menu. */
502
566
  defer(type: "reply", ephemeral: boolean): Promise<boolean>;
503
567
  /**Show a modal as reply to this context menu. */
@@ -534,7 +598,12 @@ export type ODAutocompleteResponderManagerIdConstraint = Record<string, {
534
598
  * - And so much more!
535
599
  */
536
600
  export declare class ODAutocompleteResponderManager<IdList extends ODAutocompleteResponderManagerIdConstraint = ODAutocompleteResponderManagerIdConstraint> extends ODManager<ODAutocompleteResponder<"autocomplete", any>> {
537
- #private;
601
+ /**An alias to the Open Discord client manager. */
602
+ private client;
603
+ /**The callback executed when the default workers take too much time to reply. */
604
+ private timeoutErrorCallback;
605
+ /**The amount of milliseconds before the timeout error callback is executed. */
606
+ private timeoutMs;
538
607
  constructor(debug: ODDebugger, debugname: string, client: ODClientManager);
539
608
  /**Set the message to send when the response times out! */
540
609
  setTimeoutErrorCallback(callback: ODResponderTimeoutErrorCallback<ODAutocompleteResponderInstance, "autocomplete"> | null, ms: number | null): void;
@@ -551,7 +620,7 @@ export declare class ODAutocompleteResponderManager<IdList extends ODAutocomplet
551
620
  *
552
621
  * An instance is an active autocomplete interaction. You can reply to the autocomplete using `reply()`.
553
622
  */
554
- export declare class ODAutocompleteResponderInstance {
623
+ export declare class ODAutocompleteResponderInstance extends ODBaseResponderInstance {
555
624
  /**The interaction which is the source of this instance. */
556
625
  interaction: discord.AutocompleteInteraction;
557
626
  /**Did a worker already respond to this instance/interaction? */