@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
@@ -1,264 +0,0 @@
1
- ///////////////////////////////////////
2
- //CONFIG MODULE
3
- ///////////////////////////////////////
4
- import { ODId, ODManager, ODManagerData, ODNoGeneric, ODPromiseVoid, ODSystemError, ODValidId, ODValidJsonType } from "./base.js"
5
- import nodepath from "path"
6
- import { ODDebugger } from "./console.js"
7
- import fs from "fs"
8
- import * as fjs from "formatted-json-stringify"
9
- import { jsonc } from "jsonc"
10
-
11
- /**## ODConfigManagerIdConstraint `type`
12
- * The constraint/layout for id mappings/interfaces of the `ODConfigManager` class.
13
- */
14
- export type ODConfigManagerIdConstraint = Record<string,ODConfig<any>>
15
-
16
- /**## ODConfigManager `class`
17
- * This is an Open Discord config manager.
18
- *
19
- * It manages all config files in the bot and allows plugins to access config files from Open Discord & other plugins!
20
- *
21
- * You can use this class to get/change/add a config file (`ODConfig`) in your plugin!
22
- */
23
- export class ODConfigManager<IdList extends ODConfigManagerIdConstraint = ODConfigManagerIdConstraint> extends ODManager<ODConfig<any>> {
24
- constructor(debug:ODDebugger){
25
- super(debug,"config")
26
- }
27
-
28
- add(data:ODConfig<any>|ODConfig<any>[],overwrite?:boolean): boolean {
29
- if (this.debug){
30
- if (Array.isArray(data)){
31
- for (const d of data){
32
- d.useDebug(this.debug)
33
- }
34
- }else data.useDebug(this.debug)
35
- }
36
- return super.add(data,overwrite)
37
- }
38
- /**Init all config files. */
39
- async init(){
40
- for (const config of this.getAll()){
41
- try{
42
- await config.init()
43
- }catch(err:any){
44
- process.emit("uncaughtException",new ODSystemError(err))
45
- }
46
- }
47
- }
48
-
49
- get<ConfigId extends keyof ODNoGeneric<IdList>>(id:ConfigId): IdList[ConfigId]
50
- get(id:ODValidId): ODConfig<any>|null
51
-
52
- get(id:ODValidId): ODConfig<any>|null {
53
- return super.get(id)
54
- }
55
-
56
- remove<ConfigId extends keyof ODNoGeneric<IdList>>(id:ConfigId): IdList[ConfigId]
57
- remove(id:ODValidId): ODConfig<any>|null
58
-
59
- remove(id:ODValidId): ODConfig<any>|null {
60
- return super.remove(id)
61
- }
62
-
63
- exists(id:keyof ODNoGeneric<IdList>): boolean
64
- exists(id:ODValidId): boolean
65
-
66
- exists(id:ODValidId): boolean {
67
- return super.exists(id)
68
- }
69
- }
70
-
71
- /**## ODConfig `class`
72
- * This is an Open Discord config helper.
73
- * This class doesn't do anything at all, it just gives a template & basic methods for a config. Use `ODJsonConfig` instead!
74
- *
75
- * You can use this class if you want to create your own config implementation (e.g. `yml`, `xml`,...)!
76
- */
77
- export abstract class ODConfig<Data extends any> extends ODManagerData {
78
- /**The name of the file with extension. */
79
- file: string = ""
80
- /**The path to the file relative to the main directory. */
81
- path: string = ""
82
- /**An object/array of the entire config file! Variables inside it can be edited while the bot is running! */
83
- data: Data
84
- /**Is this config already initiated? */
85
- initiated: boolean = false
86
- /**An array of listeners to run when the config gets reloaded. These are not executed on the initial loading. */
87
- protected reloadListeners: Function[] = []
88
- /**Alias to Open Discord debugger. */
89
- protected debug: ODDebugger|null = null
90
-
91
- constructor(id:ODValidId, data:any){
92
- super(id)
93
- this.data = data
94
- }
95
-
96
- /**Use the Open Discord debugger for logs. */
97
- useDebug(debug:ODDebugger|null){
98
- this.debug = debug
99
- }
100
- /**Init the config. */
101
- init(): ODPromiseVoid {
102
- this.initiated = true
103
- if (this.debug) this.debug.debug("Initiated config '"+this.file+"' in ODConfigManager.",[{key:"id",value:this.id.value}])
104
- //please implement this feature in your own config extension & extend this function.
105
- }
106
- /**Reload the config. Be aware that this doesn't update the config data everywhere in the bot! */
107
- reload(): ODPromiseVoid {
108
- if (this.debug) this.debug.debug("Reloaded config '"+this.file+"' in ODConfigManager.",[{key:"id",value:this.id.value}])
109
- //please implement this feature in your own config extension & extend this function.
110
- }
111
- /**Save the edited config to the filesystem. This is used by the Interactive Setup CLI. It's not recommended to use this while the bot is running. */
112
- save(): ODPromiseVoid {
113
- if (this.debug) this.debug.debug("Saved config '"+this.file+"' in ODConfigManager.",[{key:"id",value:this.id.value}])
114
- //please implement this feature in your own config extension & extend this function.
115
- }
116
- /**Listen for a reload of this JSON file! */
117
- onReload(cb:Function){
118
- this.reloadListeners.push(cb)
119
- }
120
- /**Remove all reload listeners. Not recommended! */
121
- removeAllReloadListeners(){
122
- this.reloadListeners = []
123
- }
124
- }
125
-
126
- /**## ODJsonConfig `class`
127
- * This is an Open Discord JSON config.
128
- * You can use this class to get & edit variables from the config files or to create your own JSON config!
129
- * @example
130
- * //create a config from: ./config/test.json with the id "some-config"
131
- * const config = new api.ODJsonConfig("some-config","test.json")
132
- *
133
- * //create a config with custom dir: ./plugins/testplugin/test.json
134
- * const config = new api.ODJsonConfig("plugin-config","test.json","./plugins/testplugin/")
135
- */
136
- export class ODJsonConfig<Data extends any> extends ODConfig<Data> {
137
- formatter: fjs.custom.BaseFormatter
138
-
139
- constructor(id:ODValidId, file:string, customPath?:string, formatter?:fjs.custom.BaseFormatter){
140
- super(id,{})
141
- this.file = (file.endsWith(".json")) ? file : file+".json"
142
- this.path = customPath ? nodepath.join("./",customPath,this.file) : nodepath.join("./config/",this.file)
143
- this.formatter = formatter ?? new fjs.DefaultFormatter(null,true," ")
144
- }
145
-
146
- /**Init the config. */
147
- init(): ODPromiseVoid {
148
- if (!fs.existsSync(this.path)) throw new ODSystemError("Unable to parse config \""+nodepath.join("./",this.path)+"\", the file doesn't exist!")
149
- try{
150
- this.data = JSON.parse(fs.readFileSync(this.path).toString())
151
- super.init()
152
- }catch(err){
153
- process.emit("uncaughtException",err)
154
- throw new ODSystemError("Unable to parse config \""+nodepath.join("./",this.path)+"\"!")
155
- }
156
- }
157
- /**Reload the config. Be aware that this doesn't update the config data everywhere in the bot! */
158
- reload(){
159
- if (!this.initiated) throw new ODSystemError("Unable to reload config \""+nodepath.join("./",this.path)+"\", the file hasn't been initiated yet!")
160
- if (!fs.existsSync(this.path)) throw new ODSystemError("Unable to reload config \""+nodepath.join("./",this.path)+"\", the file doesn't exist!")
161
- try{
162
- this.data = JSON.parse(fs.readFileSync(this.path).toString())
163
- super.reload()
164
- this.reloadListeners.forEach((cb) => {
165
- try{
166
- cb()
167
- }catch(err){
168
- process.emit("uncaughtException",err)
169
- }
170
- })
171
- }catch(err){
172
- process.emit("uncaughtException",err)
173
- throw new ODSystemError("Unable to reload config \""+nodepath.join("./",this.path)+"\"!")
174
- }
175
- }
176
- /**Save the edited config to the filesystem. This is used by the Interactive Setup CLI. It's not recommended to use this while the bot is running. */
177
- save(): ODPromiseVoid {
178
- if (!this.initiated) throw new ODSystemError("Unable to save config \""+nodepath.join("./",this.path)+"\", the file hasn't been initiated yet!")
179
- try{
180
- const contents = this.formatter.stringify(this.data as ODValidJsonType)
181
- fs.writeFileSync(this.path,contents)
182
- super.save()
183
- }catch(err){
184
- process.emit("uncaughtException",err)
185
- throw new ODSystemError("Unable to save config \""+nodepath.join("./",this.path)+"\"!")
186
- }
187
- }
188
- }
189
-
190
- /**## ODJsonCommentsConfig `class`
191
- * An Open Discord JSONC (`.jsonc`) config.
192
- * Use this class to get & edit variables from the config files or to create your own JSON config!
193
- * @example
194
- * //create a config from: ./config/test.jsonc with the id "some-config"
195
- * const config = new api.ODJsonCommentsConfig("some-config","test.jsonc")
196
- *
197
- * //create a config with custom dir: ./plugins/testplugin/test.jsonc
198
- * const config = new api.ODJsonCommentsConfig("plugin-config","test.jsonc","./plugins/testplugin/")
199
- */
200
- export class ODJsonCommentsConfig<Data extends any> extends ODConfig<Data> {
201
- formatter: fjs.custom.BaseFormatter
202
-
203
- constructor(id:ODValidId, file:string, customPath?:string, formatter?:fjs.custom.BaseFormatter){
204
- super(id,{})
205
- this.file = (file.endsWith(".jsonc")) ? file : file+".jsonc"
206
- this.path = customPath ? nodepath.join("./",customPath,this.file) : nodepath.join("./config/",this.file)
207
- this.formatter = formatter ?? new fjs.DefaultFormatter(null,true," ")
208
- }
209
-
210
- /**Init the config. */
211
- init(): ODPromiseVoid {
212
- if (!fs.existsSync(this.path)) throw new ODSystemError("Unable to parse JSONC config \""+nodepath.join("./",this.path)+"\", the file doesn't exist!")
213
- try{
214
- this.data = jsonc.parse(fs.readFileSync(this.path).toString())
215
- super.init()
216
- }catch(err){
217
- process.emit("uncaughtException",err)
218
- throw new ODSystemError("Unable to parse JSONC config \""+nodepath.join("./",this.path)+"\"!")
219
- }
220
- }
221
- /**Reload the config. Be aware that this doesn't update the config data everywhere in the bot! */
222
- reload(){
223
- if (!this.initiated) throw new ODSystemError("Unable to reload JSONC config \""+nodepath.join("./",this.path)+"\", the file hasn't been initiated yet!")
224
- if (!fs.existsSync(this.path)) throw new ODSystemError("Unable to JSONC reload config \""+nodepath.join("./",this.path)+"\", the file doesn't exist!")
225
- try{
226
- this.data = jsonc.parse(fs.readFileSync(this.path).toString())
227
- super.reload()
228
- this.reloadListeners.forEach((cb) => {
229
- try{
230
- cb()
231
- }catch(err){
232
- process.emit("uncaughtException",err)
233
- }
234
- })
235
- }catch(err){
236
- process.emit("uncaughtException",err)
237
- throw new ODSystemError("Unable to reload JSONC config \""+nodepath.join("./",this.path)+"\"!")
238
- }
239
- }
240
- /**Save the edited config to the filesystem. This is used by the Interactive Setup CLI. It's not recommended to use this while the bot is running. */
241
- save(): ODPromiseVoid {
242
- if (!this.initiated) throw new ODSystemError("Unable to save JSONC config \""+nodepath.join("./",this.path)+"\", the file hasn't been initiated yet!")
243
- try{
244
- const contents = this.formatter.stringify(this.data as ODValidJsonType)
245
- fs.writeFileSync(this.path,contents)
246
- super.save()
247
- }catch(err){
248
- process.emit("uncaughtException",err)
249
- throw new ODSystemError("Unable to save JSONC config \""+nodepath.join("./",this.path)+"\"!")
250
- }
251
- }
252
- }
253
-
254
- /**## ODMemoryConfig `class`
255
- * An Open Discord memory config.
256
- * This config lives in-memory and does not have any connection to the filesystem.
257
- *
258
- * It is perfect for temporary configs or using the `ODChecker` without a real config file.
259
- */
260
- export class ODMemoryConfig<Data extends any> extends ODConfig<Data> {
261
- constructor(id:ODValidId,data:Data){
262
- super(id,data)
263
- }
264
- }