@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
@@ -13,7 +13,6 @@ export type ODConfigManagerIdConstraint = Record<string, ODConfig<any>>;
13
13
  * You can use this class to get/change/add a config file (`ODConfig`) in your plugin!
14
14
  */
15
15
  export declare class ODConfigManager<IdList extends ODConfigManagerIdConstraint = ODConfigManagerIdConstraint> extends ODManager<ODConfig<any>> {
16
- #private;
17
16
  constructor(debug: ODDebugger);
18
17
  add(data: ODConfig<any> | ODConfig<any>[], overwrite?: boolean): boolean;
19
18
  /**Init all config files. */
@@ -31,7 +30,7 @@ export declare class ODConfigManager<IdList extends ODConfigManagerIdConstraint
31
30
  *
32
31
  * You can use this class if you want to create your own config implementation (e.g. `yml`, `xml`,...)!
33
32
  */
34
- export declare class ODConfig<Data extends any> extends ODManagerData {
33
+ export declare abstract class ODConfig<Data extends any> extends ODManagerData {
35
34
  /**The name of the file with extension. */
36
35
  file: string;
37
36
  /**The path to the file relative to the main directory. */
@@ -78,3 +77,32 @@ export declare class ODJsonConfig<Data extends any> extends ODConfig<Data> {
78
77
  /**Save the edited config to the filesystem. This is used by the Interactive Setup CLI. It's not recommended to use this while the bot is running. */
79
78
  save(): ODPromiseVoid;
80
79
  }
80
+ /**## ODJsonCommentsConfig `class`
81
+ * An Open Discord JSONC (`.jsonc`) config.
82
+ * Use this class to get & edit variables from the config files or to create your own JSON config!
83
+ * @example
84
+ * //create a config from: ./config/test.jsonc with the id "some-config"
85
+ * const config = new api.ODJsonCommentsConfig("some-config","test.jsonc")
86
+ *
87
+ * //create a config with custom dir: ./plugins/testplugin/test.jsonc
88
+ * const config = new api.ODJsonCommentsConfig("plugin-config","test.jsonc","./plugins/testplugin/")
89
+ */
90
+ export declare class ODJsonCommentsConfig<Data extends any> extends ODConfig<Data> {
91
+ formatter: fjs.custom.BaseFormatter;
92
+ constructor(id: ODValidId, file: string, customPath?: string, formatter?: fjs.custom.BaseFormatter);
93
+ /**Init the config. */
94
+ init(): ODPromiseVoid;
95
+ /**Reload the config. Be aware that this doesn't update the config data everywhere in the bot! */
96
+ reload(): void;
97
+ /**Save the edited config to the filesystem. This is used by the Interactive Setup CLI. It's not recommended to use this while the bot is running. */
98
+ save(): ODPromiseVoid;
99
+ }
100
+ /**## ODMemoryConfig `class`
101
+ * An Open Discord memory config.
102
+ * This config lives in-memory and does not have any connection to the filesystem.
103
+ *
104
+ * It is perfect for temporary configs or using the `ODChecker` without a real config file.
105
+ */
106
+ export declare class ODMemoryConfig<Data extends any> extends ODConfig<Data> {
107
+ constructor(id: ODValidId, data: Data);
108
+ }
@@ -5,6 +5,7 @@ import { ODManager, ODManagerData, ODSystemError } from "./base.js";
5
5
  import nodepath from "path";
6
6
  import fs from "fs";
7
7
  import * as fjs from "formatted-json-stringify";
8
+ import { jsonc } from "jsonc";
8
9
  /**## ODConfigManager `class`
9
10
  * This is an Open Discord config manager.
10
11
  *
@@ -13,17 +14,19 @@ import * as fjs from "formatted-json-stringify";
13
14
  * You can use this class to get/change/add a config file (`ODConfig`) in your plugin!
14
15
  */
15
16
  export class ODConfigManager extends ODManager {
16
- /**Alias to Open Discord debugger. */
17
- #debug;
18
17
  constructor(debug) {
19
18
  super(debug, "config");
20
- this.#debug = debug;
21
19
  }
22
20
  add(data, overwrite) {
23
- if (Array.isArray(data))
24
- data.forEach((d) => d.useDebug(this.#debug));
25
- else
26
- data.useDebug(this.#debug);
21
+ if (this.debug) {
22
+ if (Array.isArray(data)) {
23
+ for (const d of data) {
24
+ d.useDebug(this.debug);
25
+ }
26
+ }
27
+ else
28
+ data.useDebug(this.debug);
29
+ }
27
30
  return super.add(data, overwrite);
28
31
  }
29
32
  /**Init all config files. */
@@ -171,3 +174,83 @@ export class ODJsonConfig extends ODConfig {
171
174
  }
172
175
  }
173
176
  }
177
+ /**## ODJsonCommentsConfig `class`
178
+ * An Open Discord JSONC (`.jsonc`) config.
179
+ * Use this class to get & edit variables from the config files or to create your own JSON config!
180
+ * @example
181
+ * //create a config from: ./config/test.jsonc with the id "some-config"
182
+ * const config = new api.ODJsonCommentsConfig("some-config","test.jsonc")
183
+ *
184
+ * //create a config with custom dir: ./plugins/testplugin/test.jsonc
185
+ * const config = new api.ODJsonCommentsConfig("plugin-config","test.jsonc","./plugins/testplugin/")
186
+ */
187
+ export class ODJsonCommentsConfig extends ODConfig {
188
+ formatter;
189
+ constructor(id, file, customPath, formatter) {
190
+ super(id, {});
191
+ this.file = (file.endsWith(".jsonc")) ? file : file + ".jsonc";
192
+ this.path = customPath ? nodepath.join("./", customPath, this.file) : nodepath.join("./config/", this.file);
193
+ this.formatter = formatter ?? new fjs.DefaultFormatter(null, true, " ");
194
+ }
195
+ /**Init the config. */
196
+ init() {
197
+ if (!fs.existsSync(this.path))
198
+ throw new ODSystemError("Unable to parse JSONC config \"" + nodepath.join("./", this.path) + "\", the file doesn't exist!");
199
+ try {
200
+ this.data = jsonc.parse(fs.readFileSync(this.path).toString());
201
+ super.init();
202
+ }
203
+ catch (err) {
204
+ process.emit("uncaughtException", err);
205
+ throw new ODSystemError("Unable to parse JSONC config \"" + nodepath.join("./", this.path) + "\"!");
206
+ }
207
+ }
208
+ /**Reload the config. Be aware that this doesn't update the config data everywhere in the bot! */
209
+ reload() {
210
+ if (!this.initiated)
211
+ throw new ODSystemError("Unable to reload JSONC config \"" + nodepath.join("./", this.path) + "\", the file hasn't been initiated yet!");
212
+ if (!fs.existsSync(this.path))
213
+ throw new ODSystemError("Unable to JSONC reload config \"" + nodepath.join("./", this.path) + "\", the file doesn't exist!");
214
+ try {
215
+ this.data = jsonc.parse(fs.readFileSync(this.path).toString());
216
+ super.reload();
217
+ this.reloadListeners.forEach((cb) => {
218
+ try {
219
+ cb();
220
+ }
221
+ catch (err) {
222
+ process.emit("uncaughtException", err);
223
+ }
224
+ });
225
+ }
226
+ catch (err) {
227
+ process.emit("uncaughtException", err);
228
+ throw new ODSystemError("Unable to reload JSONC config \"" + nodepath.join("./", this.path) + "\"!");
229
+ }
230
+ }
231
+ /**Save the edited config to the filesystem. This is used by the Interactive Setup CLI. It's not recommended to use this while the bot is running. */
232
+ save() {
233
+ if (!this.initiated)
234
+ throw new ODSystemError("Unable to save JSONC config \"" + nodepath.join("./", this.path) + "\", the file hasn't been initiated yet!");
235
+ try {
236
+ const contents = this.formatter.stringify(this.data);
237
+ fs.writeFileSync(this.path, contents);
238
+ super.save();
239
+ }
240
+ catch (err) {
241
+ process.emit("uncaughtException", err);
242
+ throw new ODSystemError("Unable to save JSONC config \"" + nodepath.join("./", this.path) + "\"!");
243
+ }
244
+ }
245
+ }
246
+ /**## ODMemoryConfig `class`
247
+ * An Open Discord memory config.
248
+ * This config lives in-memory and does not have any connection to the filesystem.
249
+ *
250
+ * It is perfect for temporary configs or using the `ODChecker` without a real config file.
251
+ */
252
+ export class ODMemoryConfig extends ODConfig {
253
+ constructor(id, data) {
254
+ super(id, data);
255
+ }
256
+ }
@@ -123,7 +123,6 @@ export type ODConsoleMessageTypes = "info" | "system" | "plugin" | "debug" | "wa
123
123
  * The debug file (`debug.txt`) is handled in a sub-manager!
124
124
  */
125
125
  export declare class ODConsoleManager {
126
- #private;
127
126
  /**The history of `ODConsoleMessage`'s and `ODError`'s since startup */
128
127
  history: (ODConsoleMessage | ODError)[];
129
128
  /**The max length of the history. The oldest messages will be removed when over the limit */
@@ -137,6 +136,8 @@ export declare class ODConsoleManager {
137
136
  log(message: ODConsoleMessage): void;
138
137
  log(message: ODError): void;
139
138
  log(message: string, type?: ODConsoleMessageTypes, params?: ODConsoleMessageParam[]): void;
139
+ /**Shorten the history when it exceeds the max history length! */
140
+ protected purgeHistory(): void;
140
141
  }
141
142
  /**## ODDebugFileManager `class`
142
143
  * This is the Open Discord debug file manager.
@@ -147,7 +148,6 @@ export declare class ODConsoleManager {
147
148
  * Using this class, you can change the max length of this file and some other cool things!
148
149
  */
149
150
  export declare class ODDebugFileManager {
150
- #private;
151
151
  /**The path to the debugfile (`./debug.txt` by default) */
152
152
  path: string;
153
153
  /**The filename of the debugfile (`debug.txt` by default) */
@@ -157,6 +157,16 @@ export declare class ODDebugFileManager {
157
157
  /**The max length of the debug file. */
158
158
  maxlines: number;
159
159
  constructor(path: string, filename: string, maxlines: number, version: ODVersion);
160
+ /**Check if the debug file exists */
161
+ protected existsDebugFile(): boolean;
162
+ /**Read from the debug file */
163
+ protected readDebugFile(): string | false;
164
+ /**Write to the debug file and shorten it when needed. */
165
+ protected writeDebugFile(text: string): void;
166
+ /**Generate the statistics/header of the debug file (containing the version) */
167
+ protected createStatsText(): string;
168
+ /**Write the statistics/header to the debug file on startup */
169
+ protected writeStartupStats(): void;
160
170
  /**Write an `ODConsoleMessage` to the debug file */
161
171
  writeConsoleMessage(message: ODConsoleMessage): void;
162
172
  /**Write an `ODError` to the debug file */
@@ -289,9 +299,10 @@ export type ODLiveStatusManagerIdConstraint = Record<string, ODLiveStatusSource>
289
299
  * Access it in the global `opendiscord.startscreen.livestatus` variable!
290
300
  */
291
301
  export declare class ODLiveStatusManager<IdList extends ODLiveStatusManagerIdConstraint = ODLiveStatusManagerIdConstraint> extends ODManager<ODLiveStatusSource> {
292
- #private;
293
302
  /**The class responsible for rendering the livestatus messages. */
294
303
  renderer: ODLiveStatusRenderer;
304
+ /**A reference to the ODMain or "opendiscord" global variable */
305
+ protected main: ODMain | null;
295
306
  constructor(debug: ODDebugger, console: ODConsoleManager);
296
307
  /**Get the messages from all sources combined! */
297
308
  getAllMessages(): Promise<ODLiveStatusSourceData[]>;
@@ -310,7 +321,8 @@ export declare class ODLiveStatusManager<IdList extends ODLiveStatusManagerIdCon
310
321
  * It's responsible for rendering all LiveStatus messages to the console.
311
322
  */
312
323
  export declare class ODLiveStatusRenderer {
313
- #private;
324
+ /**A reference to the ODConsoleManager or "opendiscord.console" global variable */
325
+ protected console: ODConsoleManager;
314
326
  constructor(console: ODConsoleManager);
315
327
  /**Render all messages */
316
328
  render(messages: ODLiveStatusSourceData[]): string;
@@ -252,10 +252,10 @@ export class ODConsoleManager {
252
252
  this.debugfile.writeConsoleMessage(newMessage);
253
253
  this.history.push(newMessage);
254
254
  }
255
- this.#purgeHistory();
255
+ this.purgeHistory();
256
256
  }
257
257
  /**Shorten the history when it exceeds the max history length! */
258
- #purgeHistory() {
258
+ purgeHistory() {
259
259
  if (this.history.length > this.historylength)
260
260
  this.history.shift();
261
261
  }
@@ -282,15 +282,15 @@ export class ODDebugFileManager {
282
282
  this.filename = filename;
283
283
  this.version = version;
284
284
  this.maxlines = maxlines;
285
- this.#writeStartupStats();
285
+ this.writeStartupStats();
286
286
  }
287
287
  /**Check if the debug file exists */
288
- #existsDebugFile() {
288
+ existsDebugFile() {
289
289
  return fs.existsSync(this.path);
290
290
  }
291
291
  /**Read from the debug file */
292
- #readDebugFile() {
293
- if (this.#existsDebugFile()) {
292
+ readDebugFile() {
293
+ if (this.existsDebugFile()) {
294
294
  try {
295
295
  return fs.readFileSync(this.path).toString();
296
296
  }
@@ -303,8 +303,8 @@ export class ODDebugFileManager {
303
303
  }
304
304
  }
305
305
  /**Write to the debug file and shorten it when needed. */
306
- #writeDebugFile(text) {
307
- const currenttext = this.#readDebugFile();
306
+ writeDebugFile(text) {
307
+ const currenttext = this.readDebugFile();
308
308
  if (currenttext) {
309
309
  const splitted = currenttext.split("\n");
310
310
  if (splitted.length + text.split("\n").length > this.maxlines) {
@@ -315,12 +315,12 @@ export class ODDebugFileManager {
315
315
  }
316
316
  else {
317
317
  //write new file:
318
- const newtext = this.#createStatsText() + text;
318
+ const newtext = this.createStatsText() + text;
319
319
  fs.writeFileSync(this.path, newtext);
320
320
  }
321
321
  }
322
322
  /**Generate the statistics/header of the debug file (containing the version) */
323
- #createStatsText() {
323
+ createStatsText() {
324
324
  const date = new Date();
325
325
  const dstring = `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
326
326
  return [
@@ -332,8 +332,8 @@ export class ODDebugFileManager {
332
332
  ].join("\n");
333
333
  }
334
334
  /**Write the statistics/header to the debug file on startup */
335
- #writeStartupStats() {
336
- const currenttext = this.#readDebugFile();
335
+ writeStartupStats() {
336
+ const currenttext = this.readDebugFile();
337
337
  if (currenttext) {
338
338
  //edit previous file:
339
339
  const splitted = currenttext.split("\n");
@@ -341,31 +341,31 @@ export class ODDebugFileManager {
341
341
  if (splitted.length + 11 > this.maxlines) {
342
342
  splitted.splice(0, ((splitted.length + 11) - this.maxlines));
343
343
  }
344
- splitted.unshift(this.#createStatsText());
344
+ splitted.unshift(this.createStatsText());
345
345
  splitted.push("\n---------------------------------------------------------------------\n---------------------------------------------------------------------\n");
346
346
  fs.writeFileSync(this.path, splitted.join("\n"));
347
347
  }
348
348
  else {
349
349
  //write new file:
350
- const newtext = this.#createStatsText();
350
+ const newtext = this.createStatsText();
351
351
  fs.writeFileSync(this.path, newtext);
352
352
  }
353
353
  }
354
354
  /**Write an `ODConsoleMessage` to the debug file */
355
355
  writeConsoleMessage(message) {
356
- this.#writeDebugFile(message.toDebugString());
356
+ this.writeDebugFile(message.toDebugString());
357
357
  }
358
358
  /**Write an `ODError` to the debug file */
359
359
  writeErrorMessage(error) {
360
- this.#writeDebugFile(error.toDebugString());
360
+ this.writeDebugFile(error.toDebugString());
361
361
  }
362
362
  /**Write custom text to the debug file */
363
363
  writeText(text) {
364
- this.#writeDebugFile(text);
364
+ this.writeDebugFile(text);
365
365
  }
366
366
  /**Write a custom note to the debug file (starting with `[NOTE]:`) */
367
367
  writeNote(text) {
368
- this.#writeDebugFile("[NOTE]: " + text);
368
+ this.writeDebugFile("[NOTE]: " + text);
369
369
  }
370
370
  }
371
371
  /**## ODDebugger `class`
@@ -506,19 +506,19 @@ export class ODLiveStatusManager extends ODManager {
506
506
  /**The class responsible for rendering the livestatus messages. */
507
507
  renderer;
508
508
  /**A reference to the ODMain or "opendiscord" global variable */
509
- #main = null;
509
+ main = null;
510
510
  constructor(debug, console) {
511
511
  super(debug, "livestatus source");
512
512
  this.renderer = new ODLiveStatusRenderer(console);
513
513
  }
514
514
  /**Get the messages from all sources combined! */
515
515
  async getAllMessages() {
516
- if (!this.#main)
516
+ if (!this.main)
517
517
  throw new ODSystemError("ODLiveStatusManager:getAllMessages() --> Unable to get messages, 'opendiscord/ODMain' has not been connected!");
518
518
  const messages = [];
519
519
  for (const source of this.getAll()) {
520
520
  try {
521
- messages.push(...(await source.getMessages(this.#main)));
521
+ messages.push(...(await source.getMessages(this.main)));
522
522
  }
523
523
  catch { }
524
524
  }
@@ -526,7 +526,7 @@ export class ODLiveStatusManager extends ODManager {
526
526
  }
527
527
  /**Set the opendiscord `ODMain` class to use for fetching message filters. */
528
528
  useMain(main) {
529
- this.#main = main;
529
+ this.main = main;
530
530
  }
531
531
  get(id) {
532
532
  return super.get(id);
@@ -545,9 +545,9 @@ export class ODLiveStatusManager extends ODManager {
545
545
  */
546
546
  export class ODLiveStatusRenderer {
547
547
  /**A reference to the ODConsoleManager or "opendiscord.console" global variable */
548
- #console;
548
+ console;
549
549
  constructor(console) {
550
- this.#console = console;
550
+ this.console = console;
551
551
  }
552
552
  /**Render all messages */
553
553
  render(messages) {
@@ -583,7 +583,7 @@ export class ODLiveStatusRenderer {
583
583
  return final.join("\n");
584
584
  }
585
585
  catch {
586
- this.#console.log("Failed to render LiveStatus messages!", "error");
586
+ this.console.log("Failed to render LiveStatus messages!", "error");
587
587
  return "";
588
588
  }
589
589
  }
@@ -42,19 +42,19 @@ export declare class ODCooldownData<Data extends object> extends ODManagerData {
42
42
  *
43
43
  * There are also premade cooldowns available in the bot!
44
44
  */
45
- export declare class ODCooldown<Data extends object> extends ODManagerData {
45
+ export declare abstract class ODCooldown<Data extends object> extends ODManagerData {
46
46
  data: ODManager<ODCooldownData<Data>>;
47
47
  /**Is this cooldown already initialized? */
48
48
  ready: boolean;
49
49
  constructor(id: ODValidId);
50
50
  /**Check this id and start cooldown when it exeeds the limit! Returns `true` when on cooldown! */
51
- use(id: string): boolean;
51
+ abstract use(id: string): boolean;
52
52
  /**Check this id without starting or updating the cooldown. Returns `true` when on cooldown! */
53
- check(id: string): boolean;
53
+ abstract check(id: string): boolean;
54
54
  /**Remove the cooldown for an id when available.*/
55
- delete(id: string): void;
55
+ abstract delete(id: string): void;
56
56
  /**Initialize the internal systems of this cooldown. */
57
- init(): Promise<void>;
57
+ abstract init(): Promise<void> | void;
58
58
  }
59
59
  /**## ODCounterCooldown `class`
60
60
  * This is an Open Discord counter cooldown.
@@ -1,7 +1,7 @@
1
1
  ///////////////////////////////////////
2
2
  //COOLDOWN MODULE
3
3
  ///////////////////////////////////////
4
- import { ODManager, ODSystemError, ODManagerData } from "./base.js";
4
+ import { ODManager, ODManagerData } from "./base.js";
5
5
  /**## ODCooldownManager `class`
6
6
  * This is an Open Discord cooldown manager.
7
7
  *
@@ -60,22 +60,6 @@ export class ODCooldown extends ODManagerData {
60
60
  constructor(id) {
61
61
  super(id);
62
62
  }
63
- /**Check this id and start cooldown when it exeeds the limit! Returns `true` when on cooldown! */
64
- use(id) {
65
- throw new ODSystemError("Tried to use an unimplemented ODCooldown!");
66
- }
67
- /**Check this id without starting or updating the cooldown. Returns `true` when on cooldown! */
68
- check(id) {
69
- throw new ODSystemError("Tried to use an unimplemented ODCooldown!");
70
- }
71
- /**Remove the cooldown for an id when available.*/
72
- delete(id) {
73
- throw new ODSystemError("Tried to use an unimplemented ODCooldown!");
74
- }
75
- /**Initialize the internal systems of this cooldown. */
76
- async init() {
77
- throw new ODSystemError("Tried to use an unimplemented ODCooldown!");
78
- }
79
63
  }
80
64
  /**## ODCounterCooldown `class`
81
65
  * This is an Open Discord counter cooldown.
@@ -33,36 +33,44 @@ export type ODDatabaseIdConstraint = Record<string, ODValidJsonType>;
33
33
  *
34
34
  * You can use this class if you want to create your own database implementation (e.g. `mongodb`, `mysql`,...)!
35
35
  */
36
- export declare class ODDatabase<IdList extends ODDatabaseIdConstraint = ODDatabaseIdConstraint> extends ODManagerData {
36
+ export declare abstract class ODDatabase<IdList extends ODDatabaseIdConstraint = ODDatabaseIdConstraint> extends ODManagerData {
37
37
  /**The name of the file with extension. */
38
38
  file: string;
39
39
  /**The path to the file relative to the main directory. */
40
40
  path: string;
41
41
  /**Init the database. */
42
- init(): ODPromiseVoid;
42
+ abstract init(): ODPromiseVoid;
43
43
  /**Add/Overwrite a specific category & key in the database. Returns `true` when overwritten. */
44
- set<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId, key: string, value: IdList[CategoryId]): ODOptionalPromise<boolean>;
45
- set(category: string, key: string, value: ODValidJsonType): ODOptionalPromise<boolean>;
44
+ abstract set<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId, key: string, value: IdList[CategoryId]): ODOptionalPromise<boolean>;
45
+ abstract set(category: string, key: string, value: ODValidJsonType): ODOptionalPromise<boolean>;
46
+ abstract set(category: string, key: string, value: ODValidJsonType): ODOptionalPromise<boolean>;
46
47
  /**Get a specific category & key in the database */
47
- get<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId, key: string): ODOptionalPromise<IdList[CategoryId] | undefined>;
48
- get(category: string, key: string): ODOptionalPromise<ODValidJsonType | undefined>;
48
+ abstract get<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId, key: string): ODOptionalPromise<IdList[CategoryId] | undefined>;
49
+ abstract get(category: string, key: string): ODOptionalPromise<ODValidJsonType | undefined>;
50
+ abstract get(category: string, key: string): ODOptionalPromise<ODValidJsonType | undefined>;
49
51
  /**Delete a specific category & key in the database */
50
- delete<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId, key: string): ODOptionalPromise<boolean>;
51
- delete(category: string, key: string): ODOptionalPromise<boolean>;
52
+ abstract delete<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId, key: string): ODOptionalPromise<boolean>;
53
+ abstract delete(category: string, key: string): ODOptionalPromise<boolean>;
54
+ abstract delete(category: string, key: string): ODOptionalPromise<boolean>;
52
55
  /**Check if a specific category & key exists in the database */
53
- exists(category: keyof ODNoGeneric<IdList>, key: string): ODOptionalPromise<boolean>;
54
- exists(category: string, key: string): ODOptionalPromise<boolean>;
56
+ abstract exists(category: keyof ODNoGeneric<IdList>, key: string): ODOptionalPromise<boolean>;
57
+ abstract exists(category: string, key: string): ODOptionalPromise<boolean>;
58
+ abstract exists(category: string, key: string): ODOptionalPromise<boolean>;
55
59
  /**Get a specific category in the database */
56
- getCategory<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId): ODOptionalPromise<{
60
+ abstract getCategory<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId): ODOptionalPromise<{
57
61
  key: string;
58
62
  value: IdList[CategoryId];
59
63
  }[] | undefined>;
60
- getCategory(category: string): ODOptionalPromise<{
64
+ abstract getCategory(category: string): ODOptionalPromise<{
65
+ key: string;
66
+ value: ODValidJsonType;
67
+ }[] | undefined>;
68
+ abstract getCategory(category: string): ODOptionalPromise<{
61
69
  key: string;
62
70
  value: ODValidJsonType;
63
71
  }[] | undefined>;
64
72
  /**Get all values in the database */
65
- getAll(): ODOptionalPromise<ODJsonDatabaseStructure>;
73
+ abstract getAll(): ODOptionalPromise<ODJsonDatabaseStructure>;
66
74
  }
67
75
  /**## ODJsonDatabaseStructure `type`
68
76
  * This is the structure of how a JSON database file!
@@ -47,29 +47,6 @@ export class ODDatabase extends ODManagerData {
47
47
  file = "";
48
48
  /**The path to the file relative to the main directory. */
49
49
  path = "";
50
- /**Init the database. */
51
- init() {
52
- //nothing
53
- }
54
- set(category, key, value) {
55
- return false;
56
- }
57
- get(category, key) {
58
- return undefined;
59
- }
60
- delete(category, key) {
61
- return false;
62
- }
63
- exists(category, key) {
64
- return false;
65
- }
66
- getCategory(category) {
67
- return undefined;
68
- }
69
- /**Get all values in the database */
70
- getAll() {
71
- return [];
72
- }
73
50
  }
74
51
  /**## ODJsonDatabase `class`
75
52
  * This is an Open Discord JSON database.
@@ -11,7 +11,8 @@ export type ODEventCallback = (...args: any) => ODPromiseVoid;
11
11
  * The function of this specific class is to manage all listeners for a specifc event!
12
12
  */
13
13
  export declare class ODEvent<Callback extends ODEventCallback = ODEventCallback> extends ODManagerData {
14
- #private;
14
+ /**Alias to Open Discord debugger. */
15
+ protected debug?: ODDebugger;
15
16
  /**The list of permanent listeners. */
16
17
  listeners: Function[];
17
18
  /**The list of one-time listeners. List is cleared every time the event is emitted. */
@@ -20,6 +21,8 @@ export declare class ODEvent<Callback extends ODEventCallback = ODEventCallback>
20
21
  listenerLimit: number;
21
22
  /**Use the Open Discord debugger in this manager for logs*/
22
23
  useDebug(debug: ODDebugger | null): void;
24
+ /**Get a collection of listeners combined from both types. Also clears the one-time listeners array! */
25
+ protected getCurrentListeners(): Function[];
23
26
  /**Edit the listener limit */
24
27
  setListenerLimit(limit: number): void;
25
28
  /**Add a permanent callback to this event. This will stay as long as the bot is running! */
@@ -44,7 +47,6 @@ export type ODEventManagerIdConstraint = Record<string, ODEvent>;
44
47
  * All events are available in the `opendiscord.events` global!
45
48
  */
46
49
  export declare class ODEventManager<IdList extends ODEventManagerIdConstraint = ODEventManagerIdConstraint> extends ODManager<ODEvent> {
47
- #private;
48
50
  constructor(debug: ODDebugger);
49
51
  add(data: ODEvent, overwrite?: boolean): boolean;
50
52
  get<EventId extends keyof ODNoGeneric<IdList>>(id: EventId): IdList[EventId];
@@ -11,7 +11,7 @@ import { ODWarningConsoleMessage } from "./console.js";
11
11
  */
12
12
  export class ODEvent extends ODManagerData {
13
13
  /**Alias to Open Discord debugger. */
14
- #debug;
14
+ debug;
15
15
  /**The list of permanent listeners. */
16
16
  listeners = [];
17
17
  /**The list of one-time listeners. List is cleared every time the event is emitted. */
@@ -20,10 +20,10 @@ export class ODEvent extends ODManagerData {
20
20
  listenerLimit = 25;
21
21
  /**Use the Open Discord debugger in this manager for logs*/
22
22
  useDebug(debug) {
23
- this.#debug = debug ?? undefined;
23
+ this.debug = debug ?? undefined;
24
24
  }
25
25
  /**Get a collection of listeners combined from both types. Also clears the one-time listeners array! */
26
- #getCurrentListeners() {
26
+ getCurrentListeners() {
27
27
  const final = [];
28
28
  this.oncelisteners.forEach((l) => final.push(l));
29
29
  this.listeners.forEach((l) => final.push(l));
@@ -38,8 +38,8 @@ export class ODEvent extends ODManagerData {
38
38
  listen(callback) {
39
39
  this.listeners.push(callback);
40
40
  if (this.listeners.length > this.listenerLimit) {
41
- if (this.#debug)
42
- this.#debug.console.log(new ODWarningConsoleMessage("Possible event memory leak detected!", [
41
+ if (this.debug)
42
+ this.debug.console.log(new ODWarningConsoleMessage("Possible event memory leak detected!", [
43
43
  { key: "event", value: this.id.value },
44
44
  { key: "listeners", value: this.listeners.length.toString() }
45
45
  ]));
@@ -57,7 +57,7 @@ export class ODEvent extends ODManagerData {
57
57
  }
58
58
  /**Emit this event to all listeners. You are required to provide all parameters of the event! */
59
59
  async emit(params) {
60
- for (const listener of this.#getCurrentListeners()) {
60
+ for (const listener of this.getCurrentListeners()) {
61
61
  try {
62
62
  await listener(...params);
63
63
  }
@@ -76,14 +76,12 @@ export class ODEvent extends ODManagerData {
76
76
  * All events are available in the `opendiscord.events` global!
77
77
  */
78
78
  export class ODEventManager extends ODManager {
79
- /**Reference to the Open Discord debugger */
80
- #debug;
81
79
  constructor(debug) {
82
80
  super(debug, "event");
83
- this.#debug = debug;
84
81
  }
85
82
  add(data, overwrite) {
86
- data.useDebug(this.#debug);
83
+ if (this.debug)
84
+ data.useDebug(this.debug);
87
85
  return super.add(data, overwrite);
88
86
  }
89
87
  get(id) {
@@ -36,7 +36,7 @@ export type ODFuseStringArray<FuseList extends object> = {
36
36
  */
37
37
  export declare class ODFuseManager<FuseList extends object> {
38
38
  /**A list of all the defaults */
39
- private fuses;
39
+ protected fuses: FuseList;
40
40
  constructor(fuses: FuseList);
41
41
  /**Set a fuse to a specific value. Remember! All plugins can edit these values, so your value could be overwritten! */
42
42
  setFuse<DefaultName extends keyof FuseList>(key: DefaultName, value: FuseList[DefaultName]): void;