@open-discord-bots/framework 0.2.17 → 0.3.0

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 (49) hide show
  1. package/dist/api/index.d.ts +16 -15
  2. package/dist/api/index.js +16 -15
  3. package/dist/api/main.d.ts +31 -23
  4. package/dist/api/main.js +3 -1
  5. package/dist/api/modules/action.d.ts +2 -2
  6. package/dist/api/modules/action.js +1 -5
  7. package/dist/api/modules/base.d.ts +2 -2
  8. package/dist/api/modules/builder.d.ts +2 -2
  9. package/dist/api/modules/builder.js +0 -4
  10. package/dist/api/modules/checker.d.ts +2 -2
  11. package/dist/api/modules/checker.js +2 -6
  12. package/dist/api/modules/component.d.ts +922 -0
  13. package/dist/api/modules/component.js +1344 -0
  14. package/dist/api/modules/config.d.ts +30 -1
  15. package/dist/api/modules/config.js +81 -0
  16. package/dist/api/modules/cooldown.d.ts +5 -5
  17. package/dist/api/modules/cooldown.js +1 -17
  18. package/dist/api/modules/database.d.ts +21 -13
  19. package/dist/api/modules/database.js +0 -23
  20. package/dist/api/modules/helpmenu.d.ts +9 -7
  21. package/dist/api/modules/helpmenu.js +22 -17
  22. package/dist/api/modules/language.d.ts +2 -2
  23. package/dist/api/modules/language.js +3 -7
  24. package/dist/api/modules/progressbar.d.ts +2 -1
  25. package/dist/api/modules/progressbar.js +1 -1
  26. package/dist/api/modules/responder.d.ts +2 -2
  27. package/dist/api/modules/responder.js +0 -4
  28. package/dist/api/modules/session.d.ts +1 -1
  29. package/dist/api/modules/session.js +1 -1
  30. package/dist/api/modules/startscreen.d.ts +2 -2
  31. package/dist/api/modules/startscreen.js +5 -3
  32. package/package.json +3 -2
  33. package/src/api/index.ts +16 -15
  34. package/src/api/main.ts +33 -24
  35. package/src/api/modules/action.ts +2 -4
  36. package/src/api/modules/base.ts +2 -2
  37. package/src/api/modules/builder.ts +2 -4
  38. package/src/api/modules/checker.ts +5 -6
  39. package/src/api/modules/component.ts +1822 -0
  40. package/src/api/modules/config.ts +78 -1
  41. package/src/api/modules/cooldown.ts +8 -13
  42. package/src/api/modules/database.ts +24 -32
  43. package/src/api/modules/helpmenu.ts +29 -22
  44. package/src/api/modules/language.ts +5 -7
  45. package/src/api/modules/progressbar.ts +2 -3
  46. package/src/api/modules/responder.ts +2 -4
  47. package/src/api/modules/session.ts +1 -1
  48. package/src/api/modules/startscreen.ts +6 -4
  49. package/src/api/modules/component.txt +0 -350
package/src/api/main.ts CHANGED
@@ -23,12 +23,13 @@ import { ODPostManager } from "./modules/post.js"
23
23
  import { ODClientManager } from "./modules/client.js"
24
24
  import { ODSharedFuseManager } from "./modules/fuse.js"
25
25
  import { ODStartScreenManager } from "./modules/startscreen.js"
26
+ import { ODComponentManager } from "./modules/component.js"
26
27
 
27
28
  /**## ODMainManagers `interface`
28
29
  * The global properties for the main class of the bot.
29
30
  */
30
31
  export interface ODMainManagers {
31
- /**The manager that handles all versions in the bot. */
32
+ /**A collection of versions of the bot, systems, frameworks & services. */
32
33
  versions: ODVersionManager
33
34
 
34
35
  /**The timestamp that the (node.js) process of the bot started. */
@@ -49,49 +50,55 @@ export interface ODMainManagers {
49
50
  plugins: ODPluginManager
50
51
  /**The manager that manages & checks all the console flags of the bot. (like `--debug`) */
51
52
  flags: ODFlagManager
52
- /**The manager responsible for progress bars in the console. */
53
+ /**The manager responsible for displaying progress bars in the console. */
53
54
  progressbars: ODProgressBarManager
54
- /**The manager that manages & contains all the config files of the bot. (like `config/general.json`) */
55
+ /**A collection of all the config files of the bot and plugins. (like `config/general.json`) */
55
56
  configs: ODConfigManager
56
- /**The manager that manages & contains all the databases of the bot. (like `database/global.json`) */
57
+ /**A collection of all the databases of the bot and plugins. (like `database/global.json`) */
57
58
  databases: ODDatabaseManager
58
- /**The manager that manages all the data sessions of the bot. (it's a temporary database) */
59
+ /**A collection of all the sessions of the bot. (Sessions are temporary objects stored in memory) */
59
60
  sessions: ODSessionManager
60
- /**The manager that manages all languages & translations of the bot. (but not for plugins) */
61
+ /**The global translation manager which manges all language files, translations & switches between them. (Does not manage translations for plugins) */
61
62
  languages: ODLanguageManager
62
63
 
63
- /**The manager that handles & executes all config checkers in the bot. (the code that checks if you have something wrong in your config) */
64
+ /**The manager responsible for checking the bot & plugin configs. (it checks for mistakes in your config) */
64
65
  checkers: ODCheckerManager
65
- /**The manager that manages all builders in the bot. (e.g. buttons, dropdowns, messages, modals, etc) */
66
+ /**A collection of button, dropdown, embed, ... templates which can be used to construct messages and modals.
67
+ * ### (🚨 Better alternative: `opendiscord.components (ODComponentManager)`)
68
+ */
66
69
  builders: ODBuilderManager
67
- /**The manager that manages all responders in the bot. (e.g. commands, buttons, dropdowns, modals) */
70
+ /**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, ...)
71
+ * ### (✅ New replacement for: `opendiscord.builders (ODBuilderManager)`)
72
+ */
73
+ components: ODComponentManager
74
+ /**The manager that handles responses to all interactions of the bot. (e.g. slash/text commands, buttons, dropdowns, modals) */
68
75
  responders: ODResponderManager
69
- /**The manager that manages all actions or procedures in the bot. (e.g. ticket-creation, ticket-deletion, ticket-claiming, etc) */
76
+ /**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, ...) */
70
77
  actions: ODActionManager
71
- /**The manager that manages all verify bars in the bot. (the ✅ ❌ buttons) */
78
+ /**A collection of verify bars from the bot. (the ✅ ❌ buttons in messages) */
72
79
  verifybars: ODVerifyBarManager
73
- /**The manager that contains all permissions for commands & actions in the bot. (use it to check if someone has admin perms or not) */
80
+ /**A manager which will help with calculating permissions for commands & actions. */
74
81
  permissions: ODPermissionManager
75
- /**The manager that contains all cooldowns of the bot. (e.g. ticket-cooldowns) */
82
+ /**The manager which will manage cooldowns in the bot. (e.g. ticket-create cooldowns) */
76
83
  cooldowns: ODCooldownManager
77
- /**The manager that manages & renders the Open Discord help menu. (not the embed, but the text) */
84
+ /**The manager that collects & renders the Open Discord help menu contents. (not the final embed) */
78
85
  helpmenu: ODHelpMenuManager
79
- /**The manager that manages, saves & renders the Open Discord statistics. (not the embed, but the text & database) */
86
+ /**The manager that registers, saves & updates statistics in the database. */
80
87
  statistics: ODStatisticManager
81
- /**This manager is a place where you can put code that executes when the bot almost finishes the setup. (can be used for less important stuff that doesn't require an exact time-order) */
88
+ /**A place where you can put general-purpose code which will start on startup of the bot. (Perfect for background tasks) */
82
89
  code: ODCodeManager
83
- /**The manager that manages all posts (static discord channels) in the bot. (e.g. transcripts, logs, etc) */
90
+ /**A collection of static Discord post channels. It allows the bot to find back log, transcript or configured channels based on a linked ID. */
84
91
  posts: ODPostManager
85
92
 
86
- /**The manager responsible for everything related to the client. (e.g. status, login, slash & text commands, etc) */
93
+ /**A wrapper around the `discord.Client` class. It handles client login, activity and registering text/slash commands. */
87
94
  client: ODClientManager
88
- /**Shared fuses between Open Discord bots. With these fuses/switches, you can turn off "default behaviours" from the bot. Useful for replacing default behaviour with a custom implementation. */
95
+ /**Shared fuses between Open Discord bots. Turn off "default behaviours" from the bot which is useful for replacing default behaviour with a custom implementation. */
89
96
  sharedFuses: ODSharedFuseManager
90
- /**This manager manages all the variables in the ENV. It reads from both the `.env` file & the `process.env`. (these 2 will be combined) */
97
+ /**A manager which collects variables from the Process ENV and `.env` file. */
91
98
  env: ODEnvHelper
92
- /**The manager responsible for the livestatus system. (remote console logs) */
99
+ /**LiveStatus is a protocol which displays live updates from DJdj Development in the startscreen of the bot. (e.g. new version available) */
93
100
  livestatus: ODLiveStatusManager
94
- /**The manager responsible for the livestatus system. (remote console logs) */
101
+ /**The manager responsible for rendering the startscreen of the bot. */
95
102
  startscreen: ODStartScreenManager
96
103
  }
97
104
 
@@ -101,7 +108,7 @@ export interface ODMainManagers {
101
108
  *
102
109
  * This class can't be overwritten or extended & is available as the global variable `opendiscord`!
103
110
  */
104
- export class ODMain implements ODMainManagers {
111
+ export abstract class ODMain implements ODMainManagers {
105
112
  readonly project: ODProjectType
106
113
 
107
114
  readonly versions: ODVersionManager
@@ -123,6 +130,7 @@ export class ODMain implements ODMainManagers {
123
130
 
124
131
  readonly checkers: ODCheckerManager
125
132
  readonly builders: ODBuilderManager
133
+ readonly components: ODComponentManager
126
134
  readonly responders: ODResponderManager
127
135
  readonly actions: ODActionManager
128
136
  readonly verifybars: ODVerifyBarManager
@@ -142,7 +150,7 @@ export class ODMain implements ODMainManagers {
142
150
  constructor(managers:ODMainManagers,project:ODProjectType){
143
151
  this.project = project
144
152
  this.versions = managers.versions
145
- this.versions.add(ODVersion.fromString("opendiscord:api","v0.2.17"))
153
+ this.versions.add(ODVersion.fromString("opendiscord:api","v0.3.0"))
146
154
  this.versions.add(ODVersion.fromString("opendiscord:livestatus","v2.0.0"))
147
155
 
148
156
  this.debugfile = managers.debugfile
@@ -160,6 +168,7 @@ export class ODMain implements ODMainManagers {
160
168
 
161
169
  this.checkers = managers.checkers
162
170
  this.builders = managers.builders
171
+ this.components = managers.components
163
172
  this.client = managers.client
164
173
  this.responders = managers.responders
165
174
  this.actions = managers.actions
@@ -12,7 +12,7 @@ import { ODDebugger } from "./console.js"
12
12
  *
13
13
  * This class can't be used stand-alone & needs to be extended from!
14
14
  */
15
- export class ODActionImplementation<Origin extends string,Params extends object,Result extends object,WorkerIds extends string = string> extends ODManagerData {
15
+ export abstract class ODActionImplementation<Origin extends string,Params extends object,Result extends object,WorkerIds extends string = string> extends ODManagerData {
16
16
  /**The manager that has all workers of this implementation */
17
17
  workers: ODWorkerManager<Partial<Result>,Origin,Params,WorkerIds>
18
18
 
@@ -22,9 +22,7 @@ export class ODActionImplementation<Origin extends string,Params extends object,
22
22
  if (callback) this.workers.add(new ODWorker(callbackId ? callbackId : id,priority ?? 0,callback))
23
23
  }
24
24
  /**Execute all workers & return the result. */
25
- async run(origin:Origin, params:Params): Promise<Partial<Result>> {
26
- throw new ODSystemError("Tried to build an unimplemented ODResponderImplementation")
27
- }
25
+ abstract run(origin:Origin, params:Params): Promise<Partial<Result>>
28
26
  }
29
27
 
30
28
  /**## ODActionManagerIdConstraint `type`
@@ -140,7 +140,7 @@ export class ODId {
140
140
  * It is used to let the "onChange" event in the `ODManager` class work.
141
141
  * You can use this class when extending your own `ODManager`
142
142
  */
143
- export class ODManagerChangeHelper {
143
+ export abstract class ODManagerChangeHelper {
144
144
  #change: (() => void)|null = null
145
145
 
146
146
  /**Trigger an `onChange()` event in the parent `ODManager` of this class. */
@@ -167,7 +167,7 @@ export class ODManagerChangeHelper {
167
167
  *
168
168
  * There is an `id:ODId` property & also some events used in the manager.
169
169
  */
170
- export class ODManagerData extends ODManagerChangeHelper {
170
+ export abstract class ODManagerData extends ODManagerChangeHelper {
171
171
  /**The id of this data. */
172
172
  id: ODId
173
173
 
@@ -13,7 +13,7 @@ import { ODDebugger } from "./console.js"
13
13
  *
14
14
  * This class can't be used stand-alone & needs to be extended from!
15
15
  */
16
- export class ODBuilderImplementation<Instance,Origin extends string,Params,BuildType extends {id:ODId},WorkerIds extends string = string> extends ODManagerData {
16
+ export abstract class ODBuilderImplementation<Instance,Origin extends string,Params,BuildType extends {id:ODId},WorkerIds extends string = string> extends ODManagerData {
17
17
  /**The manager that has all workers of this implementation */
18
18
  workers: ODWorkerManager<Instance,Origin,Params,WorkerIds>
19
19
  /**Cache a build or create it every time from scratch when this.build() gets executed. */
@@ -42,9 +42,7 @@ export class ODBuilderImplementation<Instance,Origin extends string,Params,Build
42
42
  return this
43
43
  }
44
44
  /**Execute all workers & return the result. */
45
- async build(origin:Origin, params:Params): Promise<BuildType> {
46
- throw new ODSystemError("Tried to build an unimplemented ODBuilderImplementation")
47
- }
45
+ abstract build(origin:Origin, params:Params): Promise<BuildType>
48
46
  }
49
47
 
50
48
  /**## ODBuilderManager `class`
@@ -2,7 +2,7 @@
2
2
  //CONFIG CHECKER MODULE
3
3
  ///////////////////////////////////////
4
4
  import { ODDiscordIdType, ODId, ODManager, ODManagerData, ODNoGeneric, ODValidId, ODValidJsonType } from "./base.js"
5
- import { ODConfig } from "./config.js"
5
+ import { ODConfig, ODMemoryConfig } from "./config.js"
6
6
  import { ODLanguageManager } from "./language.js"
7
7
  import { ODDebugger } from "./console.js"
8
8
  import ansis from "ansis"
@@ -96,7 +96,7 @@ export class ODCheckerManager<
96
96
  }
97
97
  /**Create temporary and unlisted `ODConfig`, `ODChecker` & `ODCheckerStorage` classes. This will help you use a `ODCheckerStructure` validator without officially registering it in `opendiscord.checkers`. */
98
98
  createTemporaryCheckerEnvironment(){
99
- return new ODChecker("opendiscord:temporary-environment",new ODCheckerStorage(),0,new ODConfig("opendiscord:temporary-environment",{}),new ODCheckerStructure("opendiscord:temporary-environment",{}))
99
+ return new ODChecker("opendiscord:temporary-environment",new ODCheckerStorage(),0,new ODMemoryConfig("opendiscord:temporary-environment",{}),new ODCheckerStructure("opendiscord:temporary-environment",{}))
100
100
  }
101
101
 
102
102
  get<CheckerId extends keyof ODNoGeneric<IdList>>(id:CheckerId): IdList[CheckerId]
@@ -181,11 +181,10 @@ export class ODCheckerStorage {
181
181
  *
182
182
  * Use this class to change the config checker looks!
183
183
  */
184
- export class ODCheckerRenderer {
184
+ export abstract class ODCheckerRenderer {
185
185
  /**Get all config checker render components. These can be combined and rendered to the console. */
186
- getComponents(compact:boolean, renderEmpty:boolean, translation:ODCheckerTranslationRegister<string,string>, data:ODCheckerResult): string[] {
187
- return []
188
- }
186
+ abstract getComponents(compact:boolean, renderEmpty:boolean, translation:ODCheckerTranslationRegister<string,string>, data:ODCheckerResult): string[]
187
+
189
188
  /**Render all config checker render components to the console. */
190
189
  render(components:string[]){
191
190
  if (components.length < 1) return