@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,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ODDynamicStat = exports.ODBasicStat = exports.ODStat = exports.ODStatGlobalScope = exports.ODStatScope = exports.ODStatsManager = void 0;
|
|
4
|
+
///////////////////////////////////////
|
|
5
|
+
//STAT MODULE
|
|
6
|
+
///////////////////////////////////////
|
|
7
|
+
const base_1 = require("./base");
|
|
8
|
+
/**## ODStatsManager `class`
|
|
9
|
+
* This is an Open Discord stats manager.
|
|
10
|
+
*
|
|
11
|
+
* This class is responsible for managing all stats of the bot.
|
|
12
|
+
* Stats are categorized in "scopes" which can be accessed in this manager.
|
|
13
|
+
*
|
|
14
|
+
* Stats can be accessed in the individual scopes.
|
|
15
|
+
*/
|
|
16
|
+
class ODStatsManager extends base_1.ODManager {
|
|
17
|
+
/**Alias to Open Discord debugger. */
|
|
18
|
+
#debug;
|
|
19
|
+
/**Alias to Open Discord stats database. */
|
|
20
|
+
database = null;
|
|
21
|
+
/**All the listeners for the init event. */
|
|
22
|
+
#initListeners = [];
|
|
23
|
+
constructor(debug) {
|
|
24
|
+
super(debug, "stat scope");
|
|
25
|
+
this.#debug = debug;
|
|
26
|
+
}
|
|
27
|
+
/**Select the database to use to read/write all stats from/to. */
|
|
28
|
+
useDatabase(database) {
|
|
29
|
+
this.database = database;
|
|
30
|
+
}
|
|
31
|
+
add(data, overwrite) {
|
|
32
|
+
data.useDebug(this.#debug, "stat");
|
|
33
|
+
if (this.database)
|
|
34
|
+
data.useDatabase(this.database);
|
|
35
|
+
return super.add(data, overwrite);
|
|
36
|
+
}
|
|
37
|
+
/**Init all stats and run `onInit()` listeners. */
|
|
38
|
+
async init() {
|
|
39
|
+
if (!this.database)
|
|
40
|
+
throw new base_1.ODSystemError("Unable to initialize stats scopes due to missing database!");
|
|
41
|
+
//get all valid categories
|
|
42
|
+
const validCategories = [];
|
|
43
|
+
for (const scope of this.getAll()) {
|
|
44
|
+
validCategories.push(...scope.init());
|
|
45
|
+
}
|
|
46
|
+
//filter out the deletable stats
|
|
47
|
+
const deletableStats = [];
|
|
48
|
+
const data = await this.database.getAll();
|
|
49
|
+
data.forEach((data) => {
|
|
50
|
+
if (!validCategories.includes(data.category))
|
|
51
|
+
deletableStats.push(data);
|
|
52
|
+
});
|
|
53
|
+
//do additional deletion
|
|
54
|
+
for (const cb of this.#initListeners) {
|
|
55
|
+
await cb(data, deletableStats);
|
|
56
|
+
}
|
|
57
|
+
//delete all deletable stats
|
|
58
|
+
for (const data of deletableStats) {
|
|
59
|
+
if (!this.database)
|
|
60
|
+
return;
|
|
61
|
+
await this.database.delete(data.category, data.key);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**Reset all stats. (clears the entire database) */
|
|
65
|
+
async reset() {
|
|
66
|
+
if (!this.database)
|
|
67
|
+
return;
|
|
68
|
+
const data = await this.database.getAll();
|
|
69
|
+
for (const d of data) {
|
|
70
|
+
if (!this.database)
|
|
71
|
+
return;
|
|
72
|
+
await this.database.delete(d.category, d.key);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**Run a function when the stats are initialized. This can be used to clear stats from users that left the server or tickets which don't exist anymore. */
|
|
76
|
+
onInit(callback) {
|
|
77
|
+
this.#initListeners.push(callback);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.ODStatsManager = ODStatsManager;
|
|
81
|
+
/**## ODStatScope `class`
|
|
82
|
+
* This is an Open Discord stat scope.
|
|
83
|
+
*
|
|
84
|
+
* A scope can contain multiple stats. Every scope is seperated from other scopes.
|
|
85
|
+
* Here, you can read & write the values of all stats.
|
|
86
|
+
*
|
|
87
|
+
* The built-in Open Discord scopes are: `global`, `user`, `ticket`
|
|
88
|
+
*/
|
|
89
|
+
class ODStatScope extends base_1.ODManager {
|
|
90
|
+
/**The id of this statistics scope. */
|
|
91
|
+
id;
|
|
92
|
+
/**Is this stat scope already initialized? */
|
|
93
|
+
ready = false;
|
|
94
|
+
/**Alias to Open Discord stats database. */
|
|
95
|
+
database = null;
|
|
96
|
+
/**The name of this scope (used in embed title) */
|
|
97
|
+
name;
|
|
98
|
+
constructor(id, name) {
|
|
99
|
+
super();
|
|
100
|
+
this.id = new base_1.ODId(id);
|
|
101
|
+
this.name = name;
|
|
102
|
+
}
|
|
103
|
+
/**Select the database to use to read/write all stats from/to. (Automatically assigned when used in `ODStatsManager`) */
|
|
104
|
+
useDatabase(database) {
|
|
105
|
+
this.database = database;
|
|
106
|
+
}
|
|
107
|
+
/**Get the value of a statistic. The `scopeId` is the unique id of the user, channel, role, etc that the stats are related to. */
|
|
108
|
+
async getStat(id, scopeId) {
|
|
109
|
+
if (!this.database)
|
|
110
|
+
return null;
|
|
111
|
+
const newId = new base_1.ODId(id);
|
|
112
|
+
const data = await this.database.get(this.id.value + "_" + newId.value, scopeId);
|
|
113
|
+
if (typeof data == "undefined") {
|
|
114
|
+
//set stats to default value & return
|
|
115
|
+
return this.resetStat(id, scopeId);
|
|
116
|
+
}
|
|
117
|
+
else if (typeof data == "string" || typeof data == "boolean" || typeof data == "number") {
|
|
118
|
+
//return value received from database
|
|
119
|
+
return data;
|
|
120
|
+
}
|
|
121
|
+
//return null on error
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
/**Get the value of a statistic for all `scopeId`'s. The `scopeId` is the unique id of the user, channel, role, etc that the stats are related to. */
|
|
125
|
+
async getAllStats(id) {
|
|
126
|
+
if (!this.database)
|
|
127
|
+
return [];
|
|
128
|
+
const newId = new base_1.ODId(id);
|
|
129
|
+
const data = await this.database.getCategory(this.id.value + "_" + newId.value) ?? [];
|
|
130
|
+
const output = [];
|
|
131
|
+
for (const stat of data) {
|
|
132
|
+
if (typeof stat.value == "string" || typeof stat.value == "boolean" || typeof stat.value == "number") {
|
|
133
|
+
//return value received from database
|
|
134
|
+
output.push({ id: stat.key, value: stat.value });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//return null on error
|
|
138
|
+
return output;
|
|
139
|
+
}
|
|
140
|
+
/**Set, increase or decrease the value of a statistic. The `scopeId` is the unique id of the user, channel, role, etc that the stats are related to. */
|
|
141
|
+
async setStat(id, scopeId, value, mode) {
|
|
142
|
+
if (!this.database)
|
|
143
|
+
return false;
|
|
144
|
+
const stat = this.get(id);
|
|
145
|
+
if (!stat)
|
|
146
|
+
return false;
|
|
147
|
+
if (mode == "set" || typeof value != "number") {
|
|
148
|
+
await this.database.set(this.id.value + "_" + stat.id.value, scopeId, value);
|
|
149
|
+
}
|
|
150
|
+
else if (mode == "increase") {
|
|
151
|
+
const currentValue = await this.getStat(id, scopeId);
|
|
152
|
+
if (typeof currentValue != "number")
|
|
153
|
+
await this.database.set(this.id.value + "_" + stat.id.value, scopeId, 0 + value);
|
|
154
|
+
else
|
|
155
|
+
await this.database.set(this.id.value + "_" + stat.id.value, scopeId, currentValue + value);
|
|
156
|
+
}
|
|
157
|
+
else if (mode == "decrease") {
|
|
158
|
+
const currentValue = await this.getStat(id, scopeId);
|
|
159
|
+
if (typeof currentValue != "number")
|
|
160
|
+
await this.database.set(this.id.value + "_" + stat.id.value, scopeId, 0 - value);
|
|
161
|
+
else
|
|
162
|
+
await this.database.set(this.id.value + "_" + stat.id.value, scopeId, currentValue - value);
|
|
163
|
+
}
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
/**Reset the value of a statistic to the initial value. The `scopeId` is the unique id of the user, channel, role, etc that the stats are related to. */
|
|
167
|
+
async resetStat(id, scopeId) {
|
|
168
|
+
if (!this.database)
|
|
169
|
+
return null;
|
|
170
|
+
const stat = this.get(id);
|
|
171
|
+
if (!stat)
|
|
172
|
+
return null;
|
|
173
|
+
if (stat.value != null)
|
|
174
|
+
await this.database.set(this.id.value + "_" + stat.id.value, scopeId, stat.value);
|
|
175
|
+
return stat.value;
|
|
176
|
+
}
|
|
177
|
+
/**Initialize this stat scope & return a list of all statistic ids in the following format: `<scopeid>_<statid>` */
|
|
178
|
+
init() {
|
|
179
|
+
//get all valid stats categories
|
|
180
|
+
this.ready = true;
|
|
181
|
+
return this.getAll().map((stat) => this.id.value + "_" + stat.id.value);
|
|
182
|
+
}
|
|
183
|
+
/**Render all stats in this scope for usage in a discord message/embed. */
|
|
184
|
+
async render(scopeId, guild, channel, user) {
|
|
185
|
+
//sort from high priority to low
|
|
186
|
+
const derefArray = [...this.getAll()];
|
|
187
|
+
derefArray.sort((a, b) => {
|
|
188
|
+
return b.priority - a.priority;
|
|
189
|
+
});
|
|
190
|
+
const result = [];
|
|
191
|
+
for (const stat of derefArray) {
|
|
192
|
+
try {
|
|
193
|
+
if (stat instanceof ODDynamicStat) {
|
|
194
|
+
//dynamic render (without value)
|
|
195
|
+
result.push(await stat.render("", scopeId, guild, channel, user));
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
//normal render (with value)
|
|
199
|
+
const value = await this.getStat(stat.id, scopeId);
|
|
200
|
+
if (value != null)
|
|
201
|
+
result.push(await stat.render(value, scopeId, guild, channel, user));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
process.emit("uncaughtException", err);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return result.filter((stat) => stat !== "").join("\n");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.ODStatScope = ODStatScope;
|
|
212
|
+
/**## ODStatGlobalScope `class`
|
|
213
|
+
* This is an Open Discord stat global scope.
|
|
214
|
+
*
|
|
215
|
+
* A scope can contain multiple stats. Every scope is seperated from other scopes.
|
|
216
|
+
* Here, you can read & write the values of all stats.
|
|
217
|
+
*
|
|
218
|
+
* This scope is made specifically for the global stats of Open Discord.
|
|
219
|
+
*/
|
|
220
|
+
class ODStatGlobalScope extends ODStatScope {
|
|
221
|
+
getStat(id) {
|
|
222
|
+
return super.getStat(id, "GLOBAL");
|
|
223
|
+
}
|
|
224
|
+
getAllStats(id) {
|
|
225
|
+
return super.getAllStats(id);
|
|
226
|
+
}
|
|
227
|
+
setStat(id, value, mode) {
|
|
228
|
+
return super.setStat(id, "GLOBAL", value, mode);
|
|
229
|
+
}
|
|
230
|
+
resetStat(id) {
|
|
231
|
+
return super.resetStat(id, "GLOBAL");
|
|
232
|
+
}
|
|
233
|
+
render(scopeId, guild, channel, user) {
|
|
234
|
+
return super.render("GLOBAL", guild, channel, user);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
exports.ODStatGlobalScope = ODStatGlobalScope;
|
|
238
|
+
/**## ODStat `class`
|
|
239
|
+
* This is an Open Discord statistic.
|
|
240
|
+
*
|
|
241
|
+
* This single statistic doesn't do anything except defining the rules of this statistic.
|
|
242
|
+
* Use it in a stats scope to register a new statistic. A statistic can also include a priority to choose the render priority.
|
|
243
|
+
*
|
|
244
|
+
* It's recommended to use the `ODBasicStat` & `ODDynamicStat` classes instead of this one!
|
|
245
|
+
*/
|
|
246
|
+
class ODStat extends base_1.ODManagerData {
|
|
247
|
+
/**The priority of this statistic. */
|
|
248
|
+
priority;
|
|
249
|
+
/**The render function of this statistic. */
|
|
250
|
+
render;
|
|
251
|
+
/**The value of this statistic. */
|
|
252
|
+
value;
|
|
253
|
+
constructor(id, priority, render, value) {
|
|
254
|
+
super(id);
|
|
255
|
+
this.priority = priority;
|
|
256
|
+
this.render = render;
|
|
257
|
+
this.value = value ?? null;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
exports.ODStat = ODStat;
|
|
261
|
+
/**## ODBasicStat `class`
|
|
262
|
+
* This is an Open Discord basic statistic.
|
|
263
|
+
*
|
|
264
|
+
* This single statistic will store a number, boolean or string in the database.
|
|
265
|
+
* Use it to create a simple statistic for any stats scope.
|
|
266
|
+
*/
|
|
267
|
+
class ODBasicStat extends ODStat {
|
|
268
|
+
/**The name of this stat. Rendered in discord embeds/messages. */
|
|
269
|
+
name;
|
|
270
|
+
constructor(id, priority, name, value) {
|
|
271
|
+
super(id, priority, (value) => {
|
|
272
|
+
return "" + name + ": `" + value.toString() + "`";
|
|
273
|
+
}, value);
|
|
274
|
+
this.name = name;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.ODBasicStat = ODBasicStat;
|
|
278
|
+
/**## ODDynamicStat `class`
|
|
279
|
+
* This is an Open Discord dynamic statistic.
|
|
280
|
+
*
|
|
281
|
+
* A dynamic statistic does not store anything in the database! Instead, it will execute a function to return a custom result.
|
|
282
|
+
* This can be used to show statistics which are not stored in the database.
|
|
283
|
+
*
|
|
284
|
+
* This is used in Open Discord for the live ticket status, participants & system status.
|
|
285
|
+
*/
|
|
286
|
+
class ODDynamicStat extends ODStat {
|
|
287
|
+
constructor(id, priority, render) {
|
|
288
|
+
super(id, priority, (value, scopeId, guild, channel, user) => {
|
|
289
|
+
return render(scopeId, guild, channel, user);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
exports.ODDynamicStat = ODDynamicStat;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ODManager, ODManagerData, ODValidId } from "./base";
|
|
2
|
+
import { ODMessage } from "./builder";
|
|
3
|
+
import { ODDebugger } from "./console";
|
|
4
|
+
import { ODButtonResponderInstance } from "./responder";
|
|
5
|
+
import * as discord from "discord.js";
|
|
6
|
+
import { ODWorkerManager } from "./worker";
|
|
7
|
+
/**## ODVerifyBar `class`
|
|
8
|
+
* This is an Open Discord verifybar.
|
|
9
|
+
*
|
|
10
|
+
* It is contains 2 sets of workers and a lot of utilities for the (✅ ❌) verifybars in the bot.
|
|
11
|
+
*
|
|
12
|
+
* It doesn't contain the code which activates or spawns the verifybars!
|
|
13
|
+
*/
|
|
14
|
+
export declare class ODVerifyBar extends ODManagerData {
|
|
15
|
+
/**All workers that will run when the verifybar is accepted. */
|
|
16
|
+
success: ODWorkerManager<ODButtonResponderInstance, "verifybar", {
|
|
17
|
+
data: string | null;
|
|
18
|
+
verifybarMessage: discord.Message<boolean> | null;
|
|
19
|
+
}>;
|
|
20
|
+
/**All workers that will run when the verifybar is stopped. */
|
|
21
|
+
failure: ODWorkerManager<ODButtonResponderInstance, "verifybar", {
|
|
22
|
+
data: string | null;
|
|
23
|
+
verifybarMessage: discord.Message<boolean> | null;
|
|
24
|
+
}>;
|
|
25
|
+
/**The message that will be built wen activating this verifybar. */
|
|
26
|
+
message: ODMessage<"verifybar", {
|
|
27
|
+
guild: discord.Guild | null;
|
|
28
|
+
channel: discord.TextBasedChannel;
|
|
29
|
+
user: discord.User;
|
|
30
|
+
verifybar: ODVerifyBar;
|
|
31
|
+
originalMessage: discord.Message<boolean>;
|
|
32
|
+
}>;
|
|
33
|
+
/**When disabled, it will skip the verifybar and instantly fire the `success` workers. */
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
constructor(id: ODValidId, message: ODMessage<"verifybar", {
|
|
36
|
+
guild: discord.Guild | null;
|
|
37
|
+
channel: discord.TextBasedChannel;
|
|
38
|
+
user: discord.User;
|
|
39
|
+
originalMessage: discord.Message<boolean>;
|
|
40
|
+
}>, enabled?: boolean);
|
|
41
|
+
/**Build the message and reply to a button with this verifybar. */
|
|
42
|
+
activate(responder: ODButtonResponderInstance): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
/**## ODVerifyBarManager `class`
|
|
45
|
+
* This is an Open Discord verifybar manager.
|
|
46
|
+
*
|
|
47
|
+
* It contains all (✅ ❌) verifybars in the bot.
|
|
48
|
+
* The `ODVerifyBar` classes contain `ODWorkerManager`'s that will be fired when the continue/stop buttons are pressed.
|
|
49
|
+
*
|
|
50
|
+
* It doesn't contain the code which activates the verifybars! This should be implemented by your own.
|
|
51
|
+
*/
|
|
52
|
+
export declare class ODVerifyBarManager extends ODManager<ODVerifyBar> {
|
|
53
|
+
constructor(debug: ODDebugger);
|
|
54
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ODVerifyBarManager = exports.ODVerifyBar = void 0;
|
|
4
|
+
///////////////////////////////////////
|
|
5
|
+
//VERIFYBAR MODULE
|
|
6
|
+
///////////////////////////////////////
|
|
7
|
+
const base_1 = require("./base");
|
|
8
|
+
const worker_1 = require("./worker");
|
|
9
|
+
/**## ODVerifyBar `class`
|
|
10
|
+
* This is an Open Discord verifybar.
|
|
11
|
+
*
|
|
12
|
+
* It is contains 2 sets of workers and a lot of utilities for the (✅ ❌) verifybars in the bot.
|
|
13
|
+
*
|
|
14
|
+
* It doesn't contain the code which activates or spawns the verifybars!
|
|
15
|
+
*/
|
|
16
|
+
class ODVerifyBar extends base_1.ODManagerData {
|
|
17
|
+
/**All workers that will run when the verifybar is accepted. */
|
|
18
|
+
success;
|
|
19
|
+
/**All workers that will run when the verifybar is stopped. */
|
|
20
|
+
failure;
|
|
21
|
+
/**The message that will be built wen activating this verifybar. */
|
|
22
|
+
message;
|
|
23
|
+
/**When disabled, it will skip the verifybar and instantly fire the `success` workers. */
|
|
24
|
+
enabled;
|
|
25
|
+
constructor(id, message, enabled) {
|
|
26
|
+
super(id);
|
|
27
|
+
this.success = new worker_1.ODWorkerManager("descending");
|
|
28
|
+
this.failure = new worker_1.ODWorkerManager("descending");
|
|
29
|
+
this.message = message;
|
|
30
|
+
this.enabled = enabled ?? true;
|
|
31
|
+
}
|
|
32
|
+
/**Build the message and reply to a button with this verifybar. */
|
|
33
|
+
async activate(responder) {
|
|
34
|
+
if (this.enabled) {
|
|
35
|
+
//show verifybar
|
|
36
|
+
const { guild, channel, user, message } = responder;
|
|
37
|
+
await responder.update(await this.message.build("verifybar", { guild, channel, user, verifybar: this, originalMessage: message }));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
//instant success
|
|
41
|
+
if (this.success)
|
|
42
|
+
await this.success.executeWorkers(responder, "verifybar", { data: null, verifybarMessage: null });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.ODVerifyBar = ODVerifyBar;
|
|
47
|
+
/**## ODVerifyBarManager `class`
|
|
48
|
+
* This is an Open Discord verifybar manager.
|
|
49
|
+
*
|
|
50
|
+
* It contains all (✅ ❌) verifybars in the bot.
|
|
51
|
+
* The `ODVerifyBar` classes contain `ODWorkerManager`'s that will be fired when the continue/stop buttons are pressed.
|
|
52
|
+
*
|
|
53
|
+
* It doesn't contain the code which activates the verifybars! This should be implemented by your own.
|
|
54
|
+
*/
|
|
55
|
+
class ODVerifyBarManager extends base_1.ODManager {
|
|
56
|
+
constructor(debug) {
|
|
57
|
+
super(debug, "verifybar");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ODVerifyBarManager = ODVerifyBarManager;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ODManager, ODManagerData, ODValidId } from "./base";
|
|
2
|
+
/**## ODWorkerCallback `type`
|
|
3
|
+
* This is the callback used in `ODWorker`!
|
|
4
|
+
*/
|
|
5
|
+
export type ODWorkerCallback<Instance, Source extends string, Params> = (instance: Instance, params: Params, source: Source, cancel: () => void) => void | Promise<void>;
|
|
6
|
+
/**## ODWorker `class`
|
|
7
|
+
* This is an Open Discord worker.
|
|
8
|
+
*
|
|
9
|
+
* You can compare it with a normal javascript callback, but slightly more advanced!
|
|
10
|
+
*
|
|
11
|
+
* - It has an `id` for identification of the function
|
|
12
|
+
* - A `priority` to know when to execute this callback (related to others)
|
|
13
|
+
* - It knows who called this callback (`source`)
|
|
14
|
+
* - And much more!
|
|
15
|
+
*/
|
|
16
|
+
export declare class ODWorker<Instance, Source extends string, Params> extends ODManagerData {
|
|
17
|
+
/**The priority of this worker */
|
|
18
|
+
priority: number;
|
|
19
|
+
/**The main callback of this worker */
|
|
20
|
+
callback: ODWorkerCallback<Instance, Source, Params>;
|
|
21
|
+
constructor(id: ODValidId, priority: number, callback: ODWorkerCallback<Instance, Source, Params>);
|
|
22
|
+
}
|
|
23
|
+
/**## ODWorker `class`
|
|
24
|
+
* This is an Open Discord worker manager.
|
|
25
|
+
*
|
|
26
|
+
* It manages & executes `ODWorker`'s in the correct order.
|
|
27
|
+
*
|
|
28
|
+
* You can register a custom worker in this class to create a message or button.
|
|
29
|
+
*/
|
|
30
|
+
export declare class ODWorkerManager<Instance, Source extends string, Params> extends ODManager<ODWorker<Instance, Source, Params>> {
|
|
31
|
+
#private;
|
|
32
|
+
/**The backup worker will be executed when one of the workers fails or cancels execution. */
|
|
33
|
+
backupWorker: ODWorker<{
|
|
34
|
+
reason: "error" | "cancel";
|
|
35
|
+
}, Source, Params> | null;
|
|
36
|
+
constructor(priorityOrder: "ascending" | "descending");
|
|
37
|
+
/**Get all workers in sorted order. */
|
|
38
|
+
getSortedWorkers(priority: "ascending" | "descending"): ODWorker<Instance, Source, Params>[];
|
|
39
|
+
/**Execute all workers on an instance using the given source & parameters. */
|
|
40
|
+
executeWorkers(instance: Instance, source: Source, params: Params): Promise<void>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ODWorkerManager = exports.ODWorker = void 0;
|
|
4
|
+
///////////////////////////////////////
|
|
5
|
+
//WORKER MODULE
|
|
6
|
+
///////////////////////////////////////
|
|
7
|
+
const base_1 = require("./base");
|
|
8
|
+
/**## ODWorker `class`
|
|
9
|
+
* This is an Open Discord worker.
|
|
10
|
+
*
|
|
11
|
+
* You can compare it with a normal javascript callback, but slightly more advanced!
|
|
12
|
+
*
|
|
13
|
+
* - It has an `id` for identification of the function
|
|
14
|
+
* - A `priority` to know when to execute this callback (related to others)
|
|
15
|
+
* - It knows who called this callback (`source`)
|
|
16
|
+
* - And much more!
|
|
17
|
+
*/
|
|
18
|
+
class ODWorker extends base_1.ODManagerData {
|
|
19
|
+
/**The priority of this worker */
|
|
20
|
+
priority;
|
|
21
|
+
/**The main callback of this worker */
|
|
22
|
+
callback;
|
|
23
|
+
constructor(id, priority, callback) {
|
|
24
|
+
super(id);
|
|
25
|
+
this.priority = priority;
|
|
26
|
+
this.callback = callback;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ODWorker = ODWorker;
|
|
30
|
+
/**## ODWorker `class`
|
|
31
|
+
* This is an Open Discord worker manager.
|
|
32
|
+
*
|
|
33
|
+
* It manages & executes `ODWorker`'s in the correct order.
|
|
34
|
+
*
|
|
35
|
+
* You can register a custom worker in this class to create a message or button.
|
|
36
|
+
*/
|
|
37
|
+
class ODWorkerManager extends base_1.ODManager {
|
|
38
|
+
/**The order of execution for workers inside this manager. */
|
|
39
|
+
#priorityOrder;
|
|
40
|
+
/**The backup worker will be executed when one of the workers fails or cancels execution. */
|
|
41
|
+
backupWorker = null;
|
|
42
|
+
constructor(priorityOrder) {
|
|
43
|
+
super();
|
|
44
|
+
this.#priorityOrder = priorityOrder;
|
|
45
|
+
}
|
|
46
|
+
/**Get all workers in sorted order. */
|
|
47
|
+
getSortedWorkers(priority) {
|
|
48
|
+
const derefArray = [...this.getAll()];
|
|
49
|
+
return derefArray.sort((a, b) => {
|
|
50
|
+
if (priority == "ascending")
|
|
51
|
+
return a.priority - b.priority;
|
|
52
|
+
else
|
|
53
|
+
return b.priority - a.priority;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**Execute all workers on an instance using the given source & parameters. */
|
|
57
|
+
async executeWorkers(instance, source, params) {
|
|
58
|
+
const derefParams = { ...params };
|
|
59
|
+
const workers = this.getSortedWorkers(this.#priorityOrder);
|
|
60
|
+
let didCancel = false;
|
|
61
|
+
let didCrash = false;
|
|
62
|
+
for (const worker of workers) {
|
|
63
|
+
if (didCancel)
|
|
64
|
+
break;
|
|
65
|
+
try {
|
|
66
|
+
await worker.callback(instance, derefParams, source, () => {
|
|
67
|
+
didCancel = true;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
process.emit("uncaughtException", err);
|
|
72
|
+
didCrash = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (didCancel && this.backupWorker) {
|
|
76
|
+
try {
|
|
77
|
+
await this.backupWorker.callback({ reason: "cancel" }, derefParams, source, () => { });
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
process.emit("uncaughtException", err);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (didCrash && this.backupWorker) {
|
|
84
|
+
try {
|
|
85
|
+
await this.backupWorker.callback({ reason: "error" }, derefParams, source, () => { });
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
process.emit("uncaughtException", err);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.ODWorkerManager = ODWorkerManager;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as api from "./api";
|
|
2
|
+
/**## sharedFuses `utility variable`
|
|
3
|
+
* All shared fuses from Open Discord. Please use `opendiscord.sharedFuses` instead!
|
|
4
|
+
*/
|
|
5
|
+
export declare const sharedFuses: api.ODSharedFuseManager;
|
|
6
|
+
/**## checkNodeVersion `utility function`
|
|
7
|
+
* Check if the node.js version is v20 or higher.
|
|
8
|
+
*/
|
|
9
|
+
export declare function checkNodeVersion(project: api.ODProjectType): void;
|
|
10
|
+
/**## moduleInstalled `utility function`
|
|
11
|
+
* Use this function to check if an npm package is installed or not!
|
|
12
|
+
* @example utilities.moduleInstalled("discord.js") //check if discord.js is installed
|
|
13
|
+
*/
|
|
14
|
+
export declare function moduleInstalled(id: string, throwError?: boolean): boolean;
|
|
15
|
+
/**## initialStartupLogs `utility function`
|
|
16
|
+
* Use this function to check if an npm package is installed or not!
|
|
17
|
+
* @example utilities.moduleInstalled("discord.js") //check if discord.js is installed
|
|
18
|
+
*/
|
|
19
|
+
export declare function initialStartupLogs(opendiscord: api.ODMain, project: api.ODProjectType): void;
|
|
20
|
+
/**## timer `utility function`
|
|
21
|
+
* Use this to wait for a certain amount of milliseconds. This only works when using `await`
|
|
22
|
+
* @example await utilities.timer(1000) //wait 1sec
|
|
23
|
+
*/
|
|
24
|
+
export declare function timer(ms: number): Promise<void>;
|
|
25
|
+
/**## emojiTitle `utility function`
|
|
26
|
+
* Use this function to create a title with an emoji before/after the text. The style & divider are set in `opendiscord.sharedFuses`
|
|
27
|
+
* @example utilities.emojiTitle("📎","Links") //create a title with an emoji based on the bot emoji style
|
|
28
|
+
*/
|
|
29
|
+
export declare function emojiTitle(emoji: string, text: string): string;
|
|
30
|
+
/**## runAsync `utility function`
|
|
31
|
+
* Use this function to run a snippet of code asyncronous without creating a separate function for it!
|
|
32
|
+
*/
|
|
33
|
+
export declare function runAsync(func: () => Promise<void>): Promise<void>;
|
|
34
|
+
/**## timedAwait `utility function`
|
|
35
|
+
* Use this function to await a promise but reject after the certain timeout has been reached.
|
|
36
|
+
*/
|
|
37
|
+
export declare function timedAwait<ReturnValue>(promise: ReturnValue, timeout: number, onError: (err: Error) => void): ReturnValue;
|
|
38
|
+
/**## dateString `utility function`
|
|
39
|
+
* Use this function to create a short date string in the following format: `DD/MM/YYYY HH:MM:SS`
|
|
40
|
+
*/
|
|
41
|
+
export declare function dateString(date: any): string;
|
|
42
|
+
/**## asyncReplace `utility function`
|
|
43
|
+
* Same as `string.replace(search, value)` but with async compatibility
|
|
44
|
+
*/
|
|
45
|
+
export declare function asyncReplace(text: string, regex: RegExp, func: (value: string, ...args: any[]) => Promise<string>): Promise<string>;
|
|
46
|
+
/**## getLongestLength `utility function`
|
|
47
|
+
* Get the length of the longest string in the array.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getLongestLength(texts: string[]): number;
|
|
50
|
+
/**## ordinalNumber `utility function`
|
|
51
|
+
* Get a human readable ordinal number (e.g. 1st, 2nd, 3rd, 4th, ...) from a Javascript number.
|
|
52
|
+
*/
|
|
53
|
+
export declare function ordinalNumber(num: number): string;
|
|
54
|
+
/**## trimEmojis `utility function`
|
|
55
|
+
* Trim/remove all emoji's from a Javascript string.
|
|
56
|
+
*/
|
|
57
|
+
export declare function trimEmojis(text: any): any;
|
|
58
|
+
/**## easterEggs `utility object`
|
|
59
|
+
* Object containing data for Open Ticket easter eggs.
|
|
60
|
+
*/
|
|
61
|
+
export declare const easterEggs: api.ODEasterEggs;
|