@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
|
@@ -306,7 +306,7 @@ export class ODDefaultCheckerRenderer extends ODCheckerRenderer {
|
|
|
306
306
|
const finalFooter = [footerErrorText,footerWarningText,footerSupportText,...this.extraFooterText]
|
|
307
307
|
const finalTop = [...this.extraTopText]
|
|
308
308
|
const finalBottom = [bottomCompactInfo,...this.extraBottomText]
|
|
309
|
-
const borderLength = this
|
|
309
|
+
const borderLength = this.getLongestLength([...finalHeader,...finalFooter])
|
|
310
310
|
|
|
311
311
|
const finalComponents: string[] = []
|
|
312
312
|
|
|
@@ -314,10 +314,10 @@ export class ODDefaultCheckerRenderer extends ODCheckerRenderer {
|
|
|
314
314
|
if (!this.disableHeader){
|
|
315
315
|
finalHeader.forEach((text) => {
|
|
316
316
|
if (text.length < 1) return
|
|
317
|
-
finalComponents.push(this
|
|
317
|
+
finalComponents.push(this.createBlockFromText(text,borderLength))
|
|
318
318
|
})
|
|
319
319
|
}
|
|
320
|
-
finalComponents.push(this
|
|
320
|
+
finalComponents.push(this.getHorizontalDivider(borderLength+4))
|
|
321
321
|
|
|
322
322
|
//top
|
|
323
323
|
finalTop.forEach((text) => {
|
|
@@ -371,31 +371,31 @@ export class ODDefaultCheckerRenderer extends ODCheckerRenderer {
|
|
|
371
371
|
})
|
|
372
372
|
|
|
373
373
|
//footer
|
|
374
|
-
finalComponents.push(this
|
|
374
|
+
finalComponents.push(this.getHorizontalDivider(borderLength+4))
|
|
375
375
|
if (!this.disableFooter){
|
|
376
376
|
finalFooter.forEach((text) => {
|
|
377
377
|
if (text.length < 1) return
|
|
378
|
-
finalComponents.push(this
|
|
378
|
+
finalComponents.push(this.createBlockFromText(text,borderLength))
|
|
379
379
|
})
|
|
380
|
-
finalComponents.push(this
|
|
380
|
+
finalComponents.push(this.getHorizontalDivider(borderLength+4))
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
//return all components
|
|
384
384
|
return finalComponents
|
|
385
385
|
}
|
|
386
386
|
/**Get the length of the longest string in the array. */
|
|
387
|
-
|
|
387
|
+
private getLongestLength(texts:string[]): number {
|
|
388
388
|
return Math.max(...texts.map((t) => ansis.strip(t).length))
|
|
389
389
|
}
|
|
390
390
|
/**Get a horizontal divider used between different parts of the config checker result. */
|
|
391
|
-
|
|
391
|
+
private getHorizontalDivider(width:number): string {
|
|
392
392
|
if (width > 2) width = width-2
|
|
393
393
|
else return this.verticalFiller+this.verticalFiller
|
|
394
394
|
let divider = this.verticalFiller + this.horizontalFiller.repeat(width) + this.verticalFiller
|
|
395
395
|
return divider
|
|
396
396
|
}
|
|
397
397
|
/**Create a block of text with a vertical divider on the left & right side. */
|
|
398
|
-
|
|
398
|
+
private createBlockFromText(text:string,width:number): string {
|
|
399
399
|
if (width < 3) return this.verticalFiller+this.verticalFiller
|
|
400
400
|
let newWidth = width-ansis.strip(text).length+1
|
|
401
401
|
let final = this.verticalFiller+" "+text+" ".repeat(newWidth)+this.verticalFiller
|
|
@@ -413,14 +413,14 @@ export class ODDefaultCheckerRenderer extends ODCheckerRenderer {
|
|
|
413
413
|
*/
|
|
414
414
|
export class ODCheckerTranslationRegister<MessageIds extends string = string, OtherIds extends string = string> {
|
|
415
415
|
/**This is the array that stores all the data. ❌ **(don't edit unless really needed!)***/
|
|
416
|
-
|
|
416
|
+
protected translations: {type:"message"|"other", id:string, translation:string}[] = []
|
|
417
417
|
|
|
418
418
|
/**Get the translation from a config checker message/sentence */
|
|
419
419
|
get(type:"other", id:OtherIds): string
|
|
420
420
|
get(type:"message", id:MessageIds): string
|
|
421
421
|
get(type:"message"|"other", id:string): string|null
|
|
422
422
|
get(type:"message"|"other", id:string): string|null {
|
|
423
|
-
const result = this
|
|
423
|
+
const result = this.translations.find(d => (d.id == id) && (d.type == type))
|
|
424
424
|
return (result) ? result.translation : null
|
|
425
425
|
}
|
|
426
426
|
/**Set the translation for a config checker message/sentence. This function also overwrites existing translations!*/
|
|
@@ -428,13 +428,13 @@ export class ODCheckerTranslationRegister<MessageIds extends string = string, Ot
|
|
|
428
428
|
set(type:"message", id:MessageIds, translation:string): boolean
|
|
429
429
|
set(type:"message"|"other", id:string, translation:string): boolean
|
|
430
430
|
set(type:"message"|"other", id:string, translation:string){
|
|
431
|
-
const index = this
|
|
431
|
+
const index = this.translations.findIndex(d => (d.id == id) && (d.type == type))
|
|
432
432
|
if (index > -1){
|
|
433
433
|
//overwrite
|
|
434
|
-
this
|
|
434
|
+
this.translations[index] = {type,id,translation}
|
|
435
435
|
return true
|
|
436
436
|
}else{
|
|
437
|
-
this
|
|
437
|
+
this.translations.push({type,id,translation})
|
|
438
438
|
return false
|
|
439
439
|
}
|
|
440
440
|
}
|
|
@@ -443,16 +443,16 @@ export class ODCheckerTranslationRegister<MessageIds extends string = string, Ot
|
|
|
443
443
|
delete(type:"message", id:MessageIds): boolean
|
|
444
444
|
delete(type:"message"|"other", id:string): boolean
|
|
445
445
|
delete(type:"message"|"other", id:string){
|
|
446
|
-
const index = this
|
|
446
|
+
const index = this.translations.findIndex(d => (d.id == id) && (d.type == type))
|
|
447
447
|
if (index > -1){
|
|
448
448
|
//delete
|
|
449
|
-
this
|
|
449
|
+
this.translations.splice(index,1)
|
|
450
450
|
return true
|
|
451
451
|
}else return false
|
|
452
452
|
}
|
|
453
453
|
/**Get all translations */
|
|
454
454
|
getAll(){
|
|
455
|
-
return this
|
|
455
|
+
return this.translations
|
|
456
456
|
}
|
|
457
457
|
/**Insert the translation params into the text. */
|
|
458
458
|
insertTranslationParams(text:string, translationParams:string[]){
|
|
@@ -611,7 +611,7 @@ export class ODChecker extends ODManagerData {
|
|
|
611
611
|
}
|
|
612
612
|
|
|
613
613
|
/**Get a human-readable number string. */
|
|
614
|
-
|
|
614
|
+
protected ordinalNumber(num:number){
|
|
615
615
|
const i = Math.abs(Math.round(num))
|
|
616
616
|
const cent = i % 100
|
|
617
617
|
if (cent >= 10 && cent <= 20) return i+'th'
|
|
@@ -637,7 +637,7 @@ export class ODChecker extends ODManagerData {
|
|
|
637
637
|
const final: ODCheckerLocationTrace = []
|
|
638
638
|
trace.forEach((t) => {
|
|
639
639
|
if (typeof t == "number"){
|
|
640
|
-
final.push(`:(${this
|
|
640
|
+
final.push(`:(${this.ordinalNumber(t+1)})`)
|
|
641
641
|
}else{
|
|
642
642
|
final.push(`."${t}"`)
|
|
643
643
|
}
|
|
@@ -1122,10 +1122,10 @@ export class ODCheckerArrayStructure extends ODCheckerStructure {
|
|
|
1122
1122
|
}else if (typeof this.options.length != "undefined" && value.length == this.options.length){
|
|
1123
1123
|
checker.createMessage("opendiscord:array-length-invalid","error",`This array needs to have a length of ${this.options.length}!`,lt,null,[this.options.length.toString()],this.id,(this.options.docs ?? null))
|
|
1124
1124
|
return false
|
|
1125
|
-
}else if (typeof this.options.allowedTypes != "undefined" && !this
|
|
1125
|
+
}else if (typeof this.options.allowedTypes != "undefined" && !this.arrayAllowedTypesCheck(value,this.options.allowedTypes)){
|
|
1126
1126
|
checker.createMessage("opendiscord:array-invalid-types","error",`This array can only contain the following types: ${this.options.allowedTypes.join(", ")}!`,lt,null,[this.options.allowedTypes.join(", ").toString()],this.id,(this.options.docs ?? null))
|
|
1127
1127
|
return false
|
|
1128
|
-
}else if (typeof this.options.allowDoubles != "undefined" && !this.options.allowDoubles && this
|
|
1128
|
+
}else if (typeof this.options.allowDoubles != "undefined" && !this.options.allowDoubles && this.arrayHasDoubles(value)){
|
|
1129
1129
|
checker.createMessage("opendiscord:array-double","error","This array doesn't allow the same value twice!",lt,null,[],this.id,(this.options.docs ?? null))
|
|
1130
1130
|
return false
|
|
1131
1131
|
}else{
|
|
@@ -1149,7 +1149,7 @@ export class ODCheckerArrayStructure extends ODCheckerStructure {
|
|
|
1149
1149
|
}
|
|
1150
1150
|
|
|
1151
1151
|
/**Check this array for the allowed types */
|
|
1152
|
-
|
|
1152
|
+
protected arrayAllowedTypesCheck(array:any[],allowedTypes:("string"|"number"|"boolean"|"null"|"array"|"object"|"other")[]): boolean {
|
|
1153
1153
|
//return TRUE if ALL values are valid
|
|
1154
1154
|
return !array.some((value) => {
|
|
1155
1155
|
if (allowedTypes.includes("string") && typeof value == "string"){
|
|
@@ -1172,7 +1172,7 @@ export class ODCheckerArrayStructure extends ODCheckerStructure {
|
|
|
1172
1172
|
})
|
|
1173
1173
|
}
|
|
1174
1174
|
/**Check this array for doubles */
|
|
1175
|
-
|
|
1175
|
+
protected arrayHasDoubles(array:any[]): boolean {
|
|
1176
1176
|
const alreadyFound: string[] = []
|
|
1177
1177
|
let hasDoubles = false
|
|
1178
1178
|
array.forEach((value) => {
|
|
@@ -1622,7 +1622,7 @@ export class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure
|
|
|
1622
1622
|
if (typeof value != "string") return false
|
|
1623
1623
|
else if (emptyAllowed && value.length == 0){
|
|
1624
1624
|
return true
|
|
1625
|
-
}else if (!this
|
|
1625
|
+
}else if (!this.urlIsValid(value)){
|
|
1626
1626
|
checker.createMessage("opendiscord:url-invalid","error","This url is invalid!",lt,null,[],this.id,(this.options.docs ?? null))
|
|
1627
1627
|
return false
|
|
1628
1628
|
}else if (typeof this.urlSettings.allowHttp != "undefined" && !this.urlSettings.allowHttp && !/^(https:\/\/)/.test(value)){
|
|
@@ -1631,13 +1631,13 @@ export class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure
|
|
|
1631
1631
|
}else if (!/^(http(s)?:\/\/)/.test(value)){
|
|
1632
1632
|
checker.createMessage("opendiscord:url-invalid-protocol","error","This url can only use the http:// & https:// protocols!",lt,null,[],this.id,(this.options.docs ?? null))
|
|
1633
1633
|
return false
|
|
1634
|
-
}else if (typeof this.urlSettings.allowedHostnames != "undefined" && !this
|
|
1634
|
+
}else if (typeof this.urlSettings.allowedHostnames != "undefined" && !this.urlHasValidHostname(value,this.urlSettings.allowedHostnames)){
|
|
1635
1635
|
checker.createMessage("opendiscord:url-invalid-hostname","error","This url has a disallowed hostname!",lt,null,[],this.id,(this.options.docs ?? null))
|
|
1636
1636
|
return false
|
|
1637
|
-
}else if (typeof this.urlSettings.allowedExtensions != "undefined" && !this
|
|
1637
|
+
}else if (typeof this.urlSettings.allowedExtensions != "undefined" && !this.urlHasValidExtension(value,this.urlSettings.allowedExtensions)){
|
|
1638
1638
|
checker.createMessage("opendiscord:url-invalid-extension","error",`This url has an invalid extension! Choose between: ${this.urlSettings.allowedExtensions.join(", ")}!"`,lt,null,[this.urlSettings.allowedExtensions.join(", ")],this.id,(this.options.docs ?? null))
|
|
1639
1639
|
return false
|
|
1640
|
-
}else if (typeof this.urlSettings.allowedPaths != "undefined" && !this
|
|
1640
|
+
}else if (typeof this.urlSettings.allowedPaths != "undefined" && !this.urlHasValidPath(value,this.urlSettings.allowedPaths)){
|
|
1641
1641
|
checker.createMessage("opendiscord:url-invalid-path","error","This url has an invalid path!",lt,null,[],this.id,(this.options.docs ?? null))
|
|
1642
1642
|
return false
|
|
1643
1643
|
}else if (typeof this.urlSettings.regex != "undefined" && !this.urlSettings.regex.test(value)){
|
|
@@ -1651,7 +1651,7 @@ export class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure
|
|
|
1651
1651
|
}
|
|
1652
1652
|
|
|
1653
1653
|
/**Check for the hostname */
|
|
1654
|
-
|
|
1654
|
+
protected urlHasValidHostname(url:string,hostnames:(string|RegExp)[]): boolean {
|
|
1655
1655
|
try {
|
|
1656
1656
|
const hostname = new URL(url).hostname
|
|
1657
1657
|
return hostnames.some((rule) => {
|
|
@@ -1667,7 +1667,7 @@ export class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure
|
|
|
1667
1667
|
}
|
|
1668
1668
|
}
|
|
1669
1669
|
/**Check for the extension */
|
|
1670
|
-
|
|
1670
|
+
protected urlHasValidExtension(url:string,extensions:string[]): boolean {
|
|
1671
1671
|
try {
|
|
1672
1672
|
const path = new URL(url).pathname
|
|
1673
1673
|
return extensions.some((rule) => {
|
|
@@ -1678,7 +1678,7 @@ export class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure
|
|
|
1678
1678
|
}
|
|
1679
1679
|
}
|
|
1680
1680
|
/**Check for the path */
|
|
1681
|
-
|
|
1681
|
+
protected urlHasValidPath(url:string,paths:(string|RegExp)[]): boolean {
|
|
1682
1682
|
try {
|
|
1683
1683
|
const path = new URL(url).pathname
|
|
1684
1684
|
return paths.some((rule) => {
|
|
@@ -1693,7 +1693,7 @@ export class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure
|
|
|
1693
1693
|
}
|
|
1694
1694
|
}
|
|
1695
1695
|
/**Do general syntax check on url */
|
|
1696
|
-
|
|
1696
|
+
protected urlIsValid(url:string){
|
|
1697
1697
|
try {
|
|
1698
1698
|
new URL(url)
|
|
1699
1699
|
return true
|