@open-discord-bots/framework 0.3.14 → 0.3.16
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/README.md +5 -1
- package/dist/api/main.js +1 -1
- package/dist/api/modules/responder.js +50 -26
- package/package.json +1 -1
- package/.gitattributes +0 -2
- package/src/api/index.ts +0 -31
- package/src/api/main.ts +0 -203
- package/src/api/modules/action.ts +0 -89
- package/src/api/modules/base.ts +0 -845
- package/src/api/modules/builder.ts +0 -1755
- package/src/api/modules/checker.ts +0 -1826
- package/src/api/modules/client.ts +0 -2345
- package/src/api/modules/code.ts +0 -84
- package/src/api/modules/component.ts +0 -2000
- package/src/api/modules/config.ts +0 -264
- package/src/api/modules/console.ts +0 -697
- package/src/api/modules/cooldown.ts +0 -369
- package/src/api/modules/database.ts +0 -321
- package/src/api/modules/event.ts +0 -123
- package/src/api/modules/flag.ts +0 -99
- package/src/api/modules/fuse.ts +0 -365
- package/src/api/modules/helpmenu.ts +0 -273
- package/src/api/modules/language.ts +0 -230
- package/src/api/modules/permission.ts +0 -363
- package/src/api/modules/plugin.ts +0 -294
- package/src/api/modules/post.ts +0 -137
- package/src/api/modules/progressbar.ts +0 -370
- package/src/api/modules/responder.ts +0 -1625
- package/src/api/modules/session.ts +0 -181
- package/src/api/modules/startscreen.ts +0 -345
- package/src/api/modules/state.ts +0 -298
- package/src/api/modules/statistic.ts +0 -380
- package/src/api/modules/verifybar.ts +0 -68
- package/src/api/modules/worker.ts +0 -119
- package/src/cli/editConfig.ts +0 -930
- package/src/cli/index.ts +0 -152
- package/src/index.ts +0 -8
- package/src/startup/compilation.ts +0 -204
- package/src/startup/dump.ts +0 -46
- package/src/startup/errorHandling.ts +0 -42
- package/src/startup/pluginLauncher.ts +0 -265
- package/src/utilities/index.ts +0 -229
- package/tools/cleanup.js +0 -2
- package/tsconfig.json +0 -15
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
///////////////////////////////////////
|
|
2
|
-
//VERIFYBAR MODULE
|
|
3
|
-
///////////////////////////////////////
|
|
4
|
-
import { ODId, ODManager, ODManagerData, ODNoGeneric, ODValidId } from "./base.js"
|
|
5
|
-
import { ODDebugger } from "./console.js"
|
|
6
|
-
import { ODButtonResponderInstance } from "./responder.js"
|
|
7
|
-
import { ODWorkerManager } from "./worker.js"
|
|
8
|
-
import * as discord from "discord.js"
|
|
9
|
-
|
|
10
|
-
/**## ODVerifyBar `class`
|
|
11
|
-
* This is an Open Discord verifybar responder.
|
|
12
|
-
*
|
|
13
|
-
* It contain `ODWorkerManager`'s that will be fired when the continue/stop (✅ ❌) buttons are pressed.
|
|
14
|
-
*
|
|
15
|
-
* Verifybars don't automatically trigger these workers. The button responders of the verifybars should implement it manually.
|
|
16
|
-
*/
|
|
17
|
-
export class ODVerifyBar<ButtonIds extends string,WorkerIds extends string = string> extends ODManagerData {
|
|
18
|
-
/**All workers that will run when a button in the verifybar is pressed. */
|
|
19
|
-
workers: ODWorkerManager<ODButtonResponderInstance,"button",{verifybar:ODVerifyBar<ButtonIds,WorkerIds>,selectedButtonId:ButtonIds},WorkerIds>
|
|
20
|
-
|
|
21
|
-
constructor(id:ODValidId){
|
|
22
|
-
super(id)
|
|
23
|
-
this.workers = new ODWorkerManager("descending")
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**Activate the verifybar response to this button. */
|
|
27
|
-
async activate(responder:ODButtonResponderInstance,selectedButtonId:ButtonIds){
|
|
28
|
-
await this.workers.executeWorkers(responder,"button",{verifybar:this,selectedButtonId})
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**## ODVerifyBarManagerIdConstraint `type`
|
|
33
|
-
* The constraint/layout for id mappings/interfaces of the `ODVerifyBarManager` class.
|
|
34
|
-
*/
|
|
35
|
-
export type ODVerifyBarManagerIdConstraint = Record<string,ODVerifyBar<string>>
|
|
36
|
-
|
|
37
|
-
/**## ODVerifyBarManager `class`
|
|
38
|
-
* The Open Discord verifybar manager manages all responders for (✅ ❌) verifybars in the bot.
|
|
39
|
-
* The `ODVerifyBar` classes contain `ODWorkerManager`'s that will be fired when the continue/stop buttons are pressed.
|
|
40
|
-
*
|
|
41
|
-
* Verifybars don't automatically trigger these workers. The button responders of the verifybars should implement it manually.
|
|
42
|
-
*/
|
|
43
|
-
export class ODVerifyBarManager<IdList extends ODVerifyBarManagerIdConstraint = ODVerifyBarManagerIdConstraint> extends ODManager<ODVerifyBar<string>> {
|
|
44
|
-
constructor(debug:ODDebugger){
|
|
45
|
-
super(debug,"verifybar")
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get<VerifyBarId extends keyof ODNoGeneric<IdList>>(id:VerifyBarId): IdList[VerifyBarId]
|
|
49
|
-
get(id:ODValidId): ODVerifyBar<string>|null
|
|
50
|
-
|
|
51
|
-
get(id:ODValidId): ODVerifyBar<string>|null {
|
|
52
|
-
return super.get(id)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
remove<VerifyBarId extends keyof ODNoGeneric<IdList>>(id:VerifyBarId): IdList[VerifyBarId]
|
|
56
|
-
remove(id:ODValidId): ODVerifyBar<string>|null
|
|
57
|
-
|
|
58
|
-
remove(id:ODValidId): ODVerifyBar<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
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
///////////////////////////////////////
|
|
2
|
-
//WORKER MODULE
|
|
3
|
-
///////////////////////////////////////
|
|
4
|
-
import { ODId, ODManager, ODManagerData, ODSystemError, ODValidId } from "./base.js"
|
|
5
|
-
|
|
6
|
-
/**## ODWorkerCallback `type`
|
|
7
|
-
* This is the callback used in `ODWorker`!
|
|
8
|
-
*/
|
|
9
|
-
export type ODWorkerCallback<Instance, Origin extends string, Params> = (instance:Instance, params:Params, origin:Origin, cancel:() => void) => void|Promise<void>
|
|
10
|
-
|
|
11
|
-
/**## ODWorker `class`
|
|
12
|
-
* This is an Open Discord worker.
|
|
13
|
-
*
|
|
14
|
-
* You can compare it with a normal javascript callback, but slightly more advanced!
|
|
15
|
-
*
|
|
16
|
-
* - It has an `id` for identification of the function
|
|
17
|
-
* - A `priority` to know when to execute this callback (related to others)
|
|
18
|
-
* - It knows who called this callback (`origin`)
|
|
19
|
-
* - And much more!
|
|
20
|
-
*/
|
|
21
|
-
export class ODWorker<Instance, Origin extends string, Params> extends ODManagerData {
|
|
22
|
-
/**The priority of this worker */
|
|
23
|
-
priority: number
|
|
24
|
-
/**The main callback of this worker */
|
|
25
|
-
callback: ODWorkerCallback<Instance,Origin,Params>
|
|
26
|
-
|
|
27
|
-
constructor(id:ODValidId, priority:number, callback:ODWorkerCallback<Instance,Origin,Params>){
|
|
28
|
-
super(id)
|
|
29
|
-
this.priority = priority
|
|
30
|
-
this.callback = callback
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**Duplicate this worker. Warning: If the callback accesses external variables (outside parameters), the clone will still use those variables. This might result in unexpected behaviour! */
|
|
34
|
-
duplicate(newId?:ODValidId): ODWorker<Instance,Origin,Params> {
|
|
35
|
-
return new ODWorker<Instance,Origin,Params>(newId ?? this.id.value,this.priority,this.callback)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**## ODWorker `class`
|
|
40
|
-
* This is an Open Discord worker manager.
|
|
41
|
-
*
|
|
42
|
-
* It manages & executes `ODWorker`'s in the correct order.
|
|
43
|
-
*
|
|
44
|
-
* You can register a custom worker in this class to create a message or button.
|
|
45
|
-
*/
|
|
46
|
-
export class ODWorkerManager<Instance, Origin extends string, Params,WorkerIds extends string = string> extends ODManager<ODWorker<Instance,Origin,Params>> {
|
|
47
|
-
/**The order of execution for workers inside this manager. */
|
|
48
|
-
protected priorityOrder: "ascending"|"descending"
|
|
49
|
-
/**The backup worker will be executed when one of the workers fails or cancels execution. */
|
|
50
|
-
backupWorker: ODWorker<{reason:"error"|"cancel"},Origin,Params>|null = null
|
|
51
|
-
|
|
52
|
-
constructor(priorityOrder:"ascending"|"descending"){
|
|
53
|
-
super()
|
|
54
|
-
this.priorityOrder = priorityOrder
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**Get all workers in sorted order. */
|
|
58
|
-
getSortedWorkers(priority:"ascending"|"descending"){
|
|
59
|
-
const derefArray = [...this.getAll()]
|
|
60
|
-
|
|
61
|
-
return derefArray.sort((a,b) => {
|
|
62
|
-
if (priority == "ascending") return a.priority-b.priority
|
|
63
|
-
else return b.priority-a.priority
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
/**Execute all workers on an instance using the given origin & parameters. */
|
|
67
|
-
async executeWorkers(instance:Instance, origin:Origin, params:Params){
|
|
68
|
-
const derefParams = {...params}
|
|
69
|
-
const workers = this.getSortedWorkers(this.priorityOrder)
|
|
70
|
-
let didCancel = false
|
|
71
|
-
let didCrash = false
|
|
72
|
-
|
|
73
|
-
for (const worker of workers){
|
|
74
|
-
if (didCancel) break
|
|
75
|
-
try {
|
|
76
|
-
await worker.callback(instance,derefParams,origin,() => {
|
|
77
|
-
didCancel = true
|
|
78
|
-
})
|
|
79
|
-
}catch(err:any){
|
|
80
|
-
process.emit("uncaughtException",new ODSystemError(err))
|
|
81
|
-
didCrash = true
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (didCancel && this.backupWorker){
|
|
85
|
-
try{
|
|
86
|
-
await this.backupWorker.callback({reason:"cancel"},derefParams,origin,() => {})
|
|
87
|
-
}catch(err:any){
|
|
88
|
-
process.emit("uncaughtException",new ODSystemError(err))
|
|
89
|
-
}
|
|
90
|
-
}else if (didCrash && this.backupWorker){
|
|
91
|
-
try{
|
|
92
|
-
await this.backupWorker.callback({reason:"error"},derefParams,origin,() => {})
|
|
93
|
-
}catch(err:any){
|
|
94
|
-
process.emit("uncaughtException",new ODSystemError(err))
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
get(id:WorkerIds): ODWorker<Instance,Origin,Params>
|
|
100
|
-
get(id:ODValidId): ODWorker<Instance,Origin,Params>|null
|
|
101
|
-
|
|
102
|
-
get(id:ODValidId): ODWorker<Instance,Origin,Params>|null {
|
|
103
|
-
return super.get(id)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
remove(id:WorkerIds): ODWorker<Instance,Origin,Params>
|
|
107
|
-
remove(id:ODValidId): ODWorker<Instance,Origin,Params>|null
|
|
108
|
-
|
|
109
|
-
remove(id:ODValidId): ODWorker<Instance,Origin,Params>|null {
|
|
110
|
-
return super.remove(id)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
exists(id:WorkerIds): boolean
|
|
114
|
-
exists(id:ODValidId): boolean
|
|
115
|
-
|
|
116
|
-
exists(id:ODValidId): boolean {
|
|
117
|
-
return super.exists(id)
|
|
118
|
-
}
|
|
119
|
-
}
|