@open-discord-bots/framework 0.3.13 → 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 (43) hide show
  1. package/dist/api/main.js +1 -1
  2. package/dist/api/modules/responder.js +50 -26
  3. package/dist/api/modules/verifybar.d.ts +1 -1
  4. package/dist/api/modules/verifybar.js +1 -1
  5. package/package.json +1 -1
  6. package/src/api/index.ts +0 -31
  7. package/src/api/main.ts +0 -203
  8. package/src/api/modules/action.ts +0 -89
  9. package/src/api/modules/base.ts +0 -845
  10. package/src/api/modules/builder.ts +0 -1755
  11. package/src/api/modules/checker.ts +0 -1826
  12. package/src/api/modules/client.ts +0 -2345
  13. package/src/api/modules/code.ts +0 -84
  14. package/src/api/modules/component.ts +0 -2000
  15. package/src/api/modules/config.ts +0 -264
  16. package/src/api/modules/console.ts +0 -697
  17. package/src/api/modules/cooldown.ts +0 -369
  18. package/src/api/modules/database.ts +0 -321
  19. package/src/api/modules/event.ts +0 -123
  20. package/src/api/modules/flag.ts +0 -99
  21. package/src/api/modules/fuse.ts +0 -365
  22. package/src/api/modules/helpmenu.ts +0 -273
  23. package/src/api/modules/language.ts +0 -230
  24. package/src/api/modules/permission.ts +0 -363
  25. package/src/api/modules/plugin.ts +0 -294
  26. package/src/api/modules/post.ts +0 -137
  27. package/src/api/modules/progressbar.ts +0 -370
  28. package/src/api/modules/responder.ts +0 -1625
  29. package/src/api/modules/session.ts +0 -181
  30. package/src/api/modules/startscreen.ts +0 -345
  31. package/src/api/modules/state.ts +0 -298
  32. package/src/api/modules/statistic.ts +0 -380
  33. package/src/api/modules/verifybar.ts +0 -68
  34. package/src/api/modules/worker.ts +0 -119
  35. package/src/cli/editConfig.ts +0 -930
  36. package/src/cli/index.ts +0 -152
  37. package/src/index.ts +0 -8
  38. package/src/startup/compilation.ts +0 -204
  39. package/src/startup/dump.ts +0 -46
  40. package/src/startup/errorHandling.ts +0 -42
  41. package/src/startup/pluginLauncher.ts +0 -265
  42. package/src/utilities/index.ts +0 -229
  43. package/tools/cleanup.js +0 -2
@@ -1,273 +0,0 @@
1
- ///////////////////////////////////////
2
- //HELP MODULE
3
- ///////////////////////////////////////
4
- import { ODId, ODManager, ODManagerData, ODNoGeneric, ODSystemError, ODValidId } from "./base.js"
5
- import { ODDebugger } from "./console.js"
6
-
7
- /**## ODHelpMenuComponent `class`
8
- * This is an Open Discord help menu component.
9
- *
10
- * It can render something on the Open Discord help menu.
11
- */
12
- export abstract class ODHelpMenuComponent extends ODManagerData {
13
- /**The priority of this component. The higher, the earlier it will appear in the help menu. */
14
- priority: number
15
-
16
- constructor(id:ODValidId, priority:number){
17
- super(id)
18
- this.priority = priority
19
- }
20
-
21
- /**The render function for this component. */
22
- abstract render(page:number, category:number, location:number, mode:"slash"|"text"): string|Promise<string>
23
- }
24
-
25
- /**## ODHelpMenuTextComponent `class`
26
- * This is an Open Discord help menu text component.
27
- *
28
- * It can render a static piece of text on the Open Discord help menu.
29
- */
30
- export class ODHelpMenuTextComponent extends ODHelpMenuComponent {
31
- /**The text of this help menu component. */
32
- text: string
33
-
34
- constructor(id:ODValidId, priority:number, text:string){
35
- super(id,priority)
36
- this.text = text
37
- }
38
-
39
- render(page:number,category:number,location:number,mode:"slash"|"text"){
40
- return this.text
41
- }
42
- }
43
-
44
- /**## ODHelpMenuCommandComponentOption `interface`
45
- * This interface contains a command option for the `ODHelpMenuCommandComponent`.
46
- */
47
- export interface ODHelpMenuCommandComponentOption {
48
- /**The name of this option. */
49
- name:string,
50
- /**Is this option optional? */
51
- optional:boolean
52
- }
53
-
54
- /**## ODHelpMenuCommandComponentSettings `interface`
55
- * This interface contains the settings for the `ODHelpMenuCommandComponent`.
56
- */
57
- export interface ODHelpMenuCommandComponentSettings {
58
- /**The name of this text command. */
59
- textName?:string,
60
- /**The name of this slash command. */
61
- slashName?:string,
62
- /**Options available in the text command. */
63
- textOptions?:ODHelpMenuCommandComponentOption[],
64
- /**Options available in the slash command. */
65
- slashOptions?:ODHelpMenuCommandComponentOption[],
66
- /**The description for the text command. */
67
- textDescription?:string,
68
- /**The description for the slash command. */
69
- slashDescription?:string
70
- }
71
-
72
- /**## ODHelpMenuCommandComponent `class`
73
- * This is an Open Discord help menu command component.
74
- *
75
- * It contains a useful helper to render a command in the Open Discord help menu.
76
- */
77
- export class ODHelpMenuCommandComponent extends ODHelpMenuComponent {
78
- /**The settings for this help menu component. */
79
- settings:ODHelpMenuCommandComponentSettings
80
-
81
- constructor(id:ODValidId, priority:number, settings:ODHelpMenuCommandComponentSettings){
82
- super(id,priority)
83
- this.settings = settings
84
- }
85
-
86
- render(page:number,category:number,location:number,mode:"slash"|"text"){
87
- if (mode == "slash" && this.settings.slashName){
88
- return `\`${this.settings.slashName}${(this.settings.slashOptions) ? this.renderOptions(this.settings.slashOptions) : ""}\` ➜ ${this.settings.slashDescription ?? ""}`
89
-
90
- }else if (mode == "text" && this.settings.textName){
91
- return `\`${this.settings.textName}${(this.settings.textOptions) ? this.renderOptions(this.settings.textOptions) : ""}\` ➜ ${this.settings.textDescription ?? ""}`
92
-
93
- }else return ""
94
- }
95
-
96
- /**Utility function to render all command options. */
97
- protected renderOptions(options:ODHelpMenuCommandComponentOption[]){
98
- return " "+options.map((opt) => (opt.optional) ? `[${opt.name}]` : `<${opt.name}>`).join(" ")
99
- }
100
- }
101
-
102
- /**## ODHelpMenuCategoryIdConstraint `type`
103
- * The constraint/layout for id mappings/interfaces of the `ODHelpMenuCategory` class.
104
- */
105
- export type ODHelpMenuCategoryIdConstraint = Record<string,ODHelpMenuComponent|null>
106
-
107
- /**## ODHelpMenuCategory `class`
108
- * This is an Open Discord help menu category.
109
- *
110
- * Every category in the help menu is an embed field by default.
111
- * Try to limit the amount of components per category.
112
- */
113
- export class ODHelpMenuCategory<IdList extends ODHelpMenuCategoryIdConstraint = ODHelpMenuCategoryIdConstraint> extends ODManager<ODHelpMenuComponent> {
114
- /**The id of this category. */
115
- id: ODId
116
- /**The priority of this category. The higher, the earlier it will appear in the menu. */
117
- priority: number
118
- /**The name of this category. (can include emoji's) */
119
- name: string
120
- /**When enabled, it automatically starts this category on a new page. */
121
- newPage: boolean
122
-
123
- constructor(id:ODValidId, priority:number, name:string, newPage?:boolean){
124
- super()
125
- this.id = new ODId(id)
126
- this.priority = priority
127
- this.name = name
128
- this.newPage = newPage ?? false
129
- }
130
-
131
- /**Render this category and it's components. */
132
- async render(page:number, category:number, mode:"slash"|"text"){
133
- //sort from high priority to low
134
- const derefArray = [...this.getAll()]
135
- derefArray.sort((a,b) => {
136
- return b.priority-a.priority
137
- })
138
- const result: string[] = []
139
-
140
- let i = 0
141
- for (const component of derefArray){
142
- try {
143
- result.push(await component.render(page,category,i,mode))
144
- }catch(err:any){
145
- process.emit("uncaughtException",new ODSystemError(err))
146
- }
147
- i++
148
- }
149
-
150
- //only return the non-empty components
151
- return result.filter((component) => component !== "").join("\n\n")
152
- }
153
-
154
- get<HelpMenuComponentId extends keyof ODNoGeneric<IdList>>(id:HelpMenuComponentId): IdList[HelpMenuComponentId]
155
- get(id:ODValidId): ODHelpMenuComponent|null
156
-
157
- get(id:ODValidId): ODHelpMenuComponent|null {
158
- return super.get(id)
159
- }
160
-
161
- remove<HelpMenuComponentId extends keyof ODNoGeneric<IdList>>(id:HelpMenuComponentId): IdList[HelpMenuComponentId]
162
- remove(id:ODValidId): ODHelpMenuComponent|null
163
-
164
- remove(id:ODValidId): ODHelpMenuComponent|null {
165
- return super.remove(id)
166
- }
167
-
168
- exists(id:keyof ODNoGeneric<IdList>): boolean
169
- exists(id:ODValidId): boolean
170
-
171
- exists(id:ODValidId): boolean {
172
- return super.exists(id)
173
- }
174
- }
175
-
176
- /**## ODHelpMenuRenderResult `type`
177
- * This is the array returned when the help menu has been rendered successfully.
178
- *
179
- * It contains a list of pages, which contain categories by name & value (content).
180
- */
181
- export type ODHelpMenuRenderResult = {name:string, value:string}[][]
182
-
183
-
184
- /**## ODHelpMenuManagerIdConstraint `type`
185
- * The constraint/layout for id mappings/interfaces of the `ODHelpMenuManager` class.
186
- */
187
- export type ODHelpMenuManagerIdConstraint = Record<string,ODHelpMenuCategory>
188
-
189
- /**## ODHelpMenuManager `class`
190
- * This is an Open Discord help menu manager.
191
- *
192
- * It is responsible for rendering the entire help menu content.
193
- * You are also able to configure the amount of categories per page here.
194
- *
195
- * Fewer Categories == More Clean Menu
196
- */
197
- export class ODHelpMenuManager<IdList extends ODHelpMenuManagerIdConstraint = ODHelpMenuManagerIdConstraint> extends ODManager<ODHelpMenuCategory> {
198
- /**The amount of categories per-page. */
199
- categoriesPerPage: number = 3
200
-
201
- constructor(debug:ODDebugger){
202
- super(debug,"help menu category")
203
- }
204
-
205
- add(data:ODHelpMenuCategory, overwrite?:boolean): boolean {
206
- data.useDebug(this.debug,"help menu component")
207
- return super.add(data,overwrite)
208
- }
209
-
210
- /**Render this entire help menu & return a `ODHelpMenuRenderResult`. */
211
- async render(mode:"slash"|"text"): Promise<ODHelpMenuRenderResult> {
212
- //sort from high priority to low
213
- const derefArray = [...this.getAll()]
214
- derefArray.sort((a,b) => {
215
- return b.priority-a.priority
216
- })
217
- const result: {name:string, value:string}[][] = []
218
- let currentPage: {name:string, value:string}[] = []
219
-
220
- for (const category of derefArray){
221
- try {
222
- const renderedCategory = await category.render(result.length,currentPage.length,mode)
223
-
224
- if (renderedCategory !== ""){
225
- //create new page when category wants to
226
- if (currentPage.length > 0 && category.newPage){
227
- result.push(currentPage)
228
- currentPage = []
229
- }
230
-
231
- currentPage.push({
232
- name:category.name,
233
- value:renderedCategory
234
- })
235
-
236
- //create new page when page is full
237
- if (currentPage.length >= this.categoriesPerPage){
238
- result.push(currentPage)
239
- currentPage = []
240
- }
241
- }
242
- }catch(err){
243
- process.emit("uncaughtException",err)
244
- }
245
- }
246
-
247
- //push current page when not-empty
248
- if (currentPage.length > 0) result.push(currentPage)
249
-
250
- return result
251
- }
252
-
253
- get<HelpMenuCategoryId extends keyof ODNoGeneric<IdList>>(id:HelpMenuCategoryId): IdList[HelpMenuCategoryId]
254
- get(id:ODValidId): ODHelpMenuCategory|null
255
-
256
- get(id:ODValidId): ODHelpMenuCategory|null {
257
- return super.get(id)
258
- }
259
-
260
- remove<HelpMenuCategoryId extends keyof ODNoGeneric<IdList>>(id:HelpMenuCategoryId): IdList[HelpMenuCategoryId]
261
- remove(id:ODValidId): ODHelpMenuCategory|null
262
-
263
- remove(id:ODValidId): ODHelpMenuCategory|null {
264
- return super.remove(id)
265
- }
266
-
267
- exists(id:keyof ODNoGeneric<IdList>): boolean
268
- exists(id:ODValidId): boolean
269
-
270
- exists(id:ODValidId): boolean {
271
- return super.exists(id)
272
- }
273
- }
@@ -1,230 +0,0 @@
1
- ///////////////////////////////////////
2
- //LANGUAGE MODULE
3
- ///////////////////////////////////////
4
- import { ODId, ODManager, ODManagerData, ODNoGeneric, ODPromiseVoid, ODSystemError, ODValidId } from "./base.js"
5
- import nodepath from "path"
6
- import { ODDebugger } from "./console.js"
7
- import fs from "fs"
8
-
9
- /**## ODLanguageMetadata `interface`
10
- * This interface contains all metadata available in the language files.
11
- */
12
- export interface ODLanguageMetadata {
13
- /**The version of Open Discord this translation is made for. */
14
- otversion:string,
15
- /**The name of the language in english (with capital letter). */
16
- language:string,
17
- /**A list of translators (discord/github username) who've contributed to this language. */
18
- translators:string[],
19
- /**The last date that this translation has been modified (format: DD/MM/YYYY) */
20
- lastedited:string,
21
- /**When `true`, the translator made use of some sort of automation while creating the translation. (e.g. ChatGPT, Google Translate, DeepL, ...) */
22
- automated:boolean
23
- }
24
-
25
- /**## ODLanguageManagerIdConstraint `type`
26
- * The constraint/layout for id mappings/interfaces of the `ODLanguageManager` class.
27
- */
28
- export type ODLanguageManagerIdConstraint = Record<string,ODLanguage>
29
-
30
- /**## ODLanguageManager `class`
31
- * This is an Open Discord language manager.
32
- *
33
- * It manages all languages in the bot and manages translation for you!
34
- * Get a translation via the `getTranslation()` or `getTranslationWithParams()` methods.
35
- *
36
- * Add new languages using the `ODlanguage` class in your plugin!
37
- */
38
- export class ODLanguageManager<IdList extends ODLanguageManagerIdConstraint = ODLanguageManagerIdConstraint,TranslationIds extends string = string> extends ODManager<ODLanguage> {
39
- /**The currently selected language. */
40
- current: ODLanguage|null = null
41
- /**The currently selected backup language. (used when translation missing in current language) */
42
- backup: ODLanguage|null = null
43
-
44
- constructor(debug:ODDebugger, presets:boolean){
45
- super(debug,"language")
46
- if (presets) this.add(new ODJsonLanguage("english","english.json"))
47
- this.current = presets ? new ODJsonLanguage("english","english.json") : null
48
- this.backup = presets ? new ODJsonLanguage("english","english.json") : null
49
- }
50
-
51
- /**Set the current language by providing the ID of a language which is registered in this manager. */
52
- setCurrentLanguage(id:keyof ODNoGeneric<IdList>): void
53
- setCurrentLanguage(id:ODValidId): void
54
- setCurrentLanguage(id:ODValidId){
55
- this.current = this.get(id)
56
- const languageId = this.current?.id.value ?? "<unknown-id>"
57
- const languageAutomated = this.current?.metadata?.automated.toString() ?? "<unknown-metadata>"
58
- this.debug?.debug("Selected current language",[
59
- {key:"id",value:languageId},
60
- {key:"automated",value:languageAutomated},
61
- ])
62
- }
63
- /**Get the current language (same as `this.current`) */
64
- getCurrentLanguage(){
65
- return (this.current) ? this.current : null
66
- }
67
- /**Set the backup language by providing the ID of a language which is registered in this manager. */
68
- setBackupLanguage(id:keyof ODNoGeneric<IdList>): void
69
- setBackupLanguage(id:ODValidId): void
70
- setBackupLanguage(id:ODValidId){
71
- this.backup = this.get(id)
72
- const languageId = this.backup?.id.value ?? "<unknown-id>"
73
- const languageAutomated = this.backup?.metadata?.automated.toString() ?? "<unknown-metadata>"
74
- this.debug?.debug("Selected backup language",[
75
- {key:"id",value:languageId},
76
- {key:"automated",value:languageAutomated},
77
- ])
78
- }
79
- /**Get the backup language (same as `this.backup`) */
80
- getBackupLanguage(){
81
- return (this.backup) ? this.backup : null
82
- }
83
- /**Get the metadata of the current/backup language. */
84
- getLanguageMetadata(frombackup?:boolean): ODLanguageMetadata|null {
85
- if (frombackup) return (this.backup) ? this.backup.metadata : null
86
- return (this.current) ? this.current.metadata : null
87
- }
88
- /**Get the ID (string) of the current language. (Not backup language) */
89
- getCurrentLanguageId(){
90
- return (this.current) ? this.current.id.value : ""
91
- }
92
- /**Get a translation string by JSON location. (e.g. `"checker.system.typeError"`) */
93
- getTranslation(id:TranslationIds): string
94
- getTranslation(id:string): string|null
95
- getTranslation(id:string): string|null {
96
- if (!this.current) return this.getBackupTranslation(id)
97
-
98
- const splitted = id.split(".")
99
- let currentObject = this.current.data
100
- let result: string|false = false
101
- splitted.forEach((id) => {
102
- if (typeof currentObject[id] == "object"){
103
- currentObject = currentObject[id]
104
- }else if (typeof currentObject[id] == "string"){
105
- result = currentObject[id]
106
- }
107
- })
108
-
109
- if (typeof result == "string") return result
110
- else return this.getBackupTranslation(id)
111
- }
112
- /**Get a backup translation string by JSON location. (system only) */
113
- protected getBackupTranslation(id:string): string|null {
114
- if (!this.backup) return null
115
-
116
- const splitted = id.split(".")
117
- let currentObject = this.backup.data
118
- let result: string|false = false
119
- splitted.forEach((id) => {
120
- if (typeof currentObject[id] == "object"){
121
- currentObject = currentObject[id]
122
- }else if (typeof currentObject[id] == "string"){
123
- result = currentObject[id]
124
- }
125
- })
126
-
127
- if (typeof result == "string") return result
128
- else return null
129
- }
130
- /**Get a backup translation string by JSON location and replace `{0}`,`{1}`,`{2}`,... with the provided parameters. */
131
- getTranslationWithParams(id:TranslationIds, params:string[]): string
132
- getTranslationWithParams(id:string, params:string[]): string|null
133
- getTranslationWithParams(id:string, params:string[]): string|null {
134
- let translation = this.getTranslation(id)
135
- if (!translation) return translation
136
-
137
- params.forEach((value,index) => {
138
- if (!translation) return
139
- translation = translation.replace(`{${index}}`,value)
140
- })
141
- return translation
142
- }
143
-
144
- /**Init all language files. */
145
- async init(){
146
- for (const language of this.getAll()){
147
- try{
148
- await language.init()
149
- }catch(err:any){
150
- process.emit("uncaughtException",new ODSystemError(err))
151
- }
152
- }
153
- }
154
-
155
- get<LanguageId extends keyof ODNoGeneric<IdList>>(id:LanguageId): IdList[LanguageId]
156
- get(id:ODValidId): ODLanguage|null
157
-
158
- get(id:ODValidId): ODLanguage|null {
159
- return super.get(id)
160
- }
161
-
162
- remove<LanguageId extends keyof ODNoGeneric<IdList>>(id:LanguageId): IdList[LanguageId]
163
- remove(id:ODValidId): ODLanguage|null
164
-
165
- remove(id:ODValidId): ODLanguage|null {
166
- return super.remove(id)
167
- }
168
-
169
- exists(id:keyof ODNoGeneric<IdList>): boolean
170
- exists(id:ODValidId): boolean
171
-
172
- exists(id:ODValidId): boolean {
173
- return super.exists(id)
174
- }
175
- }
176
-
177
- /**## ODLanguage `class`
178
- * This is an Open Discord language file.
179
- *
180
- * It contains metadata and all translation strings available in this language.
181
- * Register this class to an `ODLanguageManager` to use it!
182
- *
183
- * JSON languages should be created using the `ODJsonLanguage` class instead!
184
- */
185
- export abstract class ODLanguage extends ODManagerData {
186
- /**The name of the file with extension. */
187
- file: string = ""
188
- /**The path to the file relative to the main directory. */
189
- path: string = ""
190
- /**The raw object data of the translation. */
191
- data: any
192
- /**The metadata of the language if available. */
193
- metadata: ODLanguageMetadata|null = null
194
-
195
- constructor(id:ODValidId, data:any){
196
- super(id)
197
- this.data = data
198
- }
199
-
200
- /**Init the language. */
201
- abstract init(): ODPromiseVoid
202
- }
203
-
204
- /**## ODJsonLanguage `class`
205
- * This is an Open Discord JSON language file.
206
- *
207
- * It contains metadata and all translation strings from a certain JSON file (in `./languages/`).
208
- * Register this class to an `ODLanguageManager` to use it!
209
- *
210
- * Use the `ODLanguage` class to use translations from non-JSON files!
211
- */
212
- export class ODJsonLanguage extends ODLanguage {
213
- constructor(id:ODValidId, file:string, customPath?:string){
214
- super(id,{})
215
- this.file = (file.endsWith(".json")) ? file : file+".json"
216
- this.path = customPath ? nodepath.join("./",customPath,this.file) : nodepath.join("./languages/",this.file)
217
- }
218
-
219
- /**Init the langauge. */
220
- init(): ODPromiseVoid {
221
- if (!fs.existsSync(this.path)) throw new ODSystemError("Unable to parse language \""+nodepath.join("./",this.path)+"\", the file doesn't exist!")
222
- try{
223
- this.data = JSON.parse(fs.readFileSync(this.path).toString())
224
- }catch(err){
225
- process.emit("uncaughtException",err)
226
- throw new ODSystemError("Unable to parse language \""+nodepath.join("./",this.path)+"\"!")
227
- }
228
- if (this.data["_TRANSLATION"]) this.metadata = this.data["_TRANSLATION"]
229
- }
230
- }