@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,138 @@
|
|
|
1
|
+
import { ODValidId, ODManager, ODManagerData } from "./base";
|
|
2
|
+
import { ODDebugger } from "./console";
|
|
3
|
+
/**## ODCooldownManager `class`
|
|
4
|
+
* This is an Open Discord cooldown manager.
|
|
5
|
+
*
|
|
6
|
+
* It is responsible for managing all cooldowns in Open Discord. An example of this is the ticket creation cooldown.
|
|
7
|
+
*
|
|
8
|
+
* There are many types of cooldowns available, but you can also create your own!
|
|
9
|
+
*/
|
|
10
|
+
export declare class ODCooldownManager extends ODManager<ODCooldown<object>> {
|
|
11
|
+
constructor(debug: ODDebugger);
|
|
12
|
+
/**Initiate all cooldowns in this manager. */
|
|
13
|
+
init(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
/**## ODCooldownData `class`
|
|
16
|
+
* This is Open Discord cooldown data.
|
|
17
|
+
*
|
|
18
|
+
* It contains the instance of an active cooldown (e.g. for a user). It is handled by the cooldown itself.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ODCooldownData<Data extends object> extends ODManagerData {
|
|
21
|
+
/**Is this cooldown active? */
|
|
22
|
+
active: boolean;
|
|
23
|
+
/**Additional data of this cooldown instance. (different for each cooldown type) */
|
|
24
|
+
data: Data;
|
|
25
|
+
constructor(id: ODValidId, active: boolean, data: Data);
|
|
26
|
+
}
|
|
27
|
+
/**## ODCooldown `class`
|
|
28
|
+
* This is an Open Discord cooldown.
|
|
29
|
+
*
|
|
30
|
+
* It doesn't do anything on it's own, but it provides the methods that are used to interact with a cooldown.
|
|
31
|
+
* This class can be extended from to create a working cooldown.
|
|
32
|
+
*
|
|
33
|
+
* There are also premade cooldowns available in the bot!
|
|
34
|
+
*/
|
|
35
|
+
export declare class ODCooldown<Data extends object> extends ODManagerData {
|
|
36
|
+
data: ODManager<ODCooldownData<Data>>;
|
|
37
|
+
/**Is this cooldown already initialized? */
|
|
38
|
+
ready: boolean;
|
|
39
|
+
constructor(id: ODValidId);
|
|
40
|
+
/**Check this id and start cooldown when it exeeds the limit! Returns `true` when on cooldown! */
|
|
41
|
+
use(id: string): boolean;
|
|
42
|
+
/**Check this id without starting or updating the cooldown. Returns `true` when on cooldown! */
|
|
43
|
+
check(id: string): boolean;
|
|
44
|
+
/**Remove the cooldown for an id when available.*/
|
|
45
|
+
delete(id: string): void;
|
|
46
|
+
/**Initialize the internal systems of this cooldown. */
|
|
47
|
+
init(): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
/**## ODCounterCooldown `class`
|
|
50
|
+
* This is an Open Discord counter cooldown.
|
|
51
|
+
*
|
|
52
|
+
* It is is a cooldown based on a counter. When the number exceeds the limit, the cooldown is activated.
|
|
53
|
+
* The number will automatically be decreased with a set amount & interval.
|
|
54
|
+
*/
|
|
55
|
+
export declare class ODCounterCooldown extends ODCooldown<{
|
|
56
|
+
value: number;
|
|
57
|
+
}> {
|
|
58
|
+
/**The cooldown will activate when exceeding this limit. */
|
|
59
|
+
activeLimit: number;
|
|
60
|
+
/**The cooldown will deactivate when below this limit. */
|
|
61
|
+
cancelLimit: number;
|
|
62
|
+
/**The amount to increase the counter with everytime the cooldown is triggered/updated. */
|
|
63
|
+
increment: number;
|
|
64
|
+
/**The amount to decrease the counter over time. */
|
|
65
|
+
decrement: number;
|
|
66
|
+
/**The interval between decrements in milliseconds. */
|
|
67
|
+
invervalMs: number;
|
|
68
|
+
constructor(id: ODValidId, activeLimit: number, cancelLimit: number, increment: number, decrement: number, intervalMs: number);
|
|
69
|
+
use(id: string): boolean;
|
|
70
|
+
check(id: string): boolean;
|
|
71
|
+
delete(id: string): void;
|
|
72
|
+
init(): Promise<void>;
|
|
73
|
+
}
|
|
74
|
+
/**## ODIncrementalCounterCooldown `class`
|
|
75
|
+
* This is an Open Discord incremental counter cooldown.
|
|
76
|
+
*
|
|
77
|
+
* It is is a cooldown based on an incremental counter. It is exactly the same as the normal counter,
|
|
78
|
+
* with the only difference being that it still increments when the limit is already exeeded.
|
|
79
|
+
*/
|
|
80
|
+
export declare class ODIncrementalCounterCooldown extends ODCooldown<{
|
|
81
|
+
value: number;
|
|
82
|
+
}> {
|
|
83
|
+
/**The cooldown will activate when exceeding this limit. */
|
|
84
|
+
activeLimit: number;
|
|
85
|
+
/**The cooldown will deactivate when below this limit. */
|
|
86
|
+
cancelLimit: number;
|
|
87
|
+
/**The amount to increase the counter with everytime the cooldown is triggered/updated. */
|
|
88
|
+
increment: number;
|
|
89
|
+
/**The amount to decrease the counter over time. */
|
|
90
|
+
decrement: number;
|
|
91
|
+
/**The interval between decrements in milliseconds. */
|
|
92
|
+
invervalMs: number;
|
|
93
|
+
constructor(id: ODValidId, activeLimit: number, cancelLimit: number, increment: number, decrement: number, intervalMs: number);
|
|
94
|
+
use(id: string): boolean;
|
|
95
|
+
check(id: string): boolean;
|
|
96
|
+
delete(id: string): void;
|
|
97
|
+
init(): Promise<void>;
|
|
98
|
+
}
|
|
99
|
+
/**## ODTimeoutCooldown `class`
|
|
100
|
+
* This is an Open Discord timeout cooldown.
|
|
101
|
+
*
|
|
102
|
+
* It is a cooldown based on a timer. When triggered/updated, the cooldown is activated for the set amount of time.
|
|
103
|
+
* After the timer has timed out, the cooldown will be deleted.
|
|
104
|
+
*/
|
|
105
|
+
export declare class ODTimeoutCooldown extends ODCooldown<{
|
|
106
|
+
date: number;
|
|
107
|
+
}> {
|
|
108
|
+
/**The amount of milliseconds before the cooldown times-out */
|
|
109
|
+
timeoutMs: number;
|
|
110
|
+
constructor(id: ODValidId, timeoutMs: number);
|
|
111
|
+
use(id: string): boolean;
|
|
112
|
+
check(id: string): boolean;
|
|
113
|
+
delete(id: string): void;
|
|
114
|
+
/**Get the remaining amount of milliseconds before the timeout stops. */
|
|
115
|
+
remaining(id: string): number | null;
|
|
116
|
+
init(): Promise<void>;
|
|
117
|
+
}
|
|
118
|
+
/**## ODIncrementalTimeoutCooldown `class`
|
|
119
|
+
* This is an Open Discord incremental timeout cooldown.
|
|
120
|
+
*
|
|
121
|
+
* It is is a cooldown based on an incremental timer. It is exactly the same as the normal timer,
|
|
122
|
+
* with the only difference being that it adds additional time when triggered/updated while the cooldown is already active.
|
|
123
|
+
*/
|
|
124
|
+
export declare class ODIncrementalTimeoutCooldown extends ODCooldown<{
|
|
125
|
+
date: number;
|
|
126
|
+
}> {
|
|
127
|
+
/**The amount of milliseconds before the cooldown times-out */
|
|
128
|
+
timeoutMs: number;
|
|
129
|
+
/**The amount of milliseconds to add when triggered/updated while the cooldown is already active. */
|
|
130
|
+
incrementMs: number;
|
|
131
|
+
constructor(id: ODValidId, timeoutMs: number, incrementMs: number);
|
|
132
|
+
use(id: string): boolean;
|
|
133
|
+
check(id: string): boolean;
|
|
134
|
+
delete(id: string): void;
|
|
135
|
+
/**Get the remaining amount of milliseconds before the timeout stops. */
|
|
136
|
+
remaining(id: string): number | null;
|
|
137
|
+
init(): Promise<void>;
|
|
138
|
+
}
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ODIncrementalTimeoutCooldown = exports.ODTimeoutCooldown = exports.ODIncrementalCounterCooldown = exports.ODCounterCooldown = exports.ODCooldown = exports.ODCooldownData = exports.ODCooldownManager = void 0;
|
|
4
|
+
///////////////////////////////////////
|
|
5
|
+
//COOLDOWN MODULE
|
|
6
|
+
///////////////////////////////////////
|
|
7
|
+
const base_1 = require("./base");
|
|
8
|
+
/**## ODCooldownManager `class`
|
|
9
|
+
* This is an Open Discord cooldown manager.
|
|
10
|
+
*
|
|
11
|
+
* It is responsible for managing all cooldowns in Open Discord. An example of this is the ticket creation cooldown.
|
|
12
|
+
*
|
|
13
|
+
* There are many types of cooldowns available, but you can also create your own!
|
|
14
|
+
*/
|
|
15
|
+
class ODCooldownManager extends base_1.ODManager {
|
|
16
|
+
constructor(debug) {
|
|
17
|
+
super(debug, "cooldown");
|
|
18
|
+
}
|
|
19
|
+
/**Initiate all cooldowns in this manager. */
|
|
20
|
+
async init() {
|
|
21
|
+
for (const cooldown of this.getAll()) {
|
|
22
|
+
await cooldown.init();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.ODCooldownManager = ODCooldownManager;
|
|
27
|
+
/**## ODCooldownData `class`
|
|
28
|
+
* This is Open Discord cooldown data.
|
|
29
|
+
*
|
|
30
|
+
* It contains the instance of an active cooldown (e.g. for a user). It is handled by the cooldown itself.
|
|
31
|
+
*/
|
|
32
|
+
class ODCooldownData extends base_1.ODManagerData {
|
|
33
|
+
/**Is this cooldown active? */
|
|
34
|
+
active;
|
|
35
|
+
/**Additional data of this cooldown instance. (different for each cooldown type) */
|
|
36
|
+
data;
|
|
37
|
+
constructor(id, active, data) {
|
|
38
|
+
super(id);
|
|
39
|
+
this.active = active;
|
|
40
|
+
this.data = data;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.ODCooldownData = ODCooldownData;
|
|
44
|
+
/**## ODCooldown `class`
|
|
45
|
+
* This is an Open Discord cooldown.
|
|
46
|
+
*
|
|
47
|
+
* It doesn't do anything on it's own, but it provides the methods that are used to interact with a cooldown.
|
|
48
|
+
* This class can be extended from to create a working cooldown.
|
|
49
|
+
*
|
|
50
|
+
* There are also premade cooldowns available in the bot!
|
|
51
|
+
*/
|
|
52
|
+
class ODCooldown extends base_1.ODManagerData {
|
|
53
|
+
data = new base_1.ODManager();
|
|
54
|
+
/**Is this cooldown already initialized? */
|
|
55
|
+
ready = false;
|
|
56
|
+
constructor(id) {
|
|
57
|
+
super(id);
|
|
58
|
+
}
|
|
59
|
+
/**Check this id and start cooldown when it exeeds the limit! Returns `true` when on cooldown! */
|
|
60
|
+
use(id) {
|
|
61
|
+
throw new base_1.ODSystemError("Tried to use an unimplemented ODCooldown!");
|
|
62
|
+
}
|
|
63
|
+
/**Check this id without starting or updating the cooldown. Returns `true` when on cooldown! */
|
|
64
|
+
check(id) {
|
|
65
|
+
throw new base_1.ODSystemError("Tried to use an unimplemented ODCooldown!");
|
|
66
|
+
}
|
|
67
|
+
/**Remove the cooldown for an id when available.*/
|
|
68
|
+
delete(id) {
|
|
69
|
+
throw new base_1.ODSystemError("Tried to use an unimplemented ODCooldown!");
|
|
70
|
+
}
|
|
71
|
+
/**Initialize the internal systems of this cooldown. */
|
|
72
|
+
async init() {
|
|
73
|
+
throw new base_1.ODSystemError("Tried to use an unimplemented ODCooldown!");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.ODCooldown = ODCooldown;
|
|
77
|
+
/**## ODCounterCooldown `class`
|
|
78
|
+
* This is an Open Discord counter cooldown.
|
|
79
|
+
*
|
|
80
|
+
* It is is a cooldown based on a counter. When the number exceeds the limit, the cooldown is activated.
|
|
81
|
+
* The number will automatically be decreased with a set amount & interval.
|
|
82
|
+
*/
|
|
83
|
+
class ODCounterCooldown extends ODCooldown {
|
|
84
|
+
/**The cooldown will activate when exceeding this limit. */
|
|
85
|
+
activeLimit;
|
|
86
|
+
/**The cooldown will deactivate when below this limit. */
|
|
87
|
+
cancelLimit;
|
|
88
|
+
/**The amount to increase the counter with everytime the cooldown is triggered/updated. */
|
|
89
|
+
increment;
|
|
90
|
+
/**The amount to decrease the counter over time. */
|
|
91
|
+
decrement;
|
|
92
|
+
/**The interval between decrements in milliseconds. */
|
|
93
|
+
invervalMs;
|
|
94
|
+
constructor(id, activeLimit, cancelLimit, increment, decrement, intervalMs) {
|
|
95
|
+
super(id);
|
|
96
|
+
this.activeLimit = activeLimit;
|
|
97
|
+
this.cancelLimit = cancelLimit;
|
|
98
|
+
this.increment = increment;
|
|
99
|
+
this.decrement = decrement;
|
|
100
|
+
this.invervalMs = intervalMs;
|
|
101
|
+
}
|
|
102
|
+
use(id) {
|
|
103
|
+
const cooldown = this.data.get(id);
|
|
104
|
+
if (cooldown) {
|
|
105
|
+
//cooldown for this id already exists
|
|
106
|
+
if (cooldown.active) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
else if (cooldown.data.value < this.activeLimit) {
|
|
110
|
+
cooldown.data.value = cooldown.data.value + this.increment;
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
cooldown.active = true;
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
//cooldown for this id doesn't exist
|
|
120
|
+
this.data.add(new ODCooldownData(id, (this.increment >= this.activeLimit), {
|
|
121
|
+
value: this.increment
|
|
122
|
+
}));
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
check(id) {
|
|
127
|
+
const cooldown = this.data.get(id);
|
|
128
|
+
if (cooldown) {
|
|
129
|
+
//cooldown for this id already exists
|
|
130
|
+
return cooldown.active;
|
|
131
|
+
}
|
|
132
|
+
else
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
delete(id) {
|
|
136
|
+
this.data.remove(id);
|
|
137
|
+
}
|
|
138
|
+
async init() {
|
|
139
|
+
if (this.ready)
|
|
140
|
+
return;
|
|
141
|
+
setInterval(async () => {
|
|
142
|
+
await this.data.loopAll((cooldown) => {
|
|
143
|
+
cooldown.data.value = cooldown.data.value - this.decrement;
|
|
144
|
+
if (cooldown.data.value <= this.cancelLimit) {
|
|
145
|
+
cooldown.active = false;
|
|
146
|
+
}
|
|
147
|
+
if (cooldown.data.value <= 0) {
|
|
148
|
+
this.data.remove(cooldown.id);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}, this.invervalMs);
|
|
152
|
+
this.ready = true;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.ODCounterCooldown = ODCounterCooldown;
|
|
156
|
+
/**## ODIncrementalCounterCooldown `class`
|
|
157
|
+
* This is an Open Discord incremental counter cooldown.
|
|
158
|
+
*
|
|
159
|
+
* It is is a cooldown based on an incremental counter. It is exactly the same as the normal counter,
|
|
160
|
+
* with the only difference being that it still increments when the limit is already exeeded.
|
|
161
|
+
*/
|
|
162
|
+
class ODIncrementalCounterCooldown extends ODCooldown {
|
|
163
|
+
/**The cooldown will activate when exceeding this limit. */
|
|
164
|
+
activeLimit;
|
|
165
|
+
/**The cooldown will deactivate when below this limit. */
|
|
166
|
+
cancelLimit;
|
|
167
|
+
/**The amount to increase the counter with everytime the cooldown is triggered/updated. */
|
|
168
|
+
increment;
|
|
169
|
+
/**The amount to decrease the counter over time. */
|
|
170
|
+
decrement;
|
|
171
|
+
/**The interval between decrements in milliseconds. */
|
|
172
|
+
invervalMs;
|
|
173
|
+
constructor(id, activeLimit, cancelLimit, increment, decrement, intervalMs) {
|
|
174
|
+
super(id);
|
|
175
|
+
this.activeLimit = activeLimit;
|
|
176
|
+
this.cancelLimit = cancelLimit;
|
|
177
|
+
this.increment = increment;
|
|
178
|
+
this.decrement = decrement;
|
|
179
|
+
this.invervalMs = intervalMs;
|
|
180
|
+
}
|
|
181
|
+
use(id) {
|
|
182
|
+
const cooldown = this.data.get(id);
|
|
183
|
+
if (cooldown) {
|
|
184
|
+
//cooldown for this id already exists
|
|
185
|
+
if (cooldown.active) {
|
|
186
|
+
cooldown.data.value = cooldown.data.value + this.increment;
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
else if (cooldown.data.value < this.activeLimit) {
|
|
190
|
+
cooldown.data.value = cooldown.data.value + this.increment;
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
cooldown.active = true;
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
//cooldown for this id doesn't exist
|
|
200
|
+
this.data.add(new ODCooldownData(id, (this.increment >= this.activeLimit), {
|
|
201
|
+
value: this.increment
|
|
202
|
+
}));
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
check(id) {
|
|
207
|
+
const cooldown = this.data.get(id);
|
|
208
|
+
if (cooldown) {
|
|
209
|
+
//cooldown for this id already exists
|
|
210
|
+
return cooldown.active;
|
|
211
|
+
}
|
|
212
|
+
else
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
delete(id) {
|
|
216
|
+
this.data.remove(id);
|
|
217
|
+
}
|
|
218
|
+
async init() {
|
|
219
|
+
if (this.ready)
|
|
220
|
+
return;
|
|
221
|
+
setInterval(async () => {
|
|
222
|
+
await this.data.loopAll((cooldown) => {
|
|
223
|
+
cooldown.data.value = cooldown.data.value - this.decrement;
|
|
224
|
+
if (cooldown.data.value <= this.cancelLimit) {
|
|
225
|
+
cooldown.active = false;
|
|
226
|
+
}
|
|
227
|
+
if (cooldown.data.value <= 0) {
|
|
228
|
+
this.data.remove(cooldown.id);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}, this.invervalMs);
|
|
232
|
+
this.ready = true;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.ODIncrementalCounterCooldown = ODIncrementalCounterCooldown;
|
|
236
|
+
/**## ODTimeoutCooldown `class`
|
|
237
|
+
* This is an Open Discord timeout cooldown.
|
|
238
|
+
*
|
|
239
|
+
* It is a cooldown based on a timer. When triggered/updated, the cooldown is activated for the set amount of time.
|
|
240
|
+
* After the timer has timed out, the cooldown will be deleted.
|
|
241
|
+
*/
|
|
242
|
+
class ODTimeoutCooldown extends ODCooldown {
|
|
243
|
+
/**The amount of milliseconds before the cooldown times-out */
|
|
244
|
+
timeoutMs;
|
|
245
|
+
constructor(id, timeoutMs) {
|
|
246
|
+
super(id);
|
|
247
|
+
this.timeoutMs = timeoutMs;
|
|
248
|
+
}
|
|
249
|
+
use(id) {
|
|
250
|
+
const cooldown = this.data.get(id);
|
|
251
|
+
if (cooldown) {
|
|
252
|
+
//cooldown for this id already exists
|
|
253
|
+
if ((new Date().getTime() - cooldown.data.date) > this.timeoutMs) {
|
|
254
|
+
this.data.remove(id);
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
//cooldown for this id doesn't exist
|
|
263
|
+
this.data.add(new ODCooldownData(id, true, {
|
|
264
|
+
date: new Date().getTime()
|
|
265
|
+
}));
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
check(id) {
|
|
270
|
+
const cooldown = this.data.get(id);
|
|
271
|
+
if (cooldown) {
|
|
272
|
+
//cooldown for this id already exists
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
else
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
delete(id) {
|
|
279
|
+
this.data.remove(id);
|
|
280
|
+
}
|
|
281
|
+
/**Get the remaining amount of milliseconds before the timeout stops. */
|
|
282
|
+
remaining(id) {
|
|
283
|
+
const cooldown = this.data.get(id);
|
|
284
|
+
if (!cooldown)
|
|
285
|
+
return null;
|
|
286
|
+
const rawResult = this.timeoutMs - (new Date().getTime() - cooldown.data.date);
|
|
287
|
+
return (rawResult > 0) ? rawResult : 0;
|
|
288
|
+
}
|
|
289
|
+
async init() {
|
|
290
|
+
if (this.ready)
|
|
291
|
+
return;
|
|
292
|
+
this.ready = true;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
exports.ODTimeoutCooldown = ODTimeoutCooldown;
|
|
296
|
+
/**## ODIncrementalTimeoutCooldown `class`
|
|
297
|
+
* This is an Open Discord incremental timeout cooldown.
|
|
298
|
+
*
|
|
299
|
+
* It is is a cooldown based on an incremental timer. It is exactly the same as the normal timer,
|
|
300
|
+
* with the only difference being that it adds additional time when triggered/updated while the cooldown is already active.
|
|
301
|
+
*/
|
|
302
|
+
class ODIncrementalTimeoutCooldown extends ODCooldown {
|
|
303
|
+
/**The amount of milliseconds before the cooldown times-out */
|
|
304
|
+
timeoutMs;
|
|
305
|
+
/**The amount of milliseconds to add when triggered/updated while the cooldown is already active. */
|
|
306
|
+
incrementMs;
|
|
307
|
+
constructor(id, timeoutMs, incrementMs) {
|
|
308
|
+
super(id);
|
|
309
|
+
this.timeoutMs = timeoutMs;
|
|
310
|
+
this.incrementMs = incrementMs;
|
|
311
|
+
}
|
|
312
|
+
use(id) {
|
|
313
|
+
const cooldown = this.data.get(id);
|
|
314
|
+
if (cooldown) {
|
|
315
|
+
//cooldown for this id already exists
|
|
316
|
+
if ((new Date().getTime() - cooldown.data.date) > this.timeoutMs) {
|
|
317
|
+
this.data.remove(id);
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
cooldown.data.date = cooldown.data.date + this.incrementMs;
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
//cooldown for this id doesn't exist
|
|
327
|
+
this.data.add(new ODCooldownData(id, true, {
|
|
328
|
+
date: new Date().getTime()
|
|
329
|
+
}));
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
check(id) {
|
|
334
|
+
const cooldown = this.data.get(id);
|
|
335
|
+
if (cooldown) {
|
|
336
|
+
//cooldown for this id already exists
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
else
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
delete(id) {
|
|
343
|
+
this.data.remove(id);
|
|
344
|
+
}
|
|
345
|
+
/**Get the remaining amount of milliseconds before the timeout stops. */
|
|
346
|
+
remaining(id) {
|
|
347
|
+
const cooldown = this.data.get(id);
|
|
348
|
+
if (!cooldown)
|
|
349
|
+
return null;
|
|
350
|
+
const rawResult = this.timeoutMs - (new Date().getTime() - cooldown.data.date);
|
|
351
|
+
return (rawResult > 0) ? rawResult : 0;
|
|
352
|
+
}
|
|
353
|
+
async init() {
|
|
354
|
+
if (this.ready)
|
|
355
|
+
return;
|
|
356
|
+
this.ready = true;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
exports.ODIncrementalTimeoutCooldown = ODIncrementalTimeoutCooldown;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { ODManager, ODManagerData, ODOptionalPromise, ODPromiseVoid, ODValidId, ODValidJsonType } from "./base";
|
|
2
|
+
import { ODDebugger } from "./console";
|
|
3
|
+
import * as fjs from "formatted-json-stringify";
|
|
4
|
+
/**## ODDatabaseManager `class`
|
|
5
|
+
* This is an Open Discord database manager.
|
|
6
|
+
*
|
|
7
|
+
* It manages all databases in the bot and allows to permanently store data from the bot!
|
|
8
|
+
*
|
|
9
|
+
* You can use this class to get/add a database (`ODDatabase`) in your plugin!
|
|
10
|
+
*/
|
|
11
|
+
export declare class ODDatabaseManager extends ODManager<ODDatabase> {
|
|
12
|
+
constructor(debug: ODDebugger);
|
|
13
|
+
/**Init all database files. */
|
|
14
|
+
init(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/**## ODDatabase `class`
|
|
17
|
+
* This is an Open Discord database template.
|
|
18
|
+
* This class doesn't do anything at all, it just gives a template & basic methods for a database. Use `ODJsonDatabase` instead!
|
|
19
|
+
*
|
|
20
|
+
* You can use this class if you want to create your own database implementation (e.g. `mongodb`, `mysql`,...)!
|
|
21
|
+
*/
|
|
22
|
+
export declare class ODDatabase extends ODManagerData {
|
|
23
|
+
/**The name of the file with extension. */
|
|
24
|
+
file: string;
|
|
25
|
+
/**The path to the file relative to the main directory. */
|
|
26
|
+
path: string;
|
|
27
|
+
/**Init the database. */
|
|
28
|
+
init(): ODPromiseVoid;
|
|
29
|
+
/**Add/Overwrite a specific category & key in the database. Returns `true` when overwritten. */
|
|
30
|
+
set(category: string, key: string, value: ODValidJsonType): ODOptionalPromise<boolean>;
|
|
31
|
+
/**Get a specific category & key in the database */
|
|
32
|
+
get(category: string, key: string): ODOptionalPromise<ODValidJsonType | undefined>;
|
|
33
|
+
/**Delete a specific category & key in the database */
|
|
34
|
+
delete(category: string, key: string): ODOptionalPromise<boolean>;
|
|
35
|
+
/**Check if a specific category & key exists in the database */
|
|
36
|
+
exists(category: string, key: string): ODOptionalPromise<boolean>;
|
|
37
|
+
/**Get a specific category in the database */
|
|
38
|
+
getCategory(category: string): ODOptionalPromise<{
|
|
39
|
+
key: string;
|
|
40
|
+
value: ODValidJsonType;
|
|
41
|
+
}[] | undefined>;
|
|
42
|
+
/**Get all values in the database */
|
|
43
|
+
getAll(): ODOptionalPromise<ODJsonDatabaseStructure>;
|
|
44
|
+
}
|
|
45
|
+
/**## ODJsonDatabaseStructure `type`
|
|
46
|
+
* This is the structure of how a JSON database file!
|
|
47
|
+
*/
|
|
48
|
+
export type ODJsonDatabaseStructure = {
|
|
49
|
+
category: string;
|
|
50
|
+
key: string;
|
|
51
|
+
value: ODValidJsonType;
|
|
52
|
+
}[];
|
|
53
|
+
/**## ODJsonDatabase `class`
|
|
54
|
+
* This is an Open Discord JSON database.
|
|
55
|
+
* It stores data in a `json` file as a large `Array` using the `category`, `key`, `value` strategy.
|
|
56
|
+
* You can store the following types: `string`, `number`, `boolean`, `array`, `object` & `null`!
|
|
57
|
+
*
|
|
58
|
+
* You can use this class if you want to add your own database or to use an existing one!
|
|
59
|
+
*/
|
|
60
|
+
export declare class ODJsonDatabase extends ODDatabase {
|
|
61
|
+
#private;
|
|
62
|
+
constructor(id: ODValidId, file: string, customPath?: string);
|
|
63
|
+
/**Init the database. */
|
|
64
|
+
init(): ODPromiseVoid;
|
|
65
|
+
/**Set/overwrite the value of `category` & `key`. Returns `true` when overwritten!
|
|
66
|
+
* @example
|
|
67
|
+
* const didOverwrite = database.setData("category","key","value") //value can be any of the valid types
|
|
68
|
+
* //You need an ODJsonDatabase class named "database" for this example to work!
|
|
69
|
+
*/
|
|
70
|
+
set(category: string, key: string, value: ODValidJsonType): ODOptionalPromise<boolean>;
|
|
71
|
+
/**Get the value of `category` & `key`. Returns `undefined` when non-existent!
|
|
72
|
+
* @example
|
|
73
|
+
* const data = database.getData("category","key") //data will be the value
|
|
74
|
+
* //You need an ODJsonDatabase class named "database" for this example to work!
|
|
75
|
+
*/
|
|
76
|
+
get(category: string, key: string): ODOptionalPromise<ODValidJsonType | undefined>;
|
|
77
|
+
/**Remove the value of `category` & `key`. Returns `undefined` when non-existent!
|
|
78
|
+
* @example
|
|
79
|
+
* const didExist = database.deleteData("category","key") //delete this value
|
|
80
|
+
* //You need an ODJsonDatabase class named "database" for this example to work!
|
|
81
|
+
*/
|
|
82
|
+
delete(category: string, key: string): ODOptionalPromise<boolean>;
|
|
83
|
+
/**Check if a value of `category` & `key` exists. Returns `false` when non-existent! */
|
|
84
|
+
exists(category: string, key: string): ODOptionalPromise<boolean>;
|
|
85
|
+
/**Get all values in `category`. Returns `undefined` when non-existent! */
|
|
86
|
+
getCategory(category: string): ODOptionalPromise<{
|
|
87
|
+
key: string;
|
|
88
|
+
value: ODValidJsonType;
|
|
89
|
+
}[] | undefined>;
|
|
90
|
+
/**Get all values in `category`. */
|
|
91
|
+
getAll(): ODOptionalPromise<ODJsonDatabaseStructure>;
|
|
92
|
+
}
|
|
93
|
+
/**## ODFormattedJsonDatabase `class`
|
|
94
|
+
* This is an Open Discord Formatted JSON database.
|
|
95
|
+
* It stores data in a `json` file as a large `Array` using the `category`, `key`, `value` strategy.
|
|
96
|
+
* You can store the following types: `string`, `number`, `boolean`, `array`, `object` & `null`!
|
|
97
|
+
*
|
|
98
|
+
* This one is exactly the same as `ODJsonDatabase`, but it has a formatter from the `formatted-json-stringify` package.
|
|
99
|
+
* This can help you organise it a little bit better!
|
|
100
|
+
*/
|
|
101
|
+
export declare class ODFormattedJsonDatabase extends ODDatabase {
|
|
102
|
+
#private;
|
|
103
|
+
/**The formatter to use on the database array */
|
|
104
|
+
formatter: fjs.ArrayFormatter;
|
|
105
|
+
constructor(id: ODValidId, file: string, formatter: fjs.ArrayFormatter, customPath?: string);
|
|
106
|
+
/**Init the database. */
|
|
107
|
+
init(): ODPromiseVoid;
|
|
108
|
+
/**Set/overwrite the value of `category` & `key`. Returns `true` when overwritten!
|
|
109
|
+
* @example
|
|
110
|
+
* const didOverwrite = database.setData("category","key","value") //value can be any of the valid types
|
|
111
|
+
* //You need an ODFormattedJsonDatabase class named "database" for this example to work!
|
|
112
|
+
*/
|
|
113
|
+
set(category: string, key: string, value: ODValidJsonType): ODOptionalPromise<boolean>;
|
|
114
|
+
/**Get the value of `category` & `key`. Returns `undefined` when non-existent!
|
|
115
|
+
* @example
|
|
116
|
+
* const data = database.getData("category","key") //data will be the value
|
|
117
|
+
* //You need an ODFormattedJsonDatabase class named "database" for this example to work!
|
|
118
|
+
*/
|
|
119
|
+
get(category: string, key: string): ODOptionalPromise<ODValidJsonType | undefined>;
|
|
120
|
+
/**Remove the value of `category` & `key`. Returns `undefined` when non-existent!
|
|
121
|
+
* @example
|
|
122
|
+
* const didExist = database.deleteData("category","key") //delete this value
|
|
123
|
+
* //You need an ODFormattedJsonDatabase class named "database" for this example to work!
|
|
124
|
+
*/
|
|
125
|
+
delete(category: string, key: string): ODOptionalPromise<boolean>;
|
|
126
|
+
/**Check if a value of `category` & `key` exists. Returns `false` when non-existent! */
|
|
127
|
+
exists(category: string, key: string): ODOptionalPromise<boolean>;
|
|
128
|
+
/**Get all values in `category`. Returns `undefined` when non-existent! */
|
|
129
|
+
getCategory(category: string): ODOptionalPromise<{
|
|
130
|
+
key: string;
|
|
131
|
+
value: ODValidJsonType;
|
|
132
|
+
}[] | undefined>;
|
|
133
|
+
/**Get all values in `category`. */
|
|
134
|
+
getAll(): ODOptionalPromise<ODJsonDatabaseStructure>;
|
|
135
|
+
}
|