@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,155 @@
|
|
|
1
|
+
///////////////////////////////////////
|
|
2
|
+
//SESSION MODULE
|
|
3
|
+
///////////////////////////////////////
|
|
4
|
+
import { ODId, ODManager, ODManagerData, ODValidId } from "./base"
|
|
5
|
+
import { ODDebugger } from "./console"
|
|
6
|
+
import * as crypto from "crypto"
|
|
7
|
+
|
|
8
|
+
/**## ODSessionManager `class`
|
|
9
|
+
* This is an Open Discord session manager.
|
|
10
|
+
*
|
|
11
|
+
* It contains all sessions in Open Discord. Sessions are a sort of temporary storage which will be cleared when the bot stops.
|
|
12
|
+
* Data in sessions have a randomly generated key which will always be unique.
|
|
13
|
+
*
|
|
14
|
+
* Visit the `ODSession` class for more info
|
|
15
|
+
*/
|
|
16
|
+
export class ODSessionManager extends ODManager<ODSession> {
|
|
17
|
+
constructor(debug:ODDebugger){
|
|
18
|
+
super(debug,"session")
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**## ODSessionInstance `interface`
|
|
23
|
+
* This interface represents a single session instance. It contains an id, data & some dates.
|
|
24
|
+
*/
|
|
25
|
+
export interface ODSessionInstance {
|
|
26
|
+
/**The id of this session instance. */
|
|
27
|
+
id:string,
|
|
28
|
+
/**The creation date of this session instance. */
|
|
29
|
+
creation:number,
|
|
30
|
+
/**The custom amount of minutes before this session expires. */
|
|
31
|
+
timeout:number|null,
|
|
32
|
+
/**This is the data from this session instance */
|
|
33
|
+
data:any
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**## ODSessionTimeoutCallback `type`
|
|
37
|
+
* This is the callback used for session timeout listeners.
|
|
38
|
+
*/
|
|
39
|
+
export type ODSessionTimeoutCallback = (id:string, timeout:"default"|"custom", data:any, creation:Date) => void
|
|
40
|
+
|
|
41
|
+
/**## ODSession `class`
|
|
42
|
+
* This is an Open Discord session.
|
|
43
|
+
*
|
|
44
|
+
* It can be used to create 100% unique id's for usage in the bot. An id can also store additional data which isn't saved to the filesystem.
|
|
45
|
+
* You can almost compare it to the PHP session system.
|
|
46
|
+
*/
|
|
47
|
+
export class ODSession extends ODManagerData {
|
|
48
|
+
/**The history of previously generated instance ids. Used to reduce the risk of generating the same id twice. */
|
|
49
|
+
#idHistory: string[] = []
|
|
50
|
+
/**The max length of the instance id history. */
|
|
51
|
+
#maxIdHistoryLength: number = 500
|
|
52
|
+
/**An array of all the currently active session instances. */
|
|
53
|
+
sessions: ODSessionInstance[] = []
|
|
54
|
+
/**The default amount of minutes before a session automatically stops. */
|
|
55
|
+
timeoutMinutes: number = 30
|
|
56
|
+
/**The id of the auto-timeout session checker interval */
|
|
57
|
+
#intervalId: NodeJS.Timeout
|
|
58
|
+
/**Listeners for when a session times-out. */
|
|
59
|
+
#timeoutListeners: ODSessionTimeoutCallback[] = []
|
|
60
|
+
|
|
61
|
+
constructor(id:ODValidId, intervalSeconds?:number){
|
|
62
|
+
super(id)
|
|
63
|
+
|
|
64
|
+
//create the auto-timeout session checker
|
|
65
|
+
this.#intervalId = setInterval(() => {
|
|
66
|
+
const deletableSessions: {instance:ODSessionInstance,reason:"default"|"custom"}[] = []
|
|
67
|
+
|
|
68
|
+
//collect all deletable sessions
|
|
69
|
+
this.sessions.forEach((session) => {
|
|
70
|
+
if (session.timeout && (new Date().getTime() - session.creation) > session.timeout*60000){
|
|
71
|
+
//stop session => custom timeout
|
|
72
|
+
deletableSessions.push({instance:session,reason:"custom"})
|
|
73
|
+
}else if (!session.timeout && (new Date().getTime() - session.creation) > this.timeoutMinutes*60000){
|
|
74
|
+
//stop session => default timeout
|
|
75
|
+
deletableSessions.push({instance:session,reason:"default"})
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
//permanently delete sessions
|
|
80
|
+
deletableSessions.forEach((session) => {
|
|
81
|
+
const index = this.sessions.findIndex((s) => s.id === session.instance.id)
|
|
82
|
+
this.sessions.splice(index,1)
|
|
83
|
+
|
|
84
|
+
//emit timeout listeners
|
|
85
|
+
this.#timeoutListeners.forEach((cb) => cb(session.instance.id,session.reason,session.instance.data,new Date(session.instance.creation)))
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
},((intervalSeconds) ? (intervalSeconds * 1000) : 60000))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**Create a unique hex id of 8 characters and add it to the instance id history */
|
|
92
|
+
#createUniqueId(): string {
|
|
93
|
+
const hex = crypto.randomBytes(4).toString("hex")
|
|
94
|
+
if (this.#idHistory.includes(hex)){
|
|
95
|
+
return this.#createUniqueId()
|
|
96
|
+
}else{
|
|
97
|
+
this.#idHistory.push(hex)
|
|
98
|
+
if (this.#idHistory.length > this.#maxIdHistoryLength) this.#idHistory.shift()
|
|
99
|
+
return hex
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**Stop the global interval that automatically deletes timed-out sessions. (This action can't be reverted!) */
|
|
103
|
+
stopAutoTimeout(){
|
|
104
|
+
clearInterval(this.#intervalId)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**Start a session instance with data. Returns the unique id required to access the session. */
|
|
108
|
+
start(data?:any): string {
|
|
109
|
+
const id = this.#createUniqueId()
|
|
110
|
+
this.sessions.push({
|
|
111
|
+
id,data,
|
|
112
|
+
creation:new Date().getTime(),
|
|
113
|
+
timeout:null
|
|
114
|
+
})
|
|
115
|
+
return id
|
|
116
|
+
}
|
|
117
|
+
/**Get the data of a session instance. Returns `null` when not found. */
|
|
118
|
+
data(id:string): any|null {
|
|
119
|
+
const session = this.sessions.find((session) => session.id === id)
|
|
120
|
+
if (!session) return null
|
|
121
|
+
return session.data
|
|
122
|
+
}
|
|
123
|
+
/**Stop & delete a session instance. Returns `true` when sucessful. */
|
|
124
|
+
stop(id:string): boolean {
|
|
125
|
+
const index = this.sessions.findIndex((session) => session.id === id)
|
|
126
|
+
if (index < 0) return false
|
|
127
|
+
this.sessions.splice(index,1)
|
|
128
|
+
return true
|
|
129
|
+
}
|
|
130
|
+
/**Update the data of a session instance. Returns `true` when sucessful. */
|
|
131
|
+
update(id:string, data:any): boolean {
|
|
132
|
+
const session = this.sessions.find((session) => session.id === id)
|
|
133
|
+
if (!session) return false
|
|
134
|
+
session.data = data
|
|
135
|
+
return true
|
|
136
|
+
}
|
|
137
|
+
/**Change the global or session timeout minutes. Returns `true` when sucessful. */
|
|
138
|
+
setTimeout(min:number, id?:string): boolean {
|
|
139
|
+
if (!id){
|
|
140
|
+
//change global timeout minutes
|
|
141
|
+
this.timeoutMinutes = min
|
|
142
|
+
return true
|
|
143
|
+
}else{
|
|
144
|
+
//change session instance timeout minutes
|
|
145
|
+
const session = this.sessions.find((session) => session.id === id)
|
|
146
|
+
if (!session) return false
|
|
147
|
+
session.timeout = min
|
|
148
|
+
return true
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**Listen for a session timeout (default or custom) */
|
|
152
|
+
onTimeout(callback:ODSessionTimeoutCallback){
|
|
153
|
+
this.#timeoutListeners.push(callback)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
///////////////////////////////////////
|
|
2
|
+
//STARTSCREEN MODULE
|
|
3
|
+
///////////////////////////////////////
|
|
4
|
+
import { ODId, ODManager, ODManagerData, ODValidId } from "./base"
|
|
5
|
+
import { ODDebugger, ODError, ODLiveStatusManager } from "./console"
|
|
6
|
+
import { ODFlag } from "./flag"
|
|
7
|
+
import { ODPlugin, ODUnknownCrashedPlugin } from "./plugin"
|
|
8
|
+
import ansis from "ansis"
|
|
9
|
+
|
|
10
|
+
/**## ODStartScreenComponentRenderCallback `type`
|
|
11
|
+
* This is the render function of a startscreen component. It also sends the location of where the component is rendered.
|
|
12
|
+
*/
|
|
13
|
+
export type ODStartScreenComponentRenderCallback = (location:number) => string|Promise<string>
|
|
14
|
+
|
|
15
|
+
/**## ODStartScreenManager `class`
|
|
16
|
+
* This is an Open Discord startscreen manager.
|
|
17
|
+
*
|
|
18
|
+
* This class is responsible for managing & rendering the startscreen of the bot.
|
|
19
|
+
* The startscreen is the part you see when the bot has started up successfully. (e.g. the Open Discord logo, logs, livestatus, flags, ...)
|
|
20
|
+
*/
|
|
21
|
+
export class ODStartScreenManager extends ODManager<ODStartScreenComponent> {
|
|
22
|
+
/**Alias to the Open Discord debugger. */
|
|
23
|
+
#debug: ODDebugger
|
|
24
|
+
/**Alias to the livestatus manager. */
|
|
25
|
+
livestatus: ODLiveStatusManager
|
|
26
|
+
|
|
27
|
+
constructor(debug:ODDebugger,livestatus:ODLiveStatusManager){
|
|
28
|
+
super(debug,"startscreen component")
|
|
29
|
+
this.#debug = debug
|
|
30
|
+
this.livestatus = livestatus
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**Get all components in sorted order. */
|
|
34
|
+
getSortedComponents(priority:"ascending"|"descending"){
|
|
35
|
+
return this.getAll().sort((a,b) => {
|
|
36
|
+
if (priority == "ascending") return a.priority-b.priority
|
|
37
|
+
else return b.priority-a.priority
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
/**Render all startscreen components in priority order. */
|
|
41
|
+
async renderAllComponents(){
|
|
42
|
+
const components = this.getSortedComponents("descending")
|
|
43
|
+
|
|
44
|
+
let location = 0
|
|
45
|
+
for (const component of components){
|
|
46
|
+
try {
|
|
47
|
+
const renderedText = await component.renderAll(location)
|
|
48
|
+
console.log(renderedText)
|
|
49
|
+
this.#debug.console.debugfile.writeText("[STARTSCREEN] Component: \""+component.id+"\"\n"+ansis.strip(renderedText))
|
|
50
|
+
}catch(e){
|
|
51
|
+
this.#debug.console.log("Unable to render \""+component.id+"\" startscreen component!","error")
|
|
52
|
+
this.#debug.console.debugfile.writeErrorMessage(new ODError(e,"uncaughtException"))
|
|
53
|
+
}
|
|
54
|
+
location++
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**## ODStartScreenComponent `class`
|
|
60
|
+
* This is an Open Discord startscreen component.
|
|
61
|
+
*
|
|
62
|
+
* This component can be rendered to the start screen of the bot.
|
|
63
|
+
* An optional priority can be specified to choose the location of the component.
|
|
64
|
+
*
|
|
65
|
+
* It's recommended to use pre-built components except if you really need a custom one.
|
|
66
|
+
*/
|
|
67
|
+
export class ODStartScreenComponent extends ODManagerData {
|
|
68
|
+
/**The priority of this component. */
|
|
69
|
+
priority: number
|
|
70
|
+
/**An optional render function which will be inserted before the default renderer. */
|
|
71
|
+
renderBefore: ODStartScreenComponentRenderCallback|null = null
|
|
72
|
+
/**The render function which will render the contents of this component. */
|
|
73
|
+
render: ODStartScreenComponentRenderCallback
|
|
74
|
+
/**An optional render function which will be inserted behind the default renderer. */
|
|
75
|
+
renderAfter: ODStartScreenComponentRenderCallback|null = null
|
|
76
|
+
|
|
77
|
+
constructor(id:ODValidId, priority:number, render:ODStartScreenComponentRenderCallback){
|
|
78
|
+
super(id)
|
|
79
|
+
this.priority = priority
|
|
80
|
+
this.render = render
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**Render this component and combine it with the `renderBefore` & `renderAfter` contents. */
|
|
84
|
+
async renderAll(location:number){
|
|
85
|
+
const textBefore = (this.renderBefore) ? await this.renderBefore(location) : ""
|
|
86
|
+
const text = await this.render(location)
|
|
87
|
+
const textAfter = (this.renderAfter) ? await this.renderAfter(location) : ""
|
|
88
|
+
return (textBefore ? textBefore+"\n" : "")+text+(textAfter ? "\n"+textAfter : "")
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**## ODStartScreenProperty `type`
|
|
93
|
+
* This interface contains properties used in a few default templates of the startscreen component.
|
|
94
|
+
*/
|
|
95
|
+
export interface ODStartScreenProperty {
|
|
96
|
+
/**The key or name of this property. */
|
|
97
|
+
key:string,
|
|
98
|
+
/**The value or contents of this property. */
|
|
99
|
+
value:string
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**## ODStartScreenLogoComponent `class`
|
|
103
|
+
* This is an Open Discord startscreen logo component.
|
|
104
|
+
*
|
|
105
|
+
* This component will render an ASCII art logo (from an array) to the startscreen. Every property in the array is another row.
|
|
106
|
+
* An optional priority can be specified to choose the location of the component.
|
|
107
|
+
*/
|
|
108
|
+
export class ODStartScreenLogoComponent extends ODStartScreenComponent {
|
|
109
|
+
/**The ASCII logo contents. */
|
|
110
|
+
logo: string[]
|
|
111
|
+
/**When enabled, the component will add a new line above the logo. */
|
|
112
|
+
topPadding: boolean
|
|
113
|
+
/**When enabled, the component will add a new line below the logo. */
|
|
114
|
+
bottomPadding: boolean
|
|
115
|
+
/**The color of the logo in hex format. */
|
|
116
|
+
logoHexColor: string
|
|
117
|
+
|
|
118
|
+
constructor(id:ODValidId, priority:number, logo:string[], topPadding?:boolean, bottomPadding?:boolean, logoHexColor?:string){
|
|
119
|
+
super(id,priority,() => {
|
|
120
|
+
const renderedTop = (this.topPadding ? "\n" : "")
|
|
121
|
+
const renderedLogo = this.logo.join("\n")
|
|
122
|
+
const renderedBottom = (this.bottomPadding ? "\n" : "")
|
|
123
|
+
return ansis.hex(this.logoHexColor)(renderedTop+renderedLogo+renderedBottom)
|
|
124
|
+
})
|
|
125
|
+
this.logo = logo
|
|
126
|
+
this.topPadding = topPadding ?? false
|
|
127
|
+
this.bottomPadding = bottomPadding ?? false
|
|
128
|
+
this.logoHexColor = logoHexColor ?? "#f8ba00"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**## ODStartScreenHeaderAlignmentSettings `type`
|
|
133
|
+
* This interface contains all settings used in the startscreen header component.
|
|
134
|
+
*/
|
|
135
|
+
export interface ODStartScreenHeaderAlignmentSettings {
|
|
136
|
+
/**The alignment settings for this header. */
|
|
137
|
+
align:"center"|"left"|"right",
|
|
138
|
+
/**The width or component to use when calculating center & right alignment. */
|
|
139
|
+
width:number|ODStartScreenComponent
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**## ODStartScreenHeaderComponent `class`
|
|
143
|
+
* This is an Open Discord startscreen header component.
|
|
144
|
+
*
|
|
145
|
+
* This component will render a header to the startscreen. Properties can be aligned left, right or centered.
|
|
146
|
+
* An optional priority can be specified to choose the location of the component.
|
|
147
|
+
*/
|
|
148
|
+
export class ODStartScreenHeaderComponent extends ODStartScreenComponent {
|
|
149
|
+
/**All properties of this header component. */
|
|
150
|
+
properties: ODStartScreenProperty[]
|
|
151
|
+
/**The spacer used between properties. */
|
|
152
|
+
spacer: string
|
|
153
|
+
/**The alignment settings of this header component. */
|
|
154
|
+
align: ODStartScreenHeaderAlignmentSettings|null
|
|
155
|
+
|
|
156
|
+
constructor(id:ODValidId, priority:number, properties:ODStartScreenProperty[], spacer?:string, align?:ODStartScreenHeaderAlignmentSettings){
|
|
157
|
+
super(id,priority,async () => {
|
|
158
|
+
const renderedProperties = ansis.bold(this.properties.map((prop) => prop.key+": "+prop.value).join(this.spacer))
|
|
159
|
+
if (!this.align || this.align.align == "left"){
|
|
160
|
+
return renderedProperties
|
|
161
|
+
}else if (this.align.align == "right"){
|
|
162
|
+
const width = (typeof this.align.width == "number") ? this.align.width : (
|
|
163
|
+
ansis.strip(await this.align.width.renderAll(0)).split("\n").map((row) => row.length).reduce((prev,curr) => {
|
|
164
|
+
if (prev < curr) return curr
|
|
165
|
+
else return prev
|
|
166
|
+
},0)
|
|
167
|
+
)
|
|
168
|
+
const offset = width - ansis.strip(renderedProperties).length
|
|
169
|
+
if (offset < 0) return renderedProperties
|
|
170
|
+
else{
|
|
171
|
+
return (" ".repeat(offset) + renderedProperties)
|
|
172
|
+
}
|
|
173
|
+
}else if (this.align.align == "center"){
|
|
174
|
+
const width = (typeof this.align.width == "number") ? this.align.width : (
|
|
175
|
+
ansis.strip(await this.align.width.renderAll(0)).split("\n").map((row) => row.length).reduce((prev,curr) => {
|
|
176
|
+
if (prev < curr) return curr
|
|
177
|
+
else return prev
|
|
178
|
+
})
|
|
179
|
+
)
|
|
180
|
+
const offset = Math.round((width - ansis.strip(renderedProperties).length)/2)
|
|
181
|
+
if (offset < 0) return renderedProperties
|
|
182
|
+
else{
|
|
183
|
+
return (" ".repeat(offset) + renderedProperties)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return renderedProperties
|
|
187
|
+
})
|
|
188
|
+
this.properties = properties
|
|
189
|
+
this.spacer = spacer ?? " - "
|
|
190
|
+
this.align = align ?? null
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**## ODStartScreenCategoryComponent `class`
|
|
195
|
+
* This is an Open Discord startscreen category component.
|
|
196
|
+
*
|
|
197
|
+
* This component will render a category to the startscreen. This will only render the category name. You'll need to provide your own renderer for the contents.
|
|
198
|
+
* An optional priority can be specified to choose the location of the component.
|
|
199
|
+
*/
|
|
200
|
+
export class ODStartScreenCategoryComponent extends ODStartScreenComponent {
|
|
201
|
+
/**The name of this category. */
|
|
202
|
+
name: string
|
|
203
|
+
/**When enabled, this category will still be rendered when the contents are empty. (enabled by default) */
|
|
204
|
+
renderIfEmpty: boolean
|
|
205
|
+
|
|
206
|
+
constructor(id:ODValidId, priority:number, name:string, render:ODStartScreenComponentRenderCallback, renderIfEmpty?:boolean){
|
|
207
|
+
super(id,priority,async (location) => {
|
|
208
|
+
const contents = await render(location)
|
|
209
|
+
if (contents != "" || this.renderIfEmpty){
|
|
210
|
+
return ansis.bold.underline("\n"+name.toUpperCase()+(contents != "" ? ":\n" : ":")) + contents
|
|
211
|
+
}else return ""
|
|
212
|
+
})
|
|
213
|
+
this.name = name
|
|
214
|
+
this.renderIfEmpty = renderIfEmpty ?? true
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**## ODStartScreenPropertiesCategoryComponent `class`
|
|
219
|
+
* This is an Open Discord startscreen properties category component.
|
|
220
|
+
*
|
|
221
|
+
* This component will render a properties category to the startscreen. This will list the properties in the category.
|
|
222
|
+
* An optional priority can be specified to choose the location of the component.
|
|
223
|
+
*/
|
|
224
|
+
export class ODStartScreenPropertiesCategoryComponent extends ODStartScreenCategoryComponent {
|
|
225
|
+
/**The properties of this category component. */
|
|
226
|
+
properties: ODStartScreenProperty[]
|
|
227
|
+
/**The hex color for the key/name of all the properties. */
|
|
228
|
+
propertyHexColor: string
|
|
229
|
+
|
|
230
|
+
constructor(id:ODValidId, priority:number, name:string, properties:ODStartScreenProperty[], propertyHexColor?:string, renderIfEmpty?:boolean){
|
|
231
|
+
super(id,priority,name,() => {
|
|
232
|
+
return this.properties.map((prop) => ansis.hex(this.propertyHexColor)(prop.key+": ")+prop.value).join("\n")
|
|
233
|
+
},renderIfEmpty)
|
|
234
|
+
|
|
235
|
+
this.properties = properties
|
|
236
|
+
this.propertyHexColor = propertyHexColor ?? "#f8ba00"
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**## ODStartScreenFlagsCategoryComponent `class`
|
|
241
|
+
* This is an Open Discord startscreen flags category component.
|
|
242
|
+
*
|
|
243
|
+
* This component will render a flags category to the startscreen. This will list the enabled flags in the category.
|
|
244
|
+
* An optional priority can be specified to choose the location of the component.
|
|
245
|
+
*/
|
|
246
|
+
export class ODStartScreenFlagsCategoryComponent extends ODStartScreenCategoryComponent {
|
|
247
|
+
/**A list of all flags to render. */
|
|
248
|
+
flags: ODFlag[]
|
|
249
|
+
|
|
250
|
+
constructor(id:ODValidId, priority:number, flags:ODFlag[]){
|
|
251
|
+
super(id,priority,"flags",() => {
|
|
252
|
+
return this.flags.filter((flag) => (flag.value == true)).map((flag) => ansis.blue("["+flag.name+"] "+flag.description)).join("\n")
|
|
253
|
+
},false)
|
|
254
|
+
this.flags = flags
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**## ODStartScreenPluginsCategoryComponent `class`
|
|
259
|
+
* This is an Open Discord startscreen plugins category component.
|
|
260
|
+
*
|
|
261
|
+
* This component will render a plugins category to the startscreen. This will list the enabled, disabled & crashed plugins in the category.
|
|
262
|
+
* An optional priority can be specified to choose the location of the component.
|
|
263
|
+
*/
|
|
264
|
+
export class ODStartScreenPluginsCategoryComponent extends ODStartScreenCategoryComponent {
|
|
265
|
+
/**A list of all plugins to render. */
|
|
266
|
+
plugins: ODPlugin[]
|
|
267
|
+
/**A list of all crashed plugins to render. */
|
|
268
|
+
unknownCrashedPlugins: ODUnknownCrashedPlugin[]
|
|
269
|
+
|
|
270
|
+
constructor(id:ODValidId, priority:number, plugins:ODPlugin[], unknownCrashedPlugins:ODUnknownCrashedPlugin[]){
|
|
271
|
+
super(id,priority,"plugins",() => {
|
|
272
|
+
const disabledPlugins = this.plugins.filter((plugin) => !plugin.enabled)
|
|
273
|
+
|
|
274
|
+
const renderedActivePlugins = this.plugins.filter((plugin) => plugin.enabled && plugin.executed).sort((a,b) => b.priority-a.priority).map((plugin) => ansis.green("✅ ["+plugin.name+"] "+plugin.details.shortDescription))
|
|
275
|
+
const renderedCrashedPlugins = this.plugins.filter((plugin) => plugin.enabled && plugin.crashed).sort((a,b) => b.priority-a.priority).map((plugin) => ansis.red("❌ ["+plugin.name+"] "+plugin.details.shortDescription))
|
|
276
|
+
const renderedDisabledPlugins = (disabledPlugins.length > 4) ? [ansis.gray("💤 (+"+disabledPlugins.length+" disabled plugins)")] : disabledPlugins.sort((a,b) => b.priority-a.priority).map((plugin) => ansis.gray("💤 ["+plugin.name+"] "+plugin.details.shortDescription))
|
|
277
|
+
const renderedUnknownPlugins = unknownCrashedPlugins.map((plugin) => ansis.red("❌ ["+plugin.name+"] "+plugin.description))
|
|
278
|
+
|
|
279
|
+
return [
|
|
280
|
+
...renderedActivePlugins,
|
|
281
|
+
...renderedDisabledPlugins,
|
|
282
|
+
...renderedCrashedPlugins,
|
|
283
|
+
...renderedUnknownPlugins
|
|
284
|
+
].join("\n")
|
|
285
|
+
},false)
|
|
286
|
+
this.plugins = plugins
|
|
287
|
+
this.unknownCrashedPlugins = unknownCrashedPlugins
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**## ODStartScreenLiveStatusCategoryComponent `class`
|
|
292
|
+
* This is an Open Discord startscreen livestatus category component.
|
|
293
|
+
*
|
|
294
|
+
* This component will render a livestatus category to the startscreen. This will list the livestatus messages in the category.
|
|
295
|
+
* An optional priority can be specified to choose the location of the component.
|
|
296
|
+
*/
|
|
297
|
+
export class ODStartScreenLiveStatusCategoryComponent extends ODStartScreenCategoryComponent {
|
|
298
|
+
/**A reference to the Open Discord livestatus manager. */
|
|
299
|
+
livestatus: ODLiveStatusManager
|
|
300
|
+
|
|
301
|
+
constructor(id:ODValidId, priority:number, livestatus:ODLiveStatusManager){
|
|
302
|
+
super(id,priority,"livestatus",async () => {
|
|
303
|
+
const messages = await this.livestatus.getAllMessages()
|
|
304
|
+
return this.livestatus.renderer.render(messages)
|
|
305
|
+
},false)
|
|
306
|
+
this.livestatus = livestatus
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**## ODStartScreenLogsCategoryComponent `class`
|
|
311
|
+
* This is an Open Discord startscreen logs category component.
|
|
312
|
+
*
|
|
313
|
+
* This component will render a logs category to the startscreen. This will only render the logs category name.
|
|
314
|
+
* An optional priority can be specified to choose the location of the component.
|
|
315
|
+
*/
|
|
316
|
+
export class ODStartScreenLogCategoryComponent extends ODStartScreenCategoryComponent {
|
|
317
|
+
constructor(id:ODValidId, priority:number){
|
|
318
|
+
super(id,priority,"logs",() => "",true)
|
|
319
|
+
}
|
|
320
|
+
}
|