@open-discord-bots/framework 0.0.1 → 0.0.2
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.
- package/LICENSE.md +713 -0
- package/README.md +104 -0
- package/dist/api/api.d.ts +26 -0
- package/dist/api/api.js +44 -0
- package/dist/api/main.d.ts +133 -0
- package/dist/api/main.js +87 -0
- package/dist/api/modules/action.d.ts +34 -0
- package/dist/api/modules/action.js +58 -0
- package/dist/api/modules/base.d.ts +329 -0
- package/dist/api/modules/base.js +804 -0
- package/dist/api/modules/builder.d.ts +647 -0
- package/dist/api/modules/builder.js +1441 -0
- package/dist/api/modules/checker.d.ts +648 -0
- package/dist/api/modules/checker.js +1324 -0
- package/dist/api/modules/client.d.ts +768 -0
- package/dist/api/modules/client.js +1859 -0
- package/dist/api/modules/code.d.ts +33 -0
- package/dist/api/modules/code.js +57 -0
- package/dist/api/modules/config.d.ts +70 -0
- package/dist/api/modules/config.js +206 -0
- package/dist/api/modules/console.d.ts +305 -0
- package/dist/api/modules/console.js +598 -0
- package/dist/api/modules/cooldown.d.ts +138 -0
- package/dist/api/modules/cooldown.js +359 -0
- package/dist/api/modules/database.d.ts +135 -0
- package/dist/api/modules/database.js +271 -0
- package/dist/api/modules/event.d.ts +43 -0
- package/dist/api/modules/event.js +100 -0
- package/dist/api/modules/flag.d.ts +40 -0
- package/dist/api/modules/flag.js +72 -0
- package/dist/api/modules/fuse.d.ts +218 -0
- package/dist/api/modules/fuse.js +123 -0
- package/dist/api/modules/helpmenu.d.ts +106 -0
- package/dist/api/modules/helpmenu.js +167 -0
- package/dist/api/modules/language.d.ts +85 -0
- package/dist/api/modules/language.js +195 -0
- package/dist/api/modules/permission.d.ts +121 -0
- package/dist/api/modules/permission.js +314 -0
- package/dist/api/modules/plugin.d.ts +128 -0
- package/dist/api/modules/plugin.js +168 -0
- package/dist/api/modules/post.d.ts +44 -0
- package/dist/api/modules/post.js +92 -0
- package/dist/api/modules/progressbar.d.ts +108 -0
- package/dist/api/modules/progressbar.js +233 -0
- package/dist/api/modules/responder.d.ts +506 -0
- package/dist/api/modules/responder.js +1468 -0
- package/dist/api/modules/session.d.ts +58 -0
- package/dist/api/modules/session.js +171 -0
- package/dist/api/modules/startscreen.d.ts +165 -0
- package/dist/api/modules/startscreen.js +293 -0
- package/dist/api/modules/stat.d.ts +142 -0
- package/dist/api/modules/stat.js +293 -0
- package/dist/api/modules/verifybar.d.ts +54 -0
- package/dist/api/modules/verifybar.js +60 -0
- package/dist/api/modules/worker.d.ts +41 -0
- package/dist/api/modules/worker.js +93 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +254 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +40 -0
- package/dist/startup/dump.d.ts +14 -0
- package/dist/startup/dump.js +79 -0
- package/dist/startup/errorHandling.d.ts +2 -0
- package/dist/startup/errorHandling.js +43 -0
- package/dist/startup/pluginLauncher.d.ts +2 -0
- package/dist/startup/pluginLauncher.js +202 -0
- package/package.json +9 -3
- package/src/api/api.ts +29 -0
- package/src/api/main.ts +189 -0
- package/src/api/modules/action.ts +58 -0
- package/src/api/modules/base.ts +811 -0
- package/src/api/modules/builder.ts +1554 -0
- package/src/api/modules/checker.ts +1549 -0
- package/src/api/modules/client.ts +2247 -0
- package/src/api/modules/code.ts +58 -0
- package/src/api/modules/config.ts +159 -0
- package/src/api/modules/console.ts +665 -0
- package/src/api/modules/cooldown.ts +348 -0
- package/src/api/modules/database.ts +278 -0
- package/src/api/modules/event.ts +99 -0
- package/src/api/modules/flag.ts +73 -0
- package/src/api/modules/fuse.ts +348 -0
- package/src/api/modules/helpmenu.ts +216 -0
- package/src/api/modules/language.ts +201 -0
- package/src/api/modules/permission.ts +340 -0
- package/src/api/modules/plugin.ts +242 -0
- package/src/api/modules/post.ts +90 -0
- package/src/api/modules/progressbar.ts +232 -0
- package/src/api/modules/responder.ts +1420 -0
- package/src/api/modules/session.ts +155 -0
- package/src/api/modules/startscreen.ts +320 -0
- package/src/api/modules/stat.ts +313 -0
- package/src/api/modules/verifybar.ts +61 -0
- package/src/api/modules/worker.ts +93 -0
- package/src/api/utils.ts +206 -0
- package/src/cli/cli.ts +151 -0
- package/src/cli/editConfig.ts +943 -0
- package/src/index.ts +6 -1
- package/src/startup/compilation.ts +186 -0
- package/src/startup/dump.ts +45 -0
- package/src/startup/errorHandling.ts +38 -0
- package/src/startup/pluginLauncher.ts +261 -0
- package/LICENSE +0 -21
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
///////////////////////////////////////
|
|
2
|
+
//CODE MODULE
|
|
3
|
+
///////////////////////////////////////
|
|
4
|
+
import { ODId, ODManager, ODManagerData, ODValidId } from "./base"
|
|
5
|
+
import { ODDebugger } from "./console"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**## ODCode `class`
|
|
9
|
+
* This is an Open Discord code runner.
|
|
10
|
+
*
|
|
11
|
+
* Using this, you're able to execute a function just before the startup screen. (90% of the code is already loaded)
|
|
12
|
+
* You can also specify a priority to change the execution order.
|
|
13
|
+
* In Open Discord, this is used for the following processes:
|
|
14
|
+
* - Autoclose/delete
|
|
15
|
+
* - Database syncronisation (with tickets, stats & used options)
|
|
16
|
+
* - Panel auto-update
|
|
17
|
+
* - Database Garbage Collection (removing tickets that don't exist anymore)
|
|
18
|
+
* - And more!
|
|
19
|
+
*/
|
|
20
|
+
export class ODCode extends ODManagerData {
|
|
21
|
+
/**The priority of this code */
|
|
22
|
+
priority: number
|
|
23
|
+
/**The main function of this code */
|
|
24
|
+
func: () => void|Promise<void>
|
|
25
|
+
|
|
26
|
+
constructor(id:ODValidId, priority:number, func:() => void|Promise<void>){
|
|
27
|
+
super(id)
|
|
28
|
+
this.priority = priority
|
|
29
|
+
this.func = func
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**## ODCodeManager `class`
|
|
34
|
+
* This is an Open Discord code manager.
|
|
35
|
+
*
|
|
36
|
+
* It manages & executes `ODCode`'s in the correct order.
|
|
37
|
+
*
|
|
38
|
+
* Use this to register a function/code which executes just before the startup screen. (90% is already loaded)
|
|
39
|
+
*/
|
|
40
|
+
export class ODCodeManager extends ODManager<ODCode> {
|
|
41
|
+
constructor(debug:ODDebugger){
|
|
42
|
+
super(debug,"code")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**Execute all `ODCode` functions in order of their priority (high to low). */
|
|
46
|
+
async execute(){
|
|
47
|
+
const derefArray = [...this.getAll()]
|
|
48
|
+
const workers = derefArray.sort((a,b) => b.priority-a.priority)
|
|
49
|
+
|
|
50
|
+
for (const worker of workers){
|
|
51
|
+
try {
|
|
52
|
+
await worker.func()
|
|
53
|
+
}catch(err){
|
|
54
|
+
process.emit("uncaughtException",err)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
///////////////////////////////////////
|
|
2
|
+
//CONFIG MODULE
|
|
3
|
+
///////////////////////////////////////
|
|
4
|
+
import { ODId, ODManager, ODManagerData, ODPromiseVoid, ODSystemError, ODValidId } from "./base"
|
|
5
|
+
import nodepath from "path"
|
|
6
|
+
import { ODDebugger } from "./console"
|
|
7
|
+
import fs from "fs"
|
|
8
|
+
import * as fjs from "formatted-json-stringify"
|
|
9
|
+
|
|
10
|
+
/**## ODConfigManager `class`
|
|
11
|
+
* This is an Open Discord config manager.
|
|
12
|
+
*
|
|
13
|
+
* It manages all config files in the bot and allows plugins to access config files from Open Discord & other plugins!
|
|
14
|
+
*
|
|
15
|
+
* You can use this class to get/change/add a config file (`ODConfig`) in your plugin!
|
|
16
|
+
*/
|
|
17
|
+
export class ODConfigManager extends ODManager<ODConfig> {
|
|
18
|
+
/**Alias to Open Discord debugger. */
|
|
19
|
+
#debug: ODDebugger
|
|
20
|
+
|
|
21
|
+
constructor(debug:ODDebugger){
|
|
22
|
+
super(debug,"config")
|
|
23
|
+
this.#debug = debug
|
|
24
|
+
}
|
|
25
|
+
add(data:ODConfig|ODConfig[],overwrite?:boolean): boolean {
|
|
26
|
+
if (Array.isArray(data)) data.forEach((d) => d.useDebug(this.#debug))
|
|
27
|
+
else data.useDebug(this.#debug)
|
|
28
|
+
return super.add(data,overwrite)
|
|
29
|
+
}
|
|
30
|
+
/**Init all config files. */
|
|
31
|
+
async init(){
|
|
32
|
+
for (const config of this.getAll()){
|
|
33
|
+
try{
|
|
34
|
+
await config.init()
|
|
35
|
+
}catch(err){
|
|
36
|
+
process.emit("uncaughtException",new ODSystemError(err))
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**## ODConfig `class`
|
|
43
|
+
* This is an Open Discord config helper.
|
|
44
|
+
* This class doesn't do anything at all, it just gives a template & basic methods for a config. Use `ODJsonConfig` instead!
|
|
45
|
+
*
|
|
46
|
+
* You can use this class if you want to create your own config implementation (e.g. `yml`, `xml`,...)!
|
|
47
|
+
*/
|
|
48
|
+
export class ODConfig extends ODManagerData {
|
|
49
|
+
/**The name of the file with extension. */
|
|
50
|
+
file: string = ""
|
|
51
|
+
/**The path to the file relative to the main directory. */
|
|
52
|
+
path: string = ""
|
|
53
|
+
/**An object/array of the entire config file! Variables inside it can be edited while the bot is running! */
|
|
54
|
+
data: any
|
|
55
|
+
/**Is this config already initiated? */
|
|
56
|
+
initiated: boolean = false
|
|
57
|
+
/**An array of listeners to run when the config gets reloaded. These are not executed on the initial loading. */
|
|
58
|
+
protected reloadListeners: Function[] = []
|
|
59
|
+
/**Alias to Open Discord debugger. */
|
|
60
|
+
protected debug: ODDebugger|null = null
|
|
61
|
+
|
|
62
|
+
constructor(id:ODValidId, data:any){
|
|
63
|
+
super(id)
|
|
64
|
+
this.data = data
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**Use the Open Discord debugger for logs. */
|
|
68
|
+
useDebug(debug:ODDebugger|null){
|
|
69
|
+
this.debug = debug
|
|
70
|
+
}
|
|
71
|
+
/**Init the config. */
|
|
72
|
+
init(): ODPromiseVoid {
|
|
73
|
+
this.initiated = true
|
|
74
|
+
if (this.debug) this.debug.debug("Initiated config '"+this.file+"' in ODConfigManager.",[{key:"id",value:this.id.value}])
|
|
75
|
+
//please implement this feature in your own config extension & extend this function.
|
|
76
|
+
}
|
|
77
|
+
/**Reload the config. Be aware that this doesn't update the config data everywhere in the bot! */
|
|
78
|
+
reload(): ODPromiseVoid {
|
|
79
|
+
if (this.debug) this.debug.debug("Reloaded config '"+this.file+"' in ODConfigManager.",[{key:"id",value:this.id.value}])
|
|
80
|
+
//please implement this feature in your own config extension & extend this function.
|
|
81
|
+
}
|
|
82
|
+
/**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. */
|
|
83
|
+
save(): ODPromiseVoid {
|
|
84
|
+
if (this.debug) this.debug.debug("Saved config '"+this.file+"' in ODConfigManager.",[{key:"id",value:this.id.value}])
|
|
85
|
+
//please implement this feature in your own config extension & extend this function.
|
|
86
|
+
}
|
|
87
|
+
/**Listen for a reload of this JSON file! */
|
|
88
|
+
onReload(cb:Function){
|
|
89
|
+
this.reloadListeners.push(cb)
|
|
90
|
+
}
|
|
91
|
+
/**Remove all reload listeners. Not recommended! */
|
|
92
|
+
removeAllReloadListeners(){
|
|
93
|
+
this.reloadListeners = []
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**## ODJsonConfig `class`
|
|
98
|
+
* This is an Open Discord JSON config.
|
|
99
|
+
* You can use this class to get & edit variables from the config files or to create your own JSON config!
|
|
100
|
+
* @example
|
|
101
|
+
* //create a config from: ./config/test.json with the id "some-config"
|
|
102
|
+
* const config = new api.ODJsonConfig("some-config","test.json")
|
|
103
|
+
*
|
|
104
|
+
* //create a config with custom dir: ./plugins/testplugin/test.json
|
|
105
|
+
* const config = new api.ODJsonConfig("plugin-config","test.json","./plugins/testplugin/")
|
|
106
|
+
*/
|
|
107
|
+
export class ODJsonConfig extends ODConfig {
|
|
108
|
+
formatter: fjs.custom.BaseFormatter
|
|
109
|
+
|
|
110
|
+
constructor(id:ODValidId, file:string, customPath?:string, formatter?:fjs.custom.BaseFormatter){
|
|
111
|
+
super(id,{})
|
|
112
|
+
this.file = (file.endsWith(".json")) ? file : file+".json"
|
|
113
|
+
this.path = customPath ? nodepath.join("./",customPath,this.file) : nodepath.join("./config/",this.file)
|
|
114
|
+
this.formatter = formatter ?? new fjs.DefaultFormatter(null,true," ")
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**Init the config. */
|
|
118
|
+
init(): ODPromiseVoid {
|
|
119
|
+
if (!fs.existsSync(this.path)) throw new ODSystemError("Unable to parse config \""+nodepath.join("./",this.path)+"\", the file doesn't exist!")
|
|
120
|
+
try{
|
|
121
|
+
this.data = JSON.parse(fs.readFileSync(this.path).toString())
|
|
122
|
+
super.init()
|
|
123
|
+
}catch(err){
|
|
124
|
+
process.emit("uncaughtException",err)
|
|
125
|
+
throw new ODSystemError("Unable to parse config \""+nodepath.join("./",this.path)+"\"!")
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**Reload the config. Be aware that this doesn't update the config data everywhere in the bot! */
|
|
129
|
+
reload(){
|
|
130
|
+
if (!this.initiated) throw new ODSystemError("Unable to reload config \""+nodepath.join("./",this.path)+"\", the file hasn't been initiated yet!")
|
|
131
|
+
if (!fs.existsSync(this.path)) throw new ODSystemError("Unable to reload config \""+nodepath.join("./",this.path)+"\", the file doesn't exist!")
|
|
132
|
+
try{
|
|
133
|
+
this.data = JSON.parse(fs.readFileSync(this.path).toString())
|
|
134
|
+
super.reload()
|
|
135
|
+
this.reloadListeners.forEach((cb) => {
|
|
136
|
+
try{
|
|
137
|
+
cb()
|
|
138
|
+
}catch(err){
|
|
139
|
+
process.emit("uncaughtException",err)
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
}catch(err){
|
|
143
|
+
process.emit("uncaughtException",err)
|
|
144
|
+
throw new ODSystemError("Unable to reload config \""+nodepath.join("./",this.path)+"\"!")
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**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. */
|
|
148
|
+
save(): ODPromiseVoid {
|
|
149
|
+
if (!this.initiated) throw new ODSystemError("Unable to save config \""+nodepath.join("./",this.path)+"\", the file hasn't been initiated yet!")
|
|
150
|
+
try{
|
|
151
|
+
const contents = this.formatter.stringify(this.data)
|
|
152
|
+
fs.writeFileSync(this.path,contents)
|
|
153
|
+
super.save()
|
|
154
|
+
}catch(err){
|
|
155
|
+
process.emit("uncaughtException",err)
|
|
156
|
+
throw new ODSystemError("Unable to save config \""+nodepath.join("./",this.path)+"\"!")
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|