@open-discord-bots/framework 0.2.4 → 0.2.6
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/README.md +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/main.d.ts +3 -3
- package/dist/api/main.js +2 -2
- package/dist/api/modules/action.d.ts +4 -4
- package/dist/api/modules/base.d.ts +12 -6
- package/dist/api/modules/builder.d.ts +25 -25
- package/dist/api/modules/checker.d.ts +7 -7
- package/dist/api/modules/client.d.ts +13 -13
- package/dist/api/modules/code.d.ts +5 -5
- package/dist/api/modules/code.js +1 -1
- package/dist/api/modules/config.d.ts +4 -4
- package/dist/api/modules/console.d.ts +4 -4
- package/dist/api/modules/console.js +2 -2
- package/dist/api/modules/cooldown.d.ts +4 -4
- package/dist/api/modules/database.d.ts +13 -13
- package/dist/api/modules/event.d.ts +4 -4
- package/dist/api/modules/flag.d.ts +4 -4
- package/dist/api/modules/fuse.d.ts +6 -6
- package/dist/api/modules/fuse.js +3 -3
- package/dist/api/modules/helpmenu.d.ts +7 -7
- package/dist/api/modules/language.d.ts +6 -6
- package/dist/api/modules/permission.d.ts +4 -4
- package/dist/api/modules/plugin.d.ts +7 -7
- package/dist/api/modules/post.d.ts +4 -4
- package/dist/api/modules/progressbar.d.ts +7 -7
- package/dist/api/modules/responder.d.ts +19 -19
- package/dist/api/modules/session.d.ts +4 -4
- package/dist/api/modules/startscreen.d.ts +4 -4
- package/dist/api/modules/statistic.d.ts +176 -0
- package/dist/api/modules/{stat.js → statistic.js} +52 -52
- package/dist/api/modules/verifybar.d.ts +4 -4
- package/package.json +1 -1
- package/src/api/index.ts +1 -1
- package/src/api/main.ts +14 -14
- package/src/api/modules/action.ts +4 -4
- package/src/api/modules/base.ts +15 -10
- package/src/api/modules/builder.ts +25 -25
- package/src/api/modules/checker.ts +7 -7
- package/src/api/modules/client.ts +13 -13
- package/src/api/modules/code.ts +5 -5
- package/src/api/modules/config.ts +4 -4
- package/src/api/modules/console.ts +6 -6
- package/src/api/modules/cooldown.ts +4 -4
- package/src/api/modules/database.ts +13 -13
- package/src/api/modules/event.ts +4 -4
- package/src/api/modules/flag.ts +4 -4
- package/src/api/modules/fuse.ts +9 -9
- package/src/api/modules/helpmenu.ts +7 -7
- package/src/api/modules/language.ts +6 -6
- package/src/api/modules/permission.ts +4 -4
- package/src/api/modules/plugin.ts +7 -7
- package/src/api/modules/post.ts +4 -4
- package/src/api/modules/progressbar.ts +7 -7
- package/src/api/modules/responder.ts +19 -19
- package/src/api/modules/session.ts +4 -4
- package/src/api/modules/startscreen.ts +4 -4
- package/src/api/modules/{stat.ts → statistic.ts} +117 -117
- package/src/api/modules/verifybar.ts +4 -4
- package/dist/api/modules/stat.d.ts +0 -176
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ODDynamicStatistic = exports.ODBaseStatistic = exports.ODStatistic = exports.ODStatisticGlobalScope = exports.ODStatisticScope = exports.ODStatisticManager = void 0;
|
|
4
4
|
///////////////////////////////////////
|
|
5
|
-
//
|
|
5
|
+
//STATISTIC MODULE
|
|
6
6
|
///////////////////////////////////////
|
|
7
7
|
const base_1 = require("./base");
|
|
8
|
-
/**##
|
|
9
|
-
* This is an Open Discord
|
|
8
|
+
/**## ODStatisticManager `class`
|
|
9
|
+
* This is an Open Discord statistics manager.
|
|
10
10
|
*
|
|
11
|
-
* This class is responsible for managing all
|
|
12
|
-
*
|
|
11
|
+
* This class is responsible for managing all statistics of the bot.
|
|
12
|
+
* Statistic are categorized in "scopes" which can be accessed in this manager.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* Statistic can be accessed in the individual scopes.
|
|
15
15
|
*/
|
|
16
|
-
class
|
|
16
|
+
class ODStatisticManager extends base_1.ODManager {
|
|
17
17
|
/**Alias to Open Discord debugger. */
|
|
18
18
|
#debug;
|
|
19
|
-
/**Alias to Open Discord
|
|
19
|
+
/**Alias to Open Discord statistics database. */
|
|
20
20
|
database = null;
|
|
21
21
|
/**All the listeners for the init event. */
|
|
22
22
|
#initListeners = [];
|
|
23
23
|
constructor(debug) {
|
|
24
|
-
super(debug, "
|
|
24
|
+
super(debug, "statistic scope");
|
|
25
25
|
this.#debug = debug;
|
|
26
26
|
}
|
|
27
|
-
/**Select the database to use to read/write all
|
|
27
|
+
/**Select the database to use to read/write all statistics from/to. */
|
|
28
28
|
useDatabase(database) {
|
|
29
29
|
this.database = database;
|
|
30
30
|
}
|
|
@@ -34,16 +34,16 @@ class ODStatsManager extends base_1.ODManager {
|
|
|
34
34
|
data.useDatabase(this.database);
|
|
35
35
|
return super.add(data, overwrite);
|
|
36
36
|
}
|
|
37
|
-
/**Init all
|
|
37
|
+
/**Init all statistics and run `onInit()` listeners. */
|
|
38
38
|
async init() {
|
|
39
39
|
if (!this.database)
|
|
40
|
-
throw new base_1.ODSystemError("Unable to initialize
|
|
40
|
+
throw new base_1.ODSystemError("Unable to initialize statistics scopes due to missing database!");
|
|
41
41
|
//get all valid categories
|
|
42
42
|
const validCategories = [];
|
|
43
43
|
for (const scope of this.getAll()) {
|
|
44
44
|
validCategories.push(...scope.init());
|
|
45
45
|
}
|
|
46
|
-
//filter out the deletable
|
|
46
|
+
//filter out the deletable statistics
|
|
47
47
|
const deletableStats = [];
|
|
48
48
|
const data = await this.database.getAll();
|
|
49
49
|
data.forEach((data) => {
|
|
@@ -54,14 +54,14 @@ class ODStatsManager extends base_1.ODManager {
|
|
|
54
54
|
for (const cb of this.#initListeners) {
|
|
55
55
|
await cb(data, deletableStats);
|
|
56
56
|
}
|
|
57
|
-
//delete all deletable
|
|
57
|
+
//delete all deletable statistics
|
|
58
58
|
for (const data of deletableStats) {
|
|
59
59
|
if (!this.database)
|
|
60
60
|
return;
|
|
61
61
|
await this.database.delete(data.category, data.key);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
/**Reset all
|
|
64
|
+
/**Reset all statistics. (clears the entire database) */
|
|
65
65
|
async reset() {
|
|
66
66
|
if (!this.database)
|
|
67
67
|
return;
|
|
@@ -72,7 +72,7 @@ class ODStatsManager extends base_1.ODManager {
|
|
|
72
72
|
await this.database.delete(d.category, d.key);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
/**Run a function when the
|
|
75
|
+
/**Run a function when the statistics are initialized. This can be used to clear statistics from users that left the server or tickets which don't exist anymore. */
|
|
76
76
|
onInit(callback) {
|
|
77
77
|
this.#initListeners.push(callback);
|
|
78
78
|
}
|
|
@@ -86,21 +86,21 @@ class ODStatsManager extends base_1.ODManager {
|
|
|
86
86
|
return super.exists(id);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
exports.
|
|
90
|
-
/**##
|
|
91
|
-
* This is an Open Discord
|
|
89
|
+
exports.ODStatisticManager = ODStatisticManager;
|
|
90
|
+
/**## ODStatisticScope `class`
|
|
91
|
+
* This is an Open Discord statistic scope.
|
|
92
92
|
*
|
|
93
|
-
* A scope can contain multiple
|
|
94
|
-
* Here, you can read & write the values of all
|
|
93
|
+
* A scope can contain multiple statistics. Every scope is seperated from other scopes.
|
|
94
|
+
* Here, you can read & write the values of all statistics.
|
|
95
95
|
*
|
|
96
96
|
* The built-in Open Discord scopes are: `global`, `user`, `ticket`
|
|
97
97
|
*/
|
|
98
|
-
class
|
|
98
|
+
class ODStatisticScope extends base_1.ODManager {
|
|
99
99
|
/**The id of this statistics scope. */
|
|
100
100
|
id;
|
|
101
|
-
/**Is this
|
|
101
|
+
/**Is this scope already initialized? */
|
|
102
102
|
ready = false;
|
|
103
|
-
/**Alias to Open Discord
|
|
103
|
+
/**Alias to Open Discord statistics database. */
|
|
104
104
|
database = null;
|
|
105
105
|
/**The name of this scope (used in embed title) */
|
|
106
106
|
name;
|
|
@@ -109,7 +109,7 @@ class ODStatScope extends base_1.ODManager {
|
|
|
109
109
|
this.id = new base_1.ODId(id);
|
|
110
110
|
this.name = name;
|
|
111
111
|
}
|
|
112
|
-
/**Select the database to use to read/write all
|
|
112
|
+
/**Select the database to use to read/write all statistics from/to. (Automatically assigned when used in `ODStatisticManager`) */
|
|
113
113
|
useDatabase(database) {
|
|
114
114
|
this.database = database;
|
|
115
115
|
}
|
|
@@ -119,7 +119,7 @@ class ODStatScope extends base_1.ODManager {
|
|
|
119
119
|
const newId = new base_1.ODId(id);
|
|
120
120
|
const data = await this.database.get(this.id.value + "_" + newId.value, scopeId);
|
|
121
121
|
if (typeof data == "undefined") {
|
|
122
|
-
//set
|
|
122
|
+
//set statistics to default value & return
|
|
123
123
|
return this.resetStat(id, scopeId);
|
|
124
124
|
}
|
|
125
125
|
else if (typeof data == "string" || typeof data == "boolean" || typeof data == "number") {
|
|
@@ -179,13 +179,13 @@ class ODStatScope extends base_1.ODManager {
|
|
|
179
179
|
await this.database.set(this.id.value + "_" + stat.id.value, scopeId, stat.value);
|
|
180
180
|
return stat.value;
|
|
181
181
|
}
|
|
182
|
-
/**Initialize this
|
|
182
|
+
/**Initialize this statistic scope & return a list of all statistic ids in the following format: `<scopeid>_<statid>` */
|
|
183
183
|
init() {
|
|
184
|
-
//get all valid
|
|
184
|
+
//get all valid statistics categories
|
|
185
185
|
this.ready = true;
|
|
186
186
|
return this.getAll().map((stat) => this.id.value + "_" + stat.id.value);
|
|
187
187
|
}
|
|
188
|
-
/**Render all
|
|
188
|
+
/**Render all statistics in this scope for usage in a discord message/embed. */
|
|
189
189
|
async render(scopeId, guild, channel, user) {
|
|
190
190
|
//sort from high priority to low
|
|
191
191
|
const derefArray = [...this.getAll()];
|
|
@@ -195,7 +195,7 @@ class ODStatScope extends base_1.ODManager {
|
|
|
195
195
|
const result = [];
|
|
196
196
|
for (const stat of derefArray) {
|
|
197
197
|
try {
|
|
198
|
-
if (stat instanceof
|
|
198
|
+
if (stat instanceof ODDynamicStatistic) {
|
|
199
199
|
//dynamic render (without value)
|
|
200
200
|
result.push(await stat.render("", scopeId, guild, channel, user));
|
|
201
201
|
}
|
|
@@ -222,16 +222,16 @@ class ODStatScope extends base_1.ODManager {
|
|
|
222
222
|
return super.exists(id);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
exports.
|
|
226
|
-
/**##
|
|
227
|
-
* This is an Open Discord
|
|
225
|
+
exports.ODStatisticScope = ODStatisticScope;
|
|
226
|
+
/**## ODStatisticGlobalScope `class`
|
|
227
|
+
* This is an Open Discord statistic global scope.
|
|
228
228
|
*
|
|
229
|
-
* A scope can contain multiple
|
|
230
|
-
* Here, you can read & write the values of all
|
|
229
|
+
* A scope can contain multiple statistics. Every scope is seperated from other scopes.
|
|
230
|
+
* Here, you can read & write the values of all statistics.
|
|
231
231
|
*
|
|
232
|
-
* This scope is made specifically for the global
|
|
232
|
+
* This scope is made specifically for the global statistics of Open Discord.
|
|
233
233
|
*/
|
|
234
|
-
class
|
|
234
|
+
class ODStatisticGlobalScope extends ODStatisticScope {
|
|
235
235
|
getStat(id) {
|
|
236
236
|
return super.getStat(id, "GLOBAL");
|
|
237
237
|
}
|
|
@@ -248,16 +248,16 @@ class ODStatGlobalScope extends ODStatScope {
|
|
|
248
248
|
return super.render("GLOBAL", guild, channel, user);
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
|
-
exports.
|
|
252
|
-
/**##
|
|
251
|
+
exports.ODStatisticGlobalScope = ODStatisticGlobalScope;
|
|
252
|
+
/**## ODStatistic `class`
|
|
253
253
|
* This is an Open Discord statistic.
|
|
254
254
|
*
|
|
255
255
|
* This single statistic doesn't do anything except defining the rules of this statistic.
|
|
256
|
-
* Use it in a
|
|
256
|
+
* Use it in a statistics scope to register a new statistic. A statistic can also include a priority to choose the render priority.
|
|
257
257
|
*
|
|
258
|
-
* It's recommended to use the `
|
|
258
|
+
* It's recommended to use the `ODBaseStatistic` & `ODDynamicStatistic` classes instead of this one!
|
|
259
259
|
*/
|
|
260
|
-
class
|
|
260
|
+
class ODStatistic extends base_1.ODManagerData {
|
|
261
261
|
/**The priority of this statistic. */
|
|
262
262
|
priority;
|
|
263
263
|
/**The render function of this statistic. */
|
|
@@ -271,15 +271,15 @@ class ODStat extends base_1.ODManagerData {
|
|
|
271
271
|
this.value = value ?? null;
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
|
-
exports.
|
|
275
|
-
/**##
|
|
274
|
+
exports.ODStatistic = ODStatistic;
|
|
275
|
+
/**## ODBaseStatistic `class`
|
|
276
276
|
* This is an Open Discord basic statistic.
|
|
277
277
|
*
|
|
278
278
|
* This single statistic will store a number, boolean or string in the database.
|
|
279
|
-
* Use it to create a simple statistic for any
|
|
279
|
+
* Use it to create a simple statistic for any statistics scope.
|
|
280
280
|
*/
|
|
281
|
-
class
|
|
282
|
-
/**The name of this
|
|
281
|
+
class ODBaseStatistic extends ODStatistic {
|
|
282
|
+
/**The name of this statistic. Rendered in discord embeds/messages. */
|
|
283
283
|
name;
|
|
284
284
|
constructor(id, priority, name, value) {
|
|
285
285
|
super(id, priority, (value) => {
|
|
@@ -288,8 +288,8 @@ class ODBasicStat extends ODStat {
|
|
|
288
288
|
this.name = name;
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
|
-
exports.
|
|
292
|
-
/**##
|
|
291
|
+
exports.ODBaseStatistic = ODBaseStatistic;
|
|
292
|
+
/**## ODDynamicStatistic `class`
|
|
293
293
|
* This is an Open Discord dynamic statistic.
|
|
294
294
|
*
|
|
295
295
|
* A dynamic statistic does not store anything in the database! Instead, it will execute a function to return a custom result.
|
|
@@ -297,11 +297,11 @@ exports.ODBasicStat = ODBasicStat;
|
|
|
297
297
|
*
|
|
298
298
|
* This is used in Open Discord for the live ticket status, participants & system status.
|
|
299
299
|
*/
|
|
300
|
-
class
|
|
300
|
+
class ODDynamicStatistic extends ODStatistic {
|
|
301
301
|
constructor(id, priority, render) {
|
|
302
302
|
super(id, priority, (value, scopeId, guild, channel, user) => {
|
|
303
303
|
return render(scopeId, guild, channel, user);
|
|
304
304
|
});
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
|
-
exports.
|
|
307
|
+
exports.ODDynamicStatistic = ODDynamicStatistic;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ODManager, ODManagerData, ODValidId } from "./base";
|
|
1
|
+
import { ODManager, ODManagerData, ODNoGeneric, ODValidId } from "./base";
|
|
2
2
|
import { ODMessage } from "./builder";
|
|
3
3
|
import { ODDebugger } from "./console";
|
|
4
4
|
import { ODButtonResponderInstance } from "./responder";
|
|
@@ -59,10 +59,10 @@ export type ODVerifyBarManagerIdConstraint = Record<string, {
|
|
|
59
59
|
*/
|
|
60
60
|
export declare class ODVerifyBarManager<IdList extends ODVerifyBarManagerIdConstraint = ODVerifyBarManagerIdConstraint> extends ODManager<ODVerifyBar> {
|
|
61
61
|
constructor(debug: ODDebugger);
|
|
62
|
-
get<VerifyBarId extends keyof IdList
|
|
62
|
+
get<VerifyBarId extends keyof ODNoGeneric<IdList>>(id: VerifyBarId): ODVerifyBar<IdList[VerifyBarId]["successWorkerIds"], IdList[VerifyBarId]["failureWorkerIds"]>;
|
|
63
63
|
get(id: ODValidId): ODVerifyBar | null;
|
|
64
|
-
remove<VerifyBarId extends keyof IdList
|
|
64
|
+
remove<VerifyBarId extends keyof ODNoGeneric<IdList>>(id: VerifyBarId): ODVerifyBar<IdList[VerifyBarId]["successWorkerIds"], IdList[VerifyBarId]["failureWorkerIds"]>;
|
|
65
65
|
remove(id: ODValidId): ODVerifyBar | null;
|
|
66
|
-
exists(id: keyof IdList): boolean;
|
|
66
|
+
exists(id: keyof ODNoGeneric<IdList>): boolean;
|
|
67
67
|
exists(id: ODValidId): boolean;
|
|
68
68
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-discord-bots/framework",
|
|
3
3
|
"author": "DJj123dj",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.6",
|
|
5
5
|
"description": "The core framework of the popular open-source discord bots: Open Ticket & Open Moderation.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
package/src/api/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ export * from "./modules/action"
|
|
|
20
20
|
export * from "./modules/permission"
|
|
21
21
|
export * from "./modules/helpmenu"
|
|
22
22
|
export * from "./modules/session"
|
|
23
|
-
export * from "./modules/
|
|
23
|
+
export * from "./modules/statistic"
|
|
24
24
|
export * from "./modules/code"
|
|
25
25
|
export * from "./modules/cooldown"
|
|
26
26
|
export * from "./modules/post"
|
package/src/api/main.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
//BASE MODULES
|
|
2
|
-
import { ODEnvHelper, ODProjectType, ODVersion, ODVersionManager
|
|
3
|
-
import { ODConsoleManager, ODConsoleMessage, ODConsoleMessageParam, ODConsoleMessageTypes, ODDebugFileManager, ODDebugger, ODError, ODLiveStatusManager
|
|
4
|
-
import {
|
|
2
|
+
import { ODEnvHelper, ODProjectType, ODVersion, ODVersionManager } from "./modules/base"
|
|
3
|
+
import { ODConsoleManager, ODConsoleMessage, ODConsoleMessageParam, ODConsoleMessageTypes, ODDebugFileManager, ODDebugger, ODError, ODLiveStatusManager } from "./modules/console"
|
|
4
|
+
import { ODCheckerManager } from "./modules/checker"
|
|
5
5
|
import { ODEventManager } from "./modules/event"
|
|
6
6
|
import { ODPluginManager } from "./modules/plugin"
|
|
7
7
|
import { ODFlagManager } from "./modules/flag"
|
|
8
8
|
import { ODProgressBarManager } from "./modules/progressbar"
|
|
9
|
-
import { ODConfigManager
|
|
10
|
-
import { ODDatabaseManager
|
|
9
|
+
import { ODConfigManager } from "./modules/config"
|
|
10
|
+
import { ODDatabaseManager } from "./modules/database"
|
|
11
11
|
import { ODSessionManager } from "./modules/session"
|
|
12
12
|
import { ODLanguageManager } from "./modules/language"
|
|
13
|
-
import { ODBuilderManager
|
|
13
|
+
import { ODBuilderManager } from "./modules/builder"
|
|
14
14
|
import { ODResponderManager } from "./modules/responder"
|
|
15
|
-
import { ODActionManager
|
|
15
|
+
import { ODActionManager } from "./modules/action"
|
|
16
16
|
import { ODVerifyBarManager } from "./modules/verifybar"
|
|
17
17
|
import { ODPermissionManager } from "./modules/permission"
|
|
18
|
-
import { ODCooldownManager
|
|
18
|
+
import { ODCooldownManager } from "./modules/cooldown"
|
|
19
19
|
import { ODHelpMenuManager } from "./modules/helpmenu"
|
|
20
|
-
import {
|
|
21
|
-
import { ODCodeManager
|
|
20
|
+
import { ODStatisticManager } from "./modules/statistic"
|
|
21
|
+
import { ODCodeManager } from "./modules/code"
|
|
22
22
|
import { ODPostManager } from "./modules/post"
|
|
23
|
-
import { ODClientManager
|
|
23
|
+
import { ODClientManager } from "./modules/client"
|
|
24
24
|
import { ODSharedFuseManager } from "./modules/fuse"
|
|
25
25
|
import { ODStartScreenManager } from "./modules/startscreen"
|
|
26
26
|
|
|
@@ -77,7 +77,7 @@ export interface ODMainManagers {
|
|
|
77
77
|
/**The manager that manages & renders the Open Discord help menu. (not the embed, but the text) */
|
|
78
78
|
helpmenu: ODHelpMenuManager
|
|
79
79
|
/**The manager that manages, saves & renders the Open Discord statistics. (not the embed, but the text & database) */
|
|
80
|
-
|
|
80
|
+
statistics: ODStatisticManager
|
|
81
81
|
/**This manager is a place where you can put code that executes when the bot almost finishes the setup. (can be used for less important stuff that doesn't require an exact time-order) */
|
|
82
82
|
code: ODCodeManager
|
|
83
83
|
/**The manager that manages all posts (static discord channels) in the bot. (e.g. transcripts, logs, etc) */
|
|
@@ -129,7 +129,7 @@ export class ODMain implements ODMainManagers {
|
|
|
129
129
|
readonly permissions: ODPermissionManager
|
|
130
130
|
readonly cooldowns: ODCooldownManager
|
|
131
131
|
readonly helpmenu: ODHelpMenuManager
|
|
132
|
-
readonly
|
|
132
|
+
readonly statistics: ODStatisticManager
|
|
133
133
|
readonly code: ODCodeManager
|
|
134
134
|
readonly posts: ODPostManager
|
|
135
135
|
|
|
@@ -167,7 +167,7 @@ export class ODMain implements ODMainManagers {
|
|
|
167
167
|
this.permissions = managers.permissions
|
|
168
168
|
this.cooldowns = managers.cooldowns
|
|
169
169
|
this.helpmenu = managers.helpmenu
|
|
170
|
-
this.
|
|
170
|
+
this.statistics = managers.statistics
|
|
171
171
|
this.code = managers.code
|
|
172
172
|
this.posts = managers.posts
|
|
173
173
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
///////////////////////////////////////
|
|
2
2
|
//ACTION MODULE
|
|
3
3
|
///////////////////////////////////////
|
|
4
|
-
import { ODId, ODManager, ODValidId, ODSystemError, ODManagerData } from "./base"
|
|
4
|
+
import { ODId, ODManager, ODValidId, ODSystemError, ODManagerData, ODNoGeneric } from "./base"
|
|
5
5
|
import { ODWorkerManager, ODWorkerCallback, ODWorker } from "./worker"
|
|
6
6
|
import { ODDebugger } from "./console"
|
|
7
7
|
|
|
@@ -47,21 +47,21 @@ export class ODActionManager<IdList extends ODActionManagerIdConstraint = ODActi
|
|
|
47
47
|
super(debug,"action")
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
get<ActionId extends keyof IdList
|
|
50
|
+
get<ActionId extends keyof ODNoGeneric<IdList>>(id:ActionId): ODAction<IdList[ActionId]["source"],IdList[ActionId]["params"],IdList[ActionId]["result"],IdList[ActionId]["workers"]>
|
|
51
51
|
get(id:ODValidId): ODAction<string,{},{},string>|null
|
|
52
52
|
|
|
53
53
|
get(id:ODValidId): ODAction<string,{},{},string>|null {
|
|
54
54
|
return super.get(id)
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
remove<ActionId extends keyof IdList
|
|
57
|
+
remove<ActionId extends keyof ODNoGeneric<IdList>>(id:ActionId): ODAction<IdList[ActionId]["source"],IdList[ActionId]["params"],IdList[ActionId]["result"],IdList[ActionId]["workers"]>
|
|
58
58
|
remove(id:ODValidId): ODAction<string,{},{},string>|null
|
|
59
59
|
|
|
60
60
|
remove(id:ODValidId): ODAction<string,{},{},string>|null {
|
|
61
61
|
return super.remove(id)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
exists(id:keyof IdList): boolean
|
|
64
|
+
exists(id:keyof ODNoGeneric<IdList>): boolean
|
|
65
65
|
exists(id:ODValidId): boolean
|
|
66
66
|
|
|
67
67
|
exists(id:ODValidId): boolean {
|
package/src/api/modules/base.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//BASE MODULE
|
|
3
3
|
///////////////////////////////////////
|
|
4
4
|
import * as fs from "fs"
|
|
5
|
-
import {
|
|
5
|
+
import { ODDebugger } from "./console"
|
|
6
6
|
import type { ODMain } from "../main"
|
|
7
7
|
|
|
8
8
|
/**## ODPromiseVoid `type`
|
|
@@ -15,7 +15,6 @@ export type ODPromiseVoid = void|Promise<void>
|
|
|
15
15
|
*/
|
|
16
16
|
export type ODOptionalPromise<T> = T|Promise<T>
|
|
17
17
|
|
|
18
|
-
|
|
19
18
|
/**## ODValidButtonColor `type`
|
|
20
19
|
* This is a collection of all the possible button colors.
|
|
21
20
|
*/
|
|
@@ -27,22 +26,21 @@ export type ODValidButtonColor = "gray"|"red"|"green"|"blue"
|
|
|
27
26
|
export type ODProjectType = "openticket"|"openmoderation"
|
|
28
27
|
|
|
29
28
|
/**## ODValidId `type`
|
|
30
|
-
*
|
|
29
|
+
* A valid Open Discord identifier. It can be an `ODId` or `string`!
|
|
31
30
|
*
|
|
32
31
|
* You will see this type in many functions from Open Discord.
|
|
33
32
|
*/
|
|
34
33
|
export type ODValidId = string|number|symbol|ODId
|
|
35
34
|
|
|
36
35
|
/**## ODValidJsonType `type`
|
|
37
|
-
*
|
|
36
|
+
* A collection of all types that can be stored in a JSON file!
|
|
38
37
|
*
|
|
39
38
|
* list: `string`, `number`, `boolean`, `array`, `object`, `null`
|
|
40
39
|
*/
|
|
41
40
|
export type ODValidJsonType = string|number|boolean|object|ODValidJsonType[]|null
|
|
42
41
|
|
|
43
|
-
|
|
44
42
|
/**## ODInterfaceWithPartialProperty `type`
|
|
45
|
-
*
|
|
43
|
+
* A utility type to create an interface where some properties are optional!
|
|
46
44
|
*/
|
|
47
45
|
export type ODInterfaceWithPartialProperty<Interface,Key extends keyof Interface> = Omit<Interface,Key> & Partial<Pick<Interface,Key>>
|
|
48
46
|
|
|
@@ -51,6 +49,13 @@ export type ODInterfaceWithPartialProperty<Interface,Key extends keyof Interface
|
|
|
51
49
|
*/
|
|
52
50
|
export type ODDiscordIdType = "role"|"server"|"channel"|"category"|"user"|"member"|"interaction"|"message"
|
|
53
51
|
|
|
52
|
+
/**## ODNoGeneric `type`
|
|
53
|
+
* A utility type to remove generic index signatures from interfaces. This is required for providing autocomplete in all `IdList`'s of the `ODManagers`.
|
|
54
|
+
*/
|
|
55
|
+
export type ODNoGeneric<T extends Record<string|number|symbol,any>> = {
|
|
56
|
+
[K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K]
|
|
57
|
+
}
|
|
58
|
+
|
|
54
59
|
/**## ODId `class`
|
|
55
60
|
* This is an Open Discord identifier.
|
|
56
61
|
*
|
|
@@ -210,7 +215,7 @@ export class ODManager<DataType extends ODManagerData> extends ODManagerChangeHe
|
|
|
210
215
|
this.#debug = debug
|
|
211
216
|
this.#debugname = debugname
|
|
212
217
|
}
|
|
213
|
-
|
|
218
|
+
|
|
214
219
|
/**Add data to the manager. The `ODId` in the data class will be used as identifier! You can optionally select to overwrite existing data!*/
|
|
215
220
|
add(data:DataType|DataType[], overwrite?:boolean): boolean {
|
|
216
221
|
//repeat same command when data is an array
|
|
@@ -407,21 +412,21 @@ export class ODVersionManager<IdList extends ODVersionManagerIdConstraint = ODVe
|
|
|
407
412
|
super()
|
|
408
413
|
}
|
|
409
414
|
|
|
410
|
-
get<VersionId extends keyof IdList
|
|
415
|
+
get<VersionId extends keyof ODNoGeneric<IdList>>(id:VersionId): IdList[VersionId]
|
|
411
416
|
get(id:ODValidId): ODVersion|null
|
|
412
417
|
|
|
413
418
|
get(id:ODValidId): ODVersion|null {
|
|
414
419
|
return super.get(id)
|
|
415
420
|
}
|
|
416
421
|
|
|
417
|
-
remove<VersionId extends keyof IdList
|
|
422
|
+
remove<VersionId extends keyof ODNoGeneric<IdList>>(id:VersionId): IdList[VersionId]
|
|
418
423
|
remove(id:ODValidId): ODVersion|null
|
|
419
424
|
|
|
420
425
|
remove(id:ODValidId): ODVersion|null {
|
|
421
426
|
return super.remove(id)
|
|
422
427
|
}
|
|
423
428
|
|
|
424
|
-
exists(id:keyof IdList): boolean
|
|
429
|
+
exists(id:keyof ODNoGeneric<IdList>): boolean
|
|
425
430
|
exists(id:ODValidId): boolean
|
|
426
431
|
|
|
427
432
|
exists(id:ODValidId): boolean {
|