@open-discord-bots/framework 0.2.17 → 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.
Files changed (76) hide show
  1. package/dist/api/index.d.ts +16 -15
  2. package/dist/api/index.js +16 -15
  3. package/dist/api/main.d.ts +31 -23
  4. package/dist/api/main.js +3 -1
  5. package/dist/api/modules/action.d.ts +2 -2
  6. package/dist/api/modules/action.js +1 -5
  7. package/dist/api/modules/base.d.ts +29 -11
  8. package/dist/api/modules/base.js +78 -80
  9. package/dist/api/modules/builder.d.ts +2 -11
  10. package/dist/api/modules/builder.js +0 -4
  11. package/dist/api/modules/checker.d.ts +28 -7
  12. package/dist/api/modules/checker.js +33 -37
  13. package/dist/api/modules/client.d.ts +66 -14
  14. package/dist/api/modules/client.js +146 -132
  15. package/dist/api/modules/component.d.ts +928 -0
  16. package/dist/api/modules/component.js +1346 -0
  17. package/dist/api/modules/config.d.ts +30 -2
  18. package/dist/api/modules/config.js +90 -7
  19. package/dist/api/modules/console.d.ts +16 -4
  20. package/dist/api/modules/console.js +25 -25
  21. package/dist/api/modules/cooldown.d.ts +5 -5
  22. package/dist/api/modules/cooldown.js +1 -17
  23. package/dist/api/modules/database.d.ts +21 -13
  24. package/dist/api/modules/database.js +0 -23
  25. package/dist/api/modules/event.d.ts +4 -2
  26. package/dist/api/modules/event.js +8 -10
  27. package/dist/api/modules/fuse.d.ts +1 -1
  28. package/dist/api/modules/helpmenu.d.ts +11 -9
  29. package/dist/api/modules/helpmenu.js +24 -22
  30. package/dist/api/modules/language.d.ts +4 -3
  31. package/dist/api/modules/language.js +9 -16
  32. package/dist/api/modules/permission.d.ts +10 -1
  33. package/dist/api/modules/permission.js +17 -20
  34. package/dist/api/modules/plugin.d.ts +2 -1
  35. package/dist/api/modules/plugin.js +2 -2
  36. package/dist/api/modules/post.d.ts +12 -4
  37. package/dist/api/modules/post.js +36 -10
  38. package/dist/api/modules/progressbar.d.ts +18 -6
  39. package/dist/api/modules/progressbar.js +35 -35
  40. package/dist/api/modules/responder.d.ts +97 -28
  41. package/dist/api/modules/responder.js +213 -176
  42. package/dist/api/modules/session.d.ts +11 -2
  43. package/dist/api/modules/session.js +16 -16
  44. package/dist/api/modules/startscreen.d.ts +2 -3
  45. package/dist/api/modules/startscreen.js +8 -9
  46. package/dist/api/modules/statistic.d.ts +2 -1
  47. package/dist/api/modules/statistic.js +4 -7
  48. package/dist/api/modules/worker.d.ts +2 -1
  49. package/dist/api/modules/worker.js +3 -3
  50. package/package.json +3 -2
  51. package/src/api/index.ts +16 -15
  52. package/src/api/main.ts +33 -24
  53. package/src/api/modules/action.ts +2 -4
  54. package/src/api/modules/base.ts +77 -79
  55. package/src/api/modules/builder.ts +2 -14
  56. package/src/api/modules/checker.ts +36 -37
  57. package/src/api/modules/client.ts +144 -136
  58. package/src/api/modules/component.ts +1826 -0
  59. package/src/api/modules/config.ts +86 -7
  60. package/src/api/modules/console.ts +25 -25
  61. package/src/api/modules/cooldown.ts +8 -13
  62. package/src/api/modules/database.ts +24 -32
  63. package/src/api/modules/event.ts +6 -10
  64. package/src/api/modules/fuse.ts +1 -1
  65. package/src/api/modules/helpmenu.ts +31 -27
  66. package/src/api/modules/language.ts +11 -16
  67. package/src/api/modules/permission.ts +17 -20
  68. package/src/api/modules/plugin.ts +2 -2
  69. package/src/api/modules/post.ts +31 -10
  70. package/src/api/modules/progressbar.ts +36 -37
  71. package/src/api/modules/responder.ts +234 -185
  72. package/src/api/modules/session.ts +15 -15
  73. package/src/api/modules/startscreen.ts +9 -10
  74. package/src/api/modules/statistic.ts +4 -7
  75. package/src/api/modules/worker.ts +3 -3
  76. package/src/api/modules/component.txt +0 -350
@@ -2,7 +2,7 @@
2
2
  //CONFIG CHECKER MODULE
3
3
  ///////////////////////////////////////
4
4
  import { ODDiscordIdType, ODId, ODManager, ODManagerData, ODNoGeneric, ODValidId, ODValidJsonType } from "./base.js"
5
- import { ODConfig } from "./config.js"
5
+ import { ODConfig, ODMemoryConfig } from "./config.js"
6
6
  import { ODLanguageManager } from "./language.js"
7
7
  import { ODDebugger } from "./console.js"
8
8
  import ansis from "ansis"
@@ -96,7 +96,7 @@ export class ODCheckerManager<
96
96
  }
97
97
  /**Create temporary and unlisted `ODConfig`, `ODChecker` & `ODCheckerStorage` classes. This will help you use a `ODCheckerStructure` validator without officially registering it in `opendiscord.checkers`. */
98
98
  createTemporaryCheckerEnvironment(){
99
- return new ODChecker("opendiscord:temporary-environment",new ODCheckerStorage(),0,new ODConfig("opendiscord:temporary-environment",{}),new ODCheckerStructure("opendiscord:temporary-environment",{}))
99
+ return new ODChecker("opendiscord:temporary-environment",new ODCheckerStorage(),0,new ODMemoryConfig("opendiscord:temporary-environment",{}),new ODCheckerStructure("opendiscord:temporary-environment",{}))
100
100
  }
101
101
 
102
102
  get<CheckerId extends keyof ODNoGeneric<IdList>>(id:CheckerId): IdList[CheckerId]
@@ -181,11 +181,10 @@ export class ODCheckerStorage {
181
181
  *
182
182
  * Use this class to change the config checker looks!
183
183
  */
184
- export class ODCheckerRenderer {
184
+ export abstract class ODCheckerRenderer {
185
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[] {
187
- return []
188
- }
186
+ abstract getComponents(compact:boolean, renderEmpty:boolean, translation:ODCheckerTranslationRegister<string,string>, data:ODCheckerResult): string[]
187
+
189
188
  /**Render all config checker render components to the console. */
190
189
  render(components:string[]){
191
190
  if (components.length < 1) return
@@ -307,7 +306,7 @@ export class ODDefaultCheckerRenderer extends ODCheckerRenderer {
307
306
  const finalFooter = [footerErrorText,footerWarningText,footerSupportText,...this.extraFooterText]
308
307
  const finalTop = [...this.extraTopText]
309
308
  const finalBottom = [bottomCompactInfo,...this.extraBottomText]
310
- const borderLength = this.#getLongestLength([...finalHeader,...finalFooter])
309
+ const borderLength = this.getLongestLength([...finalHeader,...finalFooter])
311
310
 
312
311
  const finalComponents: string[] = []
313
312
 
@@ -315,10 +314,10 @@ export class ODDefaultCheckerRenderer extends ODCheckerRenderer {
315
314
  if (!this.disableHeader){
316
315
  finalHeader.forEach((text) => {
317
316
  if (text.length < 1) return
318
- finalComponents.push(this.#createBlockFromText(text,borderLength))
317
+ finalComponents.push(this.createBlockFromText(text,borderLength))
319
318
  })
320
319
  }
321
- finalComponents.push(this.#getHorizontalDivider(borderLength+4))
320
+ finalComponents.push(this.getHorizontalDivider(borderLength+4))
322
321
 
323
322
  //top
324
323
  finalTop.forEach((text) => {
@@ -372,31 +371,31 @@ export class ODDefaultCheckerRenderer extends ODCheckerRenderer {
372
371
  })
373
372
 
374
373
  //footer
375
- finalComponents.push(this.#getHorizontalDivider(borderLength+4))
374
+ finalComponents.push(this.getHorizontalDivider(borderLength+4))
376
375
  if (!this.disableFooter){
377
376
  finalFooter.forEach((text) => {
378
377
  if (text.length < 1) return
379
- finalComponents.push(this.#createBlockFromText(text,borderLength))
378
+ finalComponents.push(this.createBlockFromText(text,borderLength))
380
379
  })
381
- finalComponents.push(this.#getHorizontalDivider(borderLength+4))
380
+ finalComponents.push(this.getHorizontalDivider(borderLength+4))
382
381
  }
383
382
 
384
383
  //return all components
385
384
  return finalComponents
386
385
  }
387
386
  /**Get the length of the longest string in the array. */
388
- #getLongestLength(texts:string[]): number {
387
+ private getLongestLength(texts:string[]): number {
389
388
  return Math.max(...texts.map((t) => ansis.strip(t).length))
390
389
  }
391
390
  /**Get a horizontal divider used between different parts of the config checker result. */
392
- #getHorizontalDivider(width:number): string {
391
+ private getHorizontalDivider(width:number): string {
393
392
  if (width > 2) width = width-2
394
393
  else return this.verticalFiller+this.verticalFiller
395
394
  let divider = this.verticalFiller + this.horizontalFiller.repeat(width) + this.verticalFiller
396
395
  return divider
397
396
  }
398
397
  /**Create a block of text with a vertical divider on the left & right side. */
399
- #createBlockFromText(text:string,width:number): string {
398
+ private createBlockFromText(text:string,width:number): string {
400
399
  if (width < 3) return this.verticalFiller+this.verticalFiller
401
400
  let newWidth = width-ansis.strip(text).length+1
402
401
  let final = this.verticalFiller+" "+text+" ".repeat(newWidth)+this.verticalFiller
@@ -414,14 +413,14 @@ export class ODDefaultCheckerRenderer extends ODCheckerRenderer {
414
413
  */
415
414
  export class ODCheckerTranslationRegister<MessageIds extends string = string, OtherIds extends string = string> {
416
415
  /**This is the array that stores all the data. ❌ **(don't edit unless really needed!)***/
417
- #translations: {type:"message"|"other", id:string, translation:string}[] = []
416
+ protected translations: {type:"message"|"other", id:string, translation:string}[] = []
418
417
 
419
418
  /**Get the translation from a config checker message/sentence */
420
419
  get(type:"other", id:OtherIds): string
421
420
  get(type:"message", id:MessageIds): string
422
421
  get(type:"message"|"other", id:string): string|null
423
422
  get(type:"message"|"other", id:string): string|null {
424
- const result = this.#translations.find(d => (d.id == id) && (d.type == type))
423
+ const result = this.translations.find(d => (d.id == id) && (d.type == type))
425
424
  return (result) ? result.translation : null
426
425
  }
427
426
  /**Set the translation for a config checker message/sentence. This function also overwrites existing translations!*/
@@ -429,13 +428,13 @@ export class ODCheckerTranslationRegister<MessageIds extends string = string, Ot
429
428
  set(type:"message", id:MessageIds, translation:string): boolean
430
429
  set(type:"message"|"other", id:string, translation:string): boolean
431
430
  set(type:"message"|"other", id:string, translation:string){
432
- const index = this.#translations.findIndex(d => (d.id == id) && (d.type == type))
431
+ const index = this.translations.findIndex(d => (d.id == id) && (d.type == type))
433
432
  if (index > -1){
434
433
  //overwrite
435
- this.#translations[index] = {type,id,translation}
434
+ this.translations[index] = {type,id,translation}
436
435
  return true
437
436
  }else{
438
- this.#translations.push({type,id,translation})
437
+ this.translations.push({type,id,translation})
439
438
  return false
440
439
  }
441
440
  }
@@ -444,16 +443,16 @@ export class ODCheckerTranslationRegister<MessageIds extends string = string, Ot
444
443
  delete(type:"message", id:MessageIds): boolean
445
444
  delete(type:"message"|"other", id:string): boolean
446
445
  delete(type:"message"|"other", id:string){
447
- const index = this.#translations.findIndex(d => (d.id == id) && (d.type == type))
446
+ const index = this.translations.findIndex(d => (d.id == id) && (d.type == type))
448
447
  if (index > -1){
449
448
  //delete
450
- this.#translations.splice(index,1)
449
+ this.translations.splice(index,1)
451
450
  return true
452
451
  }else return false
453
452
  }
454
453
  /**Get all translations */
455
454
  getAll(){
456
- return this.#translations
455
+ return this.translations
457
456
  }
458
457
  /**Insert the translation params into the text. */
459
458
  insertTranslationParams(text:string, translationParams:string[]){
@@ -612,7 +611,7 @@ export class ODChecker extends ODManagerData {
612
611
  }
613
612
 
614
613
  /**Get a human-readable number string. */
615
- #ordinalNumber(num:number){
614
+ protected ordinalNumber(num:number){
616
615
  const i = Math.abs(Math.round(num))
617
616
  const cent = i % 100
618
617
  if (cent >= 10 && cent <= 20) return i+'th'
@@ -638,7 +637,7 @@ export class ODChecker extends ODManagerData {
638
637
  const final: ODCheckerLocationTrace = []
639
638
  trace.forEach((t) => {
640
639
  if (typeof t == "number"){
641
- final.push(`:(${this.#ordinalNumber(t+1)})`)
640
+ final.push(`:(${this.ordinalNumber(t+1)})`)
642
641
  }else{
643
642
  final.push(`."${t}"`)
644
643
  }
@@ -1123,10 +1122,10 @@ export class ODCheckerArrayStructure extends ODCheckerStructure {
1123
1122
  }else if (typeof this.options.length != "undefined" && value.length == this.options.length){
1124
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))
1125
1124
  return false
1126
- }else if (typeof this.options.allowedTypes != "undefined" && !this.#arrayAllowedTypesCheck(value,this.options.allowedTypes)){
1125
+ }else if (typeof this.options.allowedTypes != "undefined" && !this.arrayAllowedTypesCheck(value,this.options.allowedTypes)){
1127
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))
1128
1127
  return false
1129
- }else if (typeof this.options.allowDoubles != "undefined" && !this.options.allowDoubles && this.#arrayHasDoubles(value)){
1128
+ }else if (typeof this.options.allowDoubles != "undefined" && !this.options.allowDoubles && this.arrayHasDoubles(value)){
1130
1129
  checker.createMessage("opendiscord:array-double","error","This array doesn't allow the same value twice!",lt,null,[],this.id,(this.options.docs ?? null))
1131
1130
  return false
1132
1131
  }else{
@@ -1150,7 +1149,7 @@ export class ODCheckerArrayStructure extends ODCheckerStructure {
1150
1149
  }
1151
1150
 
1152
1151
  /**Check this array for the allowed types */
1153
- #arrayAllowedTypesCheck(array:any[],allowedTypes:("string"|"number"|"boolean"|"null"|"array"|"object"|"other")[]): boolean {
1152
+ protected arrayAllowedTypesCheck(array:any[],allowedTypes:("string"|"number"|"boolean"|"null"|"array"|"object"|"other")[]): boolean {
1154
1153
  //return TRUE if ALL values are valid
1155
1154
  return !array.some((value) => {
1156
1155
  if (allowedTypes.includes("string") && typeof value == "string"){
@@ -1173,7 +1172,7 @@ export class ODCheckerArrayStructure extends ODCheckerStructure {
1173
1172
  })
1174
1173
  }
1175
1174
  /**Check this array for doubles */
1176
- #arrayHasDoubles(array:any[]): boolean {
1175
+ protected arrayHasDoubles(array:any[]): boolean {
1177
1176
  const alreadyFound: string[] = []
1178
1177
  let hasDoubles = false
1179
1178
  array.forEach((value) => {
@@ -1623,7 +1622,7 @@ export class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure
1623
1622
  if (typeof value != "string") return false
1624
1623
  else if (emptyAllowed && value.length == 0){
1625
1624
  return true
1626
- }else if (!this.#urlIsValid(value)){
1625
+ }else if (!this.urlIsValid(value)){
1627
1626
  checker.createMessage("opendiscord:url-invalid","error","This url is invalid!",lt,null,[],this.id,(this.options.docs ?? null))
1628
1627
  return false
1629
1628
  }else if (typeof this.urlSettings.allowHttp != "undefined" && !this.urlSettings.allowHttp && !/^(https:\/\/)/.test(value)){
@@ -1632,13 +1631,13 @@ export class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure
1632
1631
  }else if (!/^(http(s)?:\/\/)/.test(value)){
1633
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))
1634
1633
  return false
1635
- }else if (typeof this.urlSettings.allowedHostnames != "undefined" && !this.#urlHasValidHostname(value,this.urlSettings.allowedHostnames)){
1634
+ }else if (typeof this.urlSettings.allowedHostnames != "undefined" && !this.urlHasValidHostname(value,this.urlSettings.allowedHostnames)){
1636
1635
  checker.createMessage("opendiscord:url-invalid-hostname","error","This url has a disallowed hostname!",lt,null,[],this.id,(this.options.docs ?? null))
1637
1636
  return false
1638
- }else if (typeof this.urlSettings.allowedExtensions != "undefined" && !this.#urlHasValidExtension(value,this.urlSettings.allowedExtensions)){
1637
+ }else if (typeof this.urlSettings.allowedExtensions != "undefined" && !this.urlHasValidExtension(value,this.urlSettings.allowedExtensions)){
1639
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))
1640
1639
  return false
1641
- }else if (typeof this.urlSettings.allowedPaths != "undefined" && !this.#urlHasValidPath(value,this.urlSettings.allowedPaths)){
1640
+ }else if (typeof this.urlSettings.allowedPaths != "undefined" && !this.urlHasValidPath(value,this.urlSettings.allowedPaths)){
1642
1641
  checker.createMessage("opendiscord:url-invalid-path","error","This url has an invalid path!",lt,null,[],this.id,(this.options.docs ?? null))
1643
1642
  return false
1644
1643
  }else if (typeof this.urlSettings.regex != "undefined" && !this.urlSettings.regex.test(value)){
@@ -1652,7 +1651,7 @@ export class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure
1652
1651
  }
1653
1652
 
1654
1653
  /**Check for the hostname */
1655
- #urlHasValidHostname(url:string,hostnames:(string|RegExp)[]): boolean {
1654
+ protected urlHasValidHostname(url:string,hostnames:(string|RegExp)[]): boolean {
1656
1655
  try {
1657
1656
  const hostname = new URL(url).hostname
1658
1657
  return hostnames.some((rule) => {
@@ -1668,7 +1667,7 @@ export class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure
1668
1667
  }
1669
1668
  }
1670
1669
  /**Check for the extension */
1671
- #urlHasValidExtension(url:string,extensions:string[]): boolean {
1670
+ protected urlHasValidExtension(url:string,extensions:string[]): boolean {
1672
1671
  try {
1673
1672
  const path = new URL(url).pathname
1674
1673
  return extensions.some((rule) => {
@@ -1679,7 +1678,7 @@ export class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure
1679
1678
  }
1680
1679
  }
1681
1680
  /**Check for the path */
1682
- #urlHasValidPath(url:string,paths:(string|RegExp)[]): boolean {
1681
+ protected urlHasValidPath(url:string,paths:(string|RegExp)[]): boolean {
1683
1682
  try {
1684
1683
  const path = new URL(url).pathname
1685
1684
  return paths.some((rule) => {
@@ -1694,7 +1693,7 @@ export class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure
1694
1693
  }
1695
1694
  }
1696
1695
  /**Do general syntax check on url */
1697
- #urlIsValid(url:string){
1696
+ protected urlIsValid(url:string){
1698
1697
  try {
1699
1698
  new URL(url)
1700
1699
  return true