@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.
- package/dist/api/main.js +1 -1
- package/dist/api/modules/base.d.ts +27 -9
- package/dist/api/modules/base.js +78 -80
- package/dist/api/modules/builder.d.ts +0 -9
- package/dist/api/modules/checker.d.ts +26 -5
- package/dist/api/modules/checker.js +31 -31
- package/dist/api/modules/client.d.ts +66 -14
- package/dist/api/modules/client.js +146 -132
- package/dist/api/modules/component.d.ts +8 -2
- package/dist/api/modules/component.js +8 -6
- package/dist/api/modules/config.d.ts +0 -1
- package/dist/api/modules/config.js +9 -7
- package/dist/api/modules/console.d.ts +16 -4
- package/dist/api/modules/console.js +25 -25
- package/dist/api/modules/event.d.ts +4 -2
- package/dist/api/modules/event.js +8 -10
- package/dist/api/modules/fuse.d.ts +1 -1
- package/dist/api/modules/helpmenu.d.ts +2 -2
- package/dist/api/modules/helpmenu.js +4 -7
- package/dist/api/modules/language.d.ts +2 -1
- package/dist/api/modules/language.js +6 -9
- package/dist/api/modules/permission.d.ts +10 -1
- package/dist/api/modules/permission.js +17 -20
- package/dist/api/modules/plugin.d.ts +2 -1
- package/dist/api/modules/plugin.js +2 -2
- package/dist/api/modules/post.d.ts +12 -4
- package/dist/api/modules/post.js +36 -10
- package/dist/api/modules/progressbar.d.ts +16 -5
- package/dist/api/modules/progressbar.js +34 -34
- package/dist/api/modules/responder.d.ts +95 -26
- package/dist/api/modules/responder.js +213 -172
- package/dist/api/modules/session.d.ts +10 -1
- package/dist/api/modules/session.js +15 -15
- package/dist/api/modules/startscreen.d.ts +0 -1
- package/dist/api/modules/startscreen.js +3 -6
- package/dist/api/modules/statistic.d.ts +2 -1
- package/dist/api/modules/statistic.js +4 -7
- package/dist/api/modules/worker.d.ts +2 -1
- package/dist/api/modules/worker.js +3 -3
- package/package.json +1 -1
- package/src/api/main.ts +1 -1
- package/src/api/modules/base.ts +75 -77
- package/src/api/modules/builder.ts +0 -10
- package/src/api/modules/checker.ts +31 -31
- package/src/api/modules/client.ts +144 -136
- package/src/api/modules/component.ts +11 -7
- package/src/api/modules/config.ts +8 -6
- package/src/api/modules/console.ts +25 -25
- package/src/api/modules/event.ts +6 -10
- package/src/api/modules/fuse.ts +1 -1
- package/src/api/modules/helpmenu.ts +4 -7
- package/src/api/modules/language.ts +6 -9
- package/src/api/modules/permission.ts +17 -20
- package/src/api/modules/plugin.ts +2 -2
- package/src/api/modules/post.ts +31 -10
- package/src/api/modules/progressbar.ts +34 -34
- package/src/api/modules/responder.ts +232 -181
- package/src/api/modules/session.ts +14 -14
- package/src/api/modules/startscreen.ts +3 -6
- package/src/api/modules/statistic.ts +4 -7
- package/src/api/modules/worker.ts +3 -3
package/dist/api/main.js
CHANGED
|
@@ -43,7 +43,7 @@ export class ODMain {
|
|
|
43
43
|
constructor(managers, project) {
|
|
44
44
|
this.project = project;
|
|
45
45
|
this.versions = managers.versions;
|
|
46
|
-
this.versions.add(ODVersion.fromString("opendiscord:api", "v0.3.
|
|
46
|
+
this.versions.add(ODVersion.fromString("opendiscord:api", "v0.3.1"));
|
|
47
47
|
this.versions.add(ODVersion.fromString("opendiscord:livestatus", "v2.0.0"));
|
|
48
48
|
this.debugfile = managers.debugfile;
|
|
49
49
|
this.console = managers.console;
|
|
@@ -52,11 +52,14 @@ export type ODNoGeneric<T extends Record<string | number | symbol, any>> = {
|
|
|
52
52
|
* You can use this class to assign a unique id when creating configs, databases, languages & more!
|
|
53
53
|
*/
|
|
54
54
|
export declare class ODId {
|
|
55
|
-
|
|
55
|
+
/**The raw value of this `ODId` as a `string`. */
|
|
56
|
+
private rawValue;
|
|
57
|
+
/**The change listener for the parent `ODManager` of this `ODId`. */
|
|
58
|
+
private changeListener;
|
|
59
|
+
constructor(id: ODValidId);
|
|
56
60
|
/**The full value of this `ODId` as a `string`. */
|
|
57
61
|
set value(id: string);
|
|
58
62
|
get value(): string;
|
|
59
|
-
constructor(id: ODValidId);
|
|
60
63
|
/**Returns a string representation of this id. (same as `this.value`) */
|
|
61
64
|
toString(): string;
|
|
62
65
|
/**The namespace of the id before `:`. (e.g. `opendiscord` for `opendiscord:autoclose-enabled`) */
|
|
@@ -75,7 +78,7 @@ export declare class ODId {
|
|
|
75
78
|
* You can use this class when extending your own `ODManager`
|
|
76
79
|
*/
|
|
77
80
|
export declare abstract class ODManagerChangeHelper {
|
|
78
|
-
|
|
81
|
+
private changeListener;
|
|
79
82
|
/**Trigger an `onChange()` event in the parent `ODManager` of this class. */
|
|
80
83
|
protected _change(): void;
|
|
81
84
|
/****(❌ SYSTEM ONLY!!)** Set the callback executed when a value inside this class changes. */
|
|
@@ -111,7 +114,18 @@ export type ODManagerAddCallback<DataType extends ODManagerData> = (data: DataTy
|
|
|
111
114
|
* This class has many useful functions based on `ODId` (add, get, remove, getAll, getFiltered, exists, loopAll, ...)
|
|
112
115
|
*/
|
|
113
116
|
export declare class ODManager<DataType extends ODManagerData> extends ODManagerChangeHelper {
|
|
114
|
-
|
|
117
|
+
/**Alias to Open Discord debugger. */
|
|
118
|
+
protected debug?: ODDebugger;
|
|
119
|
+
/**The message to send when debugging this manager. */
|
|
120
|
+
protected debugname?: string;
|
|
121
|
+
/**The map storing all data classes in this manager. */
|
|
122
|
+
private data;
|
|
123
|
+
/**An array storing all listeners when data is added. */
|
|
124
|
+
private addListeners;
|
|
125
|
+
/**An array storing all listeners when data has changed. */
|
|
126
|
+
private changeListeners;
|
|
127
|
+
/**An array storing all listeners when data is removed. */
|
|
128
|
+
private removeListeners;
|
|
115
129
|
constructor(debug?: ODDebugger, debugname?: string);
|
|
116
130
|
/**Add data to the manager. The `ODId` in the data class will be used as identifier! You can optionally select to overwrite existing data!*/
|
|
117
131
|
add(data: DataType | DataType[], overwrite?: boolean): boolean;
|
|
@@ -149,8 +163,9 @@ export declare class ODManager<DataType extends ODManagerData> extends ODManager
|
|
|
149
163
|
* The `getSafe()` function will always return data, because when it doesn't find an id, it returns pre-configured backup data.
|
|
150
164
|
*/
|
|
151
165
|
export declare class ODManagerWithSafety<DataType extends ODManagerData> extends ODManager<DataType> {
|
|
152
|
-
|
|
153
|
-
|
|
166
|
+
/**The function that creates backup data returned in `getSafe()` when an id is missing in this manager. */
|
|
167
|
+
protected backupGenerator: () => DataType;
|
|
168
|
+
constructor(backupGenerator: () => DataType, debug?: ODDebugger, debugname?: string);
|
|
154
169
|
/**Get data that matches the `ODId`. Returns the backup data when not found.
|
|
155
170
|
*
|
|
156
171
|
* ### ⚠️ This should only be used when the data doesn't need to be written/edited
|
|
@@ -234,10 +249,13 @@ export declare class ODVersion extends ODManagerData {
|
|
|
234
249
|
* It shouldn't be used by plugins because this is an internal API feature!
|
|
235
250
|
*/
|
|
236
251
|
export declare class ODVersionMigration {
|
|
237
|
-
#private;
|
|
238
252
|
/**The version to migrate data to */
|
|
239
253
|
version: ODVersion;
|
|
240
|
-
|
|
254
|
+
/**The migration function */
|
|
255
|
+
private migrateFunc;
|
|
256
|
+
/**The migration function */
|
|
257
|
+
private migrateAfterInitFunc;
|
|
258
|
+
constructor(version: ODVersion, migrateFunc: () => void | Promise<void>, migrateAfterInitFunc: () => void | Promise<void>);
|
|
241
259
|
/**Run this version migration as a plugin. Returns `false` when something goes wrong. */
|
|
242
260
|
migrate(): Promise<boolean>;
|
|
243
261
|
/**Run this version migration as a plugin (after other plugins have loaded). Returns `false` when something goes wrong. */
|
|
@@ -309,7 +327,6 @@ export declare class ODHTTPPostRequest {
|
|
|
309
327
|
* const variableA = envHelper.getVariable("value-c","env") //only get from process.env
|
|
310
328
|
*/
|
|
311
329
|
export declare class ODEnvHelper {
|
|
312
|
-
#private;
|
|
313
330
|
/**All variables found in the `.env` file */
|
|
314
331
|
dotenv: Record<string, any>;
|
|
315
332
|
/**All variables found in `process.env` */
|
|
@@ -317,6 +334,7 @@ export declare class ODEnvHelper {
|
|
|
317
334
|
constructor(customEnvPath?: string);
|
|
318
335
|
/**Get a variable from the env */
|
|
319
336
|
getVariable(name: string, source?: "dotenv" | "env"): any | undefined;
|
|
337
|
+
protected readDotEnv(src: Buffer): Record<string, any>;
|
|
320
338
|
}
|
|
321
339
|
/**## ODSystemError `class`
|
|
322
340
|
* A wrapper for the node.js `Error` class that makes the error look better in the console!
|
package/dist/api/modules/base.js
CHANGED
|
@@ -10,18 +10,10 @@ import * as fs from "fs";
|
|
|
10
10
|
* You can use this class to assign a unique id when creating configs, databases, languages & more!
|
|
11
11
|
*/
|
|
12
12
|
export class ODId {
|
|
13
|
-
/**The
|
|
14
|
-
|
|
15
|
-
/**The full value of this `ODId` as a `string`. */
|
|
16
|
-
set value(id) {
|
|
17
|
-
this._change(this.#value, id);
|
|
18
|
-
this.#value = id;
|
|
19
|
-
}
|
|
20
|
-
get value() {
|
|
21
|
-
return this.#value;
|
|
22
|
-
}
|
|
13
|
+
/**The raw value of this `ODId` as a `string`. */
|
|
14
|
+
rawValue;
|
|
23
15
|
/**The change listener for the parent `ODManager` of this `ODId`. */
|
|
24
|
-
|
|
16
|
+
changeListener = null;
|
|
25
17
|
constructor(id) {
|
|
26
18
|
if (typeof id != "string" && !(id instanceof ODId))
|
|
27
19
|
throw new ODSystemError("Invalid constructor parameter => id:ODValidId");
|
|
@@ -35,22 +27,30 @@ export class ODId {
|
|
|
35
27
|
}
|
|
36
28
|
});
|
|
37
29
|
if (result.length > 0)
|
|
38
|
-
this
|
|
30
|
+
this.rawValue = result.join("");
|
|
39
31
|
else
|
|
40
32
|
throw new ODSystemError("invalid ID at 'new ODID(id: " + id + ")'");
|
|
41
33
|
}
|
|
42
34
|
else {
|
|
43
35
|
//id is ODId
|
|
44
|
-
this
|
|
36
|
+
this.rawValue = id.rawValue;
|
|
45
37
|
}
|
|
46
38
|
}
|
|
39
|
+
/**The full value of this `ODId` as a `string`. */
|
|
40
|
+
set value(id) {
|
|
41
|
+
this._change(this.rawValue, id);
|
|
42
|
+
this.rawValue = id;
|
|
43
|
+
}
|
|
44
|
+
get value() {
|
|
45
|
+
return this.rawValue;
|
|
46
|
+
}
|
|
47
47
|
/**Returns a string representation of this id. (same as `this.value`) */
|
|
48
48
|
toString() {
|
|
49
|
-
return this
|
|
49
|
+
return this.rawValue;
|
|
50
50
|
}
|
|
51
51
|
/**The namespace of the id before `:`. (e.g. `opendiscord` for `opendiscord:autoclose-enabled`) */
|
|
52
52
|
getNamespace() {
|
|
53
|
-
const splitted = this
|
|
53
|
+
const splitted = this.rawValue.split(":");
|
|
54
54
|
if (splitted.length > 1)
|
|
55
55
|
return splitted[0];
|
|
56
56
|
else
|
|
@@ -58,19 +58,19 @@ export class ODId {
|
|
|
58
58
|
}
|
|
59
59
|
/**The identifier of the id after `:`. (e.g. `autoclose-enabled` for `opendiscord:autoclose-enabled`) */
|
|
60
60
|
getIdentifier() {
|
|
61
|
-
const splitted = this
|
|
61
|
+
const splitted = this.rawValue.split(":");
|
|
62
62
|
if (splitted.length > 1) {
|
|
63
63
|
splitted.shift();
|
|
64
64
|
return splitted.join(":");
|
|
65
65
|
}
|
|
66
66
|
else
|
|
67
|
-
return this
|
|
67
|
+
return this.rawValue;
|
|
68
68
|
}
|
|
69
69
|
/**Trigger an `onChange()` event in the parent `ODManager` of this class. */
|
|
70
70
|
_change(oldId, newId) {
|
|
71
|
-
if (this
|
|
71
|
+
if (this.changeListener) {
|
|
72
72
|
try {
|
|
73
|
-
this
|
|
73
|
+
this.changeListener(oldId, newId);
|
|
74
74
|
}
|
|
75
75
|
catch (err) {
|
|
76
76
|
process.emit("uncaughtException", err);
|
|
@@ -80,7 +80,7 @@ export class ODId {
|
|
|
80
80
|
}
|
|
81
81
|
/****(❌ SYSTEM ONLY!!)** Set the callback executed when a value inside this class changes. */
|
|
82
82
|
changed(callback) {
|
|
83
|
-
this
|
|
83
|
+
this.changeListener = callback;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
/**## ODManagerChangeHelper `class`
|
|
@@ -90,12 +90,12 @@ export class ODId {
|
|
|
90
90
|
* You can use this class when extending your own `ODManager`
|
|
91
91
|
*/
|
|
92
92
|
export class ODManagerChangeHelper {
|
|
93
|
-
|
|
93
|
+
changeListener = null;
|
|
94
94
|
/**Trigger an `onChange()` event in the parent `ODManager` of this class. */
|
|
95
95
|
_change() {
|
|
96
|
-
if (this
|
|
96
|
+
if (this.changeListener) {
|
|
97
97
|
try {
|
|
98
|
-
this
|
|
98
|
+
this.changeListener();
|
|
99
99
|
}
|
|
100
100
|
catch (err) {
|
|
101
101
|
process.emit("uncaughtException", err);
|
|
@@ -105,7 +105,7 @@ export class ODManagerChangeHelper {
|
|
|
105
105
|
}
|
|
106
106
|
/****(❌ SYSTEM ONLY!!)** Set the callback executed when a value inside this class changes. */
|
|
107
107
|
changed(callback) {
|
|
108
|
-
this
|
|
108
|
+
this.changeListener = callback;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
/**## ODManagerData `class`
|
|
@@ -136,21 +136,21 @@ export class ODManagerData extends ODManagerChangeHelper {
|
|
|
136
136
|
*/
|
|
137
137
|
export class ODManager extends ODManagerChangeHelper {
|
|
138
138
|
/**Alias to Open Discord debugger. */
|
|
139
|
-
|
|
139
|
+
debug;
|
|
140
140
|
/**The message to send when debugging this manager. */
|
|
141
|
-
|
|
141
|
+
debugname;
|
|
142
142
|
/**The map storing all data classes in this manager. */
|
|
143
|
-
|
|
143
|
+
data = new Map();
|
|
144
144
|
/**An array storing all listeners when data is added. */
|
|
145
|
-
|
|
145
|
+
addListeners = [];
|
|
146
146
|
/**An array storing all listeners when data has changed. */
|
|
147
|
-
|
|
147
|
+
changeListeners = [];
|
|
148
148
|
/**An array storing all listeners when data is removed. */
|
|
149
|
-
|
|
149
|
+
removeListeners = [];
|
|
150
150
|
constructor(debug, debugname) {
|
|
151
151
|
super();
|
|
152
|
-
this
|
|
153
|
-
this
|
|
152
|
+
this.debug = debug;
|
|
153
|
+
this.debugname = debugname;
|
|
154
154
|
}
|
|
155
155
|
/**Add data to the manager. The `ODId` in the data class will be used as identifier! You can optionally select to overwrite existing data!*/
|
|
156
156
|
add(data, overwrite) {
|
|
@@ -163,30 +163,30 @@ export class ODManager extends ODManagerChangeHelper {
|
|
|
163
163
|
}
|
|
164
164
|
//add listener for data id change => transfer data within manager
|
|
165
165
|
data.id.changed((oldId, newId) => {
|
|
166
|
-
this
|
|
167
|
-
this
|
|
166
|
+
this.data.delete(oldId);
|
|
167
|
+
this.data.set(newId, data);
|
|
168
168
|
});
|
|
169
169
|
//add data
|
|
170
170
|
let didOverwrite;
|
|
171
|
-
if (this
|
|
171
|
+
if (this.data.has(data.id.value)) {
|
|
172
172
|
if (!overwrite)
|
|
173
|
-
throw new ODSystemError("Id '" + data.id.value + "' already exists in " + this
|
|
174
|
-
this
|
|
173
|
+
throw new ODSystemError("Id '" + data.id.value + "' already exists in " + this.debugname + " manager. Use 'overwrite:true' to allow overwriting!");
|
|
174
|
+
this.data.set(data.id.value, data);
|
|
175
175
|
didOverwrite = true;
|
|
176
|
-
if (this
|
|
177
|
-
this
|
|
176
|
+
if (this.debug)
|
|
177
|
+
this.debug.debug("Added new " + this.debugname + " to manager", [{ key: "id", value: data.id.value }, { key: "overwrite", value: "true" }]);
|
|
178
178
|
}
|
|
179
179
|
else {
|
|
180
|
-
this
|
|
180
|
+
this.data.set(data.id.value, data);
|
|
181
181
|
didOverwrite = false;
|
|
182
|
-
if (this
|
|
183
|
-
this
|
|
182
|
+
if (this.debug)
|
|
183
|
+
this.debug.debug("Added new " + this.debugname + " to manager", [{ key: "id", value: data.id.value }, { key: "overwrite", value: "false" }]);
|
|
184
184
|
}
|
|
185
185
|
//emit change listeners
|
|
186
186
|
data.changed(() => {
|
|
187
187
|
//notify change in upper-manager (because data in this manager changed)
|
|
188
188
|
this._change();
|
|
189
|
-
this
|
|
189
|
+
this.changeListeners.forEach((cb) => {
|
|
190
190
|
try {
|
|
191
191
|
cb(data);
|
|
192
192
|
}
|
|
@@ -196,7 +196,7 @@ export class ODManager extends ODManagerChangeHelper {
|
|
|
196
196
|
});
|
|
197
197
|
});
|
|
198
198
|
//emit add listeners
|
|
199
|
-
this
|
|
199
|
+
this.addListeners.forEach((cb) => {
|
|
200
200
|
try {
|
|
201
201
|
cb(data, didOverwrite);
|
|
202
202
|
}
|
|
@@ -211,7 +211,7 @@ export class ODManager extends ODManagerChangeHelper {
|
|
|
211
211
|
/**Get data that matches the `ODId`. Returns the found data.*/
|
|
212
212
|
get(id) {
|
|
213
213
|
const newId = new ODId(id);
|
|
214
|
-
const data = this
|
|
214
|
+
const data = this.data.get(newId.value);
|
|
215
215
|
if (data)
|
|
216
216
|
return data;
|
|
217
217
|
else
|
|
@@ -220,22 +220,22 @@ export class ODManager extends ODManagerChangeHelper {
|
|
|
220
220
|
/**Remove data that matches the `ODId`. Returns the removed data. */
|
|
221
221
|
remove(id) {
|
|
222
222
|
const newId = new ODId(id);
|
|
223
|
-
const data = this
|
|
223
|
+
const data = this.data.get(newId.value);
|
|
224
224
|
if (!data) {
|
|
225
|
-
if (this
|
|
226
|
-
this
|
|
225
|
+
if (this.debug)
|
|
226
|
+
this.debug.debug("Removed " + this.debugname + " from manager", [{ key: "id", value: newId.value }, { key: "found", value: "false" }]);
|
|
227
227
|
return null;
|
|
228
228
|
}
|
|
229
229
|
else {
|
|
230
|
-
this
|
|
231
|
-
if (this
|
|
232
|
-
this
|
|
230
|
+
this.data.delete(newId.value);
|
|
231
|
+
if (this.debug)
|
|
232
|
+
this.debug.debug("Removed " + this.debugname + " from manager", [{ key: "id", value: newId.value }, { key: "found", value: "true" }]);
|
|
233
233
|
}
|
|
234
234
|
//remove all listeners
|
|
235
235
|
data.id.changed(null);
|
|
236
236
|
data.changed(null);
|
|
237
237
|
//emit remove listeners
|
|
238
|
-
this
|
|
238
|
+
this.removeListeners.forEach((cb) => {
|
|
239
239
|
try {
|
|
240
240
|
cb(data);
|
|
241
241
|
}
|
|
@@ -250,30 +250,30 @@ export class ODManager extends ODManagerChangeHelper {
|
|
|
250
250
|
/**Check if data that matches the `ODId` exists. Returns a boolean. */
|
|
251
251
|
exists(id) {
|
|
252
252
|
const newId = new ODId(id);
|
|
253
|
-
if (this
|
|
253
|
+
if (this.data.has(newId.value))
|
|
254
254
|
return true;
|
|
255
255
|
else
|
|
256
256
|
return false;
|
|
257
257
|
}
|
|
258
258
|
/**Get all data inside this manager*/
|
|
259
259
|
getAll() {
|
|
260
|
-
return Array.from(this
|
|
260
|
+
return Array.from(this.data.values());
|
|
261
261
|
}
|
|
262
262
|
/**Get all data that matches inside the filter function*/
|
|
263
263
|
getFiltered(predicate) {
|
|
264
|
-
return Array.from(this
|
|
264
|
+
return Array.from(this.data.values()).filter(predicate);
|
|
265
265
|
}
|
|
266
266
|
/**Get all data where the `ODId` matches the provided RegExp. */
|
|
267
267
|
getRegex(regex) {
|
|
268
|
-
return Array.from(this
|
|
268
|
+
return Array.from(this.data.values()).filter((data) => regex.test(data.id.value));
|
|
269
269
|
}
|
|
270
270
|
/**Get the length/size/amount of the data inside this manager. */
|
|
271
271
|
getLength() {
|
|
272
|
-
return this
|
|
272
|
+
return this.data.size;
|
|
273
273
|
}
|
|
274
274
|
/**Get a list of all the ids inside this manager*/
|
|
275
275
|
getIds() {
|
|
276
|
-
const ids = Array.from(this
|
|
276
|
+
const ids = Array.from(this.data.keys());
|
|
277
277
|
return ids.map((id) => new ODId(id));
|
|
278
278
|
}
|
|
279
279
|
/**Run an iterator over all data in this manager. This method also supports async-await behaviour!*/
|
|
@@ -284,20 +284,20 @@ export class ODManager extends ODManagerChangeHelper {
|
|
|
284
284
|
}
|
|
285
285
|
/**Use the Open Discord debugger in this manager for logs*/
|
|
286
286
|
useDebug(debug, debugname) {
|
|
287
|
-
this
|
|
288
|
-
this
|
|
287
|
+
this.debug = debug;
|
|
288
|
+
this.debugname = debugname;
|
|
289
289
|
}
|
|
290
290
|
/**Listen for when data is added to this manager. */
|
|
291
291
|
onAdd(callback) {
|
|
292
|
-
this
|
|
292
|
+
this.addListeners.push(callback);
|
|
293
293
|
}
|
|
294
294
|
/**Listen for when data is changed in this manager. */
|
|
295
295
|
onChange(callback) {
|
|
296
|
-
this
|
|
296
|
+
this.changeListeners.push(callback);
|
|
297
297
|
}
|
|
298
298
|
/**Listen for when data is removed from this manager. */
|
|
299
299
|
onRemove(callback) {
|
|
300
|
-
this
|
|
300
|
+
this.removeListeners.push(callback);
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
/**## ODManagerWithSafety `class`
|
|
@@ -308,13 +308,10 @@ export class ODManager extends ODManagerChangeHelper {
|
|
|
308
308
|
*/
|
|
309
309
|
export class ODManagerWithSafety extends ODManager {
|
|
310
310
|
/**The function that creates backup data returned in `getSafe()` when an id is missing in this manager. */
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
#debugname;
|
|
314
|
-
constructor(backupCreator, debug, debugname) {
|
|
311
|
+
backupGenerator;
|
|
312
|
+
constructor(backupGenerator, debug, debugname) {
|
|
315
313
|
super(debug, debugname);
|
|
316
|
-
this
|
|
317
|
-
this.#debugname = debugname ?? "unknown";
|
|
314
|
+
this.backupGenerator = backupGenerator;
|
|
318
315
|
}
|
|
319
316
|
/**Get data that matches the `ODId`. Returns the backup data when not found.
|
|
320
317
|
*
|
|
@@ -324,8 +321,8 @@ export class ODManagerWithSafety extends ODManager {
|
|
|
324
321
|
const newId = new ODId(id);
|
|
325
322
|
const data = super.get(id);
|
|
326
323
|
if (!data) {
|
|
327
|
-
process.emit("uncaughtException", new ODSystemError("ODManagerWithSafety:getSafe(\"" + newId.value + "\") => Unknown Id => Used backup data (" + this
|
|
328
|
-
return this
|
|
324
|
+
process.emit("uncaughtException", new ODSystemError("ODManagerWithSafety:getSafe(\"" + newId.value + "\") => Unknown Id => Used backup data (" + this.debugname + " manager)"));
|
|
325
|
+
return this.backupGenerator();
|
|
329
326
|
}
|
|
330
327
|
else
|
|
331
328
|
return data;
|
|
@@ -509,18 +506,18 @@ export class ODVersionMigration {
|
|
|
509
506
|
/**The version to migrate data to */
|
|
510
507
|
version;
|
|
511
508
|
/**The migration function */
|
|
512
|
-
|
|
509
|
+
migrateFunc;
|
|
513
510
|
/**The migration function */
|
|
514
|
-
|
|
515
|
-
constructor(version,
|
|
511
|
+
migrateAfterInitFunc;
|
|
512
|
+
constructor(version, migrateFunc, migrateAfterInitFunc) {
|
|
516
513
|
this.version = version;
|
|
517
|
-
this
|
|
518
|
-
this
|
|
514
|
+
this.migrateFunc = migrateFunc;
|
|
515
|
+
this.migrateAfterInitFunc = migrateAfterInitFunc;
|
|
519
516
|
}
|
|
520
517
|
/**Run this version migration as a plugin. Returns `false` when something goes wrong. */
|
|
521
518
|
async migrate() {
|
|
522
519
|
try {
|
|
523
|
-
await this
|
|
520
|
+
await this.migrateFunc();
|
|
524
521
|
return true;
|
|
525
522
|
}
|
|
526
523
|
catch (err) {
|
|
@@ -531,7 +528,7 @@ export class ODVersionMigration {
|
|
|
531
528
|
/**Run this version migration as a plugin (after other plugins have loaded). Returns `false` when something goes wrong. */
|
|
532
529
|
async migrateAfterInit() {
|
|
533
530
|
try {
|
|
534
|
-
await this
|
|
531
|
+
await this.migrateAfterInitFunc();
|
|
535
532
|
return true;
|
|
536
533
|
}
|
|
537
534
|
catch (err) {
|
|
@@ -680,7 +677,7 @@ export class ODEnvHelper {
|
|
|
680
677
|
if (typeof customEnvPath != "undefined" && typeof customEnvPath != "string")
|
|
681
678
|
throw new ODSystemError("Invalid constructor parameter => customEnvPath?:string");
|
|
682
679
|
const path = customEnvPath ? customEnvPath : ".env";
|
|
683
|
-
this.dotenv = fs.existsSync(path) ? this
|
|
680
|
+
this.dotenv = fs.existsSync(path) ? this.readDotEnv(fs.readFileSync(path)) : {};
|
|
684
681
|
this.env = process.env;
|
|
685
682
|
}
|
|
686
683
|
/**Get a variable from the env */
|
|
@@ -706,7 +703,8 @@ export class ODEnvHelper {
|
|
|
706
703
|
//THIS CODE IS COPIED FROM THE DODENV-LIB
|
|
707
704
|
//Repo: https://github.com/motdotla/dotenv
|
|
708
705
|
//Source: https://github.com/motdotla/dotenv/blob/master/lib/main.js#L12
|
|
709
|
-
|
|
706
|
+
//All rights go to the original authors of the dotenv library.
|
|
707
|
+
readDotEnv(src) {
|
|
710
708
|
const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
711
709
|
const obj = {};
|
|
712
710
|
// Convert buffer to string
|
|
@@ -564,15 +564,6 @@ export interface ODMessageBuildResult {
|
|
|
564
564
|
/**When enabled, the bot will try to send this as an ephemeral message */
|
|
565
565
|
ephemeral: boolean;
|
|
566
566
|
}
|
|
567
|
-
/**## ODMessageBuildSentResult `interface`
|
|
568
|
-
* This interface contains the result from a sent built message. This can be used to edit, view & save the message that got created.
|
|
569
|
-
*/
|
|
570
|
-
export interface ODMessageBuildSentResult<InGuild extends boolean> {
|
|
571
|
-
/**Did the message get sent successfully? */
|
|
572
|
-
success: boolean;
|
|
573
|
-
/**The message that got sent. */
|
|
574
|
-
message: discord.Message<InGuild> | null;
|
|
575
|
-
}
|
|
576
567
|
/**## ODMessageInstance `class`
|
|
577
568
|
* This is an Open Discord message instance.
|
|
578
569
|
*
|
|
@@ -119,7 +119,6 @@ export interface ODDefaultCheckerRendererTranslations {
|
|
|
119
119
|
* This class can be found in the global variable `opendiscord.checkers.renderer`!
|
|
120
120
|
*/
|
|
121
121
|
export declare class ODDefaultCheckerRenderer extends ODCheckerRenderer {
|
|
122
|
-
#private;
|
|
123
122
|
/**The main color used when rendering the config checker. */
|
|
124
123
|
mainColor: `#${string}`;
|
|
125
124
|
/**The url to the discord support server. */
|
|
@@ -150,6 +149,12 @@ export declare class ODDefaultCheckerRenderer extends ODCheckerRenderer {
|
|
|
150
149
|
disableFooter: boolean;
|
|
151
150
|
constructor(mainColor: `#${string}`, supportUrl: string, docsUrl: string);
|
|
152
151
|
getComponents(compact: boolean, renderEmpty: boolean, translation: ODCheckerTranslationRegister<string, string>, data: ODCheckerResult): string[];
|
|
152
|
+
/**Get the length of the longest string in the array. */
|
|
153
|
+
private getLongestLength;
|
|
154
|
+
/**Get a horizontal divider used between different parts of the config checker result. */
|
|
155
|
+
private getHorizontalDivider;
|
|
156
|
+
/**Create a block of text with a vertical divider on the left & right side. */
|
|
157
|
+
private createBlockFromText;
|
|
153
158
|
}
|
|
154
159
|
/**## ODCheckerTranslationRegister `class`
|
|
155
160
|
* This is an Open Discord checker translation register.
|
|
@@ -160,7 +165,12 @@ export declare class ODDefaultCheckerRenderer extends ODCheckerRenderer {
|
|
|
160
165
|
* You can use this class if you want to translate your config checker messages! **This is optional & isn't required for the checker to work!**
|
|
161
166
|
*/
|
|
162
167
|
export declare class ODCheckerTranslationRegister<MessageIds extends string = string, OtherIds extends string = string> {
|
|
163
|
-
|
|
168
|
+
/**This is the array that stores all the data. ❌ **(don't edit unless really needed!)***/
|
|
169
|
+
protected translations: {
|
|
170
|
+
type: "message" | "other";
|
|
171
|
+
id: string;
|
|
172
|
+
translation: string;
|
|
173
|
+
}[];
|
|
164
174
|
/**Get the translation from a config checker message/sentence */
|
|
165
175
|
get(type: "other", id: OtherIds): string;
|
|
166
176
|
get(type: "message", id: MessageIds): string;
|
|
@@ -247,7 +257,6 @@ export interface ODCheckerOptions {
|
|
|
247
257
|
* You can use this class when you create your own custom config file & you want to check it for syntax errors.
|
|
248
258
|
*/
|
|
249
259
|
export declare class ODChecker extends ODManagerData {
|
|
250
|
-
#private;
|
|
251
260
|
/**The storage of this checker (reference for `ODCheckerManager.storage`) */
|
|
252
261
|
storage: ODCheckerStorage;
|
|
253
262
|
/**The higher the priority, the faster it gets checked! */
|
|
@@ -263,6 +272,8 @@ export declare class ODChecker extends ODManagerData {
|
|
|
263
272
|
/**All additional properties of this config checker. */
|
|
264
273
|
options: ODCheckerOptions;
|
|
265
274
|
constructor(id: ODValidId, storage: ODCheckerStorage, priority: number, config: ODConfig<any>, structure: ODCheckerStructure, options?: ODCheckerOptions);
|
|
275
|
+
/**Get a human-readable number string. */
|
|
276
|
+
protected ordinalNumber(num: number): string;
|
|
266
277
|
/**Run this checker. Returns all errors*/
|
|
267
278
|
check(): ODCheckerResult;
|
|
268
279
|
/**Create a string from the location trace/path in a human readable format. */
|
|
@@ -499,10 +510,13 @@ export interface ODCheckerArrayStructureOptions extends ODCheckerStructureOption
|
|
|
499
510
|
* This class will check for an array variable in a config file, customise it in the settings!
|
|
500
511
|
*/
|
|
501
512
|
export declare class ODCheckerArrayStructure extends ODCheckerStructure {
|
|
502
|
-
#private;
|
|
503
513
|
options: ODCheckerArrayStructureOptions;
|
|
504
514
|
constructor(id: ODValidId, options: ODCheckerArrayStructureOptions);
|
|
505
515
|
check(checker: ODChecker, value: Array<any>, locationTrace: ODCheckerLocationTrace): boolean;
|
|
516
|
+
/**Check this array for the allowed types */
|
|
517
|
+
protected arrayAllowedTypesCheck(array: any[], allowedTypes: ("string" | "number" | "boolean" | "null" | "array" | "object" | "other")[]): boolean;
|
|
518
|
+
/**Check this array for doubles */
|
|
519
|
+
protected arrayHasDoubles(array: any[]): boolean;
|
|
506
520
|
}
|
|
507
521
|
/**## ODCheckerNullStructureOptions `interface`
|
|
508
522
|
* This interface has the options for `ODCheckerNullStructure`!
|
|
@@ -705,12 +719,19 @@ export interface ODCheckerCustomStructureOptions_UrlString {
|
|
|
705
719
|
* **This custom checker is made for a URL (string)**
|
|
706
720
|
*/
|
|
707
721
|
export declare class ODCheckerCustomStructure_UrlString extends ODCheckerStringStructure {
|
|
708
|
-
#private;
|
|
709
722
|
/**The settings for this url */
|
|
710
723
|
readonly urlSettings: ODCheckerCustomStructureOptions_UrlString;
|
|
711
724
|
/**Is this url allowed to be empty? */
|
|
712
725
|
readonly emptyAllowed: boolean;
|
|
713
726
|
constructor(id: ODValidId, emptyAllowed: boolean, urlSettings: ODCheckerCustomStructureOptions_UrlString, options?: ODCheckerStringStructureOptions);
|
|
727
|
+
/**Check for the hostname */
|
|
728
|
+
protected urlHasValidHostname(url: string, hostnames: (string | RegExp)[]): boolean;
|
|
729
|
+
/**Check for the extension */
|
|
730
|
+
protected urlHasValidExtension(url: string, extensions: string[]): boolean;
|
|
731
|
+
/**Check for the path */
|
|
732
|
+
protected urlHasValidPath(url: string, paths: (string | RegExp)[]): boolean;
|
|
733
|
+
/**Do general syntax check on url */
|
|
734
|
+
protected urlIsValid(url: string): boolean;
|
|
714
735
|
}
|
|
715
736
|
/**## ODCheckerCustomStructure_UniqueId `class`
|
|
716
737
|
* This is an Open Discord custom checker structure.
|