@open-discord-bots/framework 0.0.1 → 0.0.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 (103) hide show
  1. package/LICENSE.md +713 -0
  2. package/README.md +104 -0
  3. package/dist/api/api.d.ts +26 -0
  4. package/dist/api/api.js +44 -0
  5. package/dist/api/main.d.ts +133 -0
  6. package/dist/api/main.js +87 -0
  7. package/dist/api/modules/action.d.ts +34 -0
  8. package/dist/api/modules/action.js +58 -0
  9. package/dist/api/modules/base.d.ts +329 -0
  10. package/dist/api/modules/base.js +804 -0
  11. package/dist/api/modules/builder.d.ts +647 -0
  12. package/dist/api/modules/builder.js +1441 -0
  13. package/dist/api/modules/checker.d.ts +648 -0
  14. package/dist/api/modules/checker.js +1324 -0
  15. package/dist/api/modules/client.d.ts +768 -0
  16. package/dist/api/modules/client.js +1859 -0
  17. package/dist/api/modules/code.d.ts +33 -0
  18. package/dist/api/modules/code.js +57 -0
  19. package/dist/api/modules/config.d.ts +70 -0
  20. package/dist/api/modules/config.js +206 -0
  21. package/dist/api/modules/console.d.ts +305 -0
  22. package/dist/api/modules/console.js +598 -0
  23. package/dist/api/modules/cooldown.d.ts +138 -0
  24. package/dist/api/modules/cooldown.js +359 -0
  25. package/dist/api/modules/database.d.ts +135 -0
  26. package/dist/api/modules/database.js +271 -0
  27. package/dist/api/modules/event.d.ts +43 -0
  28. package/dist/api/modules/event.js +100 -0
  29. package/dist/api/modules/flag.d.ts +40 -0
  30. package/dist/api/modules/flag.js +72 -0
  31. package/dist/api/modules/fuse.d.ts +218 -0
  32. package/dist/api/modules/fuse.js +123 -0
  33. package/dist/api/modules/helpmenu.d.ts +106 -0
  34. package/dist/api/modules/helpmenu.js +167 -0
  35. package/dist/api/modules/language.d.ts +85 -0
  36. package/dist/api/modules/language.js +195 -0
  37. package/dist/api/modules/permission.d.ts +121 -0
  38. package/dist/api/modules/permission.js +314 -0
  39. package/dist/api/modules/plugin.d.ts +128 -0
  40. package/dist/api/modules/plugin.js +168 -0
  41. package/dist/api/modules/post.d.ts +44 -0
  42. package/dist/api/modules/post.js +92 -0
  43. package/dist/api/modules/progressbar.d.ts +108 -0
  44. package/dist/api/modules/progressbar.js +233 -0
  45. package/dist/api/modules/responder.d.ts +506 -0
  46. package/dist/api/modules/responder.js +1468 -0
  47. package/dist/api/modules/session.d.ts +58 -0
  48. package/dist/api/modules/session.js +171 -0
  49. package/dist/api/modules/startscreen.d.ts +165 -0
  50. package/dist/api/modules/startscreen.js +293 -0
  51. package/dist/api/modules/stat.d.ts +142 -0
  52. package/dist/api/modules/stat.js +293 -0
  53. package/dist/api/modules/verifybar.d.ts +54 -0
  54. package/dist/api/modules/verifybar.js +60 -0
  55. package/dist/api/modules/worker.d.ts +41 -0
  56. package/dist/api/modules/worker.js +93 -0
  57. package/dist/api/utils.d.ts +61 -0
  58. package/dist/api/utils.js +254 -0
  59. package/dist/index.d.ts +4 -1
  60. package/dist/index.js +40 -0
  61. package/dist/startup/dump.d.ts +14 -0
  62. package/dist/startup/dump.js +79 -0
  63. package/dist/startup/errorHandling.d.ts +2 -0
  64. package/dist/startup/errorHandling.js +43 -0
  65. package/dist/startup/pluginLauncher.d.ts +2 -0
  66. package/dist/startup/pluginLauncher.js +202 -0
  67. package/package.json +9 -3
  68. package/src/api/api.ts +29 -0
  69. package/src/api/main.ts +189 -0
  70. package/src/api/modules/action.ts +58 -0
  71. package/src/api/modules/base.ts +811 -0
  72. package/src/api/modules/builder.ts +1554 -0
  73. package/src/api/modules/checker.ts +1549 -0
  74. package/src/api/modules/client.ts +2247 -0
  75. package/src/api/modules/code.ts +58 -0
  76. package/src/api/modules/config.ts +159 -0
  77. package/src/api/modules/console.ts +665 -0
  78. package/src/api/modules/cooldown.ts +348 -0
  79. package/src/api/modules/database.ts +278 -0
  80. package/src/api/modules/event.ts +99 -0
  81. package/src/api/modules/flag.ts +73 -0
  82. package/src/api/modules/fuse.ts +348 -0
  83. package/src/api/modules/helpmenu.ts +216 -0
  84. package/src/api/modules/language.ts +201 -0
  85. package/src/api/modules/permission.ts +340 -0
  86. package/src/api/modules/plugin.ts +242 -0
  87. package/src/api/modules/post.ts +90 -0
  88. package/src/api/modules/progressbar.ts +232 -0
  89. package/src/api/modules/responder.ts +1420 -0
  90. package/src/api/modules/session.ts +155 -0
  91. package/src/api/modules/startscreen.ts +320 -0
  92. package/src/api/modules/stat.ts +313 -0
  93. package/src/api/modules/verifybar.ts +61 -0
  94. package/src/api/modules/worker.ts +93 -0
  95. package/src/api/utils.ts +206 -0
  96. package/src/cli/cli.ts +151 -0
  97. package/src/cli/editConfig.ts +943 -0
  98. package/src/index.ts +6 -1
  99. package/src/startup/compilation.ts +186 -0
  100. package/src/startup/dump.ts +45 -0
  101. package/src/startup/errorHandling.ts +38 -0
  102. package/src/startup/pluginLauncher.ts +261 -0
  103. package/LICENSE +0 -21
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ODFormattedJsonDatabase = exports.ODJsonDatabase = exports.ODDatabase = exports.ODDatabaseManager = void 0;
7
+ ///////////////////////////////////////
8
+ //DATABASE MODULE
9
+ ///////////////////////////////////////
10
+ const base_1 = require("./base");
11
+ const fs_1 = __importDefault(require("fs"));
12
+ const path_1 = __importDefault(require("path"));
13
+ /**## ODDatabaseManager `class`
14
+ * This is an Open Discord database manager.
15
+ *
16
+ * It manages all databases in the bot and allows to permanently store data from the bot!
17
+ *
18
+ * You can use this class to get/add a database (`ODDatabase`) in your plugin!
19
+ */
20
+ class ODDatabaseManager extends base_1.ODManager {
21
+ constructor(debug) {
22
+ super(debug, "database");
23
+ }
24
+ /**Init all database files. */
25
+ async init() {
26
+ for (const database of this.getAll()) {
27
+ try {
28
+ await database.init();
29
+ }
30
+ catch (err) {
31
+ process.emit("uncaughtException", new base_1.ODSystemError(err));
32
+ }
33
+ }
34
+ }
35
+ }
36
+ exports.ODDatabaseManager = ODDatabaseManager;
37
+ /**## ODDatabase `class`
38
+ * This is an Open Discord database template.
39
+ * This class doesn't do anything at all, it just gives a template & basic methods for a database. Use `ODJsonDatabase` instead!
40
+ *
41
+ * You can use this class if you want to create your own database implementation (e.g. `mongodb`, `mysql`,...)!
42
+ */
43
+ class ODDatabase extends base_1.ODManagerData {
44
+ /**The name of the file with extension. */
45
+ file = "";
46
+ /**The path to the file relative to the main directory. */
47
+ path = "";
48
+ /**Init the database. */
49
+ init() {
50
+ //nothing
51
+ }
52
+ /**Add/Overwrite a specific category & key in the database. Returns `true` when overwritten. */
53
+ set(category, key, value) {
54
+ return false;
55
+ }
56
+ /**Get a specific category & key in the database */
57
+ get(category, key) {
58
+ return undefined;
59
+ }
60
+ /**Delete a specific category & key in the database */
61
+ delete(category, key) {
62
+ return false;
63
+ }
64
+ /**Check if a specific category & key exists in the database */
65
+ exists(category, key) {
66
+ return false;
67
+ }
68
+ /**Get a specific category in the database */
69
+ getCategory(category) {
70
+ return undefined;
71
+ }
72
+ /**Get all values in the database */
73
+ getAll() {
74
+ return [];
75
+ }
76
+ }
77
+ exports.ODDatabase = ODDatabase;
78
+ /**## ODJsonDatabase `class`
79
+ * This is an Open Discord JSON database.
80
+ * It stores data in a `json` file as a large `Array` using the `category`, `key`, `value` strategy.
81
+ * You can store the following types: `string`, `number`, `boolean`, `array`, `object` & `null`!
82
+ *
83
+ * You can use this class if you want to add your own database or to use an existing one!
84
+ */
85
+ class ODJsonDatabase extends ODDatabase {
86
+ constructor(id, file, customPath) {
87
+ super(id);
88
+ this.file = (file.endsWith(".json")) ? file : file + ".json";
89
+ this.path = customPath ? path_1.default.join("./", customPath, this.file) : path_1.default.join("./database/", this.file);
90
+ }
91
+ /**Init the database. */
92
+ init() {
93
+ this.#system.getData();
94
+ }
95
+ /**Set/overwrite the value of `category` & `key`. Returns `true` when overwritten!
96
+ * @example
97
+ * const didOverwrite = database.setData("category","key","value") //value can be any of the valid types
98
+ * //You need an ODJsonDatabase class named "database" for this example to work!
99
+ */
100
+ set(category, key, value) {
101
+ const currentList = this.#system.getData();
102
+ const currentData = currentList.find((d) => (d.category === category) && (d.key === key));
103
+ //overwrite when already present
104
+ if (currentData) {
105
+ currentList[currentList.indexOf(currentData)].value = value;
106
+ }
107
+ else {
108
+ currentList.push({ category, key, value });
109
+ }
110
+ this.#system.setData(currentList);
111
+ return currentData ? true : false;
112
+ }
113
+ /**Get the value of `category` & `key`. Returns `undefined` when non-existent!
114
+ * @example
115
+ * const data = database.getData("category","key") //data will be the value
116
+ * //You need an ODJsonDatabase class named "database" for this example to work!
117
+ */
118
+ get(category, key) {
119
+ const currentList = this.#system.getData();
120
+ const tempresult = currentList.find((d) => (d.category === category) && (d.key === key));
121
+ return tempresult ? tempresult.value : undefined;
122
+ }
123
+ /**Remove the value of `category` & `key`. Returns `undefined` when non-existent!
124
+ * @example
125
+ * const didExist = database.deleteData("category","key") //delete this value
126
+ * //You need an ODJsonDatabase class named "database" for this example to work!
127
+ */
128
+ delete(category, key) {
129
+ const currentList = this.#system.getData();
130
+ const currentData = currentList.find((d) => (d.category === category) && (d.key === key));
131
+ if (currentData)
132
+ currentList.splice(currentList.indexOf(currentData), 1);
133
+ this.#system.setData(currentList);
134
+ return currentData ? true : false;
135
+ }
136
+ /**Check if a value of `category` & `key` exists. Returns `false` when non-existent! */
137
+ exists(category, key) {
138
+ const currentList = this.#system.getData();
139
+ const tempresult = currentList.find((d) => (d.category === category) && (d.key === key));
140
+ return tempresult ? true : false;
141
+ }
142
+ /**Get all values in `category`. Returns `undefined` when non-existent! */
143
+ getCategory(category) {
144
+ const currentList = this.#system.getData();
145
+ const tempresult = currentList.filter((d) => (d.category === category));
146
+ return tempresult ? tempresult.map((data) => { return { key: data.key, value: data.value }; }) : undefined;
147
+ }
148
+ /**Get all values in `category`. */
149
+ getAll() {
150
+ return this.#system.getData();
151
+ }
152
+ #system = {
153
+ /**Read parsed data from the json file */
154
+ getData: () => {
155
+ if (fs_1.default.existsSync(this.path)) {
156
+ try {
157
+ return JSON.parse(fs_1.default.readFileSync(this.path).toString());
158
+ }
159
+ catch (err) {
160
+ process.emit("uncaughtException", err);
161
+ throw new base_1.ODSystemError("Unable to read database " + this.path + "! getData() read error. (see error above)");
162
+ }
163
+ }
164
+ else {
165
+ fs_1.default.writeFileSync(this.path, "[]");
166
+ return [];
167
+ }
168
+ },
169
+ /**Write parsed data to the json file */
170
+ setData: (data) => {
171
+ fs_1.default.writeFileSync(this.path, JSON.stringify(data, null, "\t"));
172
+ }
173
+ };
174
+ }
175
+ exports.ODJsonDatabase = ODJsonDatabase;
176
+ /**## ODFormattedJsonDatabase `class`
177
+ * This is an Open Discord Formatted JSON database.
178
+ * It stores data in a `json` file as a large `Array` using the `category`, `key`, `value` strategy.
179
+ * You can store the following types: `string`, `number`, `boolean`, `array`, `object` & `null`!
180
+ *
181
+ * This one is exactly the same as `ODJsonDatabase`, but it has a formatter from the `formatted-json-stringify` package.
182
+ * This can help you organise it a little bit better!
183
+ */
184
+ class ODFormattedJsonDatabase extends ODDatabase {
185
+ /**The formatter to use on the database array */
186
+ formatter;
187
+ constructor(id, file, formatter, customPath) {
188
+ super(id);
189
+ this.file = (file.endsWith(".json")) ? file : file + ".json";
190
+ this.path = customPath ? path_1.default.join("./", customPath, this.file) : path_1.default.join("./database/", this.file);
191
+ this.formatter = formatter;
192
+ }
193
+ /**Init the database. */
194
+ init() {
195
+ this.#system.getData();
196
+ }
197
+ /**Set/overwrite the value of `category` & `key`. Returns `true` when overwritten!
198
+ * @example
199
+ * const didOverwrite = database.setData("category","key","value") //value can be any of the valid types
200
+ * //You need an ODFormattedJsonDatabase class named "database" for this example to work!
201
+ */
202
+ set(category, key, value) {
203
+ const currentList = this.#system.getData();
204
+ const currentData = currentList.find((d) => (d.category === category) && (d.key === key));
205
+ //overwrite when already present
206
+ if (currentData) {
207
+ currentList[currentList.indexOf(currentData)].value = value;
208
+ }
209
+ else {
210
+ currentList.push({ category, key, value });
211
+ }
212
+ this.#system.setData(currentList);
213
+ return currentData ? true : false;
214
+ }
215
+ /**Get the value of `category` & `key`. Returns `undefined` when non-existent!
216
+ * @example
217
+ * const data = database.getData("category","key") //data will be the value
218
+ * //You need an ODFormattedJsonDatabase class named "database" for this example to work!
219
+ */
220
+ get(category, key) {
221
+ const currentList = this.#system.getData();
222
+ const tempresult = currentList.find((d) => (d.category === category) && (d.key === key));
223
+ return tempresult ? tempresult.value : undefined;
224
+ }
225
+ /**Remove the value of `category` & `key`. Returns `undefined` when non-existent!
226
+ * @example
227
+ * const didExist = database.deleteData("category","key") //delete this value
228
+ * //You need an ODFormattedJsonDatabase class named "database" for this example to work!
229
+ */
230
+ delete(category, key) {
231
+ const currentList = this.#system.getData();
232
+ const currentData = currentList.find((d) => (d.category === category) && (d.key === key));
233
+ if (currentData)
234
+ currentList.splice(currentList.indexOf(currentData), 1);
235
+ this.#system.setData(currentList);
236
+ return currentData ? true : false;
237
+ }
238
+ /**Check if a value of `category` & `key` exists. Returns `false` when non-existent! */
239
+ exists(category, key) {
240
+ const currentList = this.#system.getData();
241
+ const tempresult = currentList.find((d) => (d.category === category) && (d.key === key));
242
+ return tempresult ? true : false;
243
+ }
244
+ /**Get all values in `category`. Returns `undefined` when non-existent! */
245
+ getCategory(category) {
246
+ const currentList = this.#system.getData();
247
+ const tempresult = currentList.filter((d) => (d.category === category));
248
+ return tempresult ? tempresult.map((data) => { return { key: data.key, value: data.value }; }) : undefined;
249
+ }
250
+ /**Get all values in `category`. */
251
+ getAll() {
252
+ return this.#system.getData();
253
+ }
254
+ #system = {
255
+ /**Read parsed data from the json file */
256
+ getData: () => {
257
+ if (fs_1.default.existsSync(this.path)) {
258
+ return JSON.parse(fs_1.default.readFileSync(this.path).toString());
259
+ }
260
+ else {
261
+ fs_1.default.writeFileSync(this.path, "[]");
262
+ return [];
263
+ }
264
+ },
265
+ /**Write parsed data to the json file */
266
+ setData: (data) => {
267
+ fs_1.default.writeFileSync(this.path, this.formatter.stringify(data));
268
+ }
269
+ };
270
+ }
271
+ exports.ODFormattedJsonDatabase = ODFormattedJsonDatabase;
@@ -0,0 +1,43 @@
1
+ import { ODManagerData, ODManager, ODValidId } from "./base";
2
+ import { ODDebugger } from "./console";
3
+ /**## ODEvent `class`
4
+ * This is an Open Discord event.
5
+ *
6
+ * This class is made to work with the `ODEventManager` to handle events.
7
+ * The function of this specific class is to manage all listeners for a specifc event!
8
+ */
9
+ export declare class ODEvent extends ODManagerData {
10
+ #private;
11
+ /**The list of permanent listeners. */
12
+ listeners: Function[];
13
+ /**The list of one-time listeners. List is cleared every time the event is emitted. */
14
+ oncelisteners: Function[];
15
+ /**The max listener limit before a possible memory leak will be announced */
16
+ listenerLimit: number;
17
+ /**Use the Open Discord debugger in this manager for logs*/
18
+ useDebug(debug: ODDebugger | null): void;
19
+ /**Edit the listener limit */
20
+ setListenerLimit(limit: number): void;
21
+ /**Add a permanent callback to this event. This will stay as long as the bot is running! */
22
+ listen(callback: Function): void;
23
+ /**Add a one-time-only callback to this event. This will only trigger the callback once! */
24
+ listenOnce(callback: Function): void;
25
+ /**Wait until this event is fired! Be carefull with it, because it could block the entire bot when wrongly used! */
26
+ wait(): Promise<any[]>;
27
+ /**Emit this event to all listeners. You are required to provide all parameters of the event! */
28
+ emit(params: any[]): Promise<void>;
29
+ }
30
+ /**## ODEventManager `class`
31
+ * This is an Open Discord event manager.
32
+ *
33
+ * This class is made to manage all events in the bot. You can compare it with the built-in node.js `EventEmitter`
34
+ *
35
+ * It's not recommended to create this class yourself. Plugin events should be registered in their `plugin.json` file instead.
36
+ * All events are available in the `opendiscord.events` global!
37
+ */
38
+ export declare class ODEventManager extends ODManager<ODEvent> {
39
+ #private;
40
+ constructor(debug: ODDebugger);
41
+ add(data: ODEvent, overwrite?: boolean): boolean;
42
+ remove(id: ODValidId): ODEvent | null;
43
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ODEventManager = exports.ODEvent = void 0;
4
+ ///////////////////////////////////////
5
+ //EVENT MODULE
6
+ ///////////////////////////////////////
7
+ const base_1 = require("./base");
8
+ const console_1 = require("./console");
9
+ /**## ODEvent `class`
10
+ * This is an Open Discord event.
11
+ *
12
+ * This class is made to work with the `ODEventManager` to handle events.
13
+ * The function of this specific class is to manage all listeners for a specifc event!
14
+ */
15
+ class ODEvent extends base_1.ODManagerData {
16
+ /**Alias to Open Discord debugger. */
17
+ #debug;
18
+ /**The list of permanent listeners. */
19
+ listeners = [];
20
+ /**The list of one-time listeners. List is cleared every time the event is emitted. */
21
+ oncelisteners = [];
22
+ /**The max listener limit before a possible memory leak will be announced */
23
+ listenerLimit = 25;
24
+ /**Use the Open Discord debugger in this manager for logs*/
25
+ useDebug(debug) {
26
+ this.#debug = debug ?? undefined;
27
+ }
28
+ /**Get a collection of listeners combined from both types. Also clears the one-time listeners array! */
29
+ #getCurrentListeners() {
30
+ const final = [];
31
+ this.oncelisteners.forEach((l) => final.push(l));
32
+ this.listeners.forEach((l) => final.push(l));
33
+ this.oncelisteners = [];
34
+ return final;
35
+ }
36
+ /**Edit the listener limit */
37
+ setListenerLimit(limit) {
38
+ this.listenerLimit = limit;
39
+ }
40
+ /**Add a permanent callback to this event. This will stay as long as the bot is running! */
41
+ listen(callback) {
42
+ this.listeners.push(callback);
43
+ if (this.listeners.length > this.listenerLimit) {
44
+ if (this.#debug)
45
+ this.#debug.console.log(new console_1.ODConsoleWarningMessage("Possible event memory leak detected!", [
46
+ { key: "event", value: this.id.value },
47
+ { key: "listeners", value: this.listeners.length.toString() }
48
+ ]));
49
+ }
50
+ }
51
+ /**Add a one-time-only callback to this event. This will only trigger the callback once! */
52
+ listenOnce(callback) {
53
+ this.oncelisteners.push(callback);
54
+ }
55
+ /**Wait until this event is fired! Be carefull with it, because it could block the entire bot when wrongly used! */
56
+ async wait() {
57
+ return new Promise((resolve, reject) => {
58
+ this.oncelisteners.push((...args) => { resolve(args); });
59
+ });
60
+ }
61
+ /**Emit this event to all listeners. You are required to provide all parameters of the event! */
62
+ async emit(params) {
63
+ for (const listener of this.#getCurrentListeners()) {
64
+ try {
65
+ await listener(...params);
66
+ }
67
+ catch (err) {
68
+ process.emit("uncaughtException", err);
69
+ }
70
+ }
71
+ }
72
+ }
73
+ exports.ODEvent = ODEvent;
74
+ /**## ODEventManager `class`
75
+ * This is an Open Discord event manager.
76
+ *
77
+ * This class is made to manage all events in the bot. You can compare it with the built-in node.js `EventEmitter`
78
+ *
79
+ * It's not recommended to create this class yourself. Plugin events should be registered in their `plugin.json` file instead.
80
+ * All events are available in the `opendiscord.events` global!
81
+ */
82
+ class ODEventManager extends base_1.ODManager {
83
+ /**Reference to the Open Discord debugger */
84
+ #debug;
85
+ constructor(debug) {
86
+ super(debug, "event");
87
+ this.#debug = debug;
88
+ }
89
+ add(data, overwrite) {
90
+ data.useDebug(this.#debug);
91
+ return super.add(data, overwrite);
92
+ }
93
+ remove(id) {
94
+ const data = super.remove(id);
95
+ if (data)
96
+ data.useDebug(null);
97
+ return data;
98
+ }
99
+ }
100
+ exports.ODEventManager = ODEventManager;
@@ -0,0 +1,40 @@
1
+ import { ODValidId, ODManager, ODManagerData } from "./base";
2
+ import { ODDebugger } from "./console";
3
+ /**## ODFlag `class`
4
+ * This is an Open Discord flag.
5
+ *
6
+ * A flag is a boolean that can be specified by a parameter in the console.
7
+ * It's useful for small settings that are only required once in a while.
8
+ *
9
+ * Flags can also be enabled manually by plugins!
10
+ */
11
+ export declare class ODFlag extends ODManagerData {
12
+ /**The method that has been used to set the value of this flag. (`null` when not set) */
13
+ method: "param" | "manual" | null;
14
+ /**The name of this flag. Visible to the user. */
15
+ name: string;
16
+ /**The description of this flag. Visible to the user. */
17
+ description: string;
18
+ /**The name of the parameter in the console. (e.g. `--test`) */
19
+ param: string;
20
+ /**A list of aliases for the parameter in the console. */
21
+ aliases: string[];
22
+ /**The value of this flag. */
23
+ value: boolean;
24
+ constructor(id: ODValidId, name: string, description: string, param: string, aliases?: string[], initialValue?: boolean);
25
+ /**Set the value of this flag. */
26
+ setValue(value: boolean, method?: "param" | "manual"): void;
27
+ /**Detect if the process contains the param or aliases & set the value. Use `force` to overwrite a manually set value. */
28
+ detectProcessParams(force?: boolean): void;
29
+ }
30
+ /**## ODFlagManager `class`
31
+ * This is an Open Discord flag manager.
32
+ *
33
+ * This class is responsible for managing & initiating all flags of the bot.
34
+ * It also contains a shortcut for initiating all flags.
35
+ */
36
+ export declare class ODFlagManager extends ODManager<ODFlag> {
37
+ constructor(debug: ODDebugger);
38
+ /**Set all flags to their `process.argv` value. */
39
+ init(): Promise<void>;
40
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ODFlagManager = exports.ODFlag = void 0;
4
+ ///////////////////////////////////////
5
+ //FLAG MODULE
6
+ ///////////////////////////////////////
7
+ const base_1 = require("./base");
8
+ /**## ODFlag `class`
9
+ * This is an Open Discord flag.
10
+ *
11
+ * A flag is a boolean that can be specified by a parameter in the console.
12
+ * It's useful for small settings that are only required once in a while.
13
+ *
14
+ * Flags can also be enabled manually by plugins!
15
+ */
16
+ class ODFlag extends base_1.ODManagerData {
17
+ /**The method that has been used to set the value of this flag. (`null` when not set) */
18
+ method = null;
19
+ /**The name of this flag. Visible to the user. */
20
+ name;
21
+ /**The description of this flag. Visible to the user. */
22
+ description;
23
+ /**The name of the parameter in the console. (e.g. `--test`) */
24
+ param;
25
+ /**A list of aliases for the parameter in the console. */
26
+ aliases;
27
+ /**The value of this flag. */
28
+ value = false;
29
+ constructor(id, name, description, param, aliases, initialValue) {
30
+ super(id);
31
+ this.name = name;
32
+ this.description = description;
33
+ this.param = param;
34
+ this.aliases = aliases ?? [];
35
+ this.value = initialValue ?? false;
36
+ }
37
+ /**Set the value of this flag. */
38
+ setValue(value, method) {
39
+ this.value = value;
40
+ this.method = method ?? "manual";
41
+ }
42
+ /**Detect if the process contains the param or aliases & set the value. Use `force` to overwrite a manually set value. */
43
+ detectProcessParams(force) {
44
+ if (force) {
45
+ const params = [this.param, ...this.aliases];
46
+ this.setValue(params.some((p) => process.argv.includes(p)), "param");
47
+ }
48
+ else if (this.method != "manual") {
49
+ const params = [this.param, ...this.aliases];
50
+ this.setValue(params.some((p) => process.argv.includes(p)), "param");
51
+ }
52
+ }
53
+ }
54
+ exports.ODFlag = ODFlag;
55
+ /**## ODFlagManager `class`
56
+ * This is an Open Discord flag manager.
57
+ *
58
+ * This class is responsible for managing & initiating all flags of the bot.
59
+ * It also contains a shortcut for initiating all flags.
60
+ */
61
+ class ODFlagManager extends base_1.ODManager {
62
+ constructor(debug) {
63
+ super(debug, "flag");
64
+ }
65
+ /**Set all flags to their `process.argv` value. */
66
+ async init() {
67
+ await this.loopAll((flag) => {
68
+ flag.detectProcessParams(false);
69
+ });
70
+ }
71
+ }
72
+ exports.ODFlagManager = ODFlagManager;