@open-discord-bots/framework 0.3.0 → 0.3.2

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 (64) 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/dist/utilities/index.d.ts +7 -0
  41. package/dist/utilities/index.js +27 -0
  42. package/package.json +1 -1
  43. package/src/api/main.ts +1 -1
  44. package/src/api/modules/base.ts +75 -77
  45. package/src/api/modules/builder.ts +0 -10
  46. package/src/api/modules/checker.ts +31 -31
  47. package/src/api/modules/client.ts +144 -136
  48. package/src/api/modules/component.ts +11 -7
  49. package/src/api/modules/config.ts +8 -6
  50. package/src/api/modules/console.ts +25 -25
  51. package/src/api/modules/event.ts +6 -10
  52. package/src/api/modules/fuse.ts +1 -1
  53. package/src/api/modules/helpmenu.ts +4 -7
  54. package/src/api/modules/language.ts +6 -9
  55. package/src/api/modules/permission.ts +17 -20
  56. package/src/api/modules/plugin.ts +2 -2
  57. package/src/api/modules/post.ts +31 -10
  58. package/src/api/modules/progressbar.ts +34 -34
  59. package/src/api/modules/responder.ts +232 -181
  60. package/src/api/modules/session.ts +14 -14
  61. package/src/api/modules/startscreen.ts +3 -6
  62. package/src/api/modules/statistic.ts +4 -7
  63. package/src/api/modules/worker.ts +3 -3
  64. package/src/utilities/index.ts +22 -0
@@ -45,12 +45,21 @@ export type ODSessionTimeoutCallback = (id: string, timeout: "default" | "custom
45
45
  * You can almost compare it to the PHP session system.
46
46
  */
47
47
  export declare class ODSession extends ODManagerData {
48
- #private;
48
+ /**The history of previously generated instance ids. Used to reduce the risk of generating the same id twice. */
49
+ protected idHistory: string[];
50
+ /**The max length of the instance id history. */
51
+ protected maxIdHistoryLength: number;
49
52
  /**An array of all the currently active session instances. */
50
53
  sessions: ODSessionInstance[];
51
54
  /**The default amount of minutes before a session automatically stops. */
52
55
  timeoutMinutes: number;
56
+ /**The id of the auto-timeout session checker interval */
57
+ protected intervalId: NodeJS.Timeout;
58
+ /**Listeners for when a session times-out. */
59
+ protected timeoutListeners: ODSessionTimeoutCallback[];
53
60
  constructor(id: ODValidId, intervalSeconds?: number);
61
+ /**Create a unique hex id of 8 characters and add it to the instance id history */
62
+ protected createUniqueId(): string;
54
63
  /**Stop the global interval that automatically deletes timed-out sessions. (This action can't be reverted!) */
55
64
  stopAutoTimeout(): void;
56
65
  /**Start a session instance with data. Returns the unique id required to access the session. */
@@ -33,21 +33,21 @@ export class ODSessionManager extends ODManager {
33
33
  */
34
34
  export class ODSession extends ODManagerData {
35
35
  /**The history of previously generated instance ids. Used to reduce the risk of generating the same id twice. */
36
- #idHistory = [];
36
+ idHistory = [];
37
37
  /**The max length of the instance id history. */
38
- #maxIdHistoryLength = 500;
38
+ maxIdHistoryLength = 500;
39
39
  /**An array of all the currently active session instances. */
40
40
  sessions = [];
41
41
  /**The default amount of minutes before a session automatically stops. */
42
42
  timeoutMinutes = 30;
43
43
  /**The id of the auto-timeout session checker interval */
44
- #intervalId;
44
+ intervalId;
45
45
  /**Listeners for when a session times-out. */
46
- #timeoutListeners = [];
46
+ timeoutListeners = [];
47
47
  constructor(id, intervalSeconds) {
48
48
  super(id);
49
49
  //create the auto-timeout session checker
50
- this.#intervalId = setInterval(() => {
50
+ this.intervalId = setInterval(() => {
51
51
  const deletableSessions = [];
52
52
  //collect all deletable sessions
53
53
  this.sessions.forEach((session) => {
@@ -65,30 +65,30 @@ export class ODSession extends ODManagerData {
65
65
  const index = this.sessions.findIndex((s) => s.id === session.instance.id);
66
66
  this.sessions.splice(index, 1);
67
67
  //emit timeout listeners
68
- this.#timeoutListeners.forEach((cb) => cb(session.instance.id, session.reason, session.instance.data, new Date(session.instance.creation)));
68
+ this.timeoutListeners.forEach((cb) => cb(session.instance.id, session.reason, session.instance.data, new Date(session.instance.creation)));
69
69
  });
70
70
  }, ((intervalSeconds) ? (intervalSeconds * 1000) : 60000));
71
71
  }
72
72
  /**Create a unique hex id of 8 characters and add it to the instance id history */
73
- #createUniqueId() {
73
+ createUniqueId() {
74
74
  const hex = crypto.randomBytes(4).toString("hex");
75
- if (this.#idHistory.includes(hex)) {
76
- return this.#createUniqueId();
75
+ if (this.idHistory.includes(hex)) {
76
+ return this.createUniqueId();
77
77
  }
78
78
  else {
79
- this.#idHistory.push(hex);
80
- if (this.#idHistory.length > this.#maxIdHistoryLength)
81
- this.#idHistory.shift();
79
+ this.idHistory.push(hex);
80
+ if (this.idHistory.length > this.maxIdHistoryLength)
81
+ this.idHistory.shift();
82
82
  return hex;
83
83
  }
84
84
  }
85
85
  /**Stop the global interval that automatically deletes timed-out sessions. (This action can't be reverted!) */
86
86
  stopAutoTimeout() {
87
- clearInterval(this.#intervalId);
87
+ clearInterval(this.intervalId);
88
88
  }
89
89
  /**Start a session instance with data. Returns the unique id required to access the session. */
90
90
  start(data) {
91
- const id = this.#createUniqueId();
91
+ const id = this.createUniqueId();
92
92
  this.sessions.push({
93
93
  id, data,
94
94
  creation: new Date().getTime(),
@@ -137,6 +137,6 @@ export class ODSession extends ODManagerData {
137
137
  }
138
138
  /**Listen for a session timeout (default or custom) */
139
139
  onTimeout(callback) {
140
- this.#timeoutListeners.push(callback);
140
+ this.timeoutListeners.push(callback);
141
141
  }
142
142
  }
@@ -17,7 +17,6 @@ export type ODStartScreenManagerIdConstraint = Record<string, ODStartScreenCompo
17
17
  * The startscreen is the part you see when the bot has started up successfully. (e.g. the Open Discord logo, logs, livestatus, flags, ...)
18
18
  */
19
19
  export declare class ODStartScreenManager<IdList extends ODStartScreenManagerIdConstraint = ODStartScreenManagerIdConstraint, LiveStatus extends ODLiveStatusManager = ODLiveStatusManager> extends ODManager<ODStartScreenComponent> {
20
- #private;
21
20
  /**Alias to the livestatus manager. */
22
21
  livestatus: LiveStatus;
23
22
  constructor(debug: ODDebugger, livestatus: LiveStatus);
@@ -11,13 +11,10 @@ import ansis from "ansis";
11
11
  * The startscreen is the part you see when the bot has started up successfully. (e.g. the Open Discord logo, logs, livestatus, flags, ...)
12
12
  */
13
13
  export class ODStartScreenManager extends ODManager {
14
- /**Alias to the Open Discord debugger. */
15
- #debug;
16
14
  /**Alias to the livestatus manager. */
17
15
  livestatus;
18
16
  constructor(debug, livestatus) {
19
17
  super(debug, "startscreen component");
20
- this.#debug = debug;
21
18
  this.livestatus = livestatus;
22
19
  }
23
20
  /**Get all components in sorted order. */
@@ -37,11 +34,11 @@ export class ODStartScreenManager extends ODManager {
37
34
  try {
38
35
  const renderedText = await component.renderAll(location);
39
36
  console.log(renderedText);
40
- this.#debug.console.debugfile.writeText("[STARTSCREEN] Component: \"" + component.id + "\"\n" + ansis.strip(renderedText));
37
+ this.debug?.console.debugfile.writeText("[STARTSCREEN] Component: \"" + component.id + "\"\n" + ansis.strip(renderedText));
41
38
  }
42
39
  catch (e) {
43
- this.#debug.console.log("Unable to render \"" + component.id + "\" startscreen component!", "error");
44
- this.#debug.console.debugfile.writeErrorMessage(new ODError(e, "uncaughtException"));
40
+ this.debug?.console.log("Unable to render \"" + component.id + "\" startscreen component!", "error");
41
+ this.debug?.console.debugfile.writeErrorMessage(new ODError(e, "uncaughtException"));
45
42
  }
46
43
  location++;
47
44
  }
@@ -29,9 +29,10 @@ export type ODStatisticManagerIdConstraint = Record<string, ODStatisticScope>;
29
29
  * Statistic can be accessed in the individual scopes.
30
30
  */
31
31
  export declare class ODStatisticManager<IdList extends ODStatisticManagerIdConstraint = ODStatisticManagerIdConstraint> extends ODManager<ODStatisticScope> {
32
- #private;
33
32
  /**Alias to Open Discord statistics database. */
34
33
  database: ODDatabase<ODDatabaseIdConstraint> | null;
34
+ /**All the listeners for the init event. */
35
+ protected initListeners: ODStatisticManagerInitCallback[];
35
36
  constructor(debug: ODDebugger);
36
37
  /**Select the database to use to read/write all statistics from/to. */
37
38
  useDatabase(database: ODDatabase<ODDatabaseIdConstraint>): void;
@@ -11,22 +11,19 @@ import { ODId, ODManager, ODManagerData, ODSystemError } from "./base.js";
11
11
  * Statistic can be accessed in the individual scopes.
12
12
  */
13
13
  export class ODStatisticManager extends ODManager {
14
- /**Alias to Open Discord debugger. */
15
- #debug;
16
14
  /**Alias to Open Discord statistics database. */
17
15
  database = null;
18
16
  /**All the listeners for the init event. */
19
- #initListeners = [];
17
+ initListeners = [];
20
18
  constructor(debug) {
21
19
  super(debug, "statistic scope");
22
- this.#debug = debug;
23
20
  }
24
21
  /**Select the database to use to read/write all statistics from/to. */
25
22
  useDatabase(database) {
26
23
  this.database = database;
27
24
  }
28
25
  add(data, overwrite) {
29
- data.useDebug(this.#debug, "stat");
26
+ data.useDebug(this.debug, "stat");
30
27
  if (this.database)
31
28
  data.useDatabase(this.database);
32
29
  return super.add(data, overwrite);
@@ -48,7 +45,7 @@ export class ODStatisticManager extends ODManager {
48
45
  deletableStats.push(data);
49
46
  });
50
47
  //do additional deletion
51
- for (const cb of this.#initListeners) {
48
+ for (const cb of this.initListeners) {
52
49
  await cb(data, deletableStats);
53
50
  }
54
51
  //delete all deletable statistics
@@ -69,7 +66,7 @@ export class ODStatisticManager extends ODManager {
69
66
  }
70
67
  /**Run a function when the statistics are initialized. This can be used to clear statistics from users that left the server or tickets which don't exist anymore. */
71
68
  onInit(callback) {
72
- this.#initListeners.push(callback);
69
+ this.initListeners.push(callback);
73
70
  }
74
71
  get(id) {
75
72
  return super.get(id);
@@ -28,7 +28,8 @@ export declare class ODWorker<Instance, Origin extends string, Params> extends O
28
28
  * You can register a custom worker in this class to create a message or button.
29
29
  */
30
30
  export declare class ODWorkerManager<Instance, Origin extends string, Params, WorkerIds extends string = string> extends ODManager<ODWorker<Instance, Origin, Params>> {
31
- #private;
31
+ /**The order of execution for workers inside this manager. */
32
+ protected priorityOrder: "ascending" | "descending";
32
33
  /**The backup worker will be executed when one of the workers fails or cancels execution. */
33
34
  backupWorker: ODWorker<{
34
35
  reason: "error" | "cancel";
@@ -32,12 +32,12 @@ export class ODWorker extends ODManagerData {
32
32
  */
33
33
  export class ODWorkerManager extends ODManager {
34
34
  /**The order of execution for workers inside this manager. */
35
- #priorityOrder;
35
+ priorityOrder;
36
36
  /**The backup worker will be executed when one of the workers fails or cancels execution. */
37
37
  backupWorker = null;
38
38
  constructor(priorityOrder) {
39
39
  super();
40
- this.#priorityOrder = priorityOrder;
40
+ this.priorityOrder = priorityOrder;
41
41
  }
42
42
  /**Get all workers in sorted order. */
43
43
  getSortedWorkers(priority) {
@@ -52,7 +52,7 @@ export class ODWorkerManager extends ODManager {
52
52
  /**Execute all workers on an instance using the given origin & parameters. */
53
53
  async executeWorkers(instance, origin, params) {
54
54
  const derefParams = { ...params };
55
- const workers = this.getSortedWorkers(this.#priorityOrder);
55
+ const workers = this.getSortedWorkers(this.priorityOrder);
56
56
  let didCancel = false;
57
57
  let didCrash = false;
58
58
  for (const worker of workers) {
@@ -1,4 +1,5 @@
1
1
  import * as api from "../api/index.js";
2
+ import * as discord from "discord.js";
2
3
  /**## sharedFuses `utility variable`
3
4
  * All shared fuses from Open Discord. Please use `opendiscord.sharedFuses` instead!
4
5
  */
@@ -55,6 +56,12 @@ export declare function ordinalNumber(num: number): string;
55
56
  * Trim/remove all emoji's from a Javascript string.
56
57
  */
57
58
  export declare function trimEmojis(text: string): string;
59
+ /**## getMessageFromBuildResult `utility function`
60
+ * Get the final `messageCreateOptions` from a returned build result from builders/components.
61
+ */
62
+ export declare function getMessageFromBuildResult(build: api.ODMessageBuildResult | api.ODMessageComponentBuildResult, type: "interaction" | "message"): discord.MessageCreateOptions & {
63
+ flags: number[];
64
+ };
58
65
  /**## easterEggs `utility object`
59
66
  * Object containing data for Open Ticket easter eggs.
60
67
  */
@@ -1,6 +1,7 @@
1
1
  import * as fs from "fs";
2
2
  import ansis from "ansis";
3
3
  import * as api from "../api/index.js";
4
+ import * as discord from "discord.js";
4
5
  /**## sharedFuses `utility variable`
5
6
  * All shared fuses from Open Discord. Please use `opendiscord.sharedFuses` instead!
6
7
  */
@@ -163,6 +164,32 @@ export function ordinalNumber(num) {
163
164
  export function trimEmojis(text) {
164
165
  return text.replace(/(\p{Extended_Pictographic}(?:\uFE0F|\uFE0E)?(?:\u200D\p{Extended_Pictographic}(?:\uFE0F|\uFE0E)?)*)/gu, "");
165
166
  }
167
+ /**## getMessageFromBuildResult `utility function`
168
+ * Get the final `messageCreateOptions` from a returned build result from builders/components.
169
+ */
170
+ export function getMessageFromBuildResult(build, type) {
171
+ const msgFlags = [];
172
+ let msgData;
173
+ if ('message' in build) {
174
+ //USING BUILDERS (deprecated)
175
+ msgData = build.message;
176
+ if (build.ephemeral)
177
+ msgFlags.push(discord.MessageFlags.Ephemeral);
178
+ }
179
+ else {
180
+ //USING COMPONENTS
181
+ msgData = build.msg;
182
+ if (type == "interaction" && build.ephemeral)
183
+ msgFlags.push(discord.MessageFlags.Ephemeral); //disabled with regular messages
184
+ if (build.componentsV2)
185
+ msgFlags.push(discord.MessageFlags.IsComponentsV2);
186
+ if (build.supressEmbeds)
187
+ msgFlags.push(discord.MessageFlags.SuppressEmbeds);
188
+ if (build.supressNotifications)
189
+ msgFlags.push(discord.MessageFlags.SuppressNotifications);
190
+ }
191
+ return Object.assign(msgData, { flags: msgFlags });
192
+ }
166
193
  /**## easterEggs `utility object`
167
194
  * Object containing data for Open Ticket easter eggs.
168
195
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@open-discord-bots/framework",
3
3
  "author": "DJj123dj",
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "description": "The core framework of the popular open-source discord bots: Open Ticket & Open Moderation.",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
package/src/api/main.ts CHANGED
@@ -150,7 +150,7 @@ export abstract class ODMain implements ODMainManagers {
150
150
  constructor(managers:ODMainManagers,project:ODProjectType){
151
151
  this.project = project
152
152
  this.versions = managers.versions
153
- this.versions.add(ODVersion.fromString("opendiscord:api","v0.3.0"))
153
+ this.versions.add(ODVersion.fromString("opendiscord:api","v0.3.2"))
154
154
  this.versions.add(ODVersion.fromString("opendiscord:livestatus","v2.0.0"))
155
155
 
156
156
  this.debugfile = managers.debugfile