@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.
Files changed (61) hide show
  1. package/dist/api/main.js +1 -1
  2. package/dist/api/modules/base.d.ts +27 -9
  3. package/dist/api/modules/base.js +78 -80
  4. package/dist/api/modules/builder.d.ts +0 -9
  5. package/dist/api/modules/checker.d.ts +26 -5
  6. package/dist/api/modules/checker.js +31 -31
  7. package/dist/api/modules/client.d.ts +66 -14
  8. package/dist/api/modules/client.js +146 -132
  9. package/dist/api/modules/component.d.ts +8 -2
  10. package/dist/api/modules/component.js +8 -6
  11. package/dist/api/modules/config.d.ts +0 -1
  12. package/dist/api/modules/config.js +9 -7
  13. package/dist/api/modules/console.d.ts +16 -4
  14. package/dist/api/modules/console.js +25 -25
  15. package/dist/api/modules/event.d.ts +4 -2
  16. package/dist/api/modules/event.js +8 -10
  17. package/dist/api/modules/fuse.d.ts +1 -1
  18. package/dist/api/modules/helpmenu.d.ts +2 -2
  19. package/dist/api/modules/helpmenu.js +4 -7
  20. package/dist/api/modules/language.d.ts +2 -1
  21. package/dist/api/modules/language.js +6 -9
  22. package/dist/api/modules/permission.d.ts +10 -1
  23. package/dist/api/modules/permission.js +17 -20
  24. package/dist/api/modules/plugin.d.ts +2 -1
  25. package/dist/api/modules/plugin.js +2 -2
  26. package/dist/api/modules/post.d.ts +12 -4
  27. package/dist/api/modules/post.js +36 -10
  28. package/dist/api/modules/progressbar.d.ts +16 -5
  29. package/dist/api/modules/progressbar.js +34 -34
  30. package/dist/api/modules/responder.d.ts +95 -26
  31. package/dist/api/modules/responder.js +213 -172
  32. package/dist/api/modules/session.d.ts +10 -1
  33. package/dist/api/modules/session.js +15 -15
  34. package/dist/api/modules/startscreen.d.ts +0 -1
  35. package/dist/api/modules/startscreen.js +3 -6
  36. package/dist/api/modules/statistic.d.ts +2 -1
  37. package/dist/api/modules/statistic.js +4 -7
  38. package/dist/api/modules/worker.d.ts +2 -1
  39. package/dist/api/modules/worker.js +3 -3
  40. package/package.json +1 -1
  41. package/src/api/main.ts +1 -1
  42. package/src/api/modules/base.ts +75 -77
  43. package/src/api/modules/builder.ts +0 -10
  44. package/src/api/modules/checker.ts +31 -31
  45. package/src/api/modules/client.ts +144 -136
  46. package/src/api/modules/component.ts +11 -7
  47. package/src/api/modules/config.ts +8 -6
  48. package/src/api/modules/console.ts +25 -25
  49. package/src/api/modules/event.ts +6 -10
  50. package/src/api/modules/fuse.ts +1 -1
  51. package/src/api/modules/helpmenu.ts +4 -7
  52. package/src/api/modules/language.ts +6 -9
  53. package/src/api/modules/permission.ts +17 -20
  54. package/src/api/modules/plugin.ts +2 -2
  55. package/src/api/modules/post.ts +31 -10
  56. package/src/api/modules/progressbar.ts +34 -34
  57. package/src/api/modules/responder.ts +232 -181
  58. package/src/api/modules/session.ts +14 -14
  59. package/src/api/modules/startscreen.ts +3 -6
  60. package/src/api/modules/statistic.ts +4 -7
  61. package/src/api/modules/worker.ts +3 -3
@@ -14,15 +14,15 @@ import { ODDebugger } from "./console.js"
14
14
  */
15
15
  export class ODComponentFactoryInstance<Component extends ODComponent<object,any>> {
16
16
  /**The root component of this factory. */
17
- #rootComponent: Component|null = null
17
+ private rootComponent: Component|null = null
18
18
 
19
19
  /**The root component of this factory. */
20
20
  getComponent(){
21
- return this.#rootComponent
21
+ return this.rootComponent
22
22
  }
23
23
  /**Set the root component of this factory. */
24
24
  setComponent(c:Component|null){
25
- this.#rootComponent = c
25
+ this.rootComponent = c
26
26
  }
27
27
  }
28
28
 
@@ -272,15 +272,15 @@ export abstract class ODGroupComponent<Data extends object,ChildComponent extend
272
272
  */
273
273
  export abstract class ODParentComponent<Data extends object,ChildComponent extends ODComponent<object,any>,BuildResult> extends ODComponent<Data,BuildResult> {
274
274
  /**The child component of this parent. */
275
- #child: ChildComponent|null = null
275
+ private rawChild: ChildComponent|null = null
276
276
 
277
277
  /**The child component of this parent. */
278
278
  get child(){
279
- return this.#child
279
+ return this.rawChild
280
280
  }
281
281
  /**Set the child component of this parent. */
282
282
  setComponent(c:ChildComponent|null){
283
- this.#child = c
283
+ this.rawChild = c
284
284
  }
285
285
  }
286
286
 
@@ -322,7 +322,9 @@ export interface ODMessageComponentBuildResult {
322
322
  /**Suppress/hide embeds. */
323
323
  supressEmbeds:boolean,
324
324
  /**Do not send notifications to mentioned users or roles. */
325
- supressNotifications:boolean
325
+ supressNotifications:boolean,
326
+ /**The id of the `ODMessageComponent` this message was built with. */
327
+ id:ODId
326
328
  }
327
329
 
328
330
  /**## ODMessageComponent `class`
@@ -363,6 +365,7 @@ export class ODMessageComponent extends ODGroupComponent<ODMessageComponentData,
363
365
  }
364
366
 
365
367
  return {
368
+ id:new ODId(this.id),
366
369
  msg:{
367
370
  components,
368
371
  files:attachments,
@@ -461,6 +464,7 @@ export class ODSimpleMessageComponent extends ODGroupComponent<ODSimpleMessageCo
461
464
  }
462
465
 
463
466
  return {
467
+ id:new ODId(this.id),
464
468
  msg:{
465
469
  content,
466
470
  embeds,
@@ -21,16 +21,18 @@ export type ODConfigManagerIdConstraint = Record<string,ODConfig<any>>
21
21
  * You can use this class to get/change/add a config file (`ODConfig`) in your plugin!
22
22
  */
23
23
  export class ODConfigManager<IdList extends ODConfigManagerIdConstraint = ODConfigManagerIdConstraint> extends ODManager<ODConfig<any>> {
24
- /**Alias to Open Discord debugger. */
25
- #debug: ODDebugger
26
-
27
24
  constructor(debug:ODDebugger){
28
25
  super(debug,"config")
29
- this.#debug = debug
30
26
  }
27
+
31
28
  add(data:ODConfig<any>|ODConfig<any>[],overwrite?:boolean): boolean {
32
- if (Array.isArray(data)) data.forEach((d) => d.useDebug(this.#debug))
33
- else data.useDebug(this.#debug)
29
+ if (this.debug){
30
+ if (Array.isArray(data)){
31
+ for (const d of data){
32
+ d.useDebug(this.debug)
33
+ }
34
+ }else data.useDebug(this.debug)
35
+ }
34
36
  return super.add(data,overwrite)
35
37
  }
36
38
  /**Init all config files. */
@@ -278,10 +278,10 @@ export class ODConsoleManager {
278
278
  if (this.debugfile) this.debugfile.writeConsoleMessage(newMessage)
279
279
  this.history.push(newMessage)
280
280
  }
281
- this.#purgeHistory()
281
+ this.purgeHistory()
282
282
  }
283
283
  /**Shorten the history when it exceeds the max history length! */
284
- #purgeHistory(){
284
+ protected purgeHistory(){
285
285
  if (this.history.length > this.historylength) this.history.shift()
286
286
  }
287
287
  }
@@ -310,16 +310,16 @@ export class ODDebugFileManager {
310
310
  this.version = version
311
311
  this.maxlines = maxlines
312
312
 
313
- this.#writeStartupStats()
313
+ this.writeStartupStats()
314
314
  }
315
315
 
316
316
  /**Check if the debug file exists */
317
- #existsDebugFile(){
317
+ protected existsDebugFile(){
318
318
  return fs.existsSync(this.path)
319
319
  }
320
320
  /**Read from the debug file */
321
- #readDebugFile(){
322
- if (this.#existsDebugFile()){
321
+ protected readDebugFile(){
322
+ if (this.existsDebugFile()){
323
323
  try {
324
324
  return fs.readFileSync(this.path).toString()
325
325
  }catch{
@@ -330,8 +330,8 @@ export class ODDebugFileManager {
330
330
  }
331
331
  }
332
332
  /**Write to the debug file and shorten it when needed. */
333
- #writeDebugFile(text:string){
334
- const currenttext = this.#readDebugFile()
333
+ protected writeDebugFile(text:string){
334
+ const currenttext = this.readDebugFile()
335
335
  if (currenttext){
336
336
  const splitted = currenttext.split("\n")
337
337
 
@@ -343,12 +343,12 @@ export class ODDebugFileManager {
343
343
  fs.writeFileSync(this.path,splitted.join("\n"))
344
344
  }else{
345
345
  //write new file:
346
- const newtext = this.#createStatsText()+text
346
+ const newtext = this.createStatsText()+text
347
347
  fs.writeFileSync(this.path,newtext)
348
348
  }
349
349
  }
350
350
  /**Generate the statistics/header of the debug file (containing the version) */
351
- #createStatsText(){
351
+ protected createStatsText(){
352
352
  const date = new Date()
353
353
  const dstring = `${date.getDate()}/${date.getMonth()+1}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`
354
354
  return [
@@ -360,8 +360,8 @@ export class ODDebugFileManager {
360
360
  ].join("\n")
361
361
  }
362
362
  /**Write the statistics/header to the debug file on startup */
363
- #writeStartupStats(){
364
- const currenttext = this.#readDebugFile()
363
+ protected writeStartupStats(){
364
+ const currenttext = this.readDebugFile()
365
365
  if (currenttext){
366
366
  //edit previous file:
367
367
  const splitted = currenttext.split("\n")
@@ -371,31 +371,31 @@ export class ODDebugFileManager {
371
371
  splitted.splice(0,((splitted.length+11) - this.maxlines))
372
372
  }
373
373
 
374
- splitted.unshift(this.#createStatsText())
374
+ splitted.unshift(this.createStatsText())
375
375
  splitted.push("\n---------------------------------------------------------------------\n---------------------------------------------------------------------\n")
376
376
 
377
377
  fs.writeFileSync(this.path,splitted.join("\n"))
378
378
  }else{
379
379
  //write new file:
380
- const newtext = this.#createStatsText()
380
+ const newtext = this.createStatsText()
381
381
  fs.writeFileSync(this.path,newtext)
382
382
  }
383
383
  }
384
384
  /**Write an `ODConsoleMessage` to the debug file */
385
385
  writeConsoleMessage(message:ODConsoleMessage){
386
- this.#writeDebugFile(message.toDebugString())
386
+ this.writeDebugFile(message.toDebugString())
387
387
  }
388
388
  /**Write an `ODError` to the debug file */
389
389
  writeErrorMessage(error:ODError){
390
- this.#writeDebugFile(error.toDebugString())
390
+ this.writeDebugFile(error.toDebugString())
391
391
  }
392
392
  /**Write custom text to the debug file */
393
393
  writeText(text:string){
394
- this.#writeDebugFile(text)
394
+ this.writeDebugFile(text)
395
395
  }
396
396
  /**Write a custom note to the debug file (starting with `[NOTE]:`) */
397
397
  writeNote(text:string){
398
- this.#writeDebugFile("[NOTE]: "+text)
398
+ this.writeDebugFile("[NOTE]: "+text)
399
399
  }
400
400
  }
401
401
 
@@ -597,7 +597,7 @@ export class ODLiveStatusManager<IdList extends ODLiveStatusManagerIdConstraint
597
597
  /**The class responsible for rendering the livestatus messages. */
598
598
  renderer: ODLiveStatusRenderer
599
599
  /**A reference to the ODMain or "opendiscord" global variable */
600
- #main: ODMain|null = null
600
+ protected main: ODMain|null = null
601
601
 
602
602
  constructor(debug:ODDebugger,console:ODConsoleManager){
603
603
  super(debug,"livestatus source")
@@ -606,18 +606,18 @@ export class ODLiveStatusManager<IdList extends ODLiveStatusManagerIdConstraint
606
606
 
607
607
  /**Get the messages from all sources combined! */
608
608
  async getAllMessages(): Promise<ODLiveStatusSourceData[]> {
609
- if (!this.#main) throw new ODSystemError("ODLiveStatusManager:getAllMessages() --> Unable to get messages, 'opendiscord/ODMain' has not been connected!")
609
+ if (!this.main) throw new ODSystemError("ODLiveStatusManager:getAllMessages() --> Unable to get messages, 'opendiscord/ODMain' has not been connected!")
610
610
  const messages: ODLiveStatusSourceData[] = []
611
611
  for (const source of this.getAll()){
612
612
  try {
613
- messages.push(...(await source.getMessages(this.#main)))
613
+ messages.push(...(await source.getMessages(this.main)))
614
614
  }catch{}
615
615
  }
616
616
  return messages
617
617
  }
618
618
  /**Set the opendiscord `ODMain` class to use for fetching message filters. */
619
619
  useMain(main:ODMain){
620
- this.#main = main
620
+ this.main = main
621
621
  }
622
622
 
623
623
  get<LiveStatusId extends keyof ODNoGeneric<IdList>>(id:LiveStatusId): IdList[LiveStatusId]
@@ -649,10 +649,10 @@ export class ODLiveStatusManager<IdList extends ODLiveStatusManagerIdConstraint
649
649
  */
650
650
  export class ODLiveStatusRenderer {
651
651
  /**A reference to the ODConsoleManager or "opendiscord.console" global variable */
652
- #console: ODConsoleManager
652
+ protected console: ODConsoleManager
653
653
 
654
654
  constructor(console:ODConsoleManager){
655
- this.#console = console
655
+ this.console = console
656
656
  }
657
657
 
658
658
  /**Render all messages */
@@ -688,7 +688,7 @@ export class ODLiveStatusRenderer {
688
688
  //return all messages
689
689
  return final.join("\n")
690
690
  }catch{
691
- this.#console.log("Failed to render LiveStatus messages!","error")
691
+ this.console.log("Failed to render LiveStatus messages!","error")
692
692
  return ""
693
693
  }
694
694
  }
@@ -17,7 +17,7 @@ export type ODEventCallback = (...args:any) => ODPromiseVoid
17
17
  */
18
18
  export class ODEvent<Callback extends ODEventCallback = ODEventCallback> extends ODManagerData {
19
19
  /**Alias to Open Discord debugger. */
20
- #debug?: ODDebugger
20
+ protected debug?: ODDebugger
21
21
  /**The list of permanent listeners. */
22
22
  listeners: Function[] = []
23
23
  /**The list of one-time listeners. List is cleared every time the event is emitted. */
@@ -27,10 +27,10 @@ export class ODEvent<Callback extends ODEventCallback = ODEventCallback> extends
27
27
 
28
28
  /**Use the Open Discord debugger in this manager for logs*/
29
29
  useDebug(debug:ODDebugger|null){
30
- this.#debug = debug ?? undefined
30
+ this.debug = debug ?? undefined
31
31
  }
32
32
  /**Get a collection of listeners combined from both types. Also clears the one-time listeners array! */
33
- #getCurrentListeners(){
33
+ protected getCurrentListeners(){
34
34
  const final: Function[] = []
35
35
  this.oncelisteners.forEach((l) => final.push(l))
36
36
  this.listeners.forEach((l) => final.push(l))
@@ -47,7 +47,7 @@ export class ODEvent<Callback extends ODEventCallback = ODEventCallback> extends
47
47
  this.listeners.push(callback)
48
48
 
49
49
  if (this.listeners.length > this.listenerLimit){
50
- if (this.#debug) this.#debug.console.log(new ODWarningConsoleMessage("Possible event memory leak detected!",[
50
+ if (this.debug) this.debug.console.log(new ODWarningConsoleMessage("Possible event memory leak detected!",[
51
51
  {key:"event",value:this.id.value},
52
52
  {key:"listeners",value:this.listeners.length.toString()}
53
53
  ]))
@@ -65,7 +65,7 @@ export class ODEvent<Callback extends ODEventCallback = ODEventCallback> extends
65
65
  }
66
66
  /**Emit this event to all listeners. You are required to provide all parameters of the event! */
67
67
  async emit(params:Parameters<Callback>): Promise<void> {
68
- for (const listener of this.#getCurrentListeners()){
68
+ for (const listener of this.getCurrentListeners()){
69
69
  try{
70
70
  await listener(...params)
71
71
  }catch(err:any){
@@ -89,16 +89,12 @@ export type ODEventManagerIdConstraint = Record<string,ODEvent>
89
89
  * All events are available in the `opendiscord.events` global!
90
90
  */
91
91
  export class ODEventManager<IdList extends ODEventManagerIdConstraint = ODEventManagerIdConstraint> extends ODManager<ODEvent> {
92
- /**Reference to the Open Discord debugger */
93
- #debug: ODDebugger
94
-
95
92
  constructor(debug:ODDebugger){
96
93
  super(debug,"event")
97
- this.#debug = debug
98
94
  }
99
95
 
100
96
  add(data:ODEvent, overwrite?:boolean): boolean {
101
- data.useDebug(this.#debug)
97
+ if (this.debug) data.useDebug(this.debug)
102
98
  return super.add(data,overwrite)
103
99
  }
104
100
 
@@ -44,7 +44,7 @@ export type ODFuseStringArray<FuseList extends object> = {
44
44
  */
45
45
  export class ODFuseManager<FuseList extends object> {
46
46
  /**A list of all the defaults */
47
- private fuses: FuseList
47
+ protected fuses: FuseList
48
48
 
49
49
  constructor(fuses:FuseList){
50
50
  this.fuses = fuses
@@ -85,16 +85,16 @@ export class ODHelpMenuCommandComponent extends ODHelpMenuComponent {
85
85
 
86
86
  render(page:number,category:number,location:number,mode:"slash"|"text"){
87
87
  if (mode == "slash" && this.settings.slashName){
88
- return `\`${this.settings.slashName}${(this.settings.slashOptions) ? this.#renderOptions(this.settings.slashOptions) : ""}\` ➜ ${this.settings.slashDescription ?? ""}`
88
+ return `\`${this.settings.slashName}${(this.settings.slashOptions) ? this.renderOptions(this.settings.slashOptions) : ""}\` ➜ ${this.settings.slashDescription ?? ""}`
89
89
 
90
90
  }else if (mode == "text" && this.settings.textName){
91
- return `\`${this.settings.textName}${(this.settings.textOptions) ? this.#renderOptions(this.settings.textOptions) : ""}\` ➜ ${this.settings.textDescription ?? ""}`
91
+ return `\`${this.settings.textName}${(this.settings.textOptions) ? this.renderOptions(this.settings.textOptions) : ""}\` ➜ ${this.settings.textDescription ?? ""}`
92
92
 
93
93
  }else return ""
94
94
  }
95
95
 
96
96
  /**Utility function to render all command options. */
97
- #renderOptions(options:ODHelpMenuCommandComponentOption[]){
97
+ protected renderOptions(options:ODHelpMenuCommandComponentOption[]){
98
98
  return " "+options.map((opt) => (opt.optional) ? `[${opt.name}]` : `<${opt.name}>`).join(" ")
99
99
  }
100
100
  }
@@ -195,18 +195,15 @@ export type ODHelpMenuManagerIdConstraint = Record<string,ODHelpMenuCategory>
195
195
  * Fewer Categories == More Clean Menu
196
196
  */
197
197
  export class ODHelpMenuManager<IdList extends ODHelpMenuManagerIdConstraint = ODHelpMenuManagerIdConstraint> extends ODManager<ODHelpMenuCategory> {
198
- /**Alias to Open Discord debugger. */
199
- #debug: ODDebugger
200
198
  /**The amount of categories per-page. */
201
199
  categoriesPerPage: number = 3
202
200
 
203
201
  constructor(debug:ODDebugger){
204
202
  super(debug,"help menu category")
205
- this.#debug = debug
206
203
  }
207
204
 
208
205
  add(data:ODHelpMenuCategory, overwrite?:boolean): boolean {
209
- data.useDebug(this.#debug,"help menu component")
206
+ data.useDebug(this.debug,"help menu component")
210
207
  return super.add(data,overwrite)
211
208
  }
212
209
 
@@ -40,15 +40,12 @@ export class ODLanguageManager<IdList extends ODLanguageManagerIdConstraint = OD
40
40
  current: ODLanguage|null = null
41
41
  /**The currently selected backup language. (used when translation missing in current language) */
42
42
  backup: ODLanguage|null = null
43
- /**An alias to Open Discord debugger. */
44
- #debug: ODDebugger
45
43
 
46
44
  constructor(debug:ODDebugger, presets:boolean){
47
45
  super(debug,"language")
48
46
  if (presets) this.add(new ODJsonLanguage("english","english.json"))
49
47
  this.current = presets ? new ODJsonLanguage("english","english.json") : null
50
48
  this.backup = presets ? new ODJsonLanguage("english","english.json") : null
51
- this.#debug = debug
52
49
  }
53
50
 
54
51
  /**Set the current language by providing the ID of a language which is registered in this manager. */
@@ -58,7 +55,7 @@ export class ODLanguageManager<IdList extends ODLanguageManagerIdConstraint = OD
58
55
  this.current = this.get(id)
59
56
  const languageId = this.current?.id.value ?? "<unknown-id>"
60
57
  const languageAutomated = this.current?.metadata?.automated.toString() ?? "<unknown-metadata>"
61
- this.#debug.debug("Selected current language",[
58
+ this.debug?.debug("Selected current language",[
62
59
  {key:"id",value:languageId},
63
60
  {key:"automated",value:languageAutomated},
64
61
  ])
@@ -74,7 +71,7 @@ export class ODLanguageManager<IdList extends ODLanguageManagerIdConstraint = OD
74
71
  this.backup = this.get(id)
75
72
  const languageId = this.backup?.id.value ?? "<unknown-id>"
76
73
  const languageAutomated = this.backup?.metadata?.automated.toString() ?? "<unknown-metadata>"
77
- this.#debug.debug("Selected backup language",[
74
+ this.debug?.debug("Selected backup language",[
78
75
  {key:"id",value:languageId},
79
76
  {key:"automated",value:languageAutomated},
80
77
  ])
@@ -96,7 +93,7 @@ export class ODLanguageManager<IdList extends ODLanguageManagerIdConstraint = OD
96
93
  getTranslation(id:TranslationIds): string
97
94
  getTranslation(id:string): string|null
98
95
  getTranslation(id:string): string|null {
99
- if (!this.current) return this.#getBackupTranslation(id)
96
+ if (!this.current) return this.getBackupTranslation(id)
100
97
 
101
98
  const splitted = id.split(".")
102
99
  let currentObject = this.current.data
@@ -110,10 +107,10 @@ export class ODLanguageManager<IdList extends ODLanguageManagerIdConstraint = OD
110
107
  })
111
108
 
112
109
  if (typeof result == "string") return result
113
- else return this.#getBackupTranslation(id)
110
+ else return this.getBackupTranslation(id)
114
111
  }
115
- /**Get a backup translation string by JSON location. (system only) */
116
- #getBackupTranslation(id:string): string|null {
112
+ /**Get a backup translation string by JSON location. (system only) */
113
+ protected getBackupTranslation(id:string): string|null {
117
114
  if (!this.backup) return null
118
115
 
119
116
  const splitted = id.split(".")
@@ -129,12 +129,10 @@ export type ODPermissionManagerIdConstraint = Record<string,ODPermission>
129
129
  * Add new permissions using the `ODPermission` class in your plugin!
130
130
  */
131
131
  export class ODPermissionManager<IdList extends ODPermissionManagerIdConstraint = ODPermissionManagerIdConstraint> extends ODManager<ODPermission> {
132
- /**Alias for Open Discord debugger. */
133
- #debug: ODDebugger
134
132
  /**The function for calculating permissions in this manager. */
135
- #calculation: ODPermissionCalculationCallback|null
133
+ private calculation: ODPermissionCalculationCallback|null
136
134
  /**An alias to the Open Discord client manager. */
137
- #client: ODClientManager
135
+ private client: ODClientManager
138
136
  /**The result which is returned when no other permissions match. (`member` by default) */
139
137
  defaultResult: ODPermissionResult = {
140
138
  level:ODPermissionLevel["member"],
@@ -145,14 +143,13 @@ export class ODPermissionManager<IdList extends ODPermissionManagerIdConstraint
145
143
 
146
144
  constructor(debug:ODDebugger, client:ODClientManager, useDefaultCalculation?:boolean){
147
145
  super(debug,"permission")
148
- this.#debug = debug
149
- this.#calculation = useDefaultCalculation ? this.#defaultCalculation : null
150
- this.#client = client
146
+ this.calculation = useDefaultCalculation ? this.defaultCalculation : null
147
+ this.client = client
151
148
  }
152
149
 
153
150
  /**Edit the permission calculation function in this manager. */
154
151
  setCalculation(calculation:ODPermissionCalculationCallback){
155
- this.#calculation = calculation
152
+ this.calculation = calculation
156
153
  }
157
154
  /**Edit the result which is returned when no other permissions match. (`member` by default) */
158
155
  setDefaultResult(result:ODPermissionResult){
@@ -161,8 +158,8 @@ export class ODPermissionManager<IdList extends ODPermissionManagerIdConstraint
161
158
  /**Get an `ODPermissionResult` based on a few context factors. Use `hasPermissions()` to simplify the result. */
162
159
  getPermissions(user:discord.User, channel?:discord.Channel|null, guild?:discord.Guild|null, settings?:ODPermissionSettings|null): Promise<ODPermissionResult> {
163
160
  try{
164
- if (!this.#calculation) throw new ODSystemError("ODPermissionManager:getPermissions() => missing perms calculation")
165
- return this.#calculation(user,channel,guild,settings)
161
+ if (!this.calculation) throw new ODSystemError("ODPermissionManager:getPermissions() => missing perms calculation")
162
+ return this.calculation(user,channel,guild,settings)
166
163
  }catch(err){
167
164
  process.emit("uncaughtException",err)
168
165
  throw new ODSystemError("ODPermissionManager:getPermissions() => failed perms calculation")
@@ -179,15 +176,15 @@ export class ODPermissionManager<IdList extends ODPermissionManagerIdConstraint
179
176
  else throw new ODSystemError("Invalid minimum permission type at ODPermissionManager.hasPermissions()")
180
177
  }
181
178
  /**Check for permissions. (default calculation) */
182
- async #defaultCalculation(user:discord.User,channel?:discord.Channel|null,guild?:discord.Guild|null, settings?:ODPermissionSettings|null): Promise<ODPermissionResult> {
183
- const globalCalc = await this.#defaultGlobalCalculation(user,channel,guild,settings)
184
- const channelCalc = await this.#defaultChannelCalculation(user,channel,guild,settings)
179
+ private async defaultCalculation(user:discord.User,channel?:discord.Channel|null,guild?:discord.Guild|null, settings?:ODPermissionSettings|null): Promise<ODPermissionResult> {
180
+ const globalCalc = await this.defaultGlobalCalculation(user,channel,guild,settings)
181
+ const channelCalc = await this.defaultChannelCalculation(user,channel,guild,settings)
185
182
 
186
183
  if (globalCalc.level > channelCalc.level) return globalCalc
187
184
  else return channelCalc
188
185
  }
189
186
  /**Check for global permissions. Result will be compared with the channel perms in `#defaultCalculation()`. */
190
- async #defaultGlobalCalculation(user:discord.User,channel?:discord.Channel|null,guild?:discord.Guild|null, settings?:ODPermissionSettings|null): Promise<ODPermissionResult> {
187
+ private async defaultGlobalCalculation(user:discord.User,channel?:discord.Channel|null,guild?:discord.Guild|null, settings?:ODPermissionSettings|null): Promise<ODPermissionResult> {
191
188
  const idRegex = (settings && typeof settings.idRegex != "undefined") ? settings.idRegex : null
192
189
  const allowGlobalUserScope = (settings && typeof settings.allowGlobalUserScope != "undefined") ? settings.allowGlobalUserScope : true
193
190
  const allowGlobalRoleScope = (settings && typeof settings.allowGlobalRoleScope != "undefined") ? settings.allowGlobalRoleScope : true
@@ -219,7 +216,7 @@ export class ODPermissionManager<IdList extends ODPermissionManagerIdConstraint
219
216
  //check for global role permissions
220
217
  if (allowGlobalRoleScope){
221
218
  if (guild){
222
- const member = await this.#client.fetchGuildMember(guild,user.id)
219
+ const member = await this.client.fetchGuildMember(guild,user.id)
223
220
  if (member){
224
221
  const memberRoles = member.roles.cache.map((role) => role.id)
225
222
  const roles = this.getFiltered((permission) => (!idRegex || (idRegex && idRegex.test(permission.id.value))) && permission.scope == "global-role" && (permission.value instanceof discord.Role) && memberRoles.includes(permission.value.id) && permission.value.guild.id == guild.id)
@@ -250,7 +247,7 @@ export class ODPermissionManager<IdList extends ODPermissionManagerIdConstraint
250
247
  return {...this.defaultResult}
251
248
  }
252
249
  /**Check for channel permissions. Result will be compared with the global perms in `#defaultCalculation()`. */
253
- async #defaultChannelCalculation(user:discord.User,channel?:discord.Channel|null,guild?:discord.Guild|null, settings?:ODPermissionSettings|null): Promise<ODPermissionResult> {
250
+ private async defaultChannelCalculation(user:discord.User,channel?:discord.Channel|null,guild?:discord.Guild|null, settings?:ODPermissionSettings|null): Promise<ODPermissionResult> {
254
251
  const idRegex = (settings && typeof settings.idRegex != "undefined") ? settings.idRegex : null
255
252
  const allowChannelUserScope = (settings && typeof settings.allowChannelUserScope != "undefined") ? settings.allowChannelUserScope : true
256
253
  const allowChannelRoleScope = (settings && typeof settings.allowChannelRoleScope != "undefined") ? settings.allowChannelRoleScope : true
@@ -282,7 +279,7 @@ export class ODPermissionManager<IdList extends ODPermissionManagerIdConstraint
282
279
 
283
280
  //check for channel role permissions
284
281
  if (allowChannelRoleScope){
285
- const member = await this.#client.fetchGuildMember(guild,user.id)
282
+ const member = await this.client.fetchGuildMember(guild,user.id)
286
283
  if (member){
287
284
  const memberRoles = member.roles.cache.map((role) => role.id)
288
285
  const roles = this.getFiltered((permission) => (!idRegex || (idRegex && idRegex.test(permission.id.value))) && permission.scope == "channel-role" && permission.channel && (permission.channel.id == channel.id) && (permission.value instanceof discord.Role) && memberRoles.includes(permission.value.id) && permission.value.guild.id == guild.id)
@@ -328,12 +325,12 @@ export class ODPermissionManager<IdList extends ODPermissionManagerIdConstraint
328
325
  else return {hasPerms:true,isAdmin}
329
326
  }else{
330
327
  if (!guild || !member){
331
- this.#debug.debug("ODPermissionManager.checkCommandPerms(): Permission Error, Not in server! (#1)")
328
+ this.debug?.debug("ODPermissionManager.checkCommandPerms(): Permission Error, Not in server! (#1)")
332
329
  return {hasPerms:false,reason:"not-in-server"}
333
330
  }
334
- const role = await this.#client.fetchGuildRole(guild,permissionMode)
331
+ const role = await this.client.fetchGuildRole(guild,permissionMode)
335
332
  if (!role){
336
- this.#debug.debug("ODPermissionManager.checkCommandPerms(): Permission Error, Not in server! (#2)")
333
+ this.debug?.debug("ODPermissionManager.checkCommandPerms(): Permission Error, Not in server! (#2)")
337
334
  return {hasPerms:false,reason:"not-in-server"}
338
335
  }
339
336
  if (!role.members.has(member.id)) return {hasPerms:false,reason:"no-perms"}
@@ -201,7 +201,7 @@ export class ODPlugin extends ODManagerData {
201
201
  }
202
202
 
203
203
  /**Check if a npm dependency exists. */
204
- #checkDependency(id:string){
204
+ checkDependency(id:string){
205
205
  try{
206
206
  import.meta.resolve(id)
207
207
  return true
@@ -214,7 +214,7 @@ export class ODPlugin extends ODManagerData {
214
214
  dependenciesInstalled(){
215
215
  const missing: string[] = []
216
216
  this.data.npmDependencies.forEach((d) => {
217
- if (!this.#checkDependency(d)){
217
+ if (!this.checkDependency(d)){
218
218
  missing.push(d)
219
219
  }
220
220
  })
@@ -2,9 +2,11 @@
2
2
  //POST MODULE
3
3
  ///////////////////////////////////////
4
4
  import { ODId, ODManager, ODManagerData, ODNoGeneric, ODValidId } from "./base.js"
5
- import { ODMessageBuildResult, ODMessageBuildSentResult } from "./builder.js"
5
+ import { ODMessageBuildResult } from "./builder.js"
6
6
  import { ODDebugger } from "./console.js"
7
7
  import * as discord from "discord.js"
8
+ import { ODResponderSendResult } from "./responder.js"
9
+ import { ODMessageComponentBuildResult } from "./component.js"
8
10
 
9
11
  /**## ODPostManagerIdConstraint `type`
10
12
  * The constraint/layout for id mappings/interfaces of the `ODPostManager` class.
@@ -20,19 +22,19 @@ export type ODPostManagerIdConstraint = Record<string,ODPost<discord.GuildBasedC
20
22
  */
21
23
  export class ODPostManager<IdList extends ODPostManagerIdConstraint = ODPostManagerIdConstraint> extends ODManager<ODPost<discord.GuildBasedChannel>> {
22
24
  /**A reference to the main server of the bot */
23
- #guild: discord.Guild|null = null
25
+ protected guild: discord.Guild|null = null
24
26
 
25
27
  constructor(debug:ODDebugger){
26
28
  super(debug,"post")
27
29
  }
28
30
 
29
31
  add(data:ODPost<discord.GuildBasedChannel>, overwrite?:boolean): boolean {
30
- if (this.#guild) data.useGuild(this.#guild)
32
+ if (this.guild) data.useGuild(this.guild)
31
33
  return super.add(data,overwrite)
32
34
  }
33
35
  /**Initialize the post manager & all posts. */
34
36
  async init(guild:discord.Guild){
35
- this.#guild = guild
37
+ this.guild = guild
36
38
  for (const post of this.getAll()){
37
39
  post.useGuild(guild)
38
40
  await post.init()
@@ -71,7 +73,7 @@ export class ODPostManager<IdList extends ODPostManagerIdConstraint = ODPostMana
71
73
  */
72
74
  export class ODPost<ChannelType extends discord.GuildBasedChannel> extends ODManagerData {
73
75
  /**A reference to the main server of the bot */
74
- #guild: discord.Guild|null = null
76
+ protected guild: discord.Guild|null = null
75
77
  /**Is this post already initialized? */
76
78
  ready: boolean = false
77
79
  /**The discord.js channel */
@@ -86,7 +88,7 @@ export class ODPost<ChannelType extends discord.GuildBasedChannel> extends ODMan
86
88
 
87
89
  /**Use a specific guild in this class for fetching the channel*/
88
90
  useGuild(guild:discord.Guild|null){
89
- this.#guild = guild
91
+ this.guild = guild
90
92
  }
91
93
  /**Change the channel id to another channel! */
92
94
  setChannelId(id:string){
@@ -95,22 +97,41 @@ export class ODPost<ChannelType extends discord.GuildBasedChannel> extends ODMan
95
97
  /**Initialize the discord.js channel of this post. */
96
98
  async init(){
97
99
  if (this.ready) return
98
- if (!this.#guild) return this.channel = null
100
+ if (!this.guild) return this.channel = null
99
101
  try{
100
- this.channel = await this.#guild.channels.fetch(this.channelId) as ChannelType
102
+ this.channel = await this.guild.channels.fetch(this.channelId) as ChannelType
101
103
  }catch{
102
104
  this.channel = null
103
105
  }
104
106
  this.ready = true
105
107
  }
106
108
  /**Send a message to this channel using the Open Discord builder system */
107
- async send(msg:ODMessageBuildResult): Promise<ODMessageBuildSentResult<true>> {
109
+ async send(build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<true>> {
108
110
  if (!this.channel || !this.channel.isTextBased()) return {success:false,message:null}
109
111
  try{
110
- const sent = await this.channel.send(msg.message)
112
+ const finalMessage = this.getMessageFromBuildResult(build,"message")
113
+ const sent = await this.channel.send(finalMessage)
111
114
  return {success:true,message:sent}
112
115
  }catch{
113
116
  return {success:false,message:null}
114
117
  }
115
118
  }
119
+ /**Get the final `messageCreateOptions` from a returned build result from builders/components. */
120
+ protected getMessageFromBuildResult(build:ODMessageBuildResult|ODMessageComponentBuildResult,type:"interaction"|"message"){
121
+ const msgFlags: number[] = []
122
+ let msgData: discord.MessageCreateOptions
123
+ if ('message' in build){
124
+ //USING BUILDERS (deprecated)
125
+ msgData = build.message
126
+ if (build.ephemeral) msgFlags.push(discord.MessageFlags.Ephemeral)
127
+ }else{
128
+ //USING COMPONENTS
129
+ msgData = build.msg
130
+ if (type == "interaction" && build.ephemeral) msgFlags.push(discord.MessageFlags.Ephemeral) //disabled with regular messages
131
+ if (build.componentsV2) msgFlags.push(discord.MessageFlags.IsComponentsV2)
132
+ if (build.supressEmbeds) msgFlags.push(discord.MessageFlags.SuppressEmbeds)
133
+ if (build.supressNotifications) msgFlags.push(discord.MessageFlags.SuppressNotifications)
134
+ }
135
+ return Object.assign(msgData,{flags:msgFlags})
136
+ }
116
137
  }