@open-discord-bots/framework 0.3.14 → 0.3.15

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 (41) hide show
  1. package/dist/api/main.js +1 -1
  2. package/dist/api/modules/responder.js +50 -26
  3. package/package.json +1 -1
  4. package/src/api/index.ts +0 -31
  5. package/src/api/main.ts +0 -203
  6. package/src/api/modules/action.ts +0 -89
  7. package/src/api/modules/base.ts +0 -845
  8. package/src/api/modules/builder.ts +0 -1755
  9. package/src/api/modules/checker.ts +0 -1826
  10. package/src/api/modules/client.ts +0 -2345
  11. package/src/api/modules/code.ts +0 -84
  12. package/src/api/modules/component.ts +0 -2000
  13. package/src/api/modules/config.ts +0 -264
  14. package/src/api/modules/console.ts +0 -697
  15. package/src/api/modules/cooldown.ts +0 -369
  16. package/src/api/modules/database.ts +0 -321
  17. package/src/api/modules/event.ts +0 -123
  18. package/src/api/modules/flag.ts +0 -99
  19. package/src/api/modules/fuse.ts +0 -365
  20. package/src/api/modules/helpmenu.ts +0 -273
  21. package/src/api/modules/language.ts +0 -230
  22. package/src/api/modules/permission.ts +0 -363
  23. package/src/api/modules/plugin.ts +0 -294
  24. package/src/api/modules/post.ts +0 -137
  25. package/src/api/modules/progressbar.ts +0 -370
  26. package/src/api/modules/responder.ts +0 -1625
  27. package/src/api/modules/session.ts +0 -181
  28. package/src/api/modules/startscreen.ts +0 -345
  29. package/src/api/modules/state.ts +0 -298
  30. package/src/api/modules/statistic.ts +0 -380
  31. package/src/api/modules/verifybar.ts +0 -68
  32. package/src/api/modules/worker.ts +0 -119
  33. package/src/cli/editConfig.ts +0 -930
  34. package/src/cli/index.ts +0 -152
  35. package/src/index.ts +0 -8
  36. package/src/startup/compilation.ts +0 -204
  37. package/src/startup/dump.ts +0 -46
  38. package/src/startup/errorHandling.ts +0 -42
  39. package/src/startup/pluginLauncher.ts +0 -265
  40. package/src/utilities/index.ts +0 -229
  41. package/tools/cleanup.js +0 -2
package/dist/api/main.js CHANGED
@@ -44,7 +44,7 @@ export class ODMain {
44
44
  constructor(managers, project) {
45
45
  this.project = project;
46
46
  this.versions = managers.versions;
47
- this.versions.add(ODVersion.fromString("opendiscord:api", "v0.3.14"));
47
+ this.versions.add(ODVersion.fromString("opendiscord:api", "v0.3.15"));
48
48
  this.versions.add(ODVersion.fromString("opendiscord:livestatus", "v2.0.0"));
49
49
  this.debugfile = managers.debugfile;
50
50
  this.console = managers.console;
@@ -170,7 +170,8 @@ export class ODCommandResponderInstanceOptions {
170
170
  try {
171
171
  return this.interaction.options.getString(name, required);
172
172
  }
173
- catch {
173
+ catch (err) {
174
+ process.emit("uncaughtException", err);
174
175
  throw new ODSystemError("ODCommandResponderInstanceOptions:getString() slash command option not found!");
175
176
  }
176
177
  }
@@ -189,7 +190,8 @@ export class ODCommandResponderInstanceOptions {
189
190
  try {
190
191
  return this.interaction.options.getBoolean(name, required);
191
192
  }
192
- catch {
193
+ catch (err) {
194
+ process.emit("uncaughtException", err);
193
195
  throw new ODSystemError("ODCommandResponderInstanceOptions:getBoolean() slash command option not found!");
194
196
  }
195
197
  }
@@ -208,7 +210,8 @@ export class ODCommandResponderInstanceOptions {
208
210
  try {
209
211
  return this.interaction.options.getNumber(name, required);
210
212
  }
211
- catch {
213
+ catch (err) {
214
+ process.emit("uncaughtException", err);
212
215
  throw new ODSystemError("ODCommandResponderInstanceOptions:getNumber() slash command option not found!");
213
216
  }
214
217
  }
@@ -227,7 +230,8 @@ export class ODCommandResponderInstanceOptions {
227
230
  try {
228
231
  return this.interaction.options.getChannel(name, required);
229
232
  }
230
- catch {
233
+ catch (err) {
234
+ process.emit("uncaughtException", err);
231
235
  throw new ODSystemError("ODCommandResponderInstanceOptions:getChannel() slash command option not found!");
232
236
  }
233
237
  }
@@ -246,7 +250,8 @@ export class ODCommandResponderInstanceOptions {
246
250
  try {
247
251
  return this.interaction.options.getRole(name, required);
248
252
  }
249
- catch {
253
+ catch (err) {
254
+ process.emit("uncaughtException", err);
250
255
  throw new ODSystemError("ODCommandResponderInstanceOptions:getRole() slash command option not found!");
251
256
  }
252
257
  }
@@ -265,7 +270,8 @@ export class ODCommandResponderInstanceOptions {
265
270
  try {
266
271
  return this.interaction.options.getUser(name, required);
267
272
  }
268
- catch {
273
+ catch (err) {
274
+ process.emit("uncaughtException", err);
269
275
  throw new ODSystemError("ODCommandResponderInstanceOptions:getUser() slash command option not found!");
270
276
  }
271
277
  }
@@ -287,7 +293,8 @@ export class ODCommandResponderInstanceOptions {
287
293
  throw new ODSystemError("ODCommandResponderInstanceOptions:getGuildMember() slash command option not found!");
288
294
  return member;
289
295
  }
290
- catch {
296
+ catch (err) {
297
+ process.emit("uncaughtException", err);
291
298
  throw new ODSystemError("ODCommandResponderInstanceOptions:getGuildMember() slash command option not found!");
292
299
  }
293
300
  }
@@ -306,7 +313,8 @@ export class ODCommandResponderInstanceOptions {
306
313
  try {
307
314
  return this.interaction.options.getMentionable(name, required);
308
315
  }
309
- catch {
316
+ catch (err) {
317
+ process.emit("uncaughtException", err);
310
318
  throw new ODSystemError("ODCommandResponderInstanceOptions:getGuildMember() slash command option not found!");
311
319
  }
312
320
  }
@@ -325,7 +333,8 @@ export class ODCommandResponderInstanceOptions {
325
333
  try {
326
334
  return this.interaction.options.getSubcommandGroup(true);
327
335
  }
328
- catch {
336
+ catch (err) {
337
+ process.emit("uncaughtException", err);
329
338
  throw new ODSystemError("ODCommandResponderInstanceOptions:getSubGroup() slash command option not found!");
330
339
  }
331
340
  }
@@ -342,7 +351,8 @@ export class ODCommandResponderInstanceOptions {
342
351
  try {
343
352
  return this.interaction.options.getSubcommand(true);
344
353
  }
345
- catch {
354
+ catch (err) {
355
+ process.emit("uncaughtException", err);
346
356
  throw new ODSystemError("ODCommandResponderInstanceOptions:getSubCommand() slash command option not found!");
347
357
  }
348
358
  }
@@ -444,7 +454,8 @@ export class ODCommandResponderInstance extends ODBaseResponderInstance {
444
454
  else
445
455
  return { success: false };
446
456
  }
447
- catch {
457
+ catch (err) {
458
+ process.emit("uncaughtException", err);
448
459
  return { success: false };
449
460
  }
450
461
  }
@@ -608,7 +619,8 @@ export class ODButtonResponderInstance extends ODBaseResponderInstance {
608
619
  return { success: true, message: await sent.fetch(), ephemeral: build.ephemeral };
609
620
  }
610
621
  }
611
- catch {
622
+ catch (err) {
623
+ process.emit("uncaughtException", err);
612
624
  return { success: false };
613
625
  }
614
626
  }
@@ -627,7 +639,8 @@ export class ODButtonResponderInstance extends ODBaseResponderInstance {
627
639
  return { success: true, message: await sent.fetch(), ephemeral: build.ephemeral };
628
640
  }
629
641
  }
630
- catch {
642
+ catch (err) {
643
+ process.emit("uncaughtException", err);
631
644
  return { success: false };
632
645
  }
633
646
  }
@@ -771,7 +784,8 @@ export class ODDropdownResponderInstanceValues {
771
784
  try {
772
785
  return this.interaction.values;
773
786
  }
774
- catch {
787
+ catch (err) {
788
+ process.emit("uncaughtException", err);
775
789
  throw new ODSystemError("ODDropdownResponderInstanceValues:getStringValues() invalid values!");
776
790
  }
777
791
  }
@@ -790,7 +804,8 @@ export class ODDropdownResponderInstanceValues {
790
804
  }
791
805
  return result;
792
806
  }
793
- catch {
807
+ catch (err) {
808
+ process.emit("uncaughtException", err);
794
809
  throw new ODSystemError("ODDropdownResponderInstanceValues:getRoleValues() invalid values!");
795
810
  }
796
811
  }
@@ -807,7 +822,8 @@ export class ODDropdownResponderInstanceValues {
807
822
  }
808
823
  return result;
809
824
  }
810
- catch {
825
+ catch (err) {
826
+ process.emit("uncaughtException", err);
811
827
  throw new ODSystemError("ODDropdownResponderInstanceValues:getUserValues() invalid values!");
812
828
  }
813
829
  }
@@ -826,7 +842,8 @@ export class ODDropdownResponderInstanceValues {
826
842
  }
827
843
  return result;
828
844
  }
829
- catch {
845
+ catch (err) {
846
+ process.emit("uncaughtException", err);
830
847
  throw new ODSystemError("ODDropdownResponderInstanceValues:getChannelValues() invalid values!");
831
848
  }
832
849
  }
@@ -916,7 +933,8 @@ export class ODDropdownResponderInstance extends ODBaseResponderInstance {
916
933
  return { success: true, message: await sent.fetch(), ephemeral: build.ephemeral };
917
934
  }
918
935
  }
919
- catch {
936
+ catch (err) {
937
+ process.emit("uncaughtException", err);
920
938
  return { success: false };
921
939
  }
922
940
  }
@@ -935,7 +953,8 @@ export class ODDropdownResponderInstance extends ODBaseResponderInstance {
935
953
  return { success: true, message: await sent.fetch(), ephemeral: build.ephemeral };
936
954
  }
937
955
  }
938
- catch {
956
+ catch (err) {
957
+ process.emit("uncaughtException", err);
939
958
  return { success: false };
940
959
  }
941
960
  }
@@ -1075,7 +1094,8 @@ export class ODModalResponderInstanceValues {
1075
1094
  throw new ODSystemError("ODModalResponderInstanceValues:getTextField() field not found!");
1076
1095
  return (data) ? data.value : null;
1077
1096
  }
1078
- catch {
1097
+ catch (err) {
1098
+ process.emit("uncaughtException", err);
1079
1099
  throw new ODSystemError("ODModalResponderInstanceValues:getTextField() field not found!");
1080
1100
  }
1081
1101
  }
@@ -1130,11 +1150,12 @@ export class ODModalResponderInstance extends ODBaseResponderInstance {
1130
1150
  async reply(build) {
1131
1151
  try {
1132
1152
  const finalMessage = this.getMessageFromBuildResult(build, "interaction");
1133
- const sent = await this.interaction.followUp(finalMessage);
1153
+ const sent = await this.interaction.reply(finalMessage);
1134
1154
  this.ignoreResponderTimeout = true;
1135
- return { success: true, message: sent, ephemeral: build.ephemeral };
1155
+ return { success: true, message: await sent.fetch(), ephemeral: build.ephemeral };
1136
1156
  }
1137
- catch {
1157
+ catch (err) {
1158
+ process.emit("uncaughtException", err);
1138
1159
  return { success: false };
1139
1160
  }
1140
1161
  }
@@ -1153,7 +1174,8 @@ export class ODModalResponderInstance extends ODBaseResponderInstance {
1153
1174
  return { success: true, message: await sent.fetch(), ephemeral: build.ephemeral };
1154
1175
  }
1155
1176
  }
1156
- catch {
1177
+ catch (err) {
1178
+ process.emit("uncaughtException", err);
1157
1179
  return { success: false };
1158
1180
  }
1159
1181
  }
@@ -1304,7 +1326,8 @@ export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
1304
1326
  return { success: true, message: await sent.fetch(), ephemeral: build.ephemeral };
1305
1327
  }
1306
1328
  }
1307
- catch {
1329
+ catch (err) {
1330
+ process.emit("uncaughtException", err);
1308
1331
  return { success: false };
1309
1332
  }
1310
1333
  }
@@ -1320,7 +1343,8 @@ export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
1320
1343
  else
1321
1344
  throw new ODSystemError("Unable to update context menu interaction!");
1322
1345
  }
1323
- catch {
1346
+ catch (err) {
1347
+ process.emit("uncaughtException", err);
1324
1348
  return { success: false };
1325
1349
  }
1326
1350
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@open-discord-bots/framework",
3
3
  "author": "DJj123dj",
4
- "version": "0.3.14",
4
+ "version": "0.3.15",
5
5
  "description": "The core framework of the popular open-source discord bots: Open Ticket & Open Moderation.",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
package/src/api/index.ts DELETED
@@ -1,31 +0,0 @@
1
- //MAIN MODULE
2
- export * from "./main.js"
3
-
4
- //BASE MODULES
5
- export * from "./modules/action.js"
6
- export * from "./modules/base.js"
7
- export * from "./modules/builder.js"
8
- export * from "./modules/checker.js"
9
- export * from "./modules/client.js"
10
- export * from "./modules/code.js"
11
- export * from "./modules/component.js"
12
- export * from "./modules/config.js"
13
- export * from "./modules/console.js"
14
- export * from "./modules/cooldown.js"
15
- export * from "./modules/database.js"
16
- export * from "./modules/event.js"
17
- export * from "./modules/flag.js"
18
- export * from "./modules/fuse.js"
19
- export * from "./modules/helpmenu.js"
20
- export * from "./modules/language.js"
21
- export * from "./modules/permission.js"
22
- export * from "./modules/plugin.js"
23
- export * from "./modules/post.js"
24
- export * from "./modules/progressbar.js"
25
- export * from "./modules/responder.js"
26
- export * from "./modules/session.js"
27
- export * from "./modules/startscreen.js"
28
- export * from "./modules/state.js"
29
- export * from "./modules/statistic.js"
30
- export * from "./modules/verifybar.js"
31
- export * from "./modules/worker.js"
package/src/api/main.ts DELETED
@@ -1,203 +0,0 @@
1
- //BASE MODULES
2
- import { ODEnvHelper, ODProjectType, ODVersion, ODVersionManager } from "./modules/base.js"
3
- import { ODConsoleManager, ODConsoleMessage, ODConsoleMessageParam, ODConsoleMessageTypes, ODDebugFileManager, ODDebugger, ODError, ODLiveStatusManager } from "./modules/console.js"
4
- import { ODCheckerManager } from "./modules/checker.js"
5
- import { ODEventManager } from "./modules/event.js"
6
- import { ODPluginManager } from "./modules/plugin.js"
7
- import { ODFlagManager } from "./modules/flag.js"
8
- import { ODProgressBarManager } from "./modules/progressbar.js"
9
- import { ODConfigManager } from "./modules/config.js"
10
- import { ODDatabaseManager } from "./modules/database.js"
11
- import { ODSessionManager } from "./modules/session.js"
12
- import { ODLanguageManager } from "./modules/language.js"
13
- import { ODBuilderManager } from "./modules/builder.js"
14
- import { ODResponderManager } from "./modules/responder.js"
15
- import { ODActionManager } from "./modules/action.js"
16
- import { ODVerifyBarManager } from "./modules/verifybar.js"
17
- import { ODPermissionManager } from "./modules/permission.js"
18
- import { ODCooldownManager } from "./modules/cooldown.js"
19
- import { ODHelpMenuManager } from "./modules/helpmenu.js"
20
- import { ODStatisticManager } from "./modules/statistic.js"
21
- import { ODCodeManager } from "./modules/code.js"
22
- import { ODPostManager } from "./modules/post.js"
23
- import { ODClientManager } from "./modules/client.js"
24
- import { ODSharedFuseManager } from "./modules/fuse.js"
25
- import { ODStartScreenManager } from "./modules/startscreen.js"
26
- import { ODComponentManager } from "./modules/component.js"
27
- import { ODStateManager } from "./modules/state.js"
28
-
29
- /**## ODMainManagers `interface`
30
- * The global properties for the main class of the bot.
31
- */
32
- export interface ODMainManagers {
33
- /**A collection of versions of the bot, systems, frameworks & services. */
34
- versions: ODVersionManager
35
-
36
- /**The timestamp that the (node.js) process of the bot started. */
37
- processStartupDate: Date
38
- /**The timestamp that the bot finished loading and is ready for usage. */
39
- readyStartupDate: Date|null
40
-
41
- /**The manager responsible for the debug file. (`...debug.txt`) */
42
- debugfile: ODDebugFileManager
43
- /**The manager responsible for the console system. (logs, errors, etc) */
44
- console: ODConsoleManager
45
- /**The manager responsible for sending debug logs to the debug file. (`...debug.txt`) */
46
- debug: ODDebugger
47
- /**The manager containing all Open Discord events. */
48
- events: ODEventManager
49
-
50
- /**The manager that handles & executes all plugins in the bot. */
51
- plugins: ODPluginManager
52
- /**The manager that manages & checks all the console flags of the bot. (like `--debug`) */
53
- flags: ODFlagManager
54
- /**The manager responsible for displaying progress bars in the console. */
55
- progressbars: ODProgressBarManager
56
- /**A collection of all the config files of the bot and plugins. (like `config/general.json`) */
57
- configs: ODConfigManager
58
- /**A collection of all the databases of the bot and plugins. (like `database/global.json`) */
59
- databases: ODDatabaseManager
60
- /**A collection of all the sessions of the bot. (Sessions are temporary objects stored in memory) */
61
- sessions: ODSessionManager
62
- /**The global translation manager which manges all language files, translations & switches between them. (Does not manage translations for plugins) */
63
- languages: ODLanguageManager
64
-
65
- /**The manager responsible for checking the bot & plugin configs. (it checks for mistakes in your config) */
66
- checkers: ODCheckerManager
67
- /**A collection of button, dropdown, embed, ... templates which can be used to construct messages and modals.
68
- * ### (🚨 Better alternative: `opendiscord.components (ODComponentManager)`)
69
- */
70
- builders: ODBuilderManager
71
- /**A collection of building blocks and templates for messages & modals with native support for Discord Components v2. (e.g. buttons, dropdowns, checkboxes, radio groups, file uploads, ...)
72
- * ### (✅ New replacement for: `opendiscord.builders (ODBuilderManager)`)
73
- */
74
- components: ODComponentManager
75
- /**The manager that handles responses to all interactions of the bot. (e.g. slash/text commands, buttons, dropdowns, modals) */
76
- responders: ODResponderManager
77
- /**A collection of procedures. A procedure is a complex task which can be executed from multiple responders or events. (e.g. ticket-creation, ticket-deletion, ticket-claiming, ...) */
78
- actions: ODActionManager
79
- /**A collection of verify bars from the bot. (the ✅ ❌ buttons in messages) */
80
- verifybars: ODVerifyBarManager
81
- /**A manager which will help with calculating permissions for commands & actions. */
82
- permissions: ODPermissionManager
83
- /**The manager which will manage cooldowns in the bot. (e.g. ticket-create cooldowns) */
84
- cooldowns: ODCooldownManager
85
- /**The manager that collects & renders the Open Discord help menu contents. (not the final embed) */
86
- helpmenu: ODHelpMenuManager
87
- /**The manager that registers, saves & updates statistics in the database. */
88
- statistics: ODStatisticManager
89
- /**A place where you can put general-purpose code which will start on startup of the bot. (Perfect for background tasks) */
90
- code: ODCodeManager
91
- /**A collection of static Discord post channels. It allows the bot to find back log, transcript or configured channels based on a linked ID. */
92
- posts: ODPostManager
93
- /**A system for tracking messages or linking metadata, states or progress to Discord messages (ID-based). Features automatic garbage collection. */
94
- states: ODStateManager
95
-
96
- /**A wrapper around the `discord.Client` class. It handles client login, activity and registering text/slash commands. */
97
- client: ODClientManager
98
- /**Shared fuses between Open Discord bots. Turn off "default behaviours" from the bot which is useful for replacing default behaviour with a custom implementation. */
99
- sharedFuses: ODSharedFuseManager
100
- /**A manager which collects variables from the Process ENV and `.env` file. */
101
- env: ODEnvHelper
102
- /**LiveStatus is a protocol which displays live updates from DJdj Development in the startscreen of the bot. (e.g. new version available) */
103
- livestatus: ODLiveStatusManager
104
- /**The manager responsible for rendering the startscreen of the bot. */
105
- startscreen: ODStartScreenManager
106
- }
107
-
108
- /**## ODMain `class`
109
- * This is the main Open Discord class.
110
- * It contains all managers from the entire bot & has shortcuts to the event & logging system.
111
- *
112
- * This class can't be overwritten or extended & is available as the global variable `opendiscord`!
113
- */
114
- export abstract class ODMain implements ODMainManagers {
115
- readonly project: ODProjectType
116
-
117
- readonly versions: ODVersionManager
118
- readonly processStartupDate: Date = new Date()
119
- readyStartupDate: Date|null = null
120
-
121
- readonly debugfile: ODDebugFileManager
122
- readonly console: ODConsoleManager
123
- readonly debug: ODDebugger
124
- readonly events: ODEventManager
125
-
126
- readonly plugins: ODPluginManager
127
- readonly flags: ODFlagManager
128
- readonly progressbars: ODProgressBarManager
129
- readonly configs: ODConfigManager
130
- readonly databases: ODDatabaseManager
131
- readonly sessions: ODSessionManager
132
- readonly languages: ODLanguageManager
133
-
134
- readonly checkers: ODCheckerManager
135
- readonly builders: ODBuilderManager
136
- readonly components: ODComponentManager
137
- readonly responders: ODResponderManager
138
- readonly actions: ODActionManager
139
- readonly verifybars: ODVerifyBarManager
140
- readonly permissions: ODPermissionManager
141
- readonly cooldowns: ODCooldownManager
142
- readonly helpmenu: ODHelpMenuManager
143
- readonly statistics: ODStatisticManager
144
- readonly code: ODCodeManager
145
- readonly posts: ODPostManager
146
- readonly states: ODStateManager
147
-
148
- readonly client: ODClientManager
149
- readonly sharedFuses: ODSharedFuseManager
150
- readonly env: ODEnvHelper
151
- readonly livestatus: ODLiveStatusManager
152
- readonly startscreen: ODStartScreenManager
153
-
154
- constructor(managers:ODMainManagers,project:ODProjectType){
155
- this.project = project
156
- this.versions = managers.versions
157
- this.versions.add(ODVersion.fromString("opendiscord:api","v0.3.14"))
158
- this.versions.add(ODVersion.fromString("opendiscord:livestatus","v2.0.0"))
159
-
160
- this.debugfile = managers.debugfile
161
- this.console = managers.console
162
- this.debug = managers.debug
163
- this.events = managers.events
164
-
165
- this.plugins = managers.plugins
166
- this.flags = managers.flags
167
- this.progressbars = managers.progressbars
168
- this.configs = managers.configs
169
- this.databases = managers.databases
170
- this.sessions = managers.sessions
171
- this.languages = managers.languages
172
-
173
- this.checkers = managers.checkers
174
- this.builders = managers.builders
175
- this.components = managers.components
176
- this.client = managers.client
177
- this.responders = managers.responders
178
- this.actions = managers.actions
179
- this.verifybars = managers.verifybars
180
- this.permissions = managers.permissions
181
- this.cooldowns = managers.cooldowns
182
- this.helpmenu = managers.helpmenu
183
- this.statistics = managers.statistics
184
- this.code = managers.code
185
- this.posts = managers.posts
186
- this.states = managers.states
187
-
188
- this.sharedFuses = managers.sharedFuses
189
- this.env = managers.env
190
- this.livestatus = managers.livestatus
191
- this.startscreen = managers.startscreen
192
- }
193
-
194
- /**Log a message to the console. But in the Open Discord style :) */
195
- log(message:ODConsoleMessage): void
196
- log(message:ODError): void
197
- log(message:string, type?:ODConsoleMessageTypes, params?:ODConsoleMessageParam[]): void
198
- log(message:ODConsoleMessage|ODError|string, type?:ODConsoleMessageTypes, params?:ODConsoleMessageParam[]){
199
- if (message instanceof ODConsoleMessage) this.console.log(message)
200
- else if (message instanceof ODError) this.console.log(message)
201
- else if (["string","number","boolean","object"].includes(typeof message)) this.console.log(message,type,params)
202
- }
203
- }
@@ -1,89 +0,0 @@
1
- ///////////////////////////////////////
2
- //ACTION MODULE
3
- ///////////////////////////////////////
4
- import { ODId, ODManager, ODValidId, ODSystemError, ODManagerData, ODNoGeneric } from "./base.js"
5
- import { ODWorkerManager, ODWorkerCallback, ODWorker } from "./worker.js"
6
- import { ODDebugger } from "./console.js"
7
-
8
- /**## ODActionImplementation `class`
9
- * This is an Open Discord action implementation.
10
- *
11
- * It is a basic implementation of the `ODWorkerManager` used by all `ODAction` classes.
12
- *
13
- * This class can't be used stand-alone & needs to be extended from!
14
- */
15
- export abstract class ODActionImplementation<Origin extends string,Params extends object,Result extends object,WorkerIds extends string = string> extends ODManagerData {
16
- /**The manager that has all workers of this implementation */
17
- workers: ODWorkerManager<Partial<Result>,Origin,Params,WorkerIds>
18
-
19
- constructor(id:ODValidId, callback?:ODWorkerCallback<Partial<Result>,Origin,Params>, priority?:number, callbackId?:ODValidId){
20
- super(id)
21
- this.workers = new ODWorkerManager("descending")
22
- if (callback) this.workers.add(new ODWorker(callbackId ? callbackId : id,priority ?? 0,callback))
23
- }
24
- /**Execute all workers & return the result. */
25
- abstract run(origin:Origin, params:Params): Promise<Partial<Result>>
26
- }
27
-
28
- /**## ODActionManagerIdConstraint `type`
29
- * The constraint/layout for id mappings/interfaces of the `ODActionManager` class.
30
- */
31
- export type ODActionManagerIdConstraint = Record<string,{origin:string,params:object,result:object,workers:string}>
32
-
33
- /**## ODActionManager `class`
34
- * This is an Open Discord action manager.
35
- *
36
- * It contains all Open Discord actions. You can compare actions with some sort of "procedure".
37
- * It's a complicated task that is divided into multiple functions.
38
- *
39
- * Some examples are `ticket-creation`, `ticket-closing`, `ticket-claiming`, ...
40
- *
41
- * It's recommended to use this system in combination with Open Discord responders!
42
- */
43
- export class ODActionManager<IdList extends ODActionManagerIdConstraint = ODActionManagerIdConstraint> extends ODManager<ODAction<string,{},{},string>> {
44
- constructor(debug:ODDebugger){
45
- super(debug,"action")
46
- }
47
-
48
- get<ActionId extends keyof ODNoGeneric<IdList>>(id:ActionId): ODAction<IdList[ActionId]["origin"],IdList[ActionId]["params"],IdList[ActionId]["result"],IdList[ActionId]["workers"]>
49
- get(id:ODValidId): ODAction<string,{},{},string>|null
50
-
51
- get(id:ODValidId): ODAction<string,{},{},string>|null {
52
- return super.get(id)
53
- }
54
-
55
- remove<ActionId extends keyof ODNoGeneric<IdList>>(id:ActionId): ODAction<IdList[ActionId]["origin"],IdList[ActionId]["params"],IdList[ActionId]["result"],IdList[ActionId]["workers"]>
56
- remove(id:ODValidId): ODAction<string,{},{},string>|null
57
-
58
- remove(id:ODValidId): ODAction<string,{},{},string>|null {
59
- return super.remove(id)
60
- }
61
-
62
- exists(id:keyof ODNoGeneric<IdList>): boolean
63
- exists(id:ODValidId): boolean
64
-
65
- exists(id:ODValidId): boolean {
66
- return super.exists(id)
67
- }
68
- }
69
-
70
- /**## ODAction `class`
71
- * This is an Open Discord action.
72
- *
73
- * It is a collection of functions/workers to execute a complex workflow (e.g. creating a ticket, banning a user, ...).
74
- *
75
- * Can be used standalone.
76
- */
77
- export class ODAction<Origin extends string,Params extends object,Result extends object,WorkerIds extends string = string> extends ODActionImplementation<Origin,Params,Result,WorkerIds> {
78
- /**Run this action */
79
- async run(origin:Origin, params:Params): Promise<Partial<Result>> {
80
- //create instance
81
- const instance = {}
82
-
83
- //wait for workers to finish
84
- await this.workers.executeWorkers(instance,origin,params)
85
-
86
- //return data generated by workers
87
- return instance
88
- }
89
- }