@open-discord-bots/framework 0.2.3 → 0.2.5
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/code.d.ts +1 -1
- package/dist/api/modules/code.js +1 -1
- package/dist/api/modules/console.js +2 -2
- package/dist/api/modules/fuse.d.ts +6 -6
- package/dist/api/modules/fuse.js +3 -3
- package/dist/api/modules/progressbar.d.ts +46 -1
- package/dist/api/modules/progressbar.js +43 -1
- package/dist/api/modules/statistic.d.ts +176 -0
- package/dist/api/modules/{stat.js → statistic.js} +52 -52
- package/package.json +1 -1
- package/src/api/index.ts +1 -1
- package/src/api/main.ts +14 -14
- package/src/api/modules/code.ts +1 -1
- package/src/api/modules/console.ts +2 -2
- package/src/api/modules/fuse.ts +9 -9
- package/src/api/modules/progressbar.ts +85 -1
- package/src/api/modules/{stat.ts → statistic.ts} +114 -114
- package/dist/api/modules/stat.d.ts +0 -176
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ We do currently <b>NOT</b> provide support for <b>3rd party implementations</b>
|
|
|
45
45
|
|
|
46
46
|
- **Permissions** - An easy to use system for managing bot permissions for users, roles & channels at the same time.
|
|
47
47
|
|
|
48
|
-
- **
|
|
48
|
+
- **Statistics** - Save, modify and keep track of statistics for users, channels, roles or custom entities.
|
|
49
49
|
|
|
50
50
|
- **Workers** - Many features use a worker-based system to allow extensible/overwritable code by plugins.
|
|
51
51
|
|
package/dist/api/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export * from "./modules/action";
|
|
|
17
17
|
export * from "./modules/permission";
|
|
18
18
|
export * from "./modules/helpmenu";
|
|
19
19
|
export * from "./modules/session";
|
|
20
|
-
export * from "./modules/
|
|
20
|
+
export * from "./modules/statistic";
|
|
21
21
|
export * from "./modules/code";
|
|
22
22
|
export * from "./modules/cooldown";
|
|
23
23
|
export * from "./modules/post";
|
package/dist/api/index.js
CHANGED
|
@@ -35,7 +35,7 @@ __exportStar(require("./modules/action"), exports);
|
|
|
35
35
|
__exportStar(require("./modules/permission"), exports);
|
|
36
36
|
__exportStar(require("./modules/helpmenu"), exports);
|
|
37
37
|
__exportStar(require("./modules/session"), exports);
|
|
38
|
-
__exportStar(require("./modules/
|
|
38
|
+
__exportStar(require("./modules/statistic"), exports);
|
|
39
39
|
__exportStar(require("./modules/code"), exports);
|
|
40
40
|
__exportStar(require("./modules/cooldown"), exports);
|
|
41
41
|
__exportStar(require("./modules/post"), exports);
|
package/dist/api/main.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { ODVerifyBarManager } from "./modules/verifybar";
|
|
|
16
16
|
import { ODPermissionManager } from "./modules/permission";
|
|
17
17
|
import { ODCooldownManager } from "./modules/cooldown";
|
|
18
18
|
import { ODHelpMenuManager } from "./modules/helpmenu";
|
|
19
|
-
import {
|
|
19
|
+
import { ODStatisticManager } from "./modules/statistic";
|
|
20
20
|
import { ODCodeManager } from "./modules/code";
|
|
21
21
|
import { ODPostManager } from "./modules/post";
|
|
22
22
|
import { ODClientManager } from "./modules/client";
|
|
@@ -71,7 +71,7 @@ export interface ODMainManagers {
|
|
|
71
71
|
/**The manager that manages & renders the Open Discord help menu. (not the embed, but the text) */
|
|
72
72
|
helpmenu: ODHelpMenuManager;
|
|
73
73
|
/**The manager that manages, saves & renders the Open Discord statistics. (not the embed, but the text & database) */
|
|
74
|
-
|
|
74
|
+
statistics: ODStatisticManager;
|
|
75
75
|
/**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) */
|
|
76
76
|
code: ODCodeManager;
|
|
77
77
|
/**The manager that manages all posts (static discord channels) in the bot. (e.g. transcripts, logs, etc) */
|
|
@@ -117,7 +117,7 @@ export declare class ODMain implements ODMainManagers {
|
|
|
117
117
|
readonly permissions: ODPermissionManager;
|
|
118
118
|
readonly cooldowns: ODCooldownManager;
|
|
119
119
|
readonly helpmenu: ODHelpMenuManager;
|
|
120
|
-
readonly
|
|
120
|
+
readonly statistics: ODStatisticManager;
|
|
121
121
|
readonly code: ODCodeManager;
|
|
122
122
|
readonly posts: ODPostManager;
|
|
123
123
|
readonly client: ODClientManager;
|
package/dist/api/main.js
CHANGED
|
@@ -34,7 +34,7 @@ class ODMain {
|
|
|
34
34
|
permissions;
|
|
35
35
|
cooldowns;
|
|
36
36
|
helpmenu;
|
|
37
|
-
|
|
37
|
+
statistics;
|
|
38
38
|
code;
|
|
39
39
|
posts;
|
|
40
40
|
client;
|
|
@@ -67,7 +67,7 @@ class ODMain {
|
|
|
67
67
|
this.permissions = managers.permissions;
|
|
68
68
|
this.cooldowns = managers.cooldowns;
|
|
69
69
|
this.helpmenu = managers.helpmenu;
|
|
70
|
-
this.
|
|
70
|
+
this.statistics = managers.statistics;
|
|
71
71
|
this.code = managers.code;
|
|
72
72
|
this.posts = managers.posts;
|
|
73
73
|
this.sharedFuses = managers.sharedFuses;
|
|
@@ -7,7 +7,7 @@ import { ODDebugger } from "./console";
|
|
|
7
7
|
* You can also specify a priority to change the execution order.
|
|
8
8
|
* In Open Discord, this is used for the following processes:
|
|
9
9
|
* - Autoclose/delete
|
|
10
|
-
* - Database syncronisation (with tickets,
|
|
10
|
+
* - Database syncronisation (with tickets, statistics & used options)
|
|
11
11
|
* - Panel auto-update
|
|
12
12
|
* - Database Garbage Collection (removing tickets that don't exist anymore)
|
|
13
13
|
* - And more!
|
package/dist/api/modules/code.js
CHANGED
|
@@ -12,7 +12,7 @@ const base_1 = require("./base");
|
|
|
12
12
|
* You can also specify a priority to change the execution order.
|
|
13
13
|
* In Open Discord, this is used for the following processes:
|
|
14
14
|
* - Autoclose/delete
|
|
15
|
-
* - Database syncronisation (with tickets,
|
|
15
|
+
* - Database syncronisation (with tickets, statistics & used options)
|
|
16
16
|
* - Panel auto-update
|
|
17
17
|
* - Database Garbage Collection (removing tickets that don't exist anymore)
|
|
18
18
|
* - And more!
|
|
@@ -334,7 +334,7 @@ class ODDebugFileManager {
|
|
|
334
334
|
fs_1.default.writeFileSync(this.path, newtext);
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
|
-
/**Generate the
|
|
337
|
+
/**Generate the statistics/header of the debug file (containing the version) */
|
|
338
338
|
#createStatsText() {
|
|
339
339
|
const date = new Date();
|
|
340
340
|
const dstring = `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
|
|
@@ -346,7 +346,7 @@ class ODDebugFileManager {
|
|
|
346
346
|
"=========================\n\n"
|
|
347
347
|
].join("\n");
|
|
348
348
|
}
|
|
349
|
-
/**Write the
|
|
349
|
+
/**Write the statistics/header to the debug file on startup */
|
|
350
350
|
#writeStartupStats() {
|
|
351
351
|
const currenttext = this.#readDebugFile();
|
|
352
352
|
if (currenttext) {
|
|
@@ -182,12 +182,12 @@ export interface ODSharedFuseList {
|
|
|
182
182
|
helpMenuCategoryLoading: boolean;
|
|
183
183
|
/**Load the default Open Discord help menu components. */
|
|
184
184
|
helpMenuComponentLoading: boolean;
|
|
185
|
-
/**Load the default Open Discord
|
|
186
|
-
|
|
187
|
-
/**Load the default Open Discord
|
|
188
|
-
|
|
189
|
-
/**Initiate the default Open Discord
|
|
190
|
-
|
|
185
|
+
/**Load the default Open Discord statistic scopes. */
|
|
186
|
+
statisticScopesLoading: boolean;
|
|
187
|
+
/**Load the default Open Discord statistics. */
|
|
188
|
+
statisticLoading: boolean;
|
|
189
|
+
/**Initiate the default Open Discord statistics. */
|
|
190
|
+
statisticInitiating: boolean;
|
|
191
191
|
/**Load the default Open Discord code/functions. */
|
|
192
192
|
codeLoading: boolean;
|
|
193
193
|
/**Execute the default Open Discord code/functions. */
|
package/dist/api/modules/fuse.js
CHANGED
|
@@ -106,9 +106,9 @@ class ODSharedFuseManager extends ODFuseManager {
|
|
|
106
106
|
cooldownsInitiating: true,
|
|
107
107
|
helpMenuCategoryLoading: true,
|
|
108
108
|
helpMenuComponentLoading: true,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
statisticScopesLoading: true,
|
|
110
|
+
statisticLoading: true,
|
|
111
|
+
statisticInitiating: true,
|
|
112
112
|
codeLoading: true,
|
|
113
113
|
codeExecution: true,
|
|
114
114
|
liveStatusLoading: true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ODManager, ODManagerData, ODValidId } from "./base";
|
|
2
|
-
import { ODDebugger } from "./console";
|
|
2
|
+
import { ODDebugger, ODValidConsoleColor } from "./console";
|
|
3
3
|
/**## ODProgressBarRendererManagerIdConstraint `type`
|
|
4
4
|
* The constraint/layout for id mappings/interfaces of the `ODProgressBarRendererManager` class.
|
|
5
5
|
*/
|
|
@@ -127,3 +127,48 @@ export declare class ODManualProgressBar extends ODProgressBar {
|
|
|
127
127
|
/**Decrease the value of the progress bar. */
|
|
128
128
|
decrease(amount: number, stop?: boolean): void;
|
|
129
129
|
}
|
|
130
|
+
/**## ODDefaultProgressBarRendererLabel `type`
|
|
131
|
+
* All available label types for the default progress bar renderer
|
|
132
|
+
*/
|
|
133
|
+
export type ODDefaultProgressBarRendererLabel = "value" | "percentage" | "fraction" | "time-ms" | "time-sec" | "time-min";
|
|
134
|
+
/**## ODDefaultProgressBarRendererSettings `interface`
|
|
135
|
+
* All settings for the default progress bar renderer.
|
|
136
|
+
*/
|
|
137
|
+
export interface ODDefaultProgressBarRendererSettings {
|
|
138
|
+
/**The color of the progress bar border. */
|
|
139
|
+
borderColor: ODValidConsoleColor | "openticket" | "openmoderation";
|
|
140
|
+
/**The color of the progress bar (filled side). */
|
|
141
|
+
filledBarColor: ODValidConsoleColor | "openticket" | "openmoderation";
|
|
142
|
+
/**The color of the progress bar (empty side). */
|
|
143
|
+
emptyBarColor: ODValidConsoleColor | "openticket" | "openmoderation";
|
|
144
|
+
/**The color of the text before the progress bar. */
|
|
145
|
+
prefixColor: ODValidConsoleColor | "openticket" | "openmoderation";
|
|
146
|
+
/**The color of the text after the progress bar. */
|
|
147
|
+
suffixColor: ODValidConsoleColor | "openticket" | "openmoderation";
|
|
148
|
+
/**The color of the progress bar label. */
|
|
149
|
+
labelColor: ODValidConsoleColor | "openticket" | "openmoderation";
|
|
150
|
+
/**The character used in the left border. */
|
|
151
|
+
leftBorderChar: string;
|
|
152
|
+
/**The character used in the right border. */
|
|
153
|
+
rightBorderChar: string;
|
|
154
|
+
/**The character used in the filled side of the progress bar. */
|
|
155
|
+
filledBarChar: string;
|
|
156
|
+
/**The character used in the empty side of the progress bar. */
|
|
157
|
+
emptyBarChar: string;
|
|
158
|
+
/**The label type. (will show a number related to the progress) */
|
|
159
|
+
labelType: ODDefaultProgressBarRendererLabel;
|
|
160
|
+
/**The position of the label. */
|
|
161
|
+
labelPosition: "start" | "end";
|
|
162
|
+
/**The width of the bar. (50 characters by default) */
|
|
163
|
+
barWidth: number;
|
|
164
|
+
/**Show the bar. */
|
|
165
|
+
showBar: boolean;
|
|
166
|
+
/**Show the label. */
|
|
167
|
+
showLabel: boolean;
|
|
168
|
+
/**Show the border. */
|
|
169
|
+
showBorder: boolean;
|
|
170
|
+
}
|
|
171
|
+
export declare class ODDefaultProgressBarRenderer extends ODProgressBarRenderer<ODDefaultProgressBarRendererSettings> {
|
|
172
|
+
#private;
|
|
173
|
+
constructor(id: ODValidId, settings: ODDefaultProgressBarRendererSettings);
|
|
174
|
+
}
|
|
@@ -3,12 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ODManualProgressBar = exports.ODTimedProgressBar = exports.ODProgressBar = exports.ODProgressBarRenderer = exports.ODProgressBarManager = exports.ODProgressBarRendererManager = void 0;
|
|
6
|
+
exports.ODDefaultProgressBarRenderer = exports.ODManualProgressBar = exports.ODTimedProgressBar = exports.ODProgressBar = exports.ODProgressBarRenderer = exports.ODProgressBarManager = exports.ODProgressBarRendererManager = void 0;
|
|
7
7
|
///////////////////////////////////////
|
|
8
8
|
//PROGRESS BAR MODULE
|
|
9
9
|
///////////////////////////////////////
|
|
10
10
|
const base_1 = require("./base");
|
|
11
11
|
const readline_1 = __importDefault(require("readline"));
|
|
12
|
+
const ansis_1 = __importDefault(require("ansis"));
|
|
12
13
|
/**## ODProgressBarRendererManager `class`
|
|
13
14
|
* This is an Open Discord progress bar renderer manager.
|
|
14
15
|
*
|
|
@@ -250,3 +251,44 @@ class ODManualProgressBar extends ODProgressBar {
|
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
253
|
exports.ODManualProgressBar = ODManualProgressBar;
|
|
254
|
+
class ODDefaultProgressBarRenderer extends ODProgressBarRenderer {
|
|
255
|
+
constructor(id, settings) {
|
|
256
|
+
super(id, (settings, min, max, value, rawPrefix, rawSuffix) => {
|
|
257
|
+
const percentage = (value - min) / (max - min);
|
|
258
|
+
const barLevel = Math.round(percentage * settings.barWidth);
|
|
259
|
+
const borderAnsis = this.#switchColorAnsis(settings.borderColor);
|
|
260
|
+
const filledBarAnsis = this.#switchColorAnsis(settings.filledBarColor);
|
|
261
|
+
const emptyBarAnsis = this.#switchColorAnsis(settings.emptyBarColor);
|
|
262
|
+
const labelAnsis = this.#switchColorAnsis(settings.labelColor);
|
|
263
|
+
const prefixAnsis = this.#switchColorAnsis(settings.prefixColor);
|
|
264
|
+
const suffixAnsis = this.#switchColorAnsis(settings.suffixColor);
|
|
265
|
+
const leftBorder = (settings.showBorder) ? borderAnsis(settings.leftBorderChar) : "";
|
|
266
|
+
const rightBorder = (settings.showBorder) ? borderAnsis(settings.rightBorderChar) : "";
|
|
267
|
+
const bar = (settings.showBar) ? filledBarAnsis(settings.filledBarChar.repeat(barLevel)) + emptyBarAnsis(settings.emptyBarChar.repeat(settings.barWidth - barLevel)) : "";
|
|
268
|
+
const prefix = (rawPrefix) ? prefixAnsis(rawPrefix) + " " : "";
|
|
269
|
+
const suffix = (rawSuffix) ? " " + suffixAnsis(rawSuffix) : "";
|
|
270
|
+
let label;
|
|
271
|
+
if (!settings.showLabel)
|
|
272
|
+
label = "";
|
|
273
|
+
if (settings.labelType == "fraction")
|
|
274
|
+
label = labelAnsis(value + "/" + max);
|
|
275
|
+
else if (settings.labelType == "percentage")
|
|
276
|
+
label = labelAnsis(Math.round(percentage * 100) + "%");
|
|
277
|
+
else if (settings.labelType == "time-ms")
|
|
278
|
+
label = labelAnsis(value + "ms");
|
|
279
|
+
else if (settings.labelType == "time-sec")
|
|
280
|
+
label = labelAnsis(Math.round(value * 10) / 10 + "sec");
|
|
281
|
+
else if (settings.labelType == "time-min")
|
|
282
|
+
label = labelAnsis(Math.round(value * 10) / 10 + "min");
|
|
283
|
+
else
|
|
284
|
+
label = labelAnsis(value.toString());
|
|
285
|
+
const labelWithPrefixAndSuffix = prefix + label + suffix;
|
|
286
|
+
return (settings.labelPosition == "start") ? labelWithPrefixAndSuffix + " " + leftBorder + bar + rightBorder : leftBorder + bar + rightBorder + " " + labelWithPrefixAndSuffix;
|
|
287
|
+
}, settings);
|
|
288
|
+
}
|
|
289
|
+
/**Switch between Ansis functions based on the specified color. */
|
|
290
|
+
#switchColorAnsis(c) {
|
|
291
|
+
return (c === "openticket") ? ansis_1.default.hex("#f8ba00") : (c === "openmoderation") ? ansis_1.default.hex("#1690ff") : ansis_1.default[c];
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
exports.ODDefaultProgressBarRenderer = ODDefaultProgressBarRenderer;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { ODId, ODManager, ODManagerData, ODValidId } from "./base";
|
|
2
|
+
import { ODDebugger } from "./console";
|
|
3
|
+
import { ODDatabase, ODDatabaseIdConstraint, ODJsonDatabaseStructure } from "./database";
|
|
4
|
+
import * as discord from "discord.js";
|
|
5
|
+
/**## ODValidStatisticValue `type`
|
|
6
|
+
* These are the only allowed types for a statistic value to improve compatibility with different database systems.
|
|
7
|
+
*/
|
|
8
|
+
export type ODValidStatisticValue = string | number | boolean;
|
|
9
|
+
/**## ODStatisticManagerInitCallback `type`
|
|
10
|
+
* This callback can be used to execute something when the statistics have been initiated.
|
|
11
|
+
*
|
|
12
|
+
* By default this is used to clear statistics from users that left the server or tickets which don't exist anymore.
|
|
13
|
+
*/
|
|
14
|
+
export type ODStatisticManagerInitCallback = (database: ODJsonDatabaseStructure, deletables: ODJsonDatabaseStructure) => void | Promise<void>;
|
|
15
|
+
/**## ODStatisticScopeSetMode `type`
|
|
16
|
+
* This type contains all valid methods for changing the value of a statistic.
|
|
17
|
+
*/
|
|
18
|
+
export type ODStatisticScopeSetMode = "set" | "increase" | "decrease";
|
|
19
|
+
/**## ODStatisticManagerIdConstraint `type`
|
|
20
|
+
* The constraint/layout for id mappings/interfaces of the `ODStatisticManager` class.
|
|
21
|
+
*/
|
|
22
|
+
export type ODStatisticManagerIdConstraint = Record<string, ODStatisticScope>;
|
|
23
|
+
/**## ODStatisticManager `class`
|
|
24
|
+
* This is an Open Discord statistics manager.
|
|
25
|
+
*
|
|
26
|
+
* This class is responsible for managing all statistics of the bot.
|
|
27
|
+
* Statistic are categorized in "scopes" which can be accessed in this manager.
|
|
28
|
+
*
|
|
29
|
+
* Statistic can be accessed in the individual scopes.
|
|
30
|
+
*/
|
|
31
|
+
export declare class ODStatisticManager<IdList extends ODStatisticManagerIdConstraint = ODStatisticManagerIdConstraint> extends ODManager<ODStatisticScope> {
|
|
32
|
+
#private;
|
|
33
|
+
/**Alias to Open Discord statistics database. */
|
|
34
|
+
database: ODDatabase<ODDatabaseIdConstraint> | null;
|
|
35
|
+
constructor(debug: ODDebugger);
|
|
36
|
+
/**Select the database to use to read/write all statistics from/to. */
|
|
37
|
+
useDatabase(database: ODDatabase<ODDatabaseIdConstraint>): void;
|
|
38
|
+
add(data: ODStatisticScope, overwrite?: boolean): boolean;
|
|
39
|
+
/**Init all statistics and run `onInit()` listeners. */
|
|
40
|
+
init(): Promise<void>;
|
|
41
|
+
/**Reset all statistics. (clears the entire database) */
|
|
42
|
+
reset(): Promise<void>;
|
|
43
|
+
/**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. */
|
|
44
|
+
onInit(callback: ODStatisticManagerInitCallback): void;
|
|
45
|
+
get<ScopeId extends keyof IdList>(id: ScopeId): IdList[ScopeId];
|
|
46
|
+
get(id: ODValidId): ODStatisticScope | null;
|
|
47
|
+
remove<ScopeId extends keyof IdList>(id: ScopeId): IdList[ScopeId];
|
|
48
|
+
remove(id: ODValidId): ODStatisticScope | null;
|
|
49
|
+
exists(id: keyof IdList): boolean;
|
|
50
|
+
exists(id: ODValidId): boolean;
|
|
51
|
+
}
|
|
52
|
+
/**## ODStatisticScopeIdConstraint `type`
|
|
53
|
+
* The constraint/layout for id mappings/interfaces of the `ODStatisticScope` class.
|
|
54
|
+
*/
|
|
55
|
+
export type ODStatisticScopeIdConstraint = Record<string, ODStatistic>;
|
|
56
|
+
/**## ODStatisticScope `class`
|
|
57
|
+
* This is an Open Discord statistic scope.
|
|
58
|
+
*
|
|
59
|
+
* A scope can contain multiple statistics. Every scope is seperated from other scopes.
|
|
60
|
+
* Here, you can read & write the values of all statistics.
|
|
61
|
+
*
|
|
62
|
+
* The built-in Open Discord scopes are: `global`, `user`, `ticket`
|
|
63
|
+
*/
|
|
64
|
+
export declare class ODStatisticScope<IdList extends ODStatisticScopeIdConstraint = ODStatisticScopeIdConstraint> extends ODManager<ODStatistic> {
|
|
65
|
+
/**The id of this statistics scope. */
|
|
66
|
+
id: ODId;
|
|
67
|
+
/**Is this scope already initialized? */
|
|
68
|
+
ready: boolean;
|
|
69
|
+
/**Alias to Open Discord statistics database. */
|
|
70
|
+
database: ODDatabase<ODDatabaseIdConstraint> | null;
|
|
71
|
+
/**The name of this scope (used in embed title) */
|
|
72
|
+
name: string;
|
|
73
|
+
constructor(id: ODValidId, name: string);
|
|
74
|
+
/**Select the database to use to read/write all statistics from/to. (Automatically assigned when used in `ODStatisticManager`) */
|
|
75
|
+
useDatabase(database: ODDatabase<ODDatabaseIdConstraint>): void;
|
|
76
|
+
/**Get the value of a statistic. The `scopeId` is the unique id of the user, channel, role, etc that the statistics are related to. */
|
|
77
|
+
getStat<StatisticId extends keyof IdList>(id: StatisticId, scopeId: string): Promise<ODValidStatisticValue | null>;
|
|
78
|
+
getStat(id: ODValidId, scopeId: string): Promise<ODValidStatisticValue | null>;
|
|
79
|
+
/**Get the value of a statistic for all `scopeId`'s. The `scopeId` is the unique id of the user, channel, role, etc that the statistics are related to. */
|
|
80
|
+
getAllStats<StatisticId extends keyof IdList>(id: StatisticId): Promise<{
|
|
81
|
+
id: string;
|
|
82
|
+
value: ODValidStatisticValue;
|
|
83
|
+
}[]>;
|
|
84
|
+
getAllStats(id: ODValidId): Promise<{
|
|
85
|
+
id: string;
|
|
86
|
+
value: ODValidStatisticValue;
|
|
87
|
+
}[]>;
|
|
88
|
+
/**Set, increase or decrease the value of a statistic. The `scopeId` is the unique id of the user, channel, role, etc that the statistics are related to. */
|
|
89
|
+
setStat<StatisticId extends keyof IdList>(id: StatisticId, scopeId: string, value: ODValidStatisticValue, mode: ODStatisticScopeSetMode): Promise<boolean>;
|
|
90
|
+
setStat(id: ODValidId, scopeId: string, value: ODValidStatisticValue, mode: ODStatisticScopeSetMode): Promise<boolean>;
|
|
91
|
+
/**Reset the value of a statistic to the initial value. The `scopeId` is the unique id of the user, channel, role, etc that the statistics are related to. */
|
|
92
|
+
resetStat<StatisticId extends keyof IdList>(id: ODValidId, scopeId: string): Promise<ODValidStatisticValue | null>;
|
|
93
|
+
resetStat(id: ODValidId, scopeId: string): Promise<ODValidStatisticValue | null>;
|
|
94
|
+
/**Initialize this statistic scope & return a list of all statistic ids in the following format: `<scopeid>_<statid>` */
|
|
95
|
+
init(): string[];
|
|
96
|
+
/**Render all statistics in this scope for usage in a discord message/embed. */
|
|
97
|
+
render(scopeId: string, guild: discord.Guild, channel: discord.TextBasedChannel, user: discord.User): Promise<string>;
|
|
98
|
+
get<StatisticId extends keyof IdList>(id: StatisticId): IdList[StatisticId];
|
|
99
|
+
get(id: ODValidId): ODStatistic | null;
|
|
100
|
+
remove<StatisticId extends keyof IdList>(id: StatisticId): IdList[StatisticId];
|
|
101
|
+
remove(id: ODValidId): ODStatistic | null;
|
|
102
|
+
exists(id: keyof IdList): boolean;
|
|
103
|
+
exists(id: ODValidId): boolean;
|
|
104
|
+
}
|
|
105
|
+
/**## ODStatisticGlobalScope `class`
|
|
106
|
+
* This is an Open Discord statistic global scope.
|
|
107
|
+
*
|
|
108
|
+
* A scope can contain multiple statistics. Every scope is seperated from other scopes.
|
|
109
|
+
* Here, you can read & write the values of all statistics.
|
|
110
|
+
*
|
|
111
|
+
* This scope is made specifically for the global statistics of Open Discord.
|
|
112
|
+
*/
|
|
113
|
+
export declare class ODStatisticGlobalScope<IdList extends ODStatisticScopeIdConstraint = ODStatisticScopeIdConstraint> extends ODStatisticScope<IdList> {
|
|
114
|
+
getStat<StatisticId extends keyof IdList>(id: StatisticId): Promise<ODValidStatisticValue | null>;
|
|
115
|
+
getStat(id: ODValidId): Promise<ODValidStatisticValue | null>;
|
|
116
|
+
getAllStats<StatisticId extends keyof IdList>(id: StatisticId): Promise<{
|
|
117
|
+
id: string;
|
|
118
|
+
value: ODValidStatisticValue;
|
|
119
|
+
}[]>;
|
|
120
|
+
getAllStats(id: ODValidId): Promise<{
|
|
121
|
+
id: string;
|
|
122
|
+
value: ODValidStatisticValue;
|
|
123
|
+
}[]>;
|
|
124
|
+
setStat<StatisticId extends keyof IdList>(id: StatisticId, value: ODValidStatisticValue, mode: ODStatisticScopeSetMode): Promise<boolean>;
|
|
125
|
+
setStat(id: ODValidId, value: ODValidStatisticValue, mode: ODStatisticScopeSetMode): Promise<boolean>;
|
|
126
|
+
resetStat<StatisticId extends keyof IdList>(id: ODValidId): Promise<ODValidStatisticValue | null>;
|
|
127
|
+
resetStat(id: ODValidId): Promise<ODValidStatisticValue | null>;
|
|
128
|
+
render(scopeId: "GLOBAL", guild: discord.Guild, channel: discord.TextBasedChannel, user: discord.User): Promise<string>;
|
|
129
|
+
}
|
|
130
|
+
/**## ODStatisticRenderer `type`
|
|
131
|
+
* This callback will render a single statistic for a discord embed/message.
|
|
132
|
+
*/
|
|
133
|
+
export type ODStatisticRenderer = (value: ODValidStatisticValue, scopeId: string, guild: discord.Guild, channel: discord.TextBasedChannel, user: discord.User) => string | Promise<string>;
|
|
134
|
+
/**## ODStatistic `class`
|
|
135
|
+
* This is an Open Discord statistic.
|
|
136
|
+
*
|
|
137
|
+
* This single statistic doesn't do anything except defining the rules of this statistic.
|
|
138
|
+
* Use it in a statistics scope to register a new statistic. A statistic can also include a priority to choose the render priority.
|
|
139
|
+
*
|
|
140
|
+
* It's recommended to use the `ODBaseStatistic` & `ODDynamicStatistic` classes instead of this one!
|
|
141
|
+
*/
|
|
142
|
+
export declare class ODStatistic extends ODManagerData {
|
|
143
|
+
/**The priority of this statistic. */
|
|
144
|
+
priority: number;
|
|
145
|
+
/**The render function of this statistic. */
|
|
146
|
+
render: ODStatisticRenderer;
|
|
147
|
+
/**The value of this statistic. */
|
|
148
|
+
value: ODValidStatisticValue | null;
|
|
149
|
+
constructor(id: ODValidId, priority: number, render: ODStatisticRenderer, value?: ODValidStatisticValue);
|
|
150
|
+
}
|
|
151
|
+
/**## ODBaseStatistic `class`
|
|
152
|
+
* This is an Open Discord basic statistic.
|
|
153
|
+
*
|
|
154
|
+
* This single statistic will store a number, boolean or string in the database.
|
|
155
|
+
* Use it to create a simple statistic for any statistics scope.
|
|
156
|
+
*/
|
|
157
|
+
export declare class ODBaseStatistic extends ODStatistic {
|
|
158
|
+
/**The name of this statistic. Rendered in discord embeds/messages. */
|
|
159
|
+
name: string;
|
|
160
|
+
constructor(id: ODValidId, priority: number, name: string, value: ODValidStatisticValue);
|
|
161
|
+
}
|
|
162
|
+
/**## ODDynamicStatisticRenderer `type`
|
|
163
|
+
* This callback will render a single dynamic statistic for a discord embed/message.
|
|
164
|
+
*/
|
|
165
|
+
export type ODDynamicStatisticRenderer = (scopeId: string, guild: discord.Guild, channel: discord.TextBasedChannel, user: discord.User) => string | Promise<string>;
|
|
166
|
+
/**## ODDynamicStatistic `class`
|
|
167
|
+
* This is an Open Discord dynamic statistic.
|
|
168
|
+
*
|
|
169
|
+
* A dynamic statistic does not store anything in the database! Instead, it will execute a function to return a custom result.
|
|
170
|
+
* This can be used to show statistics which are not stored in the database.
|
|
171
|
+
*
|
|
172
|
+
* This is used in Open Discord for the live ticket status, participants & system status.
|
|
173
|
+
*/
|
|
174
|
+
export declare class ODDynamicStatistic extends ODStatistic {
|
|
175
|
+
constructor(id: ODValidId, priority: number, render: ODDynamicStatisticRenderer);
|
|
176
|
+
}
|