@open-discord-bots/framework 0.3.0 → 0.3.1
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/dist/api/main.js +1 -1
- package/dist/api/modules/base.d.ts +27 -9
- package/dist/api/modules/base.js +78 -80
- package/dist/api/modules/builder.d.ts +0 -9
- package/dist/api/modules/checker.d.ts +26 -5
- package/dist/api/modules/checker.js +31 -31
- package/dist/api/modules/client.d.ts +66 -14
- package/dist/api/modules/client.js +146 -132
- package/dist/api/modules/component.d.ts +8 -2
- package/dist/api/modules/component.js +8 -6
- package/dist/api/modules/config.d.ts +0 -1
- package/dist/api/modules/config.js +9 -7
- package/dist/api/modules/console.d.ts +16 -4
- package/dist/api/modules/console.js +25 -25
- package/dist/api/modules/event.d.ts +4 -2
- package/dist/api/modules/event.js +8 -10
- package/dist/api/modules/fuse.d.ts +1 -1
- package/dist/api/modules/helpmenu.d.ts +2 -2
- package/dist/api/modules/helpmenu.js +4 -7
- package/dist/api/modules/language.d.ts +2 -1
- package/dist/api/modules/language.js +6 -9
- package/dist/api/modules/permission.d.ts +10 -1
- package/dist/api/modules/permission.js +17 -20
- package/dist/api/modules/plugin.d.ts +2 -1
- package/dist/api/modules/plugin.js +2 -2
- package/dist/api/modules/post.d.ts +12 -4
- package/dist/api/modules/post.js +36 -10
- package/dist/api/modules/progressbar.d.ts +16 -5
- package/dist/api/modules/progressbar.js +34 -34
- package/dist/api/modules/responder.d.ts +95 -26
- package/dist/api/modules/responder.js +213 -172
- package/dist/api/modules/session.d.ts +10 -1
- package/dist/api/modules/session.js +15 -15
- package/dist/api/modules/startscreen.d.ts +0 -1
- package/dist/api/modules/startscreen.js +3 -6
- package/dist/api/modules/statistic.d.ts +2 -1
- package/dist/api/modules/statistic.js +4 -7
- package/dist/api/modules/worker.d.ts +2 -1
- package/dist/api/modules/worker.js +3 -3
- package/package.json +1 -1
- package/src/api/main.ts +1 -1
- package/src/api/modules/base.ts +75 -77
- package/src/api/modules/builder.ts +0 -10
- package/src/api/modules/checker.ts +31 -31
- package/src/api/modules/client.ts +144 -136
- package/src/api/modules/component.ts +11 -7
- package/src/api/modules/config.ts +8 -6
- package/src/api/modules/console.ts +25 -25
- package/src/api/modules/event.ts +6 -10
- package/src/api/modules/fuse.ts +1 -1
- package/src/api/modules/helpmenu.ts +4 -7
- package/src/api/modules/language.ts +6 -9
- package/src/api/modules/permission.ts +17 -20
- package/src/api/modules/plugin.ts +2 -2
- package/src/api/modules/post.ts +31 -10
- package/src/api/modules/progressbar.ts +34 -34
- package/src/api/modules/responder.ts +232 -181
- package/src/api/modules/session.ts +14 -14
- package/src/api/modules/startscreen.ts +3 -6
- package/src/api/modules/statistic.ts +4 -7
- package/src/api/modules/worker.ts +3 -3
|
@@ -72,23 +72,23 @@ export type ODSessionTimeoutCallback = (id:string, timeout:"default"|"custom", d
|
|
|
72
72
|
*/
|
|
73
73
|
export class ODSession extends ODManagerData {
|
|
74
74
|
/**The history of previously generated instance ids. Used to reduce the risk of generating the same id twice. */
|
|
75
|
-
|
|
75
|
+
protected idHistory: string[] = []
|
|
76
76
|
/**The max length of the instance id history. */
|
|
77
|
-
|
|
77
|
+
protected maxIdHistoryLength: number = 500
|
|
78
78
|
/**An array of all the currently active session instances. */
|
|
79
79
|
sessions: ODSessionInstance[] = []
|
|
80
80
|
/**The default amount of minutes before a session automatically stops. */
|
|
81
81
|
timeoutMinutes: number = 30
|
|
82
82
|
/**The id of the auto-timeout session checker interval */
|
|
83
|
-
|
|
83
|
+
protected intervalId: NodeJS.Timeout
|
|
84
84
|
/**Listeners for when a session times-out. */
|
|
85
|
-
|
|
85
|
+
protected timeoutListeners: ODSessionTimeoutCallback[] = []
|
|
86
86
|
|
|
87
87
|
constructor(id:ODValidId, intervalSeconds?:number){
|
|
88
88
|
super(id)
|
|
89
89
|
|
|
90
90
|
//create the auto-timeout session checker
|
|
91
|
-
this
|
|
91
|
+
this.intervalId = setInterval(() => {
|
|
92
92
|
const deletableSessions: {instance:ODSessionInstance,reason:"default"|"custom"}[] = []
|
|
93
93
|
|
|
94
94
|
//collect all deletable sessions
|
|
@@ -108,31 +108,31 @@ export class ODSession extends ODManagerData {
|
|
|
108
108
|
this.sessions.splice(index,1)
|
|
109
109
|
|
|
110
110
|
//emit timeout listeners
|
|
111
|
-
this
|
|
111
|
+
this.timeoutListeners.forEach((cb) => cb(session.instance.id,session.reason,session.instance.data,new Date(session.instance.creation)))
|
|
112
112
|
})
|
|
113
113
|
|
|
114
114
|
},((intervalSeconds) ? (intervalSeconds * 1000) : 60000))
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/**Create a unique hex id of 8 characters and add it to the instance id history */
|
|
118
|
-
|
|
118
|
+
protected createUniqueId(): string {
|
|
119
119
|
const hex = crypto.randomBytes(4).toString("hex")
|
|
120
|
-
if (this
|
|
121
|
-
return this
|
|
120
|
+
if (this.idHistory.includes(hex)){
|
|
121
|
+
return this.createUniqueId()
|
|
122
122
|
}else{
|
|
123
|
-
this
|
|
124
|
-
if (this
|
|
123
|
+
this.idHistory.push(hex)
|
|
124
|
+
if (this.idHistory.length > this.maxIdHistoryLength) this.idHistory.shift()
|
|
125
125
|
return hex
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
/**Stop the global interval that automatically deletes timed-out sessions. (This action can't be reverted!) */
|
|
129
129
|
stopAutoTimeout(){
|
|
130
|
-
clearInterval(this
|
|
130
|
+
clearInterval(this.intervalId)
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/**Start a session instance with data. Returns the unique id required to access the session. */
|
|
134
134
|
start(data?:any): string {
|
|
135
|
-
const id = this
|
|
135
|
+
const id = this.createUniqueId()
|
|
136
136
|
this.sessions.push({
|
|
137
137
|
id,data,
|
|
138
138
|
creation:new Date().getTime(),
|
|
@@ -176,6 +176,6 @@ export class ODSession extends ODManagerData {
|
|
|
176
176
|
}
|
|
177
177
|
/**Listen for a session timeout (default or custom) */
|
|
178
178
|
onTimeout(callback:ODSessionTimeoutCallback){
|
|
179
|
-
this
|
|
179
|
+
this.timeoutListeners.push(callback)
|
|
180
180
|
}
|
|
181
181
|
}
|
|
@@ -24,14 +24,11 @@ export type ODStartScreenManagerIdConstraint = Record<string,ODStartScreenCompon
|
|
|
24
24
|
* The startscreen is the part you see when the bot has started up successfully. (e.g. the Open Discord logo, logs, livestatus, flags, ...)
|
|
25
25
|
*/
|
|
26
26
|
export class ODStartScreenManager<IdList extends ODStartScreenManagerIdConstraint = ODStartScreenManagerIdConstraint,LiveStatus extends ODLiveStatusManager = ODLiveStatusManager> extends ODManager<ODStartScreenComponent> {
|
|
27
|
-
/**Alias to the Open Discord debugger. */
|
|
28
|
-
#debug: ODDebugger
|
|
29
27
|
/**Alias to the livestatus manager. */
|
|
30
28
|
livestatus: LiveStatus
|
|
31
29
|
|
|
32
30
|
constructor(debug:ODDebugger,livestatus:LiveStatus){
|
|
33
31
|
super(debug,"startscreen component")
|
|
34
|
-
this.#debug = debug
|
|
35
32
|
this.livestatus = livestatus
|
|
36
33
|
}
|
|
37
34
|
|
|
@@ -51,10 +48,10 @@ export class ODStartScreenManager<IdList extends ODStartScreenManagerIdConstrain
|
|
|
51
48
|
try {
|
|
52
49
|
const renderedText = await component.renderAll(location)
|
|
53
50
|
console.log(renderedText)
|
|
54
|
-
this
|
|
51
|
+
this.debug?.console.debugfile.writeText("[STARTSCREEN] Component: \""+component.id+"\"\n"+ansis.strip(renderedText))
|
|
55
52
|
}catch(e){
|
|
56
|
-
this
|
|
57
|
-
this
|
|
53
|
+
this.debug?.console.log("Unable to render \""+component.id+"\" startscreen component!","error")
|
|
54
|
+
this.debug?.console.debugfile.writeErrorMessage(new ODError(e,"uncaughtException"))
|
|
58
55
|
}
|
|
59
56
|
location++
|
|
60
57
|
}
|
|
@@ -37,16 +37,13 @@ export type ODStatisticManagerIdConstraint = Record<string,ODStatisticScope>
|
|
|
37
37
|
* Statistic can be accessed in the individual scopes.
|
|
38
38
|
*/
|
|
39
39
|
export class ODStatisticManager<IdList extends ODStatisticManagerIdConstraint = ODStatisticManagerIdConstraint> extends ODManager<ODStatisticScope> {
|
|
40
|
-
/**Alias to Open Discord debugger. */
|
|
41
|
-
#debug: ODDebugger
|
|
42
40
|
/**Alias to Open Discord statistics database. */
|
|
43
41
|
database: ODDatabase<ODDatabaseIdConstraint>|null = null
|
|
44
42
|
/**All the listeners for the init event. */
|
|
45
|
-
|
|
43
|
+
protected initListeners: ODStatisticManagerInitCallback[] = []
|
|
46
44
|
|
|
47
45
|
constructor(debug:ODDebugger){
|
|
48
46
|
super(debug,"statistic scope")
|
|
49
|
-
this.#debug = debug
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
/**Select the database to use to read/write all statistics from/to. */
|
|
@@ -54,7 +51,7 @@ export class ODStatisticManager<IdList extends ODStatisticManagerIdConstraint =
|
|
|
54
51
|
this.database = database
|
|
55
52
|
}
|
|
56
53
|
add(data:ODStatisticScope, overwrite?:boolean): boolean {
|
|
57
|
-
data.useDebug(this
|
|
54
|
+
data.useDebug(this.debug,"stat")
|
|
58
55
|
if (this.database) data.useDatabase(this.database)
|
|
59
56
|
return super.add(data,overwrite)
|
|
60
57
|
}
|
|
@@ -76,7 +73,7 @@ export class ODStatisticManager<IdList extends ODStatisticManagerIdConstraint =
|
|
|
76
73
|
})
|
|
77
74
|
|
|
78
75
|
//do additional deletion
|
|
79
|
-
for (const cb of this
|
|
76
|
+
for (const cb of this.initListeners){
|
|
80
77
|
await cb(data,deletableStats)
|
|
81
78
|
}
|
|
82
79
|
|
|
@@ -96,7 +93,7 @@ export class ODStatisticManager<IdList extends ODStatisticManagerIdConstraint =
|
|
|
96
93
|
}
|
|
97
94
|
/**Run a function when the statistics are initialized. This can be used to clear statistics from users that left the server or tickets which don't exist anymore. */
|
|
98
95
|
onInit(callback:ODStatisticManagerInitCallback){
|
|
99
|
-
this
|
|
96
|
+
this.initListeners.push(callback)
|
|
100
97
|
}
|
|
101
98
|
|
|
102
99
|
get<ScopeId extends keyof ODNoGeneric<IdList>>(id:ScopeId): IdList[ScopeId]
|
|
@@ -40,13 +40,13 @@ export class ODWorker<Instance, Origin extends string, Params> extends ODManager
|
|
|
40
40
|
*/
|
|
41
41
|
export class ODWorkerManager<Instance, Origin extends string, Params,WorkerIds extends string = string> extends ODManager<ODWorker<Instance,Origin,Params>> {
|
|
42
42
|
/**The order of execution for workers inside this manager. */
|
|
43
|
-
|
|
43
|
+
protected priorityOrder: "ascending"|"descending"
|
|
44
44
|
/**The backup worker will be executed when one of the workers fails or cancels execution. */
|
|
45
45
|
backupWorker: ODWorker<{reason:"error"|"cancel"},Origin,Params>|null = null
|
|
46
46
|
|
|
47
47
|
constructor(priorityOrder:"ascending"|"descending"){
|
|
48
48
|
super()
|
|
49
|
-
this
|
|
49
|
+
this.priorityOrder = priorityOrder
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**Get all workers in sorted order. */
|
|
@@ -61,7 +61,7 @@ export class ODWorkerManager<Instance, Origin extends string, Params,WorkerIds e
|
|
|
61
61
|
/**Execute all workers on an instance using the given origin & parameters. */
|
|
62
62
|
async executeWorkers(instance:Instance, origin:Origin, params:Params){
|
|
63
63
|
const derefParams = {...params}
|
|
64
|
-
const workers = this.getSortedWorkers(this
|
|
64
|
+
const workers = this.getSortedWorkers(this.priorityOrder)
|
|
65
65
|
let didCancel = false
|
|
66
66
|
let didCrash = false
|
|
67
67
|
|