@open-discord-bots/framework 0.1.2 → 0.2.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/README.md +21 -19
- package/dist/api/modules/action.d.ts +26 -4
- package/dist/api/modules/action.js +16 -0
- package/dist/api/modules/base.d.ts +12 -2
- package/dist/api/modules/base.js +11 -1
- package/dist/api/modules/builder.d.ts +117 -21
- package/dist/api/modules/builder.js +72 -0
- package/dist/api/modules/checker.d.ts +111 -15
- package/dist/api/modules/checker.js +201 -9
- package/dist/api/modules/client.d.ts +45 -22
- package/dist/api/modules/client.js +58 -34
- package/dist/api/modules/code.d.ts +11 -1
- package/dist/api/modules/code.js +9 -0
- package/dist/api/modules/config.d.ts +15 -5
- package/dist/api/modules/config.js +9 -0
- package/dist/api/modules/console.d.ts +11 -1
- package/dist/api/modules/console.js +9 -0
- package/dist/api/modules/cooldown.d.ts +11 -1
- package/dist/api/modules/cooldown.js +9 -0
- package/dist/api/modules/database.d.ts +36 -4
- package/dist/api/modules/database.js +9 -17
- package/dist/api/modules/event.d.ts +20 -7
- package/dist/api/modules/event.js +6 -0
- package/dist/api/modules/flag.d.ts +11 -1
- package/dist/api/modules/flag.js +9 -0
- package/dist/api/modules/helpmenu.d.ts +22 -2
- package/dist/api/modules/helpmenu.js +18 -0
- package/dist/api/modules/language.d.ts +15 -1
- package/dist/api/modules/language.js +9 -4
- package/dist/api/modules/permission.d.ts +11 -1
- package/dist/api/modules/permission.js +9 -0
- package/dist/api/modules/plugin.d.ts +23 -3
- package/dist/api/modules/plugin.js +18 -0
- package/dist/api/modules/post.d.ts +11 -1
- package/dist/api/modules/post.js +9 -0
- package/dist/api/modules/progressbar.d.ts +24 -3
- package/dist/api/modules/progressbar.js +19 -0
- package/dist/api/modules/responder.d.ts +105 -21
- package/dist/api/modules/responder.js +54 -0
- package/dist/api/modules/session.d.ts +11 -1
- package/dist/api/modules/session.js +9 -0
- package/dist/api/modules/startscreen.d.ts +17 -7
- package/dist/api/modules/startscreen.js +9 -0
- package/dist/api/modules/stat.d.ts +42 -8
- package/dist/api/modules/stat.js +18 -4
- package/dist/api/modules/verifybar.d.ts +18 -4
- package/dist/api/modules/verifybar.js +9 -0
- package/dist/api/modules/worker.d.ts +7 -1
- package/dist/api/modules/worker.js +9 -0
- package/dist/utilities/index.js +1 -0
- package/package.json +1 -1
- package/src/api/main.ts +10 -10
- package/src/api/modules/action.ts +37 -4
- package/src/api/modules/base.ts +30 -3
- package/src/api/modules/builder.ts +226 -21
- package/src/api/modules/checker.ts +292 -17
- package/src/api/modules/client.ts +129 -43
- package/src/api/modules/code.ts +27 -1
- package/src/api/modules/config.ts +33 -7
- package/src/api/modules/console.ts +27 -1
- package/src/api/modules/cooldown.ts +27 -1
- package/src/api/modules/database.ts +55 -4
- package/src/api/modules/event.ts +35 -7
- package/src/api/modules/flag.ts +27 -1
- package/src/api/modules/helpmenu.ts +55 -2
- package/src/api/modules/language.ts +35 -1
- package/src/api/modules/permission.ts +27 -1
- package/src/api/modules/plugin.ts +55 -3
- package/src/api/modules/post.ts +27 -1
- package/src/api/modules/progressbar.ts +56 -3
- package/src/api/modules/responder.ts +184 -21
- package/src/api/modules/session.ts +27 -1
- package/src/api/modules/startscreen.ts +33 -7
- package/src/api/modules/stat.ts +79 -8
- package/src/api/modules/verifybar.ts +31 -5
- package/src/api/modules/worker.ts +22 -1
- package/src/utilities/index.ts +1 -0
|
@@ -5,6 +5,7 @@ import { ODDiscordIdType, ODId, ODManager, ODManagerData, ODValidId, ODValidJson
|
|
|
5
5
|
import { ODConfig } from "./config"
|
|
6
6
|
import { ODLanguageManager } from "./language"
|
|
7
7
|
import { ODDebugger } from "./console"
|
|
8
|
+
import ansis from "ansis"
|
|
8
9
|
|
|
9
10
|
/**## ODCheckerResult `interface`
|
|
10
11
|
* This interface is the result from a config checker check() function.
|
|
@@ -14,6 +15,11 @@ export interface ODCheckerResult {
|
|
|
14
15
|
messages:ODCheckerMessage[]
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
/**## ODCheckerManagerIdConstraint `type`
|
|
19
|
+
* The constraint/layout for id mappings/interfaces of the `ODCheckerManager` class.
|
|
20
|
+
*/
|
|
21
|
+
export type ODCheckerManagerIdConstraint = Record<string,ODChecker>
|
|
22
|
+
|
|
17
23
|
/**## ODCheckerManager `class`
|
|
18
24
|
* This is an Open Discord checker manager.
|
|
19
25
|
*
|
|
@@ -21,19 +27,25 @@ export interface ODCheckerResult {
|
|
|
21
27
|
*
|
|
22
28
|
* You can use this class to get/add a config checker (`ODChecker`) in your plugin!
|
|
23
29
|
*/
|
|
24
|
-
export class ODCheckerManager
|
|
30
|
+
export class ODCheckerManager<
|
|
31
|
+
IdList extends ODCheckerManagerIdConstraint = ODCheckerManagerIdConstraint,
|
|
32
|
+
FunctionIdList extends ODCheckerFunctionManagerIdConstraint = ODCheckerFunctionManagerIdConstraint,
|
|
33
|
+
Renderer extends ODCheckerRenderer = ODCheckerRenderer,
|
|
34
|
+
TranslationMessageIds extends string = string,
|
|
35
|
+
TranslationOtherIds extends string = string
|
|
36
|
+
> extends ODManager<ODChecker> {
|
|
25
37
|
/**The global temporary storage shared between all config checkers. */
|
|
26
38
|
storage: ODCheckerStorage
|
|
27
39
|
/**The class responsible for rendering the config checker report. */
|
|
28
|
-
renderer:
|
|
40
|
+
renderer: Renderer
|
|
29
41
|
/**The class responsible for translating the config checker report. */
|
|
30
|
-
translation: ODCheckerTranslationRegister
|
|
42
|
+
translation: ODCheckerTranslationRegister<TranslationMessageIds,TranslationOtherIds>
|
|
31
43
|
/**Final functions are global functions executed just before the report is created. */
|
|
32
|
-
functions: ODCheckerFunctionManager
|
|
44
|
+
functions: ODCheckerFunctionManager<FunctionIdList>
|
|
33
45
|
/**A variable containing the last result returned from `checkAll()` */
|
|
34
46
|
lastResult: ODCheckerResult|null = null
|
|
35
47
|
|
|
36
|
-
constructor(debug:ODDebugger, storage:ODCheckerStorage, renderer:
|
|
48
|
+
constructor(debug:ODDebugger, storage:ODCheckerStorage, renderer:Renderer, translation:ODCheckerTranslationRegister<TranslationMessageIds,TranslationOtherIds>, functions:ODCheckerFunctionManager<FunctionIdList>){
|
|
37
49
|
super(debug,"config checker")
|
|
38
50
|
this.storage = storage
|
|
39
51
|
this.renderer = renderer
|
|
@@ -86,6 +98,27 @@ export class ODCheckerManager extends ODManager<ODChecker> {
|
|
|
86
98
|
createTemporaryCheckerEnvironment(){
|
|
87
99
|
return new ODChecker("opendiscord:temporary-environment",new ODCheckerStorage(),0,new ODConfig("opendiscord:temporary-environment",{}),new ODCheckerStructure("opendiscord:temporary-environment",{}))
|
|
88
100
|
}
|
|
101
|
+
|
|
102
|
+
get<CheckerId extends keyof IdList>(id:CheckerId): IdList[CheckerId]
|
|
103
|
+
get(id:ODValidId): ODChecker|null
|
|
104
|
+
|
|
105
|
+
get(id:ODValidId): ODChecker|null {
|
|
106
|
+
return super.get(id)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
remove<CheckerId extends keyof IdList>(id:CheckerId): IdList[CheckerId]
|
|
110
|
+
remove(id:ODValidId): ODChecker|null
|
|
111
|
+
|
|
112
|
+
remove(id:ODValidId): ODChecker|null {
|
|
113
|
+
return super.remove(id)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
exists(id:keyof IdList): boolean
|
|
117
|
+
exists(id:ODValidId): boolean
|
|
118
|
+
|
|
119
|
+
exists(id:ODValidId): boolean {
|
|
120
|
+
return super.exists(id)
|
|
121
|
+
}
|
|
89
122
|
}
|
|
90
123
|
|
|
91
124
|
/**## ODCheckerStorage `class`
|
|
@@ -144,16 +177,16 @@ export class ODCheckerStorage {
|
|
|
144
177
|
* This is an Open Discord checker renderer.
|
|
145
178
|
*
|
|
146
179
|
* It's responsible for rendering the config checker result in the console.
|
|
147
|
-
* This class doesn't provide any components!
|
|
180
|
+
* This class doesn't provide any components! Create new ones by extending this class.
|
|
148
181
|
*
|
|
149
|
-
*
|
|
182
|
+
* Use this class to change the config checker looks!
|
|
150
183
|
*/
|
|
151
184
|
export class ODCheckerRenderer {
|
|
152
|
-
/**Get all components */
|
|
153
|
-
getComponents(compact:boolean, renderEmpty:boolean, translation:ODCheckerTranslationRegister, data:ODCheckerResult): string[] {
|
|
185
|
+
/**Get all config checker render components. These can be combined and rendered to the console. */
|
|
186
|
+
getComponents(compact:boolean, renderEmpty:boolean, translation:ODCheckerTranslationRegister<string,string>, data:ODCheckerResult): string[] {
|
|
154
187
|
return []
|
|
155
188
|
}
|
|
156
|
-
/**Render all components */
|
|
189
|
+
/**Render all config checker render components to the console. */
|
|
157
190
|
render(components:string[]){
|
|
158
191
|
if (components.length < 1) return
|
|
159
192
|
console.log("\n")
|
|
@@ -164,6 +197,213 @@ export class ODCheckerRenderer {
|
|
|
164
197
|
}
|
|
165
198
|
}
|
|
166
199
|
|
|
200
|
+
/**## ODDefaultCheckerRendererTranslations `interface`
|
|
201
|
+
* The required translation sentences for the default checker renderer.
|
|
202
|
+
*/
|
|
203
|
+
export interface ODDefaultCheckerRendererTranslations {
|
|
204
|
+
/**Example: `OPEN DISCORD`*/
|
|
205
|
+
headerProjectName:string,
|
|
206
|
+
/**Example: `CONFIG CHECKER`*/
|
|
207
|
+
headerConfigchecker:string,
|
|
208
|
+
/**Example: `check for errors in your config files!`*/
|
|
209
|
+
headerDescription:string,
|
|
210
|
+
/**Example: `the bot won't start until all {0}'s are fixed!`*/
|
|
211
|
+
footerError:string,
|
|
212
|
+
/**Example: `it's recommended to fix all {0}'s before starting!`*/
|
|
213
|
+
footerWarning:string,
|
|
214
|
+
/**Example: `SUPPORT: {0} - DOCS: {1}`*/
|
|
215
|
+
footerSupport:string,
|
|
216
|
+
/**Example: `[ERROR]`*/
|
|
217
|
+
error:string,
|
|
218
|
+
/**Example: `[WARNING]`*/
|
|
219
|
+
warning:string,
|
|
220
|
+
/**Example: `[INFO]`*/
|
|
221
|
+
info:string,
|
|
222
|
+
/**Example: `use {0} for more information!`*/
|
|
223
|
+
compactInfo:string,
|
|
224
|
+
/**Example: `path`*/
|
|
225
|
+
dataPath:string,
|
|
226
|
+
/**Example: `docs`*/
|
|
227
|
+
dataDocs:string,
|
|
228
|
+
/**Example: `message`*/
|
|
229
|
+
dataMessage:string
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**## ODDefaultCheckerRenderer `class`
|
|
233
|
+
* This is the default render class which renders the config checkers in the console for most Open Discord projects.
|
|
234
|
+
*
|
|
235
|
+
* This class can be found in the global variable `opendiscord.checkers.renderer`!
|
|
236
|
+
*/
|
|
237
|
+
export class ODDefaultCheckerRenderer extends ODCheckerRenderer {
|
|
238
|
+
/**The main color used when rendering the config checker. */
|
|
239
|
+
mainColor: `#${string}`
|
|
240
|
+
/**The url to the discord support server. */
|
|
241
|
+
supportUrl: string
|
|
242
|
+
/**The url to the bot documentation. */
|
|
243
|
+
docsUrl: string
|
|
244
|
+
|
|
245
|
+
/**Add additional header text. */
|
|
246
|
+
extraHeaderText: string[] = []
|
|
247
|
+
/**Add additional footer text. */
|
|
248
|
+
extraFooterText: string[] = []
|
|
249
|
+
/**Add additional top text. */
|
|
250
|
+
extraTopText: string[] = []
|
|
251
|
+
/**Add additional bottom text. */
|
|
252
|
+
extraBottomText: string[] = []
|
|
253
|
+
|
|
254
|
+
/**Set the character used for horizontal lines. */
|
|
255
|
+
horizontalFiller: string = "="
|
|
256
|
+
/**Set the character used for vertical lines. */
|
|
257
|
+
verticalFiller: string = "|"
|
|
258
|
+
/**Set the prefix used for the description. */
|
|
259
|
+
descriptionSeparator: string = " => "
|
|
260
|
+
/**Set the prefix used for the header.. */
|
|
261
|
+
headerSeparator: string = " => "
|
|
262
|
+
/**Set the prefix used for the footer. */
|
|
263
|
+
footerTipPrefix: string = "=> "
|
|
264
|
+
|
|
265
|
+
/**Disable rendering the header. */
|
|
266
|
+
disableHeader: boolean = false
|
|
267
|
+
/**Disable rendering the footer. */
|
|
268
|
+
disableFooter: boolean = false
|
|
269
|
+
|
|
270
|
+
constructor(mainColor:`#${string}`,supportUrl:string,docsUrl:string){
|
|
271
|
+
super()
|
|
272
|
+
this.mainColor = mainColor
|
|
273
|
+
this.supportUrl = supportUrl
|
|
274
|
+
this.docsUrl = docsUrl
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
getComponents(compact:boolean, renderEmpty:boolean, translation:ODCheckerTranslationRegister<string,string>, data:ODCheckerResult): string[] {
|
|
278
|
+
const tm = translation
|
|
279
|
+
const t: ODDefaultCheckerRendererTranslations = {
|
|
280
|
+
headerProjectName:tm.get("other","opendiscord:header-projectname") ?? "OPEN DISCORD",
|
|
281
|
+
headerConfigchecker:tm.get("other","opendiscord:header-configchecker") ?? "CONFIG CHECKER",
|
|
282
|
+
headerDescription:tm.get("other","opendiscord:header-description") ?? "check for errors in your config files!",
|
|
283
|
+
footerError:tm.get("other","opendiscord:footer-error") ?? "the bot won't start until all {0}'s are fixed!",
|
|
284
|
+
footerWarning:tm.get("other","opendiscord:footer-warning") ?? "it's recommended to fix all {0}'s before starting!",
|
|
285
|
+
footerSupport:tm.get("other","opendiscord:footer-support") ?? "SUPPORT: {0} - DOCS: {1}",
|
|
286
|
+
error:tm.get("other","opendiscord:type-error") ?? "[ERROR]",
|
|
287
|
+
warning:tm.get("other","opendiscord:type-warning") ?? "[WARNING]",
|
|
288
|
+
info:tm.get("other","opendiscord:type-info") ?? "[INFO]",
|
|
289
|
+
compactInfo:tm.get("other","opendiscord:compact-information") ?? "use {0} for more information!",
|
|
290
|
+
dataPath:tm.get("other","opendiscord:data-path") ?? "path",
|
|
291
|
+
dataDocs:tm.get("other","opendiscord:data-docs") ?? "docs",
|
|
292
|
+
dataMessage:tm.get("other","opendiscord:data-message") ?? "message"
|
|
293
|
+
}
|
|
294
|
+
const hasErrors = data.messages.filter((m) => m.type == "error").length > 0
|
|
295
|
+
const hasWarnings = data.messages.filter((m) => m.type == "warning").length > 0
|
|
296
|
+
const hasInfo = data.messages.filter((m) => m.type == "info").length > 0
|
|
297
|
+
|
|
298
|
+
if (!renderEmpty && !hasErrors && !hasWarnings && (!hasInfo || compact)) return []
|
|
299
|
+
|
|
300
|
+
const headerText = ansis.bold.hex(this.mainColor)(t.headerProjectName)+" "+t.headerConfigchecker+this.headerSeparator+ansis.hex(this.mainColor)(t.headerDescription)
|
|
301
|
+
const footerErrorText = (hasErrors) ? this.footerTipPrefix+ansis.gray(tm.insertTranslationParams(t.footerError,[ansis.bold.red(t.error)])) : ""
|
|
302
|
+
const footerWarningText = (hasWarnings) ? this.footerTipPrefix+ansis.gray(tm.insertTranslationParams(t.footerWarning,[ansis.bold.yellow(t.warning)])) : ""
|
|
303
|
+
const footerSupportText = tm.insertTranslationParams(t.footerSupport,[ansis.green(this.supportUrl),ansis.green(this.docsUrl)])
|
|
304
|
+
const bottomCompactInfo = (compact) ? ansis.gray(tm.insertTranslationParams(t.compactInfo,[ansis.bold.green("npm start -- --checker")])) : ""
|
|
305
|
+
|
|
306
|
+
const finalHeader = [headerText,...this.extraHeaderText]
|
|
307
|
+
const finalFooter = [footerErrorText,footerWarningText,footerSupportText,...this.extraFooterText]
|
|
308
|
+
const finalTop = [...this.extraTopText]
|
|
309
|
+
const finalBottom = [bottomCompactInfo,...this.extraBottomText]
|
|
310
|
+
const borderLength = this.#getLongestLength([...finalHeader,...finalFooter])
|
|
311
|
+
|
|
312
|
+
const finalComponents: string[] = []
|
|
313
|
+
|
|
314
|
+
//header
|
|
315
|
+
if (!this.disableHeader){
|
|
316
|
+
finalHeader.forEach((text) => {
|
|
317
|
+
if (text.length < 1) return
|
|
318
|
+
finalComponents.push(this.#createBlockFromText(text,borderLength))
|
|
319
|
+
})
|
|
320
|
+
}
|
|
321
|
+
finalComponents.push(this.#getHorizontalDivider(borderLength+4))
|
|
322
|
+
|
|
323
|
+
//top
|
|
324
|
+
finalTop.forEach((text) => {
|
|
325
|
+
if (text.length < 1) return
|
|
326
|
+
finalComponents.push(this.verticalFiller+" "+text)
|
|
327
|
+
})
|
|
328
|
+
finalComponents.push(this.verticalFiller)
|
|
329
|
+
|
|
330
|
+
//messages
|
|
331
|
+
if (compact){
|
|
332
|
+
//use compact messages
|
|
333
|
+
data.messages.forEach((msg,index) => {
|
|
334
|
+
//compact mode doesn't render info
|
|
335
|
+
if (msg.type == "info") return
|
|
336
|
+
|
|
337
|
+
//check if translation available & use it if possible
|
|
338
|
+
const rawTranslation = tm.get("message",msg.messageId.value)
|
|
339
|
+
const translatedMessage = (rawTranslation) ? tm.insertTranslationParams(rawTranslation,msg.translationParams) : msg.message
|
|
340
|
+
|
|
341
|
+
if (msg.type == "error") finalComponents.push(this.verticalFiller+" "+ansis.bold.red(`${t.error} ${translatedMessage}`))
|
|
342
|
+
else if (msg.type == "warning") finalComponents.push(this.verticalFiller+" "+ansis.bold.yellow(`${t.warning} ${translatedMessage}`))
|
|
343
|
+
|
|
344
|
+
const pathSplitter = msg.path ? ":" : ""
|
|
345
|
+
finalComponents.push(this.verticalFiller+ansis.bold(this.descriptionSeparator)+ansis.cyan(`${ansis.magenta(msg.filepath+pathSplitter)} ${msg.path}`))
|
|
346
|
+
if (index != data.messages.length-1) finalComponents.push(this.verticalFiller)
|
|
347
|
+
})
|
|
348
|
+
}else{
|
|
349
|
+
//use full messages
|
|
350
|
+
data.messages.forEach((msg,index) => {
|
|
351
|
+
//check if translation available & use it if possible
|
|
352
|
+
const rawTranslation = tm.get("message",msg.messageId.value)
|
|
353
|
+
const translatedMessage = (rawTranslation) ? tm.insertTranslationParams(rawTranslation,msg.translationParams) : msg.message
|
|
354
|
+
|
|
355
|
+
if (msg.type == "error") finalComponents.push(this.verticalFiller+" "+ansis.bold.red(`${t.error} ${translatedMessage}`))
|
|
356
|
+
else if (msg.type == "warning") finalComponents.push(this.verticalFiller+" "+ansis.bold.yellow(`${t.warning} ${translatedMessage}`))
|
|
357
|
+
else if (msg.type == "info") finalComponents.push(this.verticalFiller+" "+ansis.bold.blue(`${t.info} ${translatedMessage}`))
|
|
358
|
+
|
|
359
|
+
const pathSplitter = msg.path ? ":" : ""
|
|
360
|
+
finalComponents.push(this.verticalFiller+" "+ansis.bold((t.dataPath)+this.descriptionSeparator)+ansis.cyan(`${ansis.magenta(msg.filepath+pathSplitter)} ${msg.path}`))
|
|
361
|
+
if (msg.locationDocs) finalComponents.push(this.verticalFiller+" "+ansis.bold(t.dataDocs+this.descriptionSeparator)+ansis.italic.gray(msg.locationDocs))
|
|
362
|
+
if (msg.messageDocs) finalComponents.push(this.verticalFiller+" "+ansis.bold(t.dataMessage+this.descriptionSeparator)+ansis.italic.gray(msg.messageDocs))
|
|
363
|
+
if (index != data.messages.length-1) finalComponents.push(this.verticalFiller)
|
|
364
|
+
})
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
//bottom
|
|
368
|
+
finalComponents.push(this.verticalFiller)
|
|
369
|
+
finalBottom.forEach((text) => {
|
|
370
|
+
if (text.length < 1) return
|
|
371
|
+
finalComponents.push(this.verticalFiller+" "+text)
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
//footer
|
|
375
|
+
finalComponents.push(this.#getHorizontalDivider(borderLength+4))
|
|
376
|
+
if (!this.disableFooter){
|
|
377
|
+
finalFooter.forEach((text) => {
|
|
378
|
+
if (text.length < 1) return
|
|
379
|
+
finalComponents.push(this.#createBlockFromText(text,borderLength))
|
|
380
|
+
})
|
|
381
|
+
finalComponents.push(this.#getHorizontalDivider(borderLength+4))
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
//return all components
|
|
385
|
+
return finalComponents
|
|
386
|
+
}
|
|
387
|
+
/**Get the length of the longest string in the array. */
|
|
388
|
+
#getLongestLength(texts:string[]): number {
|
|
389
|
+
return Math.max(...texts.map((t) => ansis.strip(t).length))
|
|
390
|
+
}
|
|
391
|
+
/**Get a horizontal divider used between different parts of the config checker result. */
|
|
392
|
+
#getHorizontalDivider(width:number): string {
|
|
393
|
+
if (width > 2) width = width-2
|
|
394
|
+
else return this.verticalFiller+this.verticalFiller
|
|
395
|
+
let divider = this.verticalFiller + this.horizontalFiller.repeat(width) + this.verticalFiller
|
|
396
|
+
return divider
|
|
397
|
+
}
|
|
398
|
+
/**Create a block of text with a vertical divider on the left & right side. */
|
|
399
|
+
#createBlockFromText(text:string,width:number): string {
|
|
400
|
+
if (width < 3) return this.verticalFiller+this.verticalFiller
|
|
401
|
+
let newWidth = width-ansis.strip(text).length+1
|
|
402
|
+
let final = this.verticalFiller+" "+text+" ".repeat(newWidth)+this.verticalFiller
|
|
403
|
+
return final
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
167
407
|
/**## ODCheckerTranslationRegister `class`
|
|
168
408
|
* This is an Open Discord checker translation register.
|
|
169
409
|
*
|
|
@@ -172,16 +412,22 @@ export class ODCheckerRenderer {
|
|
|
172
412
|
*
|
|
173
413
|
* You can use this class if you want to translate your config checker messages! **This is optional & isn't required for the checker to work!**
|
|
174
414
|
*/
|
|
175
|
-
export class ODCheckerTranslationRegister {
|
|
415
|
+
export class ODCheckerTranslationRegister<MessageIds extends string = string, OtherIds extends string = string> {
|
|
176
416
|
/**This is the array that stores all the data. ❌ **(don't edit unless really needed!)***/
|
|
177
417
|
#translations: {type:"message"|"other", id:string, translation:string}[] = []
|
|
178
418
|
|
|
179
419
|
/**Get the translation from a config checker message/sentence */
|
|
420
|
+
get(type:"other", id:OtherIds): string
|
|
421
|
+
get(type:"message", id:MessageIds): string
|
|
422
|
+
get(type:"message"|"other", id:string): string|null
|
|
180
423
|
get(type:"message"|"other", id:string): string|null {
|
|
181
424
|
const result = this.#translations.find(d => (d.id == id) && (d.type == type))
|
|
182
425
|
return (result) ? result.translation : null
|
|
183
426
|
}
|
|
184
427
|
/**Set the translation for a config checker message/sentence. This function also overwrites existing translations!*/
|
|
428
|
+
set(type:"other", id:OtherIds, translation:string): boolean
|
|
429
|
+
set(type:"message", id:MessageIds, translation:string): boolean
|
|
430
|
+
set(type:"message"|"other", id:string, translation:string): boolean
|
|
185
431
|
set(type:"message"|"other", id:string, translation:string){
|
|
186
432
|
const index = this.#translations.findIndex(d => (d.id == id) && (d.type == type))
|
|
187
433
|
if (index > -1){
|
|
@@ -194,6 +440,9 @@ export class ODCheckerTranslationRegister {
|
|
|
194
440
|
}
|
|
195
441
|
}
|
|
196
442
|
/**Delete the translation for a config checker message/sentence. */
|
|
443
|
+
delete(type:"other", id:OtherIds): boolean
|
|
444
|
+
delete(type:"message", id:MessageIds): boolean
|
|
445
|
+
delete(type:"message"|"other", id:string): boolean
|
|
197
446
|
delete(type:"message"|"other", id:string){
|
|
198
447
|
const index = this.#translations.findIndex(d => (d.id == id) && (d.type == type))
|
|
199
448
|
if (index > -1){
|
|
@@ -202,12 +451,10 @@ export class ODCheckerTranslationRegister {
|
|
|
202
451
|
return true
|
|
203
452
|
}else return false
|
|
204
453
|
}
|
|
205
|
-
|
|
206
454
|
/**Get all translations */
|
|
207
455
|
getAll(){
|
|
208
456
|
return this.#translations
|
|
209
457
|
}
|
|
210
|
-
|
|
211
458
|
/**Insert the translation params into the text. */
|
|
212
459
|
insertTranslationParams(text:string, translationParams:string[]){
|
|
213
460
|
translationParams.forEach((value,index) => {
|
|
@@ -216,6 +463,8 @@ export class ODCheckerTranslationRegister {
|
|
|
216
463
|
return text
|
|
217
464
|
}
|
|
218
465
|
/**A shortcut to copy translations from the `ODLanguageManager` to `ODCheckerTranslationRegister` */
|
|
466
|
+
quickTranslate(manager:ODLanguageManager, translationId:string, type:"other"|"message", id:OtherIds|MessageIds): void
|
|
467
|
+
quickTranslate(manager:ODLanguageManager, translationId:string, type:"other"|"message", id:string): void
|
|
219
468
|
quickTranslate(manager:ODLanguageManager, translationId:string, type:"other"|"message", id:string){
|
|
220
469
|
const translation = manager.getTranslation(translationId)
|
|
221
470
|
if (translation) this.set(type,id,translation)
|
|
@@ -225,7 +474,7 @@ export class ODCheckerTranslationRegister {
|
|
|
225
474
|
/**## ODCheckerFunctionCallback `type`
|
|
226
475
|
* This is the function used in the `ODCheckerFunction` class.
|
|
227
476
|
*/
|
|
228
|
-
export type ODCheckerFunctionCallback = (manager:ODCheckerManager, functions:ODCheckerFunctionManager) => ODCheckerResult
|
|
477
|
+
export type ODCheckerFunctionCallback = (manager:ODCheckerManager<ODCheckerManagerIdConstraint,ODCheckerFunctionManagerIdConstraint,ODCheckerRenderer,string,string>, functions:ODCheckerFunctionManager<ODCheckerFunctionManagerIdConstraint>) => ODCheckerResult
|
|
229
478
|
|
|
230
479
|
/**## ODCheckerFunction `class`
|
|
231
480
|
* This is an Open Discord config checker function.
|
|
@@ -243,12 +492,17 @@ export class ODCheckerFunction extends ODManagerData {
|
|
|
243
492
|
}
|
|
244
493
|
}
|
|
245
494
|
|
|
495
|
+
/**## ODCheckerFunctionManagerIdConstraint `type`
|
|
496
|
+
* The constraint/layout for id mappings/interfaces of the `ODCheckerFunctionManager` class.
|
|
497
|
+
*/
|
|
498
|
+
export type ODCheckerFunctionManagerIdConstraint = Record<string,ODCheckerFunction>
|
|
499
|
+
|
|
246
500
|
/**## ODCheckerFunctionManager `class`
|
|
247
501
|
* This is an Open Discord config checker function manager.
|
|
248
502
|
*
|
|
249
503
|
* It manages all `ODCheckerFunction`'s and it has some extra shortcuts for frequently used methods.
|
|
250
504
|
*/
|
|
251
|
-
export class ODCheckerFunctionManager extends ODManager<ODCheckerFunction> {
|
|
505
|
+
export class ODCheckerFunctionManager<IdList extends ODCheckerFunctionManagerIdConstraint = ODCheckerFunctionManagerIdConstraint> extends ODManager<ODCheckerFunction> {
|
|
252
506
|
constructor(debug:ODDebugger){
|
|
253
507
|
super(debug,"config checker function")
|
|
254
508
|
}
|
|
@@ -285,6 +539,27 @@ export class ODCheckerFunctionManager extends ODManager<ODCheckerFunction> {
|
|
|
285
539
|
locationTraceDeref(trace:ODCheckerLocationTrace): ODCheckerLocationTrace {
|
|
286
540
|
return JSON.parse(JSON.stringify(trace))
|
|
287
541
|
}
|
|
542
|
+
|
|
543
|
+
get<CheckerFunctionId extends keyof IdList>(id:CheckerFunctionId): IdList[CheckerFunctionId]
|
|
544
|
+
get(id:ODValidId): ODCheckerFunction|null
|
|
545
|
+
|
|
546
|
+
get(id:ODValidId): ODCheckerFunction|null {
|
|
547
|
+
return super.get(id)
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
remove<CheckerFunctionId extends keyof IdList>(id:CheckerFunctionId): IdList[CheckerFunctionId]
|
|
551
|
+
remove(id:ODValidId): ODCheckerFunction|null
|
|
552
|
+
|
|
553
|
+
remove(id:ODValidId): ODCheckerFunction|null {
|
|
554
|
+
return super.remove(id)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
exists(id:keyof IdList): boolean
|
|
558
|
+
exists(id:ODValidId): boolean
|
|
559
|
+
|
|
560
|
+
exists(id:ODValidId): boolean {
|
|
561
|
+
return super.exists(id)
|
|
562
|
+
}
|
|
288
563
|
}
|
|
289
564
|
|
|
290
565
|
/**## ODCheckerLocationTrace `type`
|
|
@@ -317,7 +592,7 @@ export class ODChecker extends ODManagerData {
|
|
|
317
592
|
/**The higher the priority, the faster it gets checked! */
|
|
318
593
|
priority: number
|
|
319
594
|
/**The config file that needs to be checked */
|
|
320
|
-
config: ODConfig
|
|
595
|
+
config: ODConfig<any>
|
|
321
596
|
/**The structure of the config file */
|
|
322
597
|
structure: ODCheckerStructure
|
|
323
598
|
/**Temporary storage for all error messages from the check() method (not recommended to use) */
|
|
@@ -327,7 +602,7 @@ export class ODChecker extends ODManagerData {
|
|
|
327
602
|
/**All additional properties of this config checker. */
|
|
328
603
|
options: ODCheckerOptions
|
|
329
604
|
|
|
330
|
-
constructor(id:ODValidId, storage: ODCheckerStorage, priority:number, config:ODConfig
|
|
605
|
+
constructor(id:ODValidId, storage: ODCheckerStorage, priority:number, config:ODConfig<any>, structure:ODCheckerStructure, options?:ODCheckerOptions){
|
|
331
606
|
super(id)
|
|
332
607
|
this.storage = storage
|
|
333
608
|
this.priority = priority
|