@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.
- package/LICENSE.md +713 -0
- package/README.md +104 -0
- package/dist/api/api.d.ts +26 -0
- package/dist/api/api.js +44 -0
- package/dist/api/main.d.ts +133 -0
- package/dist/api/main.js +87 -0
- package/dist/api/modules/action.d.ts +34 -0
- package/dist/api/modules/action.js +58 -0
- package/dist/api/modules/base.d.ts +329 -0
- package/dist/api/modules/base.js +804 -0
- package/dist/api/modules/builder.d.ts +647 -0
- package/dist/api/modules/builder.js +1441 -0
- package/dist/api/modules/checker.d.ts +648 -0
- package/dist/api/modules/checker.js +1324 -0
- package/dist/api/modules/client.d.ts +768 -0
- package/dist/api/modules/client.js +1859 -0
- package/dist/api/modules/code.d.ts +33 -0
- package/dist/api/modules/code.js +57 -0
- package/dist/api/modules/config.d.ts +70 -0
- package/dist/api/modules/config.js +206 -0
- package/dist/api/modules/console.d.ts +305 -0
- package/dist/api/modules/console.js +598 -0
- package/dist/api/modules/cooldown.d.ts +138 -0
- package/dist/api/modules/cooldown.js +359 -0
- package/dist/api/modules/database.d.ts +135 -0
- package/dist/api/modules/database.js +271 -0
- package/dist/api/modules/event.d.ts +43 -0
- package/dist/api/modules/event.js +100 -0
- package/dist/api/modules/flag.d.ts +40 -0
- package/dist/api/modules/flag.js +72 -0
- package/dist/api/modules/fuse.d.ts +218 -0
- package/dist/api/modules/fuse.js +123 -0
- package/dist/api/modules/helpmenu.d.ts +106 -0
- package/dist/api/modules/helpmenu.js +167 -0
- package/dist/api/modules/language.d.ts +85 -0
- package/dist/api/modules/language.js +195 -0
- package/dist/api/modules/permission.d.ts +121 -0
- package/dist/api/modules/permission.js +314 -0
- package/dist/api/modules/plugin.d.ts +128 -0
- package/dist/api/modules/plugin.js +168 -0
- package/dist/api/modules/post.d.ts +44 -0
- package/dist/api/modules/post.js +92 -0
- package/dist/api/modules/progressbar.d.ts +108 -0
- package/dist/api/modules/progressbar.js +233 -0
- package/dist/api/modules/responder.d.ts +506 -0
- package/dist/api/modules/responder.js +1468 -0
- package/dist/api/modules/session.d.ts +58 -0
- package/dist/api/modules/session.js +171 -0
- package/dist/api/modules/startscreen.d.ts +165 -0
- package/dist/api/modules/startscreen.js +293 -0
- package/dist/api/modules/stat.d.ts +142 -0
- package/dist/api/modules/stat.js +293 -0
- package/dist/api/modules/verifybar.d.ts +54 -0
- package/dist/api/modules/verifybar.js +60 -0
- package/dist/api/modules/worker.d.ts +41 -0
- package/dist/api/modules/worker.js +93 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +254 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +40 -0
- package/dist/startup/dump.d.ts +14 -0
- package/dist/startup/dump.js +79 -0
- package/dist/startup/errorHandling.d.ts +2 -0
- package/dist/startup/errorHandling.js +43 -0
- package/dist/startup/pluginLauncher.d.ts +2 -0
- package/dist/startup/pluginLauncher.js +202 -0
- package/package.json +9 -3
- package/src/api/api.ts +29 -0
- package/src/api/main.ts +189 -0
- package/src/api/modules/action.ts +58 -0
- package/src/api/modules/base.ts +811 -0
- package/src/api/modules/builder.ts +1554 -0
- package/src/api/modules/checker.ts +1549 -0
- package/src/api/modules/client.ts +2247 -0
- package/src/api/modules/code.ts +58 -0
- package/src/api/modules/config.ts +159 -0
- package/src/api/modules/console.ts +665 -0
- package/src/api/modules/cooldown.ts +348 -0
- package/src/api/modules/database.ts +278 -0
- package/src/api/modules/event.ts +99 -0
- package/src/api/modules/flag.ts +73 -0
- package/src/api/modules/fuse.ts +348 -0
- package/src/api/modules/helpmenu.ts +216 -0
- package/src/api/modules/language.ts +201 -0
- package/src/api/modules/permission.ts +340 -0
- package/src/api/modules/plugin.ts +242 -0
- package/src/api/modules/post.ts +90 -0
- package/src/api/modules/progressbar.ts +232 -0
- package/src/api/modules/responder.ts +1420 -0
- package/src/api/modules/session.ts +155 -0
- package/src/api/modules/startscreen.ts +320 -0
- package/src/api/modules/stat.ts +313 -0
- package/src/api/modules/verifybar.ts +61 -0
- package/src/api/modules/worker.ts +93 -0
- package/src/api/utils.ts +206 -0
- package/src/cli/cli.ts +151 -0
- package/src/cli/editConfig.ts +943 -0
- package/src/index.ts +6 -1
- package/src/startup/compilation.ts +186 -0
- package/src/startup/dump.ts +45 -0
- package/src/startup/errorHandling.ts +38 -0
- package/src/startup/pluginLauncher.ts +261 -0
- package/LICENSE +0 -21
|
@@ -0,0 +1,804 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ODPluginError = exports.ODSystemError = exports.ODEnvHelper = exports.ODHTTPPostRequest = exports.ODHTTPGetRequest = exports.ODVersionMigration = exports.ODVersion = exports.ODVersionManager = exports.ODManagerWithSafety = exports.ODManager = exports.ODManagerData = exports.ODManagerChangeHelper = exports.ODId = void 0;
|
|
37
|
+
///////////////////////////////////////
|
|
38
|
+
//BASE MODULE
|
|
39
|
+
///////////////////////////////////////
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
/**## ODId `class`
|
|
42
|
+
* This is an Open Discord identifier.
|
|
43
|
+
*
|
|
44
|
+
* It can only contain the following characters: `a-z`, `A-Z`, `0-9`, `:`, `-` & `_`
|
|
45
|
+
*
|
|
46
|
+
* You can use this class to assign a unique id when creating configs, databases, languages & more!
|
|
47
|
+
*/
|
|
48
|
+
class ODId {
|
|
49
|
+
/**The full value of this `ODId` as a `string`. */
|
|
50
|
+
#value;
|
|
51
|
+
/**The full value of this `ODId` as a `string`. */
|
|
52
|
+
set value(id) {
|
|
53
|
+
this._change(this.#value, id);
|
|
54
|
+
this.#value = id;
|
|
55
|
+
}
|
|
56
|
+
get value() {
|
|
57
|
+
return this.#value;
|
|
58
|
+
}
|
|
59
|
+
/**The change listener for the parent `ODManager` of this `ODId`. */
|
|
60
|
+
#change = null;
|
|
61
|
+
constructor(id) {
|
|
62
|
+
if (typeof id != "string" && !(id instanceof ODId))
|
|
63
|
+
throw new ODSystemError("Invalid constructor parameter => id:ODValidId");
|
|
64
|
+
if (typeof id == "string") {
|
|
65
|
+
//id is string
|
|
66
|
+
const result = [];
|
|
67
|
+
const charregex = /[a-zA-Z0-9éèçàêâôûî\:\-\_]/;
|
|
68
|
+
id.split("").forEach((char) => {
|
|
69
|
+
if (charregex.test(char)) {
|
|
70
|
+
result.push(char);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
if (result.length > 0)
|
|
74
|
+
this.#value = result.join("");
|
|
75
|
+
else
|
|
76
|
+
throw new ODSystemError("invalid ID at 'new ODID(id: " + id + ")'");
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
//id is ODId
|
|
80
|
+
this.#value = id.#value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**Returns a string representation of this id. (same as `this.value`) */
|
|
84
|
+
toString() {
|
|
85
|
+
return this.#value;
|
|
86
|
+
}
|
|
87
|
+
/**The namespace of the id before `:`. (e.g. `opendiscord` for `opendiscord:autoclose-enabled`) */
|
|
88
|
+
getNamespace() {
|
|
89
|
+
const splitted = this.#value.split(":");
|
|
90
|
+
if (splitted.length > 1)
|
|
91
|
+
return splitted[0];
|
|
92
|
+
else
|
|
93
|
+
return "";
|
|
94
|
+
}
|
|
95
|
+
/**The identifier of the id after `:`. (e.g. `autoclose-enabled` for `opendiscord:autoclose-enabled`) */
|
|
96
|
+
getIdentifier() {
|
|
97
|
+
const splitted = this.#value.split(":");
|
|
98
|
+
if (splitted.length > 1) {
|
|
99
|
+
splitted.shift();
|
|
100
|
+
return splitted.join(":");
|
|
101
|
+
}
|
|
102
|
+
else
|
|
103
|
+
return this.#value;
|
|
104
|
+
}
|
|
105
|
+
/**Trigger an `onChange()` event in the parent `ODManager` of this class. */
|
|
106
|
+
_change(oldId, newId) {
|
|
107
|
+
if (this.#change) {
|
|
108
|
+
try {
|
|
109
|
+
this.#change(oldId, newId);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
process.emit("uncaughtException", err);
|
|
113
|
+
throw new ODSystemError("Failed to execute _change() callback!");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/****(❌ SYSTEM ONLY!!)** Set the callback executed when a value inside this class changes. */
|
|
118
|
+
changed(callback) {
|
|
119
|
+
this.#change = callback;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.ODId = ODId;
|
|
123
|
+
/**## ODManagerChangeHelper `class`
|
|
124
|
+
* This is an Open Discord manager change helper.
|
|
125
|
+
*
|
|
126
|
+
* It is used to let the "onChange" event in the `ODManager` class work.
|
|
127
|
+
* You can use this class when extending your own `ODManager`
|
|
128
|
+
*/
|
|
129
|
+
class ODManagerChangeHelper {
|
|
130
|
+
#change = null;
|
|
131
|
+
/**Trigger an `onChange()` event in the parent `ODManager` of this class. */
|
|
132
|
+
_change() {
|
|
133
|
+
if (this.#change) {
|
|
134
|
+
try {
|
|
135
|
+
this.#change();
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
process.emit("uncaughtException", err);
|
|
139
|
+
throw new ODSystemError("Failed to execute _change() callback!");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/****(❌ SYSTEM ONLY!!)** Set the callback executed when a value inside this class changes. */
|
|
144
|
+
changed(callback) {
|
|
145
|
+
this.#change = callback;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.ODManagerChangeHelper = ODManagerChangeHelper;
|
|
149
|
+
/**## ODManagerData `class`
|
|
150
|
+
* This is Open Discord manager data.
|
|
151
|
+
*
|
|
152
|
+
* It provides a template for all classes that are used in the `ODManager`.
|
|
153
|
+
*
|
|
154
|
+
* There is an `id:ODId` property & also some events used in the manager.
|
|
155
|
+
*/
|
|
156
|
+
class ODManagerData extends ODManagerChangeHelper {
|
|
157
|
+
/**The id of this data. */
|
|
158
|
+
id;
|
|
159
|
+
constructor(id) {
|
|
160
|
+
if (typeof id != "string" && !(id instanceof ODId))
|
|
161
|
+
throw new ODSystemError("Invalid constructor parameter => id:ODValidId");
|
|
162
|
+
super();
|
|
163
|
+
this.id = new ODId(id);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.ODManagerData = ODManagerData;
|
|
167
|
+
/**## ODManager `class`
|
|
168
|
+
* This is an Open Discord manager.
|
|
169
|
+
*
|
|
170
|
+
* It can be used to store & manage classes based on their `ODId`.
|
|
171
|
+
* It is somewhat the same as the default JS `Map()`.
|
|
172
|
+
* You can extend this class when creating your own classes & managers.
|
|
173
|
+
*
|
|
174
|
+
* This class has many useful functions based on `ODId` (add, get, remove, getAll, getFiltered, exists, loopAll, ...)
|
|
175
|
+
*/
|
|
176
|
+
class ODManager extends ODManagerChangeHelper {
|
|
177
|
+
/**Alias to Open Discord debugger. */
|
|
178
|
+
#debug;
|
|
179
|
+
/**The message to send when debugging this manager. */
|
|
180
|
+
#debugname;
|
|
181
|
+
/**The map storing all data classes in this manager. */
|
|
182
|
+
#data = new Map();
|
|
183
|
+
/**An array storing all listeners when data is added. */
|
|
184
|
+
#addListeners = [];
|
|
185
|
+
/**An array storing all listeners when data has changed. */
|
|
186
|
+
#changeListeners = [];
|
|
187
|
+
/**An array storing all listeners when data is removed. */
|
|
188
|
+
#removeListeners = [];
|
|
189
|
+
constructor(debug, debugname) {
|
|
190
|
+
super();
|
|
191
|
+
this.#debug = debug;
|
|
192
|
+
this.#debugname = debugname;
|
|
193
|
+
}
|
|
194
|
+
/**Add data to the manager. The `ODId` in the data class will be used as identifier! You can optionally select to overwrite existing data!*/
|
|
195
|
+
add(data, overwrite) {
|
|
196
|
+
//repeat same command when data is an array
|
|
197
|
+
if (Array.isArray(data)) {
|
|
198
|
+
data.forEach((arrayData) => {
|
|
199
|
+
this.add(arrayData, overwrite);
|
|
200
|
+
});
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
//add listener for data id change => transfer data within manager
|
|
204
|
+
data.id.changed((oldId, newId) => {
|
|
205
|
+
this.#data.delete(oldId);
|
|
206
|
+
this.#data.set(newId, data);
|
|
207
|
+
});
|
|
208
|
+
//add data
|
|
209
|
+
let didOverwrite;
|
|
210
|
+
if (this.#data.has(data.id.value)) {
|
|
211
|
+
if (!overwrite)
|
|
212
|
+
throw new ODSystemError("Id '" + data.id.value + "' already exists in " + this.#debugname + " manager. Use 'overwrite:true' to allow overwriting!");
|
|
213
|
+
this.#data.set(data.id.value, data);
|
|
214
|
+
didOverwrite = true;
|
|
215
|
+
if (this.#debug)
|
|
216
|
+
this.#debug.debug("Added new " + this.#debugname + " to manager", [{ key: "id", value: data.id.value }, { key: "overwrite", value: "true" }]);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
this.#data.set(data.id.value, data);
|
|
220
|
+
didOverwrite = false;
|
|
221
|
+
if (this.#debug)
|
|
222
|
+
this.#debug.debug("Added new " + this.#debugname + " to manager", [{ key: "id", value: data.id.value }, { key: "overwrite", value: "false" }]);
|
|
223
|
+
}
|
|
224
|
+
//emit change listeners
|
|
225
|
+
data.changed(() => {
|
|
226
|
+
//notify change in upper-manager (because data in this manager changed)
|
|
227
|
+
this._change();
|
|
228
|
+
this.#changeListeners.forEach((cb) => {
|
|
229
|
+
try {
|
|
230
|
+
cb(data);
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
throw new ODSystemError("Failed to run manager onChange() listener.\n" + err);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
//emit add listeners
|
|
238
|
+
this.#addListeners.forEach((cb) => {
|
|
239
|
+
try {
|
|
240
|
+
cb(data, didOverwrite);
|
|
241
|
+
}
|
|
242
|
+
catch (err) {
|
|
243
|
+
throw new ODSystemError("Failed to run manager onAdd() listener.\n" + err);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
//notify change in upper-manager (because data added)
|
|
247
|
+
this._change();
|
|
248
|
+
return didOverwrite;
|
|
249
|
+
}
|
|
250
|
+
/**Get data that matches the `ODId`. Returns the found data.*/
|
|
251
|
+
get(id) {
|
|
252
|
+
const newId = new ODId(id);
|
|
253
|
+
const data = this.#data.get(newId.value);
|
|
254
|
+
if (data)
|
|
255
|
+
return data;
|
|
256
|
+
else
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
/**Remove data that matches the `ODId`. Returns the removed data. */
|
|
260
|
+
remove(id) {
|
|
261
|
+
const newId = new ODId(id);
|
|
262
|
+
const data = this.#data.get(newId.value);
|
|
263
|
+
if (!data) {
|
|
264
|
+
if (this.#debug)
|
|
265
|
+
this.#debug.debug("Removed " + this.#debugname + " from manager", [{ key: "id", value: newId.value }, { key: "found", value: "false" }]);
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
this.#data.delete(newId.value);
|
|
270
|
+
if (this.#debug)
|
|
271
|
+
this.#debug.debug("Removed " + this.#debugname + " from manager", [{ key: "id", value: newId.value }, { key: "found", value: "true" }]);
|
|
272
|
+
}
|
|
273
|
+
//remove all listeners
|
|
274
|
+
data.id.changed(null);
|
|
275
|
+
data.changed(null);
|
|
276
|
+
//emit remove listeners
|
|
277
|
+
this.#removeListeners.forEach((cb) => {
|
|
278
|
+
try {
|
|
279
|
+
cb(data);
|
|
280
|
+
}
|
|
281
|
+
catch (err) {
|
|
282
|
+
throw new ODSystemError("Failed to run manager onRemove() listener.\n" + err);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
//notify change in upper-manager (because data removed)
|
|
286
|
+
this._change();
|
|
287
|
+
return data;
|
|
288
|
+
}
|
|
289
|
+
/**Check if data that matches the `ODId` exists. Returns a boolean. */
|
|
290
|
+
exists(id) {
|
|
291
|
+
const newId = new ODId(id);
|
|
292
|
+
if (this.#data.has(newId.value))
|
|
293
|
+
return true;
|
|
294
|
+
else
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
/**Get all data inside this manager*/
|
|
298
|
+
getAll() {
|
|
299
|
+
return Array.from(this.#data.values());
|
|
300
|
+
}
|
|
301
|
+
/**Get all data that matches inside the filter function*/
|
|
302
|
+
getFiltered(predicate) {
|
|
303
|
+
return Array.from(this.#data.values()).filter(predicate);
|
|
304
|
+
}
|
|
305
|
+
/**Get all data where the `ODId` matches the provided RegExp. */
|
|
306
|
+
getRegex(regex) {
|
|
307
|
+
return Array.from(this.#data.values()).filter((data) => regex.test(data.id.value));
|
|
308
|
+
}
|
|
309
|
+
/**Get the length/size/amount of the data inside this manager. */
|
|
310
|
+
getLength() {
|
|
311
|
+
return this.#data.size;
|
|
312
|
+
}
|
|
313
|
+
/**Get a list of all the ids inside this manager*/
|
|
314
|
+
getIds() {
|
|
315
|
+
const ids = Array.from(this.#data.keys());
|
|
316
|
+
return ids.map((id) => new ODId(id));
|
|
317
|
+
}
|
|
318
|
+
/**Run an iterator over all data in this manager. This method also supports async-await behaviour!*/
|
|
319
|
+
async loopAll(cb) {
|
|
320
|
+
for (const data of this.getAll()) {
|
|
321
|
+
await cb(data, data.id);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**Use the Open Discord debugger in this manager for logs*/
|
|
325
|
+
useDebug(debug, debugname) {
|
|
326
|
+
this.#debug = debug;
|
|
327
|
+
this.#debugname = debugname;
|
|
328
|
+
}
|
|
329
|
+
/**Listen for when data is added to this manager. */
|
|
330
|
+
onAdd(callback) {
|
|
331
|
+
this.#addListeners.push(callback);
|
|
332
|
+
}
|
|
333
|
+
/**Listen for when data is changed in this manager. */
|
|
334
|
+
onChange(callback) {
|
|
335
|
+
this.#changeListeners.push(callback);
|
|
336
|
+
}
|
|
337
|
+
/**Listen for when data is removed from this manager. */
|
|
338
|
+
onRemove(callback) {
|
|
339
|
+
this.#removeListeners.push(callback);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
exports.ODManager = ODManager;
|
|
343
|
+
/**## ODManagerWithSafety `class`
|
|
344
|
+
* This is an Open Discord safe manager.
|
|
345
|
+
*
|
|
346
|
+
* It functions exactly the same as a normal `ODManager`, but it has 1 function extra!
|
|
347
|
+
* The `getSafe()` function will always return data, because when it doesn't find an id, it returns pre-configured backup data.
|
|
348
|
+
*/
|
|
349
|
+
class ODManagerWithSafety extends ODManager {
|
|
350
|
+
/**The function that creates backup data returned in `getSafe()` when an id is missing in this manager. */
|
|
351
|
+
#backupCreator;
|
|
352
|
+
/** Temporary storage for manager debug name. */
|
|
353
|
+
#debugname;
|
|
354
|
+
constructor(backupCreator, debug, debugname) {
|
|
355
|
+
super(debug, debugname);
|
|
356
|
+
this.#backupCreator = backupCreator;
|
|
357
|
+
this.#debugname = debugname ?? "unknown";
|
|
358
|
+
}
|
|
359
|
+
/**Get data that matches the `ODId`. Returns the backup data when not found.
|
|
360
|
+
*
|
|
361
|
+
* ### ⚠️ This should only be used when the data doesn't need to be written/edited
|
|
362
|
+
*/
|
|
363
|
+
getSafe(id) {
|
|
364
|
+
const data = super.get(id);
|
|
365
|
+
if (!data) {
|
|
366
|
+
process.emit("uncaughtException", new ODSystemError("ODManagerWithSafety:getSafe(\"" + id + "\") => Unknown Id => Used backup data (" + this.#debugname + " manager)"));
|
|
367
|
+
return this.#backupCreator();
|
|
368
|
+
}
|
|
369
|
+
else
|
|
370
|
+
return data;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
exports.ODManagerWithSafety = ODManagerWithSafety;
|
|
374
|
+
/**## ODVersionManager `class`
|
|
375
|
+
* A Open Discord version manager.
|
|
376
|
+
*
|
|
377
|
+
* It is used to manage different `ODVersion`'s from the bot. You will use it to check which version of the bot is used.
|
|
378
|
+
*/
|
|
379
|
+
class ODVersionManager extends ODManager {
|
|
380
|
+
constructor() {
|
|
381
|
+
super();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
exports.ODVersionManager = ODVersionManager;
|
|
385
|
+
/**## ODVersion `class`
|
|
386
|
+
* This is an Open Discord version.
|
|
387
|
+
*
|
|
388
|
+
* It has many features like comparing versions & checking if they are compatible.
|
|
389
|
+
*
|
|
390
|
+
* You can use it in your own plugin, but most of the time you will use it to check the Open Discord version!
|
|
391
|
+
*/
|
|
392
|
+
class ODVersion extends ODManagerData {
|
|
393
|
+
/**The first number of the version (example: `v1.2.3` => `1`) */
|
|
394
|
+
primary;
|
|
395
|
+
/**The second number of the version (example: `v1.2.3` => `2`) */
|
|
396
|
+
secondary;
|
|
397
|
+
/**The third number of the version (example: `v1.2.3` => `3`) */
|
|
398
|
+
tertiary;
|
|
399
|
+
constructor(id, primary, secondary, tertiary) {
|
|
400
|
+
super(id);
|
|
401
|
+
if (typeof primary != "number")
|
|
402
|
+
throw new ODSystemError("Invalid constructor parameter => primary:number");
|
|
403
|
+
if (typeof secondary != "number")
|
|
404
|
+
throw new ODSystemError("Invalid constructor parameter => secondary:number");
|
|
405
|
+
if (typeof tertiary != "number")
|
|
406
|
+
throw new ODSystemError("Invalid constructor parameter => tertiary:number");
|
|
407
|
+
this.primary = primary;
|
|
408
|
+
this.secondary = secondary;
|
|
409
|
+
this.tertiary = tertiary;
|
|
410
|
+
}
|
|
411
|
+
/**Get the version from a string (also possible with `v` prefix)
|
|
412
|
+
* @example const version = api.ODVersion.fromString("id","v1.2.3") //creates version 1.2.3
|
|
413
|
+
*/
|
|
414
|
+
static fromString(id, version) {
|
|
415
|
+
if (typeof id != "string" && !(id instanceof ODId))
|
|
416
|
+
throw new ODSystemError("Invalid function parameter => id:ODValidId");
|
|
417
|
+
if (typeof version != "string")
|
|
418
|
+
throw new ODSystemError("Invalid function parameter => version:string");
|
|
419
|
+
const versionCheck = (version.startsWith("v")) ? version.substring(1) : version;
|
|
420
|
+
const splittedVersion = versionCheck.split(".");
|
|
421
|
+
return new this(id, Number(splittedVersion[0]), Number(splittedVersion[1]), Number(splittedVersion[2]));
|
|
422
|
+
}
|
|
423
|
+
/**Get the version as a string (`noprefix:true` => with `v` prefix)
|
|
424
|
+
* @example
|
|
425
|
+
* new api.ODVersion(1,0,0).toString(false) //returns "v1.0.0"
|
|
426
|
+
* new api.ODVersion(1,0,0).toString(true) //returns "1.0.0"
|
|
427
|
+
*/
|
|
428
|
+
toString(noprefix) {
|
|
429
|
+
const prefix = noprefix ? "" : "v";
|
|
430
|
+
return prefix + [this.primary, this.secondary, this.tertiary].join(".");
|
|
431
|
+
}
|
|
432
|
+
/**Compare this version with another version and returns the result: `higher`, `lower` or `equal`
|
|
433
|
+
* @example
|
|
434
|
+
* new api.ODVersion(1,0,0).compare(new api.ODVersion(1,2,0)) //returns "lower"
|
|
435
|
+
* new api.ODVersion(1,3,0).compare(new api.ODVersion(1,2,0)) //returns "higher"
|
|
436
|
+
* new api.ODVersion(1,2,0).compare(new api.ODVersion(1,2,0)) //returns "equal"
|
|
437
|
+
*/
|
|
438
|
+
compare(comparator) {
|
|
439
|
+
if (!(comparator instanceof ODVersion))
|
|
440
|
+
throw new ODSystemError("Invalid function parameter => comparator:ODVersion");
|
|
441
|
+
if (this.primary < comparator.primary)
|
|
442
|
+
return "lower";
|
|
443
|
+
else if (this.primary > comparator.primary)
|
|
444
|
+
return "higher";
|
|
445
|
+
else {
|
|
446
|
+
if (this.secondary < comparator.secondary)
|
|
447
|
+
return "lower";
|
|
448
|
+
else if (this.secondary > comparator.secondary)
|
|
449
|
+
return "higher";
|
|
450
|
+
else {
|
|
451
|
+
if (this.tertiary < comparator.tertiary)
|
|
452
|
+
return "lower";
|
|
453
|
+
else if (this.tertiary > comparator.tertiary)
|
|
454
|
+
return "higher";
|
|
455
|
+
else
|
|
456
|
+
return "equal";
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
/**Check if this version is included in the list
|
|
461
|
+
* @example
|
|
462
|
+
* const list = [
|
|
463
|
+
* new api.ODVersion(1,0,0),
|
|
464
|
+
* new api.ODVersion(1,0,1),
|
|
465
|
+
* new api.ODVersion(1,0,2)
|
|
466
|
+
* ]
|
|
467
|
+
* new api.ODVersion(1,0,0).compatible(list) //returns true
|
|
468
|
+
* new api.ODVersion(1,0,1).compatible(list) //returns true
|
|
469
|
+
* new api.ODVersion(1,0,3).compatible(list) //returns false
|
|
470
|
+
*/
|
|
471
|
+
compatible(list) {
|
|
472
|
+
if (!Array.isArray(list))
|
|
473
|
+
throw new ODSystemError("Invalid function parameter => list:ODVersion[]");
|
|
474
|
+
if (!list.every((v) => (v instanceof ODVersion)))
|
|
475
|
+
throw new ODSystemError("Invalid function parameter => list:ODVersion[]");
|
|
476
|
+
return list.some((v) => {
|
|
477
|
+
return (v.toString() === this.toString());
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
/**Check if this version is higher or equal to the provided `requirement`. */
|
|
481
|
+
min(requirement) {
|
|
482
|
+
if (typeof requirement == "string")
|
|
483
|
+
requirement = ODVersion.fromString("temp", requirement);
|
|
484
|
+
//skip when primary version is higher or lower than current one.
|
|
485
|
+
if (this.primary < requirement.primary)
|
|
486
|
+
return false;
|
|
487
|
+
else if (this.primary > requirement.primary)
|
|
488
|
+
return true;
|
|
489
|
+
//skip when secondary version is higher or lower than current one.
|
|
490
|
+
if (this.secondary < requirement.secondary)
|
|
491
|
+
return false;
|
|
492
|
+
else if (this.secondary > requirement.secondary)
|
|
493
|
+
return true;
|
|
494
|
+
//skip when tertiary version is higher or lower than current one.
|
|
495
|
+
if (this.tertiary < requirement.tertiary)
|
|
496
|
+
return false;
|
|
497
|
+
else if (this.tertiary > requirement.tertiary)
|
|
498
|
+
return true;
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
/**Check if this version is lower or equal to the provided `requirement`. */
|
|
502
|
+
max(requirement) {
|
|
503
|
+
if (typeof requirement == "string")
|
|
504
|
+
requirement = ODVersion.fromString("temp", requirement);
|
|
505
|
+
//skip when primary version is higher or lower than current one.
|
|
506
|
+
if (this.primary < requirement.primary)
|
|
507
|
+
return true;
|
|
508
|
+
else if (this.primary > requirement.primary)
|
|
509
|
+
return false;
|
|
510
|
+
//skip when secondary version is higher or lower than current one.
|
|
511
|
+
if (this.secondary < requirement.secondary)
|
|
512
|
+
return true;
|
|
513
|
+
else if (this.secondary > requirement.secondary)
|
|
514
|
+
return false;
|
|
515
|
+
//skip when tertiary version is higher or lower than current one.
|
|
516
|
+
if (this.tertiary < requirement.tertiary)
|
|
517
|
+
return true;
|
|
518
|
+
else if (this.tertiary > requirement.tertiary)
|
|
519
|
+
return false;
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
/**Check if this version is matches the major version (`vX.X`) of the provided `requirement`. */
|
|
523
|
+
major(requirement) {
|
|
524
|
+
if (typeof requirement == "string")
|
|
525
|
+
requirement = ODVersion.fromString("temp", requirement);
|
|
526
|
+
return (this.primary == requirement.primary && this.secondary == requirement.secondary);
|
|
527
|
+
}
|
|
528
|
+
/**Check if this version is matches the minor version (`vX.X.X`) of the provided `requirement`. */
|
|
529
|
+
minor(requirement) {
|
|
530
|
+
if (typeof requirement == "string")
|
|
531
|
+
requirement = ODVersion.fromString("temp", requirement);
|
|
532
|
+
return (this.primary == requirement.primary && this.secondary == requirement.secondary && this.tertiary == requirement.tertiary);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
exports.ODVersion = ODVersion;
|
|
536
|
+
/**## ODVersionMigration `class`
|
|
537
|
+
* This class is used to manage data migration between Open Ticket versions.
|
|
538
|
+
*
|
|
539
|
+
* It shouldn't be used by plugins because this is an internal API feature!
|
|
540
|
+
*/
|
|
541
|
+
class ODVersionMigration {
|
|
542
|
+
/**The version to migrate data to */
|
|
543
|
+
version;
|
|
544
|
+
/**The migration function */
|
|
545
|
+
#func;
|
|
546
|
+
/**The migration function */
|
|
547
|
+
#afterInitFunc;
|
|
548
|
+
constructor(version, func, afterInitFunc) {
|
|
549
|
+
this.version = version;
|
|
550
|
+
this.#func = func;
|
|
551
|
+
this.#afterInitFunc = afterInitFunc;
|
|
552
|
+
}
|
|
553
|
+
/**Run this version migration as a plugin. Returns `false` when something goes wrong. */
|
|
554
|
+
async migrate() {
|
|
555
|
+
try {
|
|
556
|
+
await this.#func();
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
catch (err) {
|
|
560
|
+
process.emit("uncaughtException", err);
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
/**Run this version migration as a plugin (after other plugins have loaded). Returns `false` when something goes wrong. */
|
|
565
|
+
async migrateAfterInit() {
|
|
566
|
+
try {
|
|
567
|
+
await this.#afterInitFunc();
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
catch (err) {
|
|
571
|
+
process.emit("uncaughtException", err);
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
exports.ODVersionMigration = ODVersionMigration;
|
|
577
|
+
/**## ODHTTPGetRequest `class`
|
|
578
|
+
* This is a class that can help you with creating simple HTTP GET requests.
|
|
579
|
+
*
|
|
580
|
+
* It works using the native node.js fetch() method. You can configure all options in the constructor!
|
|
581
|
+
* @example
|
|
582
|
+
* const request = new api.ODHTTPGetRequest("https://www.example.com/abc.txt",false,{})
|
|
583
|
+
*
|
|
584
|
+
* const result = await request.run()
|
|
585
|
+
* result.body //the response body (string)
|
|
586
|
+
* result.status //the response code (number)
|
|
587
|
+
* result.response //the full response (object)
|
|
588
|
+
*/
|
|
589
|
+
class ODHTTPGetRequest {
|
|
590
|
+
/**The url used in the request */
|
|
591
|
+
url;
|
|
592
|
+
/**The request config for additional options */
|
|
593
|
+
config;
|
|
594
|
+
/**Throw on error OR return http code 500 */
|
|
595
|
+
throwOnError;
|
|
596
|
+
constructor(main, url, throwOnError, config) {
|
|
597
|
+
if (typeof url != "string")
|
|
598
|
+
throw new ODSystemError("Invalid constructor parameter => url:string");
|
|
599
|
+
if (typeof throwOnError != "boolean")
|
|
600
|
+
throw new ODSystemError("Invalid constructor parameter => throwOnError:boolean");
|
|
601
|
+
if (typeof config != "undefined" && typeof config != "object")
|
|
602
|
+
throw new ODSystemError("Invalid constructor parameter => config?:RequestInit");
|
|
603
|
+
this.url = url;
|
|
604
|
+
this.throwOnError = throwOnError;
|
|
605
|
+
const newConfig = config ?? {};
|
|
606
|
+
newConfig.method = "GET";
|
|
607
|
+
const userAgent = ((main.project == "openticket") ? "OpenDiscordBots-OpenTicket" : "OpenDiscordBots-OpenModeration") + "/" + (main.versions.get("opendiscord:version")?.toString(true) ?? "<OD:UNKNOWN_VERSION>");
|
|
608
|
+
if (newConfig.headers)
|
|
609
|
+
Object.assign(newConfig.headers, { "User-Agent": userAgent });
|
|
610
|
+
else
|
|
611
|
+
newConfig.headers = { "User-Agent": userAgent };
|
|
612
|
+
this.config = newConfig;
|
|
613
|
+
}
|
|
614
|
+
/**Execute the GET request.*/
|
|
615
|
+
run() {
|
|
616
|
+
return new Promise(async (resolve, reject) => {
|
|
617
|
+
try {
|
|
618
|
+
const response = await fetch(this.url, this.config);
|
|
619
|
+
resolve({
|
|
620
|
+
status: response.status,
|
|
621
|
+
body: (await response.text()),
|
|
622
|
+
response: response
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
catch (err) {
|
|
626
|
+
if (this.throwOnError)
|
|
627
|
+
return reject("[OPENTICKET ERROR]: ODHTTPGetRequest => Unknown fetch() error: " + err);
|
|
628
|
+
else
|
|
629
|
+
return resolve({
|
|
630
|
+
status: 500,
|
|
631
|
+
body: "Open Discord Error: Unknown fetch() error: " + err,
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
exports.ODHTTPGetRequest = ODHTTPGetRequest;
|
|
638
|
+
/**## ODHTTPPostRequest `class`
|
|
639
|
+
* This is a class that can help you with creating simple HTTP POST requests.
|
|
640
|
+
*
|
|
641
|
+
* It works using the native node.js fetch() method. You can configure all options in the constructor!
|
|
642
|
+
* @example
|
|
643
|
+
* const request = new api.ODHTTPPostRequest("https://www.example.com/abc.txt",false,{})
|
|
644
|
+
*
|
|
645
|
+
* const result = await request.run()
|
|
646
|
+
* result.body //the response body (string)
|
|
647
|
+
* result.status //the response code (number)
|
|
648
|
+
* result.response //the full response (object)
|
|
649
|
+
*/
|
|
650
|
+
class ODHTTPPostRequest {
|
|
651
|
+
/**The url used in the request */
|
|
652
|
+
url;
|
|
653
|
+
/**The request config for additional options */
|
|
654
|
+
config;
|
|
655
|
+
/**Throw on error OR return http code 500 */
|
|
656
|
+
throwOnError;
|
|
657
|
+
constructor(main, url, throwOnError, config) {
|
|
658
|
+
if (typeof url != "string")
|
|
659
|
+
throw new ODSystemError("Invalid constructor parameter => url:string");
|
|
660
|
+
if (typeof throwOnError != "boolean")
|
|
661
|
+
throw new ODSystemError("Invalid constructor parameter => throwOnError:boolean");
|
|
662
|
+
if (typeof config != "undefined" && typeof config != "object")
|
|
663
|
+
throw new ODSystemError("Invalid constructor parameter => config?:RequestInit");
|
|
664
|
+
this.url = url;
|
|
665
|
+
this.throwOnError = throwOnError;
|
|
666
|
+
const newConfig = config ?? {};
|
|
667
|
+
newConfig.method = "POST";
|
|
668
|
+
const userAgent = ((main.project == "openticket") ? "OpenDiscordBots-OpenTicket" : "OpenDiscordBots-OpenModeration") + "/" + (main.versions.get("opendiscord:version")?.toString(true) ?? "<OD:UNKNOWN_VERSION>");
|
|
669
|
+
if (newConfig.headers)
|
|
670
|
+
Object.assign(newConfig.headers, { "User-Agent": userAgent });
|
|
671
|
+
else
|
|
672
|
+
newConfig.headers = { "User-Agent": userAgent };
|
|
673
|
+
this.config = newConfig;
|
|
674
|
+
}
|
|
675
|
+
/**Execute the POST request.*/
|
|
676
|
+
run() {
|
|
677
|
+
return new Promise(async (resolve, reject) => {
|
|
678
|
+
try {
|
|
679
|
+
const response = await fetch(this.url, this.config);
|
|
680
|
+
resolve({
|
|
681
|
+
status: response.status,
|
|
682
|
+
body: (await response.text()),
|
|
683
|
+
response: response
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
catch (err) {
|
|
687
|
+
if (this.throwOnError)
|
|
688
|
+
return reject("[OPENTICKET ERROR]: ODHTTPPostRequest => Unknown fetch() error: " + err);
|
|
689
|
+
else
|
|
690
|
+
return resolve({
|
|
691
|
+
status: 500,
|
|
692
|
+
body: "Open Discord Error: Unknown fetch() error!",
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
exports.ODHTTPPostRequest = ODHTTPPostRequest;
|
|
699
|
+
/**## ODEnvHelper `class`
|
|
700
|
+
* This is a utility class that helps you with reading the ENV.
|
|
701
|
+
*
|
|
702
|
+
* It has support for the built-in `process.env` & `.env` file
|
|
703
|
+
* @example
|
|
704
|
+
* const envHelper = new api.ODEnvHelper()
|
|
705
|
+
*
|
|
706
|
+
* const variableA = envHelper.getVariable("value-a")
|
|
707
|
+
* const variableB = envHelper.getVariable("value-b","dotenv") //only get from .env
|
|
708
|
+
* const variableA = envHelper.getVariable("value-c","env") //only get from process.env
|
|
709
|
+
*/
|
|
710
|
+
class ODEnvHelper {
|
|
711
|
+
/**All variables found in the `.env` file */
|
|
712
|
+
dotenv;
|
|
713
|
+
/**All variables found in `process.env` */
|
|
714
|
+
env;
|
|
715
|
+
constructor(customEnvPath) {
|
|
716
|
+
if (typeof customEnvPath != "undefined" && typeof customEnvPath != "string")
|
|
717
|
+
throw new ODSystemError("Invalid constructor parameter => customEnvPath?:string");
|
|
718
|
+
const path = customEnvPath ? customEnvPath : ".env";
|
|
719
|
+
this.dotenv = fs.existsSync(path) ? this.#readDotEnv(fs.readFileSync(path)) : {};
|
|
720
|
+
this.env = process.env;
|
|
721
|
+
}
|
|
722
|
+
/**Get a variable from the env */
|
|
723
|
+
getVariable(name, source) {
|
|
724
|
+
if (typeof name != "string")
|
|
725
|
+
throw new ODSystemError("Invalid function parameter => name:string");
|
|
726
|
+
if ((typeof source != "undefined" && typeof source != "string") || (source && !["env", "dotenv"].includes(source)))
|
|
727
|
+
throw new ODSystemError("Invalid function parameter => source:'dotenv'|'env'");
|
|
728
|
+
if (source == "dotenv") {
|
|
729
|
+
return this.dotenv[name];
|
|
730
|
+
}
|
|
731
|
+
else if (source == "env") {
|
|
732
|
+
return this.env[name];
|
|
733
|
+
}
|
|
734
|
+
else {
|
|
735
|
+
//when no source specified => .env has priority over process.env
|
|
736
|
+
if (this.dotenv[name])
|
|
737
|
+
return this.dotenv[name];
|
|
738
|
+
else
|
|
739
|
+
return this.env[name];
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
//THIS CODE IS COPIED FROM THE DODENV-LIB
|
|
743
|
+
//Repo: https://github.com/motdotla/dotenv
|
|
744
|
+
//Source: https://github.com/motdotla/dotenv/blob/master/lib/main.js#L12
|
|
745
|
+
#readDotEnv(src) {
|
|
746
|
+
const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
747
|
+
const obj = {};
|
|
748
|
+
// Convert buffer to string
|
|
749
|
+
let lines = src.toString();
|
|
750
|
+
// Convert line breaks to same format
|
|
751
|
+
lines = lines.replace(/\r\n?/mg, '\n');
|
|
752
|
+
let match;
|
|
753
|
+
while ((match = LINE.exec(lines)) != null) {
|
|
754
|
+
const key = match[1];
|
|
755
|
+
// Default undefined or null to empty string
|
|
756
|
+
let value = (match[2] || '');
|
|
757
|
+
// Remove whitespace
|
|
758
|
+
value = value.trim();
|
|
759
|
+
// Check if double quoted
|
|
760
|
+
const maybeQuote = value[0];
|
|
761
|
+
// Remove surrounding quotes
|
|
762
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, '$2');
|
|
763
|
+
// Expand newlines if double quoted
|
|
764
|
+
if (maybeQuote === '"') {
|
|
765
|
+
value = value.replace(/\\n/g, '\n');
|
|
766
|
+
value = value.replace(/\\r/g, '\r');
|
|
767
|
+
}
|
|
768
|
+
// Add to object
|
|
769
|
+
obj[key] = value;
|
|
770
|
+
}
|
|
771
|
+
return obj;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
exports.ODEnvHelper = ODEnvHelper;
|
|
775
|
+
/**## ODSystemError `class`
|
|
776
|
+
* A wrapper for the node.js `Error` class that makes the error look better in the console!
|
|
777
|
+
*
|
|
778
|
+
* This wrapper is made for Open Discord system errors! **It can only be used by Open Discord itself!**
|
|
779
|
+
*/
|
|
780
|
+
class ODSystemError extends Error {
|
|
781
|
+
/**This variable gets detected by the error handling system to know how to render it */
|
|
782
|
+
_ODErrorType = "system";
|
|
783
|
+
/**Create an `ODSystemError` directly from an `Error` class */
|
|
784
|
+
static fromError(err) {
|
|
785
|
+
err["_ODErrorType"] = "system";
|
|
786
|
+
return err;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
exports.ODSystemError = ODSystemError;
|
|
790
|
+
/**## ODPluginError `class`
|
|
791
|
+
* A wrapper for the node.js `Error` class that makes the error look better in the console!
|
|
792
|
+
*
|
|
793
|
+
* This wrapper is made for Open Discord plugin errors! **It can only be used by plugins!**
|
|
794
|
+
*/
|
|
795
|
+
class ODPluginError extends Error {
|
|
796
|
+
/**This variable gets detected by the error handling system to know how to render it */
|
|
797
|
+
_ODErrorType = "plugin";
|
|
798
|
+
/**Create an `ODPluginError` directly from an `Error` class */
|
|
799
|
+
static fromError(err) {
|
|
800
|
+
err["_ODErrorType"] = "plugin";
|
|
801
|
+
return err;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
exports.ODPluginError = ODPluginError;
|