@open-discord-bots/framework 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE.md +713 -0
  2. package/README.md +104 -0
  3. package/dist/api/api.d.ts +26 -0
  4. package/dist/api/api.js +44 -0
  5. package/dist/api/main.d.ts +133 -0
  6. package/dist/api/main.js +87 -0
  7. package/dist/api/modules/action.d.ts +34 -0
  8. package/dist/api/modules/action.js +58 -0
  9. package/dist/api/modules/base.d.ts +329 -0
  10. package/dist/api/modules/base.js +804 -0
  11. package/dist/api/modules/builder.d.ts +647 -0
  12. package/dist/api/modules/builder.js +1441 -0
  13. package/dist/api/modules/checker.d.ts +648 -0
  14. package/dist/api/modules/checker.js +1324 -0
  15. package/dist/api/modules/client.d.ts +768 -0
  16. package/dist/api/modules/client.js +1859 -0
  17. package/dist/api/modules/code.d.ts +33 -0
  18. package/dist/api/modules/code.js +57 -0
  19. package/dist/api/modules/config.d.ts +70 -0
  20. package/dist/api/modules/config.js +206 -0
  21. package/dist/api/modules/console.d.ts +305 -0
  22. package/dist/api/modules/console.js +598 -0
  23. package/dist/api/modules/cooldown.d.ts +138 -0
  24. package/dist/api/modules/cooldown.js +359 -0
  25. package/dist/api/modules/database.d.ts +135 -0
  26. package/dist/api/modules/database.js +271 -0
  27. package/dist/api/modules/event.d.ts +43 -0
  28. package/dist/api/modules/event.js +100 -0
  29. package/dist/api/modules/flag.d.ts +40 -0
  30. package/dist/api/modules/flag.js +72 -0
  31. package/dist/api/modules/fuse.d.ts +218 -0
  32. package/dist/api/modules/fuse.js +123 -0
  33. package/dist/api/modules/helpmenu.d.ts +106 -0
  34. package/dist/api/modules/helpmenu.js +167 -0
  35. package/dist/api/modules/language.d.ts +85 -0
  36. package/dist/api/modules/language.js +195 -0
  37. package/dist/api/modules/permission.d.ts +121 -0
  38. package/dist/api/modules/permission.js +314 -0
  39. package/dist/api/modules/plugin.d.ts +128 -0
  40. package/dist/api/modules/plugin.js +168 -0
  41. package/dist/api/modules/post.d.ts +44 -0
  42. package/dist/api/modules/post.js +92 -0
  43. package/dist/api/modules/progressbar.d.ts +108 -0
  44. package/dist/api/modules/progressbar.js +233 -0
  45. package/dist/api/modules/responder.d.ts +506 -0
  46. package/dist/api/modules/responder.js +1468 -0
  47. package/dist/api/modules/session.d.ts +58 -0
  48. package/dist/api/modules/session.js +171 -0
  49. package/dist/api/modules/startscreen.d.ts +165 -0
  50. package/dist/api/modules/startscreen.js +293 -0
  51. package/dist/api/modules/stat.d.ts +142 -0
  52. package/dist/api/modules/stat.js +293 -0
  53. package/dist/api/modules/verifybar.d.ts +54 -0
  54. package/dist/api/modules/verifybar.js +60 -0
  55. package/dist/api/modules/worker.d.ts +41 -0
  56. package/dist/api/modules/worker.js +93 -0
  57. package/dist/api/utils.d.ts +61 -0
  58. package/dist/api/utils.js +254 -0
  59. package/dist/index.d.ts +4 -1
  60. package/dist/index.js +40 -0
  61. package/dist/startup/dump.d.ts +14 -0
  62. package/dist/startup/dump.js +79 -0
  63. package/dist/startup/errorHandling.d.ts +2 -0
  64. package/dist/startup/errorHandling.js +43 -0
  65. package/dist/startup/pluginLauncher.d.ts +2 -0
  66. package/dist/startup/pluginLauncher.js +202 -0
  67. package/package.json +9 -3
  68. package/src/api/api.ts +29 -0
  69. package/src/api/main.ts +189 -0
  70. package/src/api/modules/action.ts +58 -0
  71. package/src/api/modules/base.ts +811 -0
  72. package/src/api/modules/builder.ts +1554 -0
  73. package/src/api/modules/checker.ts +1549 -0
  74. package/src/api/modules/client.ts +2247 -0
  75. package/src/api/modules/code.ts +58 -0
  76. package/src/api/modules/config.ts +159 -0
  77. package/src/api/modules/console.ts +665 -0
  78. package/src/api/modules/cooldown.ts +348 -0
  79. package/src/api/modules/database.ts +278 -0
  80. package/src/api/modules/event.ts +99 -0
  81. package/src/api/modules/flag.ts +73 -0
  82. package/src/api/modules/fuse.ts +348 -0
  83. package/src/api/modules/helpmenu.ts +216 -0
  84. package/src/api/modules/language.ts +201 -0
  85. package/src/api/modules/permission.ts +340 -0
  86. package/src/api/modules/plugin.ts +242 -0
  87. package/src/api/modules/post.ts +90 -0
  88. package/src/api/modules/progressbar.ts +232 -0
  89. package/src/api/modules/responder.ts +1420 -0
  90. package/src/api/modules/session.ts +155 -0
  91. package/src/api/modules/startscreen.ts +320 -0
  92. package/src/api/modules/stat.ts +313 -0
  93. package/src/api/modules/verifybar.ts +61 -0
  94. package/src/api/modules/worker.ts +93 -0
  95. package/src/api/utils.ts +206 -0
  96. package/src/cli/cli.ts +151 -0
  97. package/src/cli/editConfig.ts +943 -0
  98. package/src/index.ts +6 -1
  99. package/src/startup/compilation.ts +186 -0
  100. package/src/startup/dump.ts +45 -0
  101. package/src/startup/errorHandling.ts +38 -0
  102. package/src/startup/pluginLauncher.ts +261 -0
  103. package/LICENSE +0 -21
@@ -0,0 +1,254 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.easterEggs = exports.sharedFuses = void 0;
40
+ exports.checkNodeVersion = checkNodeVersion;
41
+ exports.moduleInstalled = moduleInstalled;
42
+ exports.initialStartupLogs = initialStartupLogs;
43
+ exports.timer = timer;
44
+ exports.emojiTitle = emojiTitle;
45
+ exports.runAsync = runAsync;
46
+ exports.timedAwait = timedAwait;
47
+ exports.dateString = dateString;
48
+ exports.asyncReplace = asyncReplace;
49
+ exports.getLongestLength = getLongestLength;
50
+ exports.ordinalNumber = ordinalNumber;
51
+ exports.trimEmojis = trimEmojis;
52
+ const fs = __importStar(require("fs"));
53
+ const ansis_1 = __importDefault(require("ansis"));
54
+ const api = __importStar(require("./api"));
55
+ /**## sharedFuses `utility variable`
56
+ * All shared fuses from Open Discord. Please use `opendiscord.sharedFuses` instead!
57
+ */
58
+ exports.sharedFuses = new api.ODSharedFuseManager();
59
+ /**## checkNodeVersion `utility function`
60
+ * Check if the node.js version is v20 or higher.
61
+ */
62
+ function checkNodeVersion(project) {
63
+ const nodev = process.versions.node.split(".");
64
+ if (Number(nodev[0]) < 20) {
65
+ const title = (project == "openticket") ? "OPEN TICKET" : "OPEN MODERATION";
66
+ console.log("\n\n==============================\n[" + title + " ERROR]: Invalid node.js version. Open Ticket requires node.js v20 or above!\n==============================\n\n");
67
+ process.exit(1);
68
+ }
69
+ }
70
+ /**## moduleInstalled `utility function`
71
+ * Use this function to check if an npm package is installed or not!
72
+ * @example utilities.moduleInstalled("discord.js") //check if discord.js is installed
73
+ */
74
+ function moduleInstalled(id, throwError) {
75
+ try {
76
+ require.resolve(id);
77
+ return true;
78
+ }
79
+ catch {
80
+ if (throwError)
81
+ throw new Error("npm module \"" + id + "\" is not installed! Install it via 'npm install " + id + "'");
82
+ return false;
83
+ }
84
+ }
85
+ /**## initialStartupLogs `utility function`
86
+ * Use this function to check if an npm package is installed or not!
87
+ * @example utilities.moduleInstalled("discord.js") //check if discord.js is installed
88
+ */
89
+ function initialStartupLogs(opendiscord, project) {
90
+ const title = (project == "openticket") ? "OPEN TICKET" : "OPEN MODERATION";
91
+ console.log("\n--------------------------- " + title + " STARTUP ---------------------------");
92
+ opendiscord.log("Logging system activated!", "system");
93
+ opendiscord.debug.debug("Using Node.js " + process.version + "!");
94
+ try {
95
+ const packageJson = JSON.parse(fs.readFileSync("./package.json").toString());
96
+ opendiscord.debug.debug("Using discord.js " + packageJson.dependencies["discord.js"] + "!");
97
+ opendiscord.debug.debug("Using @discordjs/rest " + packageJson.dependencies["@discordjs/rest"] + "!");
98
+ opendiscord.debug.debug("Using ansis " + packageJson.dependencies["ansis"] + "!");
99
+ opendiscord.debug.debug("Using formatted-json-stringify " + packageJson.dependencies["formatted-json-stringify"] + "!");
100
+ opendiscord.debug.debug("Using terminal-kit " + packageJson.dependencies["terminal-kit"] + "!");
101
+ opendiscord.debug.debug("Using typescript " + packageJson.dependencies["typescript"] + "!");
102
+ }
103
+ catch {
104
+ opendiscord.debug.debug("Failed to fetch module versions!");
105
+ }
106
+ }
107
+ /**## timer `utility function`
108
+ * Use this to wait for a certain amount of milliseconds. This only works when using `await`
109
+ * @example await utilities.timer(1000) //wait 1sec
110
+ */
111
+ async function timer(ms) {
112
+ return new Promise((resolve) => {
113
+ setTimeout(() => {
114
+ resolve();
115
+ }, ms);
116
+ });
117
+ }
118
+ /**## emojiTitle `utility function`
119
+ * Use this function to create a title with an emoji before/after the text. The style & divider are set in `opendiscord.sharedFuses`
120
+ * @example utilities.emojiTitle("📎","Links") //create a title with an emoji based on the bot emoji style
121
+ */
122
+ function emojiTitle(emoji, text) {
123
+ const style = exports.sharedFuses.getFuse("emojiTitleStyle");
124
+ const divider = exports.sharedFuses.getFuse("emojiTitleDivider");
125
+ if (style == "disabled")
126
+ return text;
127
+ else if (style == "before")
128
+ return emoji + divider + text;
129
+ else if (style == "after")
130
+ return text + divider + emoji;
131
+ else if (style == "double")
132
+ return emoji + divider + text + divider + emoji;
133
+ else
134
+ return text;
135
+ }
136
+ /**## runAsync `utility function`
137
+ * Use this function to run a snippet of code asyncronous without creating a separate function for it!
138
+ */
139
+ async function runAsync(func) {
140
+ func();
141
+ }
142
+ /**## timedAwait `utility function`
143
+ * Use this function to await a promise but reject after the certain timeout has been reached.
144
+ */
145
+ function timedAwait(promise, timeout, onError) {
146
+ let allowResolve = true;
147
+ return new Promise(async (resolve, reject) => {
148
+ //set timeout & stop if it is before the promise resolved
149
+ setTimeout(() => {
150
+ allowResolve = false;
151
+ reject("utilities.timedAwait() => Promise Timeout");
152
+ }, timeout);
153
+ //get promise result & return if not already rejected
154
+ try {
155
+ const res = await promise;
156
+ if (allowResolve)
157
+ resolve(res);
158
+ }
159
+ catch (err) {
160
+ onError(err);
161
+ }
162
+ return promise;
163
+ });
164
+ }
165
+ /**## dateString `utility function`
166
+ * Use this function to create a short date string in the following format: `DD/MM/YYYY HH:MM:SS`
167
+ */
168
+ function dateString(date) {
169
+ return `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
170
+ }
171
+ /**## asyncReplace `utility function`
172
+ * Same as `string.replace(search, value)` but with async compatibility
173
+ */
174
+ async function asyncReplace(text, regex, func) {
175
+ const promises = [];
176
+ text.replace(regex, (match, ...args) => {
177
+ promises.push(func(match, ...args));
178
+ return match;
179
+ });
180
+ const data = await Promise.all(promises);
181
+ const result = text.replace(regex, (match) => {
182
+ const replaceResult = data.shift();
183
+ return replaceResult ?? match;
184
+ });
185
+ return result;
186
+ }
187
+ /**## getLongestLength `utility function`
188
+ * Get the length of the longest string in the array.
189
+ */
190
+ function getLongestLength(texts) {
191
+ return Math.max(...texts.map((t) => ansis_1.default.strip(t).length));
192
+ }
193
+ /**## ordinalNumber `utility function`
194
+ * Get a human readable ordinal number (e.g. 1st, 2nd, 3rd, 4th, ...) from a Javascript number.
195
+ */
196
+ function ordinalNumber(num) {
197
+ const i = Math.abs(Math.round(num));
198
+ const cent = i % 100;
199
+ if (cent >= 10 && cent <= 20)
200
+ return i + 'th';
201
+ const dec = i % 10;
202
+ if (dec === 1)
203
+ return i + 'st';
204
+ if (dec === 2)
205
+ return i + 'nd';
206
+ if (dec === 3)
207
+ return i + 'rd';
208
+ return i + 'th';
209
+ }
210
+ /**## trimEmojis `utility function`
211
+ * Trim/remove all emoji's from a Javascript string.
212
+ */
213
+ function trimEmojis(text) {
214
+ return text.replace(/(\p{Extended_Pictographic}(?:\uFE0F|\uFE0E)?(?:\u200D\p{Extended_Pictographic}(?:\uFE0F|\uFE0E)?)*)/gu, "");
215
+ }
216
+ /**## easterEggs `utility object`
217
+ * Object containing data for Open Ticket easter eggs.
218
+ */
219
+ exports.easterEggs = {
220
+ /* THANK YOU TO ALL OUR CONTRIBUTORS!!! */
221
+ creator: "779742674932072469", //DJj123dj
222
+ translators: [
223
+ "779742674932072469", //DJj123dj
224
+ "574172558006681601", //Sanke
225
+ "540639725300613136", //Guillee.3
226
+ "547231585368539136", //Mods HD
227
+ "664934139954331649", //SpyEye
228
+ "498055992962187264", //Redactado
229
+ "912052735950618705", //T0miiis
230
+ "366673202610569227", //johusens
231
+ "360780292853858306", //David.3
232
+ "950611418389024809", //Sarcastic
233
+ "461603955517161473", //Maurizo
234
+ "465111430274875402", //The_Gamer
235
+ "586376952470831104", //Erxg
236
+ "226695254433202176", //Mkevas
237
+ "437695615095275520", //NoOneNook
238
+ "530047191222583307", //Anderskiy
239
+ "719072181631320145", //ToStam
240
+ "1172870906377408512", //Stragar
241
+ "1084794575945744445", //Sasanwm
242
+ "449613814049275905", //Benzorich
243
+ "905373133085741146", //Ronalds
244
+ "918504977369018408", //Palestinian
245
+ "807970841035145216", //Kornel0706
246
+ "1198883915826475080", //Nova
247
+ "669988226819162133", //Danoglez
248
+ "1313597620996018271", //Fraden1
249
+ "547809968145956884", //TsgIndrius
250
+ "264120132660363267", //Quiradon
251
+ "1272034143777329215", //NotMega
252
+ "LOREMIPSUM", //TODO, ADD MORE IDS IN FUTURE!
253
+ ]
254
+ };
package/dist/index.d.ts CHANGED
@@ -1 +1,4 @@
1
- export {};
1
+ export * as api from "./api/api";
2
+ export * as utilities from "./api/utils";
3
+ export { loadDumpCommand } from "./startup/dump";
4
+ export { loadAllPlugins } from "./startup/pluginLauncher";
package/dist/index.js CHANGED
@@ -1,2 +1,42 @@
1
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
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.loadAllPlugins = exports.loadDumpCommand = exports.utilities = exports.api = void 0;
37
+ exports.api = __importStar(require("./api/api"));
38
+ exports.utilities = __importStar(require("./api/utils"));
39
+ var dump_1 = require("./startup/dump");
40
+ Object.defineProperty(exports, "loadDumpCommand", { enumerable: true, get: function () { return dump_1.loadDumpCommand; } });
41
+ var pluginLauncher_1 = require("./startup/pluginLauncher");
42
+ Object.defineProperty(exports, "loadAllPlugins", { enumerable: true, get: function () { return pluginLauncher_1.loadAllPlugins; } });
@@ -0,0 +1,14 @@
1
+ import { api } from "../index";
2
+ /** ### What is this?
3
+ * This is the `!OPENTICKET:dump` command.
4
+ * It's a utility command which can only be used by the creator of Open Discord/Ticket/Moderation or the owner of the bot.
5
+ * This command will send the `debug.txt` file in DM. It's not dangerous as the `debug.txt` file doesn't contain any sensitive data (only logs).
6
+ *
7
+ * ### Why does it exist?
8
+ * This command can be used to quickly get the `debug.txt` file without having access to the hosting
9
+ * in case you're helping someone with setting up (or debugging) Open Discord/Ticket/Moderation.
10
+ *
11
+ * ### Can I disable it?
12
+ * If you want to turn it off, you turn off the fuse using `opendiscord.sharedFuses.setFuse("allowDumpCommand",false)`
13
+ */
14
+ export declare const loadDumpCommand: (opendiscord: api.ODMain) => void;
@@ -0,0 +1,79 @@
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.loadDumpCommand = void 0;
37
+ const index_1 = require("../index");
38
+ const discord = __importStar(require("discord.js"));
39
+ const fs = __importStar(require("fs"));
40
+ /** ### What is this?
41
+ * This is the `!OPENTICKET:dump` command.
42
+ * It's a utility command which can only be used by the creator of Open Discord/Ticket/Moderation or the owner of the bot.
43
+ * This command will send the `debug.txt` file in DM. It's not dangerous as the `debug.txt` file doesn't contain any sensitive data (only logs).
44
+ *
45
+ * ### Why does it exist?
46
+ * This command can be used to quickly get the `debug.txt` file without having access to the hosting
47
+ * in case you're helping someone with setting up (or debugging) Open Discord/Ticket/Moderation.
48
+ *
49
+ * ### Can I disable it?
50
+ * If you want to turn it off, you turn off the fuse using `opendiscord.sharedFuses.setFuse("allowDumpCommand",false)`
51
+ */
52
+ const loadDumpCommand = (opendiscord) => {
53
+ if (!opendiscord.sharedFuses.getFuse("allowDumpCommand"))
54
+ return;
55
+ opendiscord.client.textCommands.add(new index_1.api.ODTextCommand("opendiscord:dump", {
56
+ allowBots: false,
57
+ guildPermission: true,
58
+ dmPermission: true,
59
+ name: "dump",
60
+ prefix: "!OPENTICKET:"
61
+ }));
62
+ opendiscord.client.textCommands.onInteraction("!OPENTICKET:", "dump", async (msg) => {
63
+ if (msg.author.id == "779742674932072469" || opendiscord.permissions.hasPermissions("developer", await opendiscord.permissions.getPermissions(msg.author, msg.channel, null))) {
64
+ //user is bot owner OR creator of Open Discord/Ticket/Moderation :)
65
+ opendiscord.log("Dumped " + opendiscord.debugfile.filename + "!", "system", [
66
+ { key: "user", value: msg.author.username },
67
+ { key: "id", value: msg.author.id }
68
+ ]);
69
+ const debug = fs.readFileSync(opendiscord.debugfile.path);
70
+ if (msg.channel.type != discord.ChannelType.GroupDM)
71
+ msg.channel.send({ content: "## The `" + opendiscord.debugfile.filename + "` dump is available!", files: [
72
+ new discord.AttachmentBuilder(debug)
73
+ .setName(opendiscord.debugfile.filename)
74
+ .setDescription("The Open Discord debug dump!")
75
+ ] });
76
+ }
77
+ });
78
+ };
79
+ exports.loadDumpCommand = loadDumpCommand;
@@ -0,0 +1,2 @@
1
+ import { api } from "../index";
2
+ export declare function loadErrorHandling(opendiscord: api.ODMain, project: api.ODProjectType): void;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadErrorHandling = loadErrorHandling;
4
+ const index_1 = require("../index");
5
+ function loadErrorHandling(opendiscord, project) {
6
+ process.on("uncaughtException", async (error, origin) => {
7
+ try {
8
+ const beforeEvent = opendiscord.events.get("onErrorHandling");
9
+ if (beforeEvent)
10
+ await beforeEvent.emit([error, origin]);
11
+ if (opendiscord.sharedFuses.getFuse("errorHandling")) {
12
+ //custom error messages for known errors
13
+ if (error.message.toLowerCase().includes("used disallowed intents")) {
14
+ //invalid intents
15
+ opendiscord.log(((project === "openticket") ? "Open Ticket" : "Open Moderation") + " doesn't work without Privileged Gateway Intents enabled!", "error");
16
+ opendiscord.log("Enable them in the discord developer portal!", "info");
17
+ console.log("\n");
18
+ process.exit(1);
19
+ }
20
+ else if (error.message.toLowerCase().includes("invalid discord bot token provided")) {
21
+ //invalid token
22
+ opendiscord.log("An invalid discord auth token was provided!", "error");
23
+ opendiscord.log("Check the config if you have inserted the bot token correctly!", "info");
24
+ console.log("\n");
25
+ process.exit(1);
26
+ }
27
+ else {
28
+ //unknown error
29
+ const errmsg = new index_1.api.ODError(error, origin);
30
+ opendiscord.log(errmsg);
31
+ if (opendiscord.sharedFuses.getFuse("crashOnError"))
32
+ process.exit(1);
33
+ const afterEvent = opendiscord.events.get("afterErrorHandling");
34
+ if (afterEvent)
35
+ await afterEvent.emit([error, origin, errmsg]);
36
+ }
37
+ }
38
+ }
39
+ catch (err) {
40
+ console.log("[ERROR HANDLER ERROR]:", err);
41
+ }
42
+ });
43
+ }
@@ -0,0 +1,2 @@
1
+ import { api } from "../index";
2
+ export declare const loadAllPlugins: (opendiscord: api.ODMain) => Promise<void>;
@@ -0,0 +1,202 @@
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.loadAllPlugins = void 0;
7
+ const index_1 = require("../index");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const loadAllPlugins = async (opendiscord) => {
10
+ //start launching plugins
11
+ opendiscord.log("Loading plugins...", "system");
12
+ let initPluginError = false;
13
+ if (!fs_1.default.existsSync("./plugins")) {
14
+ opendiscord.log("Couldn't find ./plugins directory, canceling all plugin execution!", "error");
15
+ return;
16
+ }
17
+ const plugins = fs_1.default.readdirSync("./plugins");
18
+ //check & validate
19
+ for (const p of plugins) {
20
+ //prechecks
21
+ if (p === ".DS_Store")
22
+ return; //ignore MacOS DS_Store file
23
+ if (!fs_1.default.statSync("./plugins/" + p).isDirectory())
24
+ return opendiscord.log("Plugin is not a directory, canceling plugin execution...", "plugin", [
25
+ { key: "plugin", value: "./plugins/" + p }
26
+ ]);
27
+ if (!fs_1.default.existsSync("./plugins/" + p + "/plugin.json")) {
28
+ initPluginError = true;
29
+ opendiscord.log("Plugin doesn't have a plugin.json, canceling plugin execution...", "plugin", [
30
+ { key: "plugin", value: "./plugins/" + p }
31
+ ]);
32
+ return;
33
+ }
34
+ //plugin loading
35
+ try {
36
+ const rawplugindata = JSON.parse(fs_1.default.readFileSync("./plugins/" + p + "/plugin.json").toString());
37
+ if (typeof rawplugindata != "object")
38
+ throw new index_1.api.ODPluginError("Failed to load plugin.json");
39
+ if (typeof rawplugindata.id != "string")
40
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/id");
41
+ if (typeof rawplugindata.name != "string")
42
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/name");
43
+ if (typeof rawplugindata.version != "string")
44
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/version");
45
+ if (typeof rawplugindata.startFile != "string")
46
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/startFile");
47
+ if (typeof rawplugindata.enabled != "boolean")
48
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/enabled");
49
+ if (typeof rawplugindata.priority != "number")
50
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/priority");
51
+ if (!Array.isArray(rawplugindata.events))
52
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/events");
53
+ if (!Array.isArray(rawplugindata.npmDependencies))
54
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/npmDependencies");
55
+ if (!Array.isArray(rawplugindata.requiredPlugins))
56
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/requiredPlugins");
57
+ if (!Array.isArray(rawplugindata.incompatiblePlugins))
58
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/incompatiblePlugins");
59
+ if (typeof rawplugindata.details != "object")
60
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/details");
61
+ if (typeof rawplugindata.details.author != "string")
62
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/details/author");
63
+ if (typeof rawplugindata.details.shortDescription != "string")
64
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/details/shortDescription");
65
+ if (typeof rawplugindata.details.longDescription != "string")
66
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/details/longDescription");
67
+ if (typeof rawplugindata.details.imageUrl != "string")
68
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/details/imageUrl");
69
+ if (typeof rawplugindata.details.projectUrl != "string")
70
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/details/projectUrl");
71
+ if (!Array.isArray(rawplugindata.details.tags))
72
+ throw new index_1.api.ODPluginError("Failed to load plugin.json/details/tags");
73
+ if (rawplugindata.id != p)
74
+ throw new index_1.api.ODPluginError("Failed to load plugin, directory name is required to match the id");
75
+ if (opendiscord.plugins.exists(rawplugindata.id))
76
+ throw new index_1.api.ODPluginError("Failed to load plugin, this id already exists in another plugin");
77
+ //plugin.json is valid => load plugin
78
+ const plugin = new index_1.api.ODPlugin(p, rawplugindata);
79
+ opendiscord.plugins.add(plugin);
80
+ }
81
+ catch (e) {
82
+ //when any of the above errors happen, crash the bot when soft mode isn't enabled
83
+ initPluginError = true;
84
+ opendiscord.log(e.message + ", canceling plugin execution...", "plugin", [
85
+ { key: "path", value: "./plugins/" + p }
86
+ ]);
87
+ opendiscord.log("You can see more about this error in the ./debug.txt file!", "info");
88
+ opendiscord.debugfile.writeText(e.stack);
89
+ //try to get some crashed plugin data
90
+ try {
91
+ const rawplugindata = JSON.parse(fs_1.default.readFileSync("./plugins/" + p + "/plugin.json").toString());
92
+ opendiscord.plugins.unknownCrashedPlugins.push({
93
+ name: rawplugindata.name ?? "./plugins/" + p,
94
+ description: (rawplugindata.details && rawplugindata.details.shortDescription) ? rawplugindata.details.shortDescription : "This plugin crashed :(",
95
+ });
96
+ }
97
+ catch { }
98
+ }
99
+ }
100
+ //sorted plugins (sorted on priority. All plugins are loaded & enabled)
101
+ const sortedPlugins = opendiscord.plugins.getAll().sort((a, b) => {
102
+ return (b.priority - a.priority);
103
+ });
104
+ //check for incompatible & missing plugins/dependencies
105
+ const incompatibilities = [];
106
+ const missingDependencies = [];
107
+ const missingPlugins = [];
108
+ //go through all plugins for errors
109
+ sortedPlugins.filter((plugin) => plugin.enabled).forEach((plugin) => {
110
+ const from = plugin.id.value;
111
+ plugin.dependenciesInstalled().forEach((missing) => missingDependencies.push({ id: from, missing }));
112
+ plugin.pluginsIncompatible(opendiscord.plugins).forEach((incompatible) => incompatibilities.push({ from, to: incompatible }));
113
+ plugin.pluginsInstalled(opendiscord.plugins).forEach((missing) => missingPlugins.push({ id: from, missing }));
114
+ });
115
+ //handle all incompatibilities
116
+ const alreadyLoggedCompatPlugins = [];
117
+ incompatibilities.forEach((match) => {
118
+ if (alreadyLoggedCompatPlugins.includes(match.from) || alreadyLoggedCompatPlugins.includes(match.to))
119
+ return;
120
+ else
121
+ alreadyLoggedCompatPlugins.push(match.from, match.to);
122
+ const fromPlugin = opendiscord.plugins.get(match.from);
123
+ if (fromPlugin && !fromPlugin.crashed) {
124
+ fromPlugin.crashed = true;
125
+ fromPlugin.crashReason = "incompatible.plugin";
126
+ }
127
+ const toPlugin = opendiscord.plugins.get(match.to);
128
+ if (toPlugin && !toPlugin.crashed) {
129
+ toPlugin.crashed = true;
130
+ toPlugin.crashReason = "incompatible.plugin";
131
+ }
132
+ opendiscord.log(`Incompatible plugins => "${match.from}" & "${match.to}", canceling plugin execution...`, "plugin", [
133
+ { key: "path1", value: "./plugins/" + match.from },
134
+ { key: "path2", value: "./plugins/" + match.to }
135
+ ]);
136
+ initPluginError = true;
137
+ });
138
+ //handle all missing dependencies
139
+ missingDependencies.forEach((match) => {
140
+ const plugin = opendiscord.plugins.get(match.id);
141
+ if (plugin && !plugin.crashed) {
142
+ plugin.crashed = true;
143
+ plugin.crashReason = "missing.dependency";
144
+ }
145
+ opendiscord.log(`Missing npm dependency "${match.missing}", canceling plugin execution...`, "plugin", [
146
+ { key: "path", value: "./plugins/" + match.id }
147
+ ]);
148
+ initPluginError = true;
149
+ });
150
+ //handle all missing plugins
151
+ missingPlugins.forEach((match) => {
152
+ const plugin = opendiscord.plugins.get(match.id);
153
+ if (plugin && !plugin.crashed) {
154
+ plugin.crashed = true;
155
+ plugin.crashReason = "missing.plugin";
156
+ }
157
+ opendiscord.log(`Missing required plugin "${match.missing}", canceling plugin execution...`, "plugin", [
158
+ { key: "path", value: "./plugins/" + match.id }
159
+ ]);
160
+ initPluginError = true;
161
+ });
162
+ //exit on error (when soft mode disabled)
163
+ if (!opendiscord.sharedFuses.getFuse("softPluginLoading") && initPluginError) {
164
+ console.log("");
165
+ opendiscord.log("Please fix all plugin errors above & try again!", "error");
166
+ process.exit(1);
167
+ }
168
+ //preload all events required for every plugin
169
+ for (const plugin of sortedPlugins) {
170
+ if (plugin.enabled)
171
+ plugin.data.events.forEach((event) => opendiscord.events.add(new index_1.api.ODEvent(event)));
172
+ }
173
+ //execute all working plugins
174
+ for (const plugin of sortedPlugins) {
175
+ const status = await plugin.execute(opendiscord.debug, false);
176
+ //exit on error (when soft mode disabled)
177
+ if (!status && !opendiscord.sharedFuses.getFuse("softPluginLoading")) {
178
+ console.log("");
179
+ opendiscord.log("Please fix all plugin errors above & try again!", "error");
180
+ process.exit(1);
181
+ }
182
+ }
183
+ for (const plugin of sortedPlugins) {
184
+ if (plugin.enabled) {
185
+ opendiscord.debug.debug("Plugin \"" + plugin.id.value + "\" loaded", [
186
+ { key: "status", value: (plugin.crashed ? "crashed" : "success") },
187
+ { key: "crashReason", value: (plugin.crashed ? (plugin.crashReason ?? "/") : "/") },
188
+ { key: "author", value: plugin.details.author },
189
+ { key: "version", value: plugin.version.toString() },
190
+ { key: "priority", value: plugin.priority.toString() }
191
+ ]);
192
+ }
193
+ else {
194
+ opendiscord.debug.debug("Plugin \"" + plugin.id.value + "\" disabled", [
195
+ { key: "author", value: plugin.details.author },
196
+ { key: "version", value: plugin.version.toString() },
197
+ { key: "priority", value: plugin.priority.toString() }
198
+ ]);
199
+ }
200
+ }
201
+ };
202
+ exports.loadAllPlugins = loadAllPlugins;