@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,598 @@
|
|
|
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.ODLiveStatusRenderer = exports.ODLiveStatusManager = exports.ODLiveStatusUrlSource = exports.ODLiveStatusFileSource = exports.ODLiveStatusSource = exports.ODDebugger = exports.ODDebugFileManager = exports.ODConsoleManager = exports.ODError = exports.ODConsoleErrorMessage = exports.ODConsoleWarningMessage = exports.ODConsoleDebugMessage = exports.ODConsolePluginMessage = exports.ODConsoleSystemMessage = exports.ODConsoleInfoMessage = exports.ODConsoleMessage = void 0;
|
|
7
|
+
///////////////////////////////////////
|
|
8
|
+
//CONSOLE MODULE
|
|
9
|
+
///////////////////////////////////////
|
|
10
|
+
const base_1 = require("./base");
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const fs_1 = __importDefault(require("fs"));
|
|
13
|
+
const ansis_1 = __importDefault(require("ansis"));
|
|
14
|
+
/**## ODConsoleMessage `class`
|
|
15
|
+
* This is an Open Discord console message.
|
|
16
|
+
*
|
|
17
|
+
* It is used to create beautiful & styled logs in the console with a prefix, message & parameters.
|
|
18
|
+
* It also has full color support using `ansis` and parameters are parsed for you!
|
|
19
|
+
*/
|
|
20
|
+
class ODConsoleMessage {
|
|
21
|
+
/**The main message sent in the console */
|
|
22
|
+
message;
|
|
23
|
+
/**An array of all the parameters in this message */
|
|
24
|
+
params;
|
|
25
|
+
/**The prefix of this message (!uppercase recommended!) */
|
|
26
|
+
prefix;
|
|
27
|
+
/**The color of the prefix of this message */
|
|
28
|
+
color;
|
|
29
|
+
constructor(message, prefix, color, params) {
|
|
30
|
+
this.message = message;
|
|
31
|
+
this.params = params ? params : [];
|
|
32
|
+
this.prefix = prefix;
|
|
33
|
+
if (["white", "red", "yellow", "green", "blue", "gray", "cyan", "magenta"].includes(color)) {
|
|
34
|
+
this.color = color;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
this.color = "white";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**Render this message to the console using `console.log`! Returns `false` when something went wrong. */
|
|
41
|
+
render() {
|
|
42
|
+
try {
|
|
43
|
+
const prefixcolor = ansis_1.default[this.color];
|
|
44
|
+
const paramsstring = " " + this.createParamsString("gray");
|
|
45
|
+
const message = prefixcolor("[" + this.prefix + "] ") + this.message;
|
|
46
|
+
console.log(message + paramsstring);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**Create a more-detailed, non-colored version of this message to store it in the `debug.txt` file! */
|
|
54
|
+
toDebugString() {
|
|
55
|
+
const pstrings = [];
|
|
56
|
+
this.params.forEach((p) => {
|
|
57
|
+
pstrings.push(p.key + ": " + p.value);
|
|
58
|
+
});
|
|
59
|
+
const pstring = (pstrings.length > 0) ? " (" + pstrings.join(", ") + ")" : "";
|
|
60
|
+
const date = new Date();
|
|
61
|
+
const dstring = `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
|
|
62
|
+
return `[${dstring} ${this.prefix}] ${this.message}${pstring}`;
|
|
63
|
+
}
|
|
64
|
+
/**Render the parameters of this message in a specific color. */
|
|
65
|
+
createParamsString(color) {
|
|
66
|
+
let validcolor = "white";
|
|
67
|
+
if (["white", "red", "yellow", "green", "blue", "gray", "cyan", "magenta"].includes(color)) {
|
|
68
|
+
validcolor = color;
|
|
69
|
+
}
|
|
70
|
+
const pstrings = [];
|
|
71
|
+
this.params.forEach((p) => {
|
|
72
|
+
if (!p.hidden)
|
|
73
|
+
pstrings.push(p.key + ": " + p.value);
|
|
74
|
+
});
|
|
75
|
+
return (pstrings.length > 0) ? ansis_1.default[validcolor](" (" + pstrings.join(", ") + ")") : "";
|
|
76
|
+
}
|
|
77
|
+
/**Set the message */
|
|
78
|
+
setMessage(message) {
|
|
79
|
+
this.message = message;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
/**Set the params */
|
|
83
|
+
setParams(params) {
|
|
84
|
+
this.params = params;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
/**Set the prefix */
|
|
88
|
+
setPrefix(prefix) {
|
|
89
|
+
this.prefix = prefix;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
/**Set the prefix color */
|
|
93
|
+
setColor(color) {
|
|
94
|
+
if (["white", "red", "yellow", "green", "blue", "gray", "cyan", "magenta"].includes(color)) {
|
|
95
|
+
this.color = color;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this.color = "white";
|
|
99
|
+
}
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.ODConsoleMessage = ODConsoleMessage;
|
|
104
|
+
/**## ODConsoleInfoMessage `class`
|
|
105
|
+
* This is an Open Discord console info message.
|
|
106
|
+
*
|
|
107
|
+
* It is the same as a normal `ODConsoleMessage`, but it has a predefined prefix & color scheme for the "INFO" messages!
|
|
108
|
+
*/
|
|
109
|
+
class ODConsoleInfoMessage extends ODConsoleMessage {
|
|
110
|
+
constructor(message, params) {
|
|
111
|
+
super(message, "INFO", "blue", params);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.ODConsoleInfoMessage = ODConsoleInfoMessage;
|
|
115
|
+
/**## ODConsoleSystemMessage `class`
|
|
116
|
+
* This is an Open Discord console system message.
|
|
117
|
+
*
|
|
118
|
+
* It is the same as a normal `ODConsoleMessage`, but it has a predefined prefix & color scheme for the "SYSTEM" messages!
|
|
119
|
+
*/
|
|
120
|
+
class ODConsoleSystemMessage extends ODConsoleMessage {
|
|
121
|
+
constructor(message, params) {
|
|
122
|
+
super(message, "SYSTEM", "green", params);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.ODConsoleSystemMessage = ODConsoleSystemMessage;
|
|
126
|
+
/**## ODConsolePluginMessage `class`
|
|
127
|
+
* This is an Open Discord console plugin message.
|
|
128
|
+
*
|
|
129
|
+
* It is the same as a normal `ODConsoleMessage`, but it has a predefined prefix & color scheme for the "PLUGIN" messages!
|
|
130
|
+
*/
|
|
131
|
+
class ODConsolePluginMessage extends ODConsoleMessage {
|
|
132
|
+
constructor(message, params) {
|
|
133
|
+
super(message, "PLUGIN", "magenta", params);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.ODConsolePluginMessage = ODConsolePluginMessage;
|
|
137
|
+
/**## ODConsoleDebugMessage `class`
|
|
138
|
+
* This is an Open Discord console debug message.
|
|
139
|
+
*
|
|
140
|
+
* It is the same as a normal `ODConsoleMessage`, but it has a predefined prefix & color scheme for the "DEBUG" messages!
|
|
141
|
+
*/
|
|
142
|
+
class ODConsoleDebugMessage extends ODConsoleMessage {
|
|
143
|
+
constructor(message, params) {
|
|
144
|
+
super(message, "DEBUG", "cyan", params);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.ODConsoleDebugMessage = ODConsoleDebugMessage;
|
|
148
|
+
/**## ODConsoleWarningMessage `class`
|
|
149
|
+
* This is an Open Discord console warning message.
|
|
150
|
+
*
|
|
151
|
+
* It is the same as a normal `ODConsoleMessage`, but it has a predefined prefix & color scheme for the "WARNING" messages!
|
|
152
|
+
*/
|
|
153
|
+
class ODConsoleWarningMessage extends ODConsoleMessage {
|
|
154
|
+
constructor(message, params) {
|
|
155
|
+
super(message, "WARNING", "yellow", params);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.ODConsoleWarningMessage = ODConsoleWarningMessage;
|
|
159
|
+
/**## ODConsoleErrorMessage `class`
|
|
160
|
+
* This is an Open Discord console error message.
|
|
161
|
+
*
|
|
162
|
+
* It is the same as a normal `ODConsoleMessage`, but it has a predefined prefix & color scheme for the "ERROR" messages!
|
|
163
|
+
*/
|
|
164
|
+
class ODConsoleErrorMessage extends ODConsoleMessage {
|
|
165
|
+
constructor(message, params) {
|
|
166
|
+
super(message, "ERROR", "red", params);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.ODConsoleErrorMessage = ODConsoleErrorMessage;
|
|
170
|
+
/**## ODError `class`
|
|
171
|
+
* This is an Open Discord error.
|
|
172
|
+
*
|
|
173
|
+
* It is used to render and log Node.js errors & crashes in a styled way to the console & `debug.txt` file!
|
|
174
|
+
*/
|
|
175
|
+
class ODError {
|
|
176
|
+
/**The original error that this class wraps around */
|
|
177
|
+
error;
|
|
178
|
+
/**The origin of the original error */
|
|
179
|
+
origin;
|
|
180
|
+
constructor(error, origin) {
|
|
181
|
+
this.error = error;
|
|
182
|
+
this.origin = origin;
|
|
183
|
+
}
|
|
184
|
+
/**Render this error to the console using `console.log`! Returns `false` when something went wrong. */
|
|
185
|
+
render() {
|
|
186
|
+
try {
|
|
187
|
+
let prefix = (this.error["_ODErrorType"] == "plugin") ? "PLUGIN ERROR" : ((this.error["_ODErrorType"] == "system") ? "OPENTICKET ERROR" : "UNKNOWN ERROR");
|
|
188
|
+
//title
|
|
189
|
+
console.log(ansis_1.default.red("[" + prefix + "]: ") + this.error.message + " | origin: " + this.origin);
|
|
190
|
+
//stack trace
|
|
191
|
+
if (this.error.stack)
|
|
192
|
+
console.log(ansis_1.default.gray(this.error.stack));
|
|
193
|
+
//additional message
|
|
194
|
+
if (this.error["_ODErrorType"] == "plugin")
|
|
195
|
+
console.log(ansis_1.default.red.bold("\nPlease report this error to the plugin developer and help us create a more stable plugin!"));
|
|
196
|
+
else
|
|
197
|
+
console.log(ansis_1.default.red.bold("\nPlease report this error to our discord server and help us create a more stable bot!"));
|
|
198
|
+
console.log(ansis_1.default.red("Also send the " + ansis_1.default.cyan.bold("debug.txt") + " file! It would help a lot!\n"));
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**Create a more-detailed, non-colored version of this error to store it in the `debug.txt` file! */
|
|
206
|
+
toDebugString() {
|
|
207
|
+
return "[UNKNOWN OD ERROR]: " + this.error.message + " | origin: " + this.origin + "\n" + this.error.stack;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.ODError = ODError;
|
|
211
|
+
/**## ODConsoleManager `class`
|
|
212
|
+
* This is the Open Discord console manager.
|
|
213
|
+
*
|
|
214
|
+
* It handles the entire console system of Open Discord. It's also the place where you need to log `ODConsoleMessage`'s.
|
|
215
|
+
* This manager keeps a short history of messages sent to the console which is configurable by plugins.
|
|
216
|
+
*
|
|
217
|
+
* The debug file (`debug.txt`) is handled in a sub-manager!
|
|
218
|
+
*/
|
|
219
|
+
class ODConsoleManager {
|
|
220
|
+
/**The history of `ODConsoleMessage`'s and `ODError`'s since startup */
|
|
221
|
+
history = [];
|
|
222
|
+
/**The max length of the history. The oldest messages will be removed when over the limit */
|
|
223
|
+
historylength = 100;
|
|
224
|
+
/**An alias to the debugfile manager. (`debug.txt`) */
|
|
225
|
+
debugfile;
|
|
226
|
+
/**Is silent mode enabled? */
|
|
227
|
+
silent = false;
|
|
228
|
+
constructor(historylength, debugfile) {
|
|
229
|
+
this.historylength = historylength;
|
|
230
|
+
this.debugfile = debugfile;
|
|
231
|
+
}
|
|
232
|
+
log(message, type, params) {
|
|
233
|
+
if (message instanceof ODConsoleMessage) {
|
|
234
|
+
if (!this.silent)
|
|
235
|
+
message.render();
|
|
236
|
+
if (this.debugfile)
|
|
237
|
+
this.debugfile.writeConsoleMessage(message);
|
|
238
|
+
this.history.push(message);
|
|
239
|
+
}
|
|
240
|
+
else if (message instanceof ODError) {
|
|
241
|
+
if (!this.silent)
|
|
242
|
+
message.render();
|
|
243
|
+
if (this.debugfile)
|
|
244
|
+
this.debugfile.writeErrorMessage(message);
|
|
245
|
+
this.history.push(message);
|
|
246
|
+
}
|
|
247
|
+
else if (["string", "number", "boolean", "object"].includes(typeof message)) {
|
|
248
|
+
let newMessage;
|
|
249
|
+
if (type == "info")
|
|
250
|
+
newMessage = new ODConsoleInfoMessage(message, params);
|
|
251
|
+
else if (type == "system")
|
|
252
|
+
newMessage = new ODConsoleSystemMessage(message, params);
|
|
253
|
+
else if (type == "plugin")
|
|
254
|
+
newMessage = new ODConsolePluginMessage(message, params);
|
|
255
|
+
else if (type == "debug")
|
|
256
|
+
newMessage = new ODConsoleDebugMessage(message, params);
|
|
257
|
+
else if (type == "warning")
|
|
258
|
+
newMessage = new ODConsoleWarningMessage(message, params);
|
|
259
|
+
else if (type == "error")
|
|
260
|
+
newMessage = new ODConsoleErrorMessage(message, params);
|
|
261
|
+
else
|
|
262
|
+
newMessage = new ODConsoleSystemMessage(message, params);
|
|
263
|
+
if (!this.silent)
|
|
264
|
+
newMessage.render();
|
|
265
|
+
if (this.debugfile)
|
|
266
|
+
this.debugfile.writeConsoleMessage(newMessage);
|
|
267
|
+
this.history.push(newMessage);
|
|
268
|
+
}
|
|
269
|
+
this.#purgeHistory();
|
|
270
|
+
}
|
|
271
|
+
/**Shorten the history when it exceeds the max history length! */
|
|
272
|
+
#purgeHistory() {
|
|
273
|
+
if (this.history.length > this.historylength)
|
|
274
|
+
this.history.shift();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.ODConsoleManager = ODConsoleManager;
|
|
278
|
+
/**## ODDebugFileManager `class`
|
|
279
|
+
* This is the Open Discord debug file manager.
|
|
280
|
+
*
|
|
281
|
+
* It manages the Open Discord debug file (`debug.txt`) which keeps a history of all system logs.
|
|
282
|
+
* There are even internal logs that aren't logged to the console which are available in this file!
|
|
283
|
+
*
|
|
284
|
+
* Using this class, you can change the max length of this file and some other cool things!
|
|
285
|
+
*/
|
|
286
|
+
class ODDebugFileManager {
|
|
287
|
+
/**The path to the debugfile (`./debug.txt` by default) */
|
|
288
|
+
path;
|
|
289
|
+
/**The filename of the debugfile (`debug.txt` by default) */
|
|
290
|
+
filename;
|
|
291
|
+
/**The current version of the bot used in the debug file. */
|
|
292
|
+
version;
|
|
293
|
+
/**The max length of the debug file. */
|
|
294
|
+
maxlines;
|
|
295
|
+
constructor(path, filename, maxlines, version) {
|
|
296
|
+
this.path = path_1.default.join(path, filename);
|
|
297
|
+
this.filename = filename;
|
|
298
|
+
this.version = version;
|
|
299
|
+
this.maxlines = maxlines;
|
|
300
|
+
this.#writeStartupStats();
|
|
301
|
+
}
|
|
302
|
+
/**Check if the debug file exists */
|
|
303
|
+
#existsDebugFile() {
|
|
304
|
+
return fs_1.default.existsSync(this.path);
|
|
305
|
+
}
|
|
306
|
+
/**Read from the debug file */
|
|
307
|
+
#readDebugFile() {
|
|
308
|
+
if (this.#existsDebugFile()) {
|
|
309
|
+
try {
|
|
310
|
+
return fs_1.default.readFileSync(this.path).toString();
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**Write to the debug file and shorten it when needed. */
|
|
321
|
+
#writeDebugFile(text) {
|
|
322
|
+
const currenttext = this.#readDebugFile();
|
|
323
|
+
if (currenttext) {
|
|
324
|
+
const splitted = currenttext.split("\n");
|
|
325
|
+
if (splitted.length + text.split("\n").length > this.maxlines) {
|
|
326
|
+
splitted.splice(7, (text.split("\n").length));
|
|
327
|
+
}
|
|
328
|
+
splitted.push(text);
|
|
329
|
+
fs_1.default.writeFileSync(this.path, splitted.join("\n"));
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
//write new file:
|
|
333
|
+
const newtext = this.#createStatsText() + text;
|
|
334
|
+
fs_1.default.writeFileSync(this.path, newtext);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**Generate the stats/header of the debug file (containing the version) */
|
|
338
|
+
#createStatsText() {
|
|
339
|
+
const date = new Date();
|
|
340
|
+
const dstring = `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
|
|
341
|
+
return [
|
|
342
|
+
"=========================",
|
|
343
|
+
"OPEN DISCORD DEBUG FILE:",
|
|
344
|
+
"version: " + this.version.toString(),
|
|
345
|
+
"last startup: " + dstring,
|
|
346
|
+
"=========================\n\n"
|
|
347
|
+
].join("\n");
|
|
348
|
+
}
|
|
349
|
+
/**Write the stats/header to the debug file on startup */
|
|
350
|
+
#writeStartupStats() {
|
|
351
|
+
const currenttext = this.#readDebugFile();
|
|
352
|
+
if (currenttext) {
|
|
353
|
+
//edit previous file:
|
|
354
|
+
const splitted = currenttext.split("\n");
|
|
355
|
+
splitted.splice(0, 7);
|
|
356
|
+
if (splitted.length + 11 > this.maxlines) {
|
|
357
|
+
splitted.splice(0, ((splitted.length + 11) - this.maxlines));
|
|
358
|
+
}
|
|
359
|
+
splitted.unshift(this.#createStatsText());
|
|
360
|
+
splitted.push("\n---------------------------------------------------------------------\n---------------------------------------------------------------------\n");
|
|
361
|
+
fs_1.default.writeFileSync(this.path, splitted.join("\n"));
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
//write new file:
|
|
365
|
+
const newtext = this.#createStatsText();
|
|
366
|
+
fs_1.default.writeFileSync(this.path, newtext);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
/**Write an `ODConsoleMessage` to the debug file */
|
|
370
|
+
writeConsoleMessage(message) {
|
|
371
|
+
this.#writeDebugFile(message.toDebugString());
|
|
372
|
+
}
|
|
373
|
+
/**Write an `ODError` to the debug file */
|
|
374
|
+
writeErrorMessage(error) {
|
|
375
|
+
this.#writeDebugFile(error.toDebugString());
|
|
376
|
+
}
|
|
377
|
+
/**Write custom text to the debug file */
|
|
378
|
+
writeText(text) {
|
|
379
|
+
this.#writeDebugFile(text);
|
|
380
|
+
}
|
|
381
|
+
/**Write a custom note to the debug file (starting with `[NOTE]:`) */
|
|
382
|
+
writeNote(text) {
|
|
383
|
+
this.#writeDebugFile("[NOTE]: " + text);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
exports.ODDebugFileManager = ODDebugFileManager;
|
|
387
|
+
/**## ODDebugger `class`
|
|
388
|
+
* This is the Open Discord debugger.
|
|
389
|
+
*
|
|
390
|
+
* It is a simple wrapper around the `ODConsoleManager` to handle debugging (primarily for `ODManagers`).
|
|
391
|
+
* Messages created using this debugger are only logged to the debug file unless specified otherwise.
|
|
392
|
+
*
|
|
393
|
+
* You will probably notice this class being used in the `ODManager` constructor.
|
|
394
|
+
*
|
|
395
|
+
* Using this system, all additions & removals inside a manager are logged to the debug file. This makes searching for errors a lot easier!
|
|
396
|
+
*/
|
|
397
|
+
class ODDebugger {
|
|
398
|
+
/**An alias to the Open Discord console manager. */
|
|
399
|
+
console;
|
|
400
|
+
/**When enabled, debug logs are also shown in the console. */
|
|
401
|
+
visible = false;
|
|
402
|
+
constructor(console) {
|
|
403
|
+
this.console = console;
|
|
404
|
+
}
|
|
405
|
+
/**Create a debug message. This will always be logged to `debug.txt` & sometimes to the console (when enabled). Returns `true` when visible */
|
|
406
|
+
debug(message, params) {
|
|
407
|
+
if (this.visible) {
|
|
408
|
+
this.console.log(new ODConsoleDebugMessage(message, params));
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
this.console.debugfile.writeConsoleMessage(new ODConsoleDebugMessage(message, params));
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
exports.ODDebugger = ODDebugger;
|
|
418
|
+
/**## ODLiveStatusSource `class`
|
|
419
|
+
* This is the Open Discord livestatus source.
|
|
420
|
+
*
|
|
421
|
+
* It is an empty template for a livestatus source.
|
|
422
|
+
* By default, you should use `ODLiveStatusUrlSource` or `ODLiveStatusFileSource`,
|
|
423
|
+
* unless you want to create one on your own!
|
|
424
|
+
*
|
|
425
|
+
* This class doesn't do anything on it's own! It's just a template!
|
|
426
|
+
*/
|
|
427
|
+
class ODLiveStatusSource extends base_1.ODManagerData {
|
|
428
|
+
/**The raw data of this source */
|
|
429
|
+
data;
|
|
430
|
+
constructor(id, data) {
|
|
431
|
+
super(id);
|
|
432
|
+
this.data = data;
|
|
433
|
+
}
|
|
434
|
+
/**Change the current data using this method! */
|
|
435
|
+
setData(data) {
|
|
436
|
+
this.data = data;
|
|
437
|
+
}
|
|
438
|
+
/**Get all messages relevant to the bot based on some parameters. */
|
|
439
|
+
async getMessages(main) {
|
|
440
|
+
const validMessages = [];
|
|
441
|
+
//parse data from ODMain
|
|
442
|
+
const currentVersion = main.versions.get("opendiscord:version")?.toString(true) ?? "<OD:UNKNOWN_VERSION>";
|
|
443
|
+
const usingSlashCommands = main.configs.get("opendiscord:general")?.data.slashCommands ?? false;
|
|
444
|
+
const usingTranscripts = false; //TODO
|
|
445
|
+
const currentLanguage = main.languages.getCurrentLanguageId();
|
|
446
|
+
const usingPlugins = (main.plugins.getLength() > 0);
|
|
447
|
+
//check data for each message
|
|
448
|
+
this.data.forEach((msg) => {
|
|
449
|
+
const { active } = msg;
|
|
450
|
+
const correctVersion = active.versions.includes(currentVersion);
|
|
451
|
+
const correctSlashMode = (usingSlashCommands && active.usingSlashCommands) || (!usingSlashCommands && active.notUsingSlashCommands);
|
|
452
|
+
const correctTranscriptMode = (usingTranscripts == "text" && active.usingTextTranscripts) || (usingTranscripts == "html" && active.usingHtmlTranscripts) || (!usingTranscripts && active.notUsingTranscripts);
|
|
453
|
+
const correctLanguage = active.languages.includes(currentLanguage) || active.allLanguages;
|
|
454
|
+
const correctPlugins = (usingPlugins && active.usingPlugins) || (!usingPlugins && active.notUsingPlugins);
|
|
455
|
+
if (correctVersion && correctLanguage && correctPlugins && correctSlashMode && correctTranscriptMode)
|
|
456
|
+
validMessages.push(msg);
|
|
457
|
+
});
|
|
458
|
+
//return the valid messages
|
|
459
|
+
return validMessages;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
exports.ODLiveStatusSource = ODLiveStatusSource;
|
|
463
|
+
/**## ODLiveStatusFileSource `class`
|
|
464
|
+
* This is the Open Discord livestatus file source.
|
|
465
|
+
*
|
|
466
|
+
* It is a LiveStatus source that will read the data from a local file.
|
|
467
|
+
*
|
|
468
|
+
* This can be used for testing/extending the LiveStatus system!
|
|
469
|
+
*/
|
|
470
|
+
class ODLiveStatusFileSource extends ODLiveStatusSource {
|
|
471
|
+
/**The path to the source file */
|
|
472
|
+
path;
|
|
473
|
+
constructor(id, path) {
|
|
474
|
+
if (fs_1.default.existsSync(path)) {
|
|
475
|
+
super(id, JSON.parse(fs_1.default.readFileSync(path).toString()));
|
|
476
|
+
}
|
|
477
|
+
else
|
|
478
|
+
throw new base_1.ODSystemError("LiveStatus source file doesn't exist!");
|
|
479
|
+
this.path = path;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
exports.ODLiveStatusFileSource = ODLiveStatusFileSource;
|
|
483
|
+
/**## ODLiveStatusUrlSource `class`
|
|
484
|
+
* This is the Open Discord livestatus url source.
|
|
485
|
+
*
|
|
486
|
+
* It is a LiveStatus source that will read the data from a http URL (json file).
|
|
487
|
+
*
|
|
488
|
+
* This is the default way of receiving LiveStatus messages!
|
|
489
|
+
*/
|
|
490
|
+
class ODLiveStatusUrlSource extends ODLiveStatusSource {
|
|
491
|
+
/**The url used in the request */
|
|
492
|
+
url;
|
|
493
|
+
/**The `ODHTTPGetRequest` helper to fetch the url! */
|
|
494
|
+
request;
|
|
495
|
+
constructor(main, id, url) {
|
|
496
|
+
super(id, []);
|
|
497
|
+
this.url = url;
|
|
498
|
+
this.request = new base_1.ODHTTPGetRequest(main, url, false);
|
|
499
|
+
}
|
|
500
|
+
async getMessages(main) {
|
|
501
|
+
//additional setup
|
|
502
|
+
this.request.url = this.url;
|
|
503
|
+
const rawRes = await this.request.run();
|
|
504
|
+
if (rawRes.status != 200)
|
|
505
|
+
throw new base_1.ODSystemError("ODLiveStatusUrlSource => Request Failed!");
|
|
506
|
+
try {
|
|
507
|
+
this.setData(JSON.parse(rawRes.body));
|
|
508
|
+
}
|
|
509
|
+
catch {
|
|
510
|
+
throw new base_1.ODSystemError("ODLiveStatusUrlSource => Request Failed!");
|
|
511
|
+
}
|
|
512
|
+
//default
|
|
513
|
+
return super.getMessages(main);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
exports.ODLiveStatusUrlSource = ODLiveStatusUrlSource;
|
|
517
|
+
/**## ODLiveStatusManager `class`
|
|
518
|
+
* This is the Open Discord livestatus manager.
|
|
519
|
+
*
|
|
520
|
+
* It manages all LiveStatus sources and has the renderer for all LiveStatus messages.
|
|
521
|
+
*
|
|
522
|
+
* You can use this to customise or add stuff to the LiveStatus system.
|
|
523
|
+
* Access it in the global `opendiscord.startscreen.livestatus` variable!
|
|
524
|
+
*/
|
|
525
|
+
class ODLiveStatusManager extends base_1.ODManager {
|
|
526
|
+
/**The class responsible for rendering the livestatus messages. */
|
|
527
|
+
renderer;
|
|
528
|
+
/**A reference to the ODMain or "opendiscord" global variable */
|
|
529
|
+
#main;
|
|
530
|
+
constructor(debug, main) {
|
|
531
|
+
super(debug, "livestatus source");
|
|
532
|
+
this.renderer = new ODLiveStatusRenderer(main.console);
|
|
533
|
+
this.#main = main;
|
|
534
|
+
}
|
|
535
|
+
/**Get the messages from all sources combined! */
|
|
536
|
+
async getAllMessages() {
|
|
537
|
+
const messages = [];
|
|
538
|
+
for (const source of this.getAll()) {
|
|
539
|
+
try {
|
|
540
|
+
messages.push(...(await source.getMessages(this.#main)));
|
|
541
|
+
}
|
|
542
|
+
catch { }
|
|
543
|
+
}
|
|
544
|
+
return messages;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
exports.ODLiveStatusManager = ODLiveStatusManager;
|
|
548
|
+
/**## ODLiveStatusRenderer `class`
|
|
549
|
+
* This is the Open Discord livestatus renderer.
|
|
550
|
+
*
|
|
551
|
+
* It's responsible for rendering all LiveStatus messages to the console.
|
|
552
|
+
*/
|
|
553
|
+
class ODLiveStatusRenderer {
|
|
554
|
+
/**A reference to the ODConsoleManager or "opendiscord.console" global variable */
|
|
555
|
+
#console;
|
|
556
|
+
constructor(console) {
|
|
557
|
+
this.#console = console;
|
|
558
|
+
}
|
|
559
|
+
/**Render all messages */
|
|
560
|
+
render(messages) {
|
|
561
|
+
try {
|
|
562
|
+
//process data
|
|
563
|
+
const final = [];
|
|
564
|
+
messages.forEach((msg) => {
|
|
565
|
+
const titleColor = msg.message.titleColor;
|
|
566
|
+
const title = "[" + msg.message.title + "] ";
|
|
567
|
+
const descriptionColor = msg.message.descriptionColor;
|
|
568
|
+
const description = msg.message.description.split("\n").map((text, row) => {
|
|
569
|
+
//first row row doesn't need prefix
|
|
570
|
+
if (row < 1)
|
|
571
|
+
return text;
|
|
572
|
+
//other rows do need a prefix
|
|
573
|
+
let text2 = text;
|
|
574
|
+
for (const i of title) {
|
|
575
|
+
text2 = " " + text2;
|
|
576
|
+
}
|
|
577
|
+
return text2;
|
|
578
|
+
}).join("\n");
|
|
579
|
+
if (!["red", "yellow", "green", "blue", "gray", "magenta", "cyan"].includes(titleColor))
|
|
580
|
+
var finalTitle = ansis_1.default.white(title);
|
|
581
|
+
else
|
|
582
|
+
var finalTitle = ansis_1.default[titleColor](title);
|
|
583
|
+
if (!["red", "yellow", "green", "blue", "gray", "magenta", "cyan"].includes(descriptionColor))
|
|
584
|
+
var finalDescription = ansis_1.default.white(description);
|
|
585
|
+
else
|
|
586
|
+
var finalDescription = ansis_1.default[descriptionColor](description);
|
|
587
|
+
final.push(finalTitle + finalDescription);
|
|
588
|
+
});
|
|
589
|
+
//return all messages
|
|
590
|
+
return final.join("\n");
|
|
591
|
+
}
|
|
592
|
+
catch {
|
|
593
|
+
this.#console.log("Failed to render LiveStatus messages!", "error");
|
|
594
|
+
return "";
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
exports.ODLiveStatusRenderer = ODLiveStatusRenderer;
|