@open-discord-bots/framework 0.2.17 → 0.3.0
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/dist/api/index.d.ts +16 -15
- package/dist/api/index.js +16 -15
- package/dist/api/main.d.ts +31 -23
- package/dist/api/main.js +3 -1
- package/dist/api/modules/action.d.ts +2 -2
- package/dist/api/modules/action.js +1 -5
- package/dist/api/modules/base.d.ts +2 -2
- package/dist/api/modules/builder.d.ts +2 -2
- package/dist/api/modules/builder.js +0 -4
- package/dist/api/modules/checker.d.ts +2 -2
- package/dist/api/modules/checker.js +2 -6
- package/dist/api/modules/component.d.ts +922 -0
- package/dist/api/modules/component.js +1344 -0
- package/dist/api/modules/config.d.ts +30 -1
- package/dist/api/modules/config.js +81 -0
- package/dist/api/modules/cooldown.d.ts +5 -5
- package/dist/api/modules/cooldown.js +1 -17
- package/dist/api/modules/database.d.ts +21 -13
- package/dist/api/modules/database.js +0 -23
- package/dist/api/modules/helpmenu.d.ts +9 -7
- package/dist/api/modules/helpmenu.js +22 -17
- package/dist/api/modules/language.d.ts +2 -2
- package/dist/api/modules/language.js +3 -7
- package/dist/api/modules/progressbar.d.ts +2 -1
- package/dist/api/modules/progressbar.js +1 -1
- package/dist/api/modules/responder.d.ts +2 -2
- package/dist/api/modules/responder.js +0 -4
- package/dist/api/modules/session.d.ts +1 -1
- package/dist/api/modules/session.js +1 -1
- package/dist/api/modules/startscreen.d.ts +2 -2
- package/dist/api/modules/startscreen.js +5 -3
- package/package.json +3 -2
- package/src/api/index.ts +16 -15
- package/src/api/main.ts +33 -24
- package/src/api/modules/action.ts +2 -4
- package/src/api/modules/base.ts +2 -2
- package/src/api/modules/builder.ts +2 -4
- package/src/api/modules/checker.ts +5 -6
- package/src/api/modules/component.ts +1822 -0
- package/src/api/modules/config.ts +78 -1
- package/src/api/modules/cooldown.ts +8 -13
- package/src/api/modules/database.ts +24 -32
- package/src/api/modules/helpmenu.ts +29 -22
- package/src/api/modules/language.ts +5 -7
- package/src/api/modules/progressbar.ts +2 -3
- package/src/api/modules/responder.ts +2 -4
- package/src/api/modules/session.ts +1 -1
- package/src/api/modules/startscreen.ts +6 -4
- package/src/api/modules/component.txt +0 -350
|
@@ -31,7 +31,7 @@ export declare class ODConfigManager<IdList extends ODConfigManagerIdConstraint
|
|
|
31
31
|
*
|
|
32
32
|
* You can use this class if you want to create your own config implementation (e.g. `yml`, `xml`,...)!
|
|
33
33
|
*/
|
|
34
|
-
export declare class ODConfig<Data extends any> extends ODManagerData {
|
|
34
|
+
export declare abstract class ODConfig<Data extends any> extends ODManagerData {
|
|
35
35
|
/**The name of the file with extension. */
|
|
36
36
|
file: string;
|
|
37
37
|
/**The path to the file relative to the main directory. */
|
|
@@ -78,3 +78,32 @@ export declare class ODJsonConfig<Data extends any> extends ODConfig<Data> {
|
|
|
78
78
|
/**Save the edited config to the filesystem. This is used by the Interactive Setup CLI. It's not recommended to use this while the bot is running. */
|
|
79
79
|
save(): ODPromiseVoid;
|
|
80
80
|
}
|
|
81
|
+
/**## ODJsonCommentsConfig `class`
|
|
82
|
+
* An Open Discord JSONC (`.jsonc`) config.
|
|
83
|
+
* Use this class to get & edit variables from the config files or to create your own JSON config!
|
|
84
|
+
* @example
|
|
85
|
+
* //create a config from: ./config/test.jsonc with the id "some-config"
|
|
86
|
+
* const config = new api.ODJsonCommentsConfig("some-config","test.jsonc")
|
|
87
|
+
*
|
|
88
|
+
* //create a config with custom dir: ./plugins/testplugin/test.jsonc
|
|
89
|
+
* const config = new api.ODJsonCommentsConfig("plugin-config","test.jsonc","./plugins/testplugin/")
|
|
90
|
+
*/
|
|
91
|
+
export declare class ODJsonCommentsConfig<Data extends any> extends ODConfig<Data> {
|
|
92
|
+
formatter: fjs.custom.BaseFormatter;
|
|
93
|
+
constructor(id: ODValidId, file: string, customPath?: string, formatter?: fjs.custom.BaseFormatter);
|
|
94
|
+
/**Init the config. */
|
|
95
|
+
init(): ODPromiseVoid;
|
|
96
|
+
/**Reload the config. Be aware that this doesn't update the config data everywhere in the bot! */
|
|
97
|
+
reload(): void;
|
|
98
|
+
/**Save the edited config to the filesystem. This is used by the Interactive Setup CLI. It's not recommended to use this while the bot is running. */
|
|
99
|
+
save(): ODPromiseVoid;
|
|
100
|
+
}
|
|
101
|
+
/**## ODMemoryConfig `class`
|
|
102
|
+
* An Open Discord memory config.
|
|
103
|
+
* This config lives in-memory and does not have any connection to the filesystem.
|
|
104
|
+
*
|
|
105
|
+
* It is perfect for temporary configs or using the `ODChecker` without a real config file.
|
|
106
|
+
*/
|
|
107
|
+
export declare class ODMemoryConfig<Data extends any> extends ODConfig<Data> {
|
|
108
|
+
constructor(id: ODValidId, data: Data);
|
|
109
|
+
}
|
|
@@ -5,6 +5,7 @@ import { ODManager, ODManagerData, ODSystemError } from "./base.js";
|
|
|
5
5
|
import nodepath from "path";
|
|
6
6
|
import fs from "fs";
|
|
7
7
|
import * as fjs from "formatted-json-stringify";
|
|
8
|
+
import { jsonc } from "jsonc";
|
|
8
9
|
/**## ODConfigManager `class`
|
|
9
10
|
* This is an Open Discord config manager.
|
|
10
11
|
*
|
|
@@ -171,3 +172,83 @@ export class ODJsonConfig extends ODConfig {
|
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
}
|
|
175
|
+
/**## ODJsonCommentsConfig `class`
|
|
176
|
+
* An Open Discord JSONC (`.jsonc`) config.
|
|
177
|
+
* Use this class to get & edit variables from the config files or to create your own JSON config!
|
|
178
|
+
* @example
|
|
179
|
+
* //create a config from: ./config/test.jsonc with the id "some-config"
|
|
180
|
+
* const config = new api.ODJsonCommentsConfig("some-config","test.jsonc")
|
|
181
|
+
*
|
|
182
|
+
* //create a config with custom dir: ./plugins/testplugin/test.jsonc
|
|
183
|
+
* const config = new api.ODJsonCommentsConfig("plugin-config","test.jsonc","./plugins/testplugin/")
|
|
184
|
+
*/
|
|
185
|
+
export class ODJsonCommentsConfig extends ODConfig {
|
|
186
|
+
formatter;
|
|
187
|
+
constructor(id, file, customPath, formatter) {
|
|
188
|
+
super(id, {});
|
|
189
|
+
this.file = (file.endsWith(".jsonc")) ? file : file + ".jsonc";
|
|
190
|
+
this.path = customPath ? nodepath.join("./", customPath, this.file) : nodepath.join("./config/", this.file);
|
|
191
|
+
this.formatter = formatter ?? new fjs.DefaultFormatter(null, true, " ");
|
|
192
|
+
}
|
|
193
|
+
/**Init the config. */
|
|
194
|
+
init() {
|
|
195
|
+
if (!fs.existsSync(this.path))
|
|
196
|
+
throw new ODSystemError("Unable to parse JSONC config \"" + nodepath.join("./", this.path) + "\", the file doesn't exist!");
|
|
197
|
+
try {
|
|
198
|
+
this.data = jsonc.parse(fs.readFileSync(this.path).toString());
|
|
199
|
+
super.init();
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
process.emit("uncaughtException", err);
|
|
203
|
+
throw new ODSystemError("Unable to parse JSONC config \"" + nodepath.join("./", this.path) + "\"!");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**Reload the config. Be aware that this doesn't update the config data everywhere in the bot! */
|
|
207
|
+
reload() {
|
|
208
|
+
if (!this.initiated)
|
|
209
|
+
throw new ODSystemError("Unable to reload JSONC config \"" + nodepath.join("./", this.path) + "\", the file hasn't been initiated yet!");
|
|
210
|
+
if (!fs.existsSync(this.path))
|
|
211
|
+
throw new ODSystemError("Unable to JSONC reload config \"" + nodepath.join("./", this.path) + "\", the file doesn't exist!");
|
|
212
|
+
try {
|
|
213
|
+
this.data = jsonc.parse(fs.readFileSync(this.path).toString());
|
|
214
|
+
super.reload();
|
|
215
|
+
this.reloadListeners.forEach((cb) => {
|
|
216
|
+
try {
|
|
217
|
+
cb();
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
process.emit("uncaughtException", err);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
process.emit("uncaughtException", err);
|
|
226
|
+
throw new ODSystemError("Unable to reload JSONC config \"" + nodepath.join("./", this.path) + "\"!");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**Save the edited config to the filesystem. This is used by the Interactive Setup CLI. It's not recommended to use this while the bot is running. */
|
|
230
|
+
save() {
|
|
231
|
+
if (!this.initiated)
|
|
232
|
+
throw new ODSystemError("Unable to save JSONC config \"" + nodepath.join("./", this.path) + "\", the file hasn't been initiated yet!");
|
|
233
|
+
try {
|
|
234
|
+
const contents = this.formatter.stringify(this.data);
|
|
235
|
+
fs.writeFileSync(this.path, contents);
|
|
236
|
+
super.save();
|
|
237
|
+
}
|
|
238
|
+
catch (err) {
|
|
239
|
+
process.emit("uncaughtException", err);
|
|
240
|
+
throw new ODSystemError("Unable to save JSONC config \"" + nodepath.join("./", this.path) + "\"!");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**## ODMemoryConfig `class`
|
|
245
|
+
* An Open Discord memory config.
|
|
246
|
+
* This config lives in-memory and does not have any connection to the filesystem.
|
|
247
|
+
*
|
|
248
|
+
* It is perfect for temporary configs or using the `ODChecker` without a real config file.
|
|
249
|
+
*/
|
|
250
|
+
export class ODMemoryConfig extends ODConfig {
|
|
251
|
+
constructor(id, data) {
|
|
252
|
+
super(id, data);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -42,19 +42,19 @@ export declare class ODCooldownData<Data extends object> extends ODManagerData {
|
|
|
42
42
|
*
|
|
43
43
|
* There are also premade cooldowns available in the bot!
|
|
44
44
|
*/
|
|
45
|
-
export declare class ODCooldown<Data extends object> extends ODManagerData {
|
|
45
|
+
export declare abstract class ODCooldown<Data extends object> extends ODManagerData {
|
|
46
46
|
data: ODManager<ODCooldownData<Data>>;
|
|
47
47
|
/**Is this cooldown already initialized? */
|
|
48
48
|
ready: boolean;
|
|
49
49
|
constructor(id: ODValidId);
|
|
50
50
|
/**Check this id and start cooldown when it exeeds the limit! Returns `true` when on cooldown! */
|
|
51
|
-
use(id: string): boolean;
|
|
51
|
+
abstract use(id: string): boolean;
|
|
52
52
|
/**Check this id without starting or updating the cooldown. Returns `true` when on cooldown! */
|
|
53
|
-
check(id: string): boolean;
|
|
53
|
+
abstract check(id: string): boolean;
|
|
54
54
|
/**Remove the cooldown for an id when available.*/
|
|
55
|
-
delete(id: string): void;
|
|
55
|
+
abstract delete(id: string): void;
|
|
56
56
|
/**Initialize the internal systems of this cooldown. */
|
|
57
|
-
init(): Promise<void
|
|
57
|
+
abstract init(): Promise<void> | void;
|
|
58
58
|
}
|
|
59
59
|
/**## ODCounterCooldown `class`
|
|
60
60
|
* This is an Open Discord counter cooldown.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
///////////////////////////////////////
|
|
2
2
|
//COOLDOWN MODULE
|
|
3
3
|
///////////////////////////////////////
|
|
4
|
-
import { ODManager,
|
|
4
|
+
import { ODManager, ODManagerData } from "./base.js";
|
|
5
5
|
/**## ODCooldownManager `class`
|
|
6
6
|
* This is an Open Discord cooldown manager.
|
|
7
7
|
*
|
|
@@ -60,22 +60,6 @@ export class ODCooldown extends ODManagerData {
|
|
|
60
60
|
constructor(id) {
|
|
61
61
|
super(id);
|
|
62
62
|
}
|
|
63
|
-
/**Check this id and start cooldown when it exeeds the limit! Returns `true` when on cooldown! */
|
|
64
|
-
use(id) {
|
|
65
|
-
throw new ODSystemError("Tried to use an unimplemented ODCooldown!");
|
|
66
|
-
}
|
|
67
|
-
/**Check this id without starting or updating the cooldown. Returns `true` when on cooldown! */
|
|
68
|
-
check(id) {
|
|
69
|
-
throw new ODSystemError("Tried to use an unimplemented ODCooldown!");
|
|
70
|
-
}
|
|
71
|
-
/**Remove the cooldown for an id when available.*/
|
|
72
|
-
delete(id) {
|
|
73
|
-
throw new ODSystemError("Tried to use an unimplemented ODCooldown!");
|
|
74
|
-
}
|
|
75
|
-
/**Initialize the internal systems of this cooldown. */
|
|
76
|
-
async init() {
|
|
77
|
-
throw new ODSystemError("Tried to use an unimplemented ODCooldown!");
|
|
78
|
-
}
|
|
79
63
|
}
|
|
80
64
|
/**## ODCounterCooldown `class`
|
|
81
65
|
* This is an Open Discord counter cooldown.
|
|
@@ -33,36 +33,44 @@ export type ODDatabaseIdConstraint = Record<string, ODValidJsonType>;
|
|
|
33
33
|
*
|
|
34
34
|
* You can use this class if you want to create your own database implementation (e.g. `mongodb`, `mysql`,...)!
|
|
35
35
|
*/
|
|
36
|
-
export declare class ODDatabase<IdList extends ODDatabaseIdConstraint = ODDatabaseIdConstraint> extends ODManagerData {
|
|
36
|
+
export declare abstract class ODDatabase<IdList extends ODDatabaseIdConstraint = ODDatabaseIdConstraint> extends ODManagerData {
|
|
37
37
|
/**The name of the file with extension. */
|
|
38
38
|
file: string;
|
|
39
39
|
/**The path to the file relative to the main directory. */
|
|
40
40
|
path: string;
|
|
41
41
|
/**Init the database. */
|
|
42
|
-
init(): ODPromiseVoid;
|
|
42
|
+
abstract init(): ODPromiseVoid;
|
|
43
43
|
/**Add/Overwrite a specific category & key in the database. Returns `true` when overwritten. */
|
|
44
|
-
set<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId, key: string, value: IdList[CategoryId]): ODOptionalPromise<boolean>;
|
|
45
|
-
set(category: string, key: string, value: ODValidJsonType): ODOptionalPromise<boolean>;
|
|
44
|
+
abstract set<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId, key: string, value: IdList[CategoryId]): ODOptionalPromise<boolean>;
|
|
45
|
+
abstract set(category: string, key: string, value: ODValidJsonType): ODOptionalPromise<boolean>;
|
|
46
|
+
abstract set(category: string, key: string, value: ODValidJsonType): ODOptionalPromise<boolean>;
|
|
46
47
|
/**Get a specific category & key in the database */
|
|
47
|
-
get<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId, key: string): ODOptionalPromise<IdList[CategoryId] | undefined>;
|
|
48
|
-
get(category: string, key: string): ODOptionalPromise<ODValidJsonType | undefined>;
|
|
48
|
+
abstract get<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId, key: string): ODOptionalPromise<IdList[CategoryId] | undefined>;
|
|
49
|
+
abstract get(category: string, key: string): ODOptionalPromise<ODValidJsonType | undefined>;
|
|
50
|
+
abstract get(category: string, key: string): ODOptionalPromise<ODValidJsonType | undefined>;
|
|
49
51
|
/**Delete a specific category & key in the database */
|
|
50
|
-
delete<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId, key: string): ODOptionalPromise<boolean>;
|
|
51
|
-
delete(category: string, key: string): ODOptionalPromise<boolean>;
|
|
52
|
+
abstract delete<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId, key: string): ODOptionalPromise<boolean>;
|
|
53
|
+
abstract delete(category: string, key: string): ODOptionalPromise<boolean>;
|
|
54
|
+
abstract delete(category: string, key: string): ODOptionalPromise<boolean>;
|
|
52
55
|
/**Check if a specific category & key exists in the database */
|
|
53
|
-
exists(category: keyof ODNoGeneric<IdList>, key: string): ODOptionalPromise<boolean>;
|
|
54
|
-
exists(category: string, key: string): ODOptionalPromise<boolean>;
|
|
56
|
+
abstract exists(category: keyof ODNoGeneric<IdList>, key: string): ODOptionalPromise<boolean>;
|
|
57
|
+
abstract exists(category: string, key: string): ODOptionalPromise<boolean>;
|
|
58
|
+
abstract exists(category: string, key: string): ODOptionalPromise<boolean>;
|
|
55
59
|
/**Get a specific category in the database */
|
|
56
|
-
getCategory<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId): ODOptionalPromise<{
|
|
60
|
+
abstract getCategory<CategoryId extends keyof ODNoGeneric<IdList>>(category: CategoryId): ODOptionalPromise<{
|
|
57
61
|
key: string;
|
|
58
62
|
value: IdList[CategoryId];
|
|
59
63
|
}[] | undefined>;
|
|
60
|
-
getCategory(category: string): ODOptionalPromise<{
|
|
64
|
+
abstract getCategory(category: string): ODOptionalPromise<{
|
|
65
|
+
key: string;
|
|
66
|
+
value: ODValidJsonType;
|
|
67
|
+
}[] | undefined>;
|
|
68
|
+
abstract getCategory(category: string): ODOptionalPromise<{
|
|
61
69
|
key: string;
|
|
62
70
|
value: ODValidJsonType;
|
|
63
71
|
}[] | undefined>;
|
|
64
72
|
/**Get all values in the database */
|
|
65
|
-
getAll(): ODOptionalPromise<ODJsonDatabaseStructure>;
|
|
73
|
+
abstract getAll(): ODOptionalPromise<ODJsonDatabaseStructure>;
|
|
66
74
|
}
|
|
67
75
|
/**## ODJsonDatabaseStructure `type`
|
|
68
76
|
* This is the structure of how a JSON database file!
|
|
@@ -47,29 +47,6 @@ export class ODDatabase extends ODManagerData {
|
|
|
47
47
|
file = "";
|
|
48
48
|
/**The path to the file relative to the main directory. */
|
|
49
49
|
path = "";
|
|
50
|
-
/**Init the database. */
|
|
51
|
-
init() {
|
|
52
|
-
//nothing
|
|
53
|
-
}
|
|
54
|
-
set(category, key, value) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
get(category, key) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
delete(category, key) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
exists(category, key) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
getCategory(category) {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
/**Get all values in the database */
|
|
70
|
-
getAll() {
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
50
|
}
|
|
74
51
|
/**## ODJsonDatabase `class`
|
|
75
52
|
* This is an Open Discord JSON database.
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { ODId, ODManager, ODManagerData, ODNoGeneric, ODValidId } from "./base.js";
|
|
2
2
|
import { ODDebugger } from "./console.js";
|
|
3
|
-
/**## ODHelpMenuComponentRenderer `type`
|
|
4
|
-
* This is the callback of the help menu component renderer. It also contains information about how & where it is rendered.
|
|
5
|
-
*/
|
|
6
|
-
export type ODHelpMenuComponentRenderer = (page: number, category: number, location: number, mode: "slash" | "text") => string | Promise<string>;
|
|
7
3
|
/**## ODHelpMenuComponent `class`
|
|
8
4
|
* This is an Open Discord help menu component.
|
|
9
5
|
*
|
|
10
6
|
* It can render something on the Open Discord help menu.
|
|
11
7
|
*/
|
|
12
|
-
export declare class ODHelpMenuComponent extends ODManagerData {
|
|
8
|
+
export declare abstract class ODHelpMenuComponent extends ODManagerData {
|
|
13
9
|
/**The priority of this component. The higher, the earlier it will appear in the help menu. */
|
|
14
10
|
priority: number;
|
|
11
|
+
constructor(id: ODValidId, priority: number);
|
|
15
12
|
/**The render function for this component. */
|
|
16
|
-
render:
|
|
17
|
-
constructor(id: ODValidId, priority: number, render: ODHelpMenuComponentRenderer);
|
|
13
|
+
abstract render(page: number, category: number, location: number, mode: "slash" | "text"): string | Promise<string>;
|
|
18
14
|
}
|
|
19
15
|
/**## ODHelpMenuTextComponent `class`
|
|
20
16
|
* This is an Open Discord help menu text component.
|
|
@@ -22,7 +18,10 @@ export declare class ODHelpMenuComponent extends ODManagerData {
|
|
|
22
18
|
* It can render a static piece of text on the Open Discord help menu.
|
|
23
19
|
*/
|
|
24
20
|
export declare class ODHelpMenuTextComponent extends ODHelpMenuComponent {
|
|
21
|
+
/**The text of this help menu component. */
|
|
22
|
+
text: string;
|
|
25
23
|
constructor(id: ODValidId, priority: number, text: string);
|
|
24
|
+
render(page: number, category: number, location: number, mode: "slash" | "text"): string;
|
|
26
25
|
}
|
|
27
26
|
/**## ODHelpMenuCommandComponentOption `interface`
|
|
28
27
|
* This interface contains a command option for the `ODHelpMenuCommandComponent`.
|
|
@@ -57,7 +56,10 @@ export interface ODHelpMenuCommandComponentSettings {
|
|
|
57
56
|
*/
|
|
58
57
|
export declare class ODHelpMenuCommandComponent extends ODHelpMenuComponent {
|
|
59
58
|
#private;
|
|
59
|
+
/**The settings for this help menu component. */
|
|
60
|
+
settings: ODHelpMenuCommandComponentSettings;
|
|
60
61
|
constructor(id: ODValidId, priority: number, settings: ODHelpMenuCommandComponentSettings);
|
|
62
|
+
render(page: number, category: number, location: number, mode: "slash" | "text"): string;
|
|
61
63
|
}
|
|
62
64
|
/**## ODHelpMenuCategoryIdConstraint `type`
|
|
63
65
|
* The constraint/layout for id mappings/interfaces of the `ODHelpMenuCategory` class.
|
|
@@ -10,12 +10,9 @@ import { ODId, ODManager, ODManagerData, ODSystemError } from "./base.js";
|
|
|
10
10
|
export class ODHelpMenuComponent extends ODManagerData {
|
|
11
11
|
/**The priority of this component. The higher, the earlier it will appear in the help menu. */
|
|
12
12
|
priority;
|
|
13
|
-
|
|
14
|
-
render;
|
|
15
|
-
constructor(id, priority, render) {
|
|
13
|
+
constructor(id, priority) {
|
|
16
14
|
super(id);
|
|
17
15
|
this.priority = priority;
|
|
18
|
-
this.render = render;
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
/**## ODHelpMenuTextComponent `class`
|
|
@@ -24,10 +21,14 @@ export class ODHelpMenuComponent extends ODManagerData {
|
|
|
24
21
|
* It can render a static piece of text on the Open Discord help menu.
|
|
25
22
|
*/
|
|
26
23
|
export class ODHelpMenuTextComponent extends ODHelpMenuComponent {
|
|
24
|
+
/**The text of this help menu component. */
|
|
25
|
+
text;
|
|
27
26
|
constructor(id, priority, text) {
|
|
28
|
-
super(id, priority
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
super(id, priority);
|
|
28
|
+
this.text = text;
|
|
29
|
+
}
|
|
30
|
+
render(page, category, location, mode) {
|
|
31
|
+
return this.text;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
/**## ODHelpMenuCommandComponent `class`
|
|
@@ -36,17 +37,21 @@ export class ODHelpMenuTextComponent extends ODHelpMenuComponent {
|
|
|
36
37
|
* It contains a useful helper to render a command in the Open Discord help menu.
|
|
37
38
|
*/
|
|
38
39
|
export class ODHelpMenuCommandComponent extends ODHelpMenuComponent {
|
|
40
|
+
/**The settings for this help menu component. */
|
|
41
|
+
settings;
|
|
39
42
|
constructor(id, priority, settings) {
|
|
40
|
-
super(id, priority
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
43
|
+
super(id, priority);
|
|
44
|
+
this.settings = settings;
|
|
45
|
+
}
|
|
46
|
+
render(page, category, location, mode) {
|
|
47
|
+
if (mode == "slash" && this.settings.slashName) {
|
|
48
|
+
return `\`${this.settings.slashName}${(this.settings.slashOptions) ? this.#renderOptions(this.settings.slashOptions) : ""}\` ➜ ${this.settings.slashDescription ?? ""}`;
|
|
49
|
+
}
|
|
50
|
+
else if (mode == "text" && this.settings.textName) {
|
|
51
|
+
return `\`${this.settings.textName}${(this.settings.textOptions) ? this.#renderOptions(this.settings.textOptions) : ""}\` ➜ ${this.settings.textDescription ?? ""}`;
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
return "";
|
|
50
55
|
}
|
|
51
56
|
/**Utility function to render all command options. */
|
|
52
57
|
#renderOptions(options) {
|
|
@@ -71,7 +71,7 @@ export declare class ODLanguageManager<IdList extends ODLanguageManagerIdConstra
|
|
|
71
71
|
*
|
|
72
72
|
* JSON languages should be created using the `ODJsonLanguage` class instead!
|
|
73
73
|
*/
|
|
74
|
-
export declare class ODLanguage extends ODManagerData {
|
|
74
|
+
export declare abstract class ODLanguage extends ODManagerData {
|
|
75
75
|
/**The name of the file with extension. */
|
|
76
76
|
file: string;
|
|
77
77
|
/**The path to the file relative to the main directory. */
|
|
@@ -82,7 +82,7 @@ export declare class ODLanguage extends ODManagerData {
|
|
|
82
82
|
metadata: ODLanguageMetadata | null;
|
|
83
83
|
constructor(id: ODValidId, data: any);
|
|
84
84
|
/**Init the language. */
|
|
85
|
-
init(): ODPromiseVoid;
|
|
85
|
+
abstract init(): ODPromiseVoid;
|
|
86
86
|
}
|
|
87
87
|
/**## ODJsonLanguage `class`
|
|
88
88
|
* This is an Open Discord JSON language file.
|
|
@@ -22,9 +22,9 @@ export class ODLanguageManager extends ODManager {
|
|
|
22
22
|
constructor(debug, presets) {
|
|
23
23
|
super(debug, "language");
|
|
24
24
|
if (presets)
|
|
25
|
-
this.add(new
|
|
26
|
-
this.current = presets ? new
|
|
27
|
-
this.backup = presets ? new
|
|
25
|
+
this.add(new ODJsonLanguage("english", "english.json"));
|
|
26
|
+
this.current = presets ? new ODJsonLanguage("english", "english.json") : null;
|
|
27
|
+
this.backup = presets ? new ODJsonLanguage("english", "english.json") : null;
|
|
28
28
|
this.#debug = debug;
|
|
29
29
|
}
|
|
30
30
|
setCurrentLanguage(id) {
|
|
@@ -155,10 +155,6 @@ export class ODLanguage extends ODManagerData {
|
|
|
155
155
|
super(id);
|
|
156
156
|
this.data = data;
|
|
157
157
|
}
|
|
158
|
-
/**Init the language. */
|
|
159
|
-
init() {
|
|
160
|
-
//nothing
|
|
161
|
-
}
|
|
162
158
|
}
|
|
163
159
|
/**## ODJsonLanguage `class`
|
|
164
160
|
* This is an Open Discord JSON language file.
|
|
@@ -59,6 +59,7 @@ export declare class ODProgressBarRenderer<Settings extends {}> extends ODManage
|
|
|
59
59
|
constructor(id: ODValidId, render: ODProgressBarRenderFunc<Settings>, settings: Settings);
|
|
60
60
|
/**Render a progress bar using this renderer. */
|
|
61
61
|
render(min: number, max: number, value: number, prefix: string | null, suffix: string | null): string;
|
|
62
|
+
/**Create a clone of this progress bar renderer, but with additional settings. */
|
|
62
63
|
withAdditionalSettings(settings: Partial<Settings>): ODProgressBarRenderer<Settings>;
|
|
63
64
|
}
|
|
64
65
|
/**## ODProgressBar `class`
|
|
@@ -69,7 +70,7 @@ export declare class ODProgressBarRenderer<Settings extends {}> extends ODManage
|
|
|
69
70
|
*
|
|
70
71
|
* Use other classes as existing templates or create your own progress bar from scratch using this class.
|
|
71
72
|
*/
|
|
72
|
-
export declare class ODProgressBar extends ODManagerData {
|
|
73
|
+
export declare abstract class ODProgressBar extends ODManagerData {
|
|
73
74
|
#private;
|
|
74
75
|
/**The renderer of this progress bar. */
|
|
75
76
|
renderer: ODProgressBarRenderer<{}>;
|
|
@@ -74,13 +74,13 @@ export class ODProgressBarRenderer extends ODManagerData {
|
|
|
74
74
|
return "<PROGRESS-BAR-ERROR>";
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
+
/**Create a clone of this progress bar renderer, but with additional settings. */
|
|
77
78
|
withAdditionalSettings(settings) {
|
|
78
79
|
const newSettings = { ...this.settings };
|
|
79
80
|
for (const key of Object.keys(settings)) {
|
|
80
81
|
if (typeof settings[key] != "undefined")
|
|
81
82
|
newSettings[key] = settings[key];
|
|
82
83
|
}
|
|
83
|
-
const idk = Object.keys(settings);
|
|
84
84
|
return new ODProgressBarRenderer(this.id, this.#render, newSettings);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -11,14 +11,14 @@ import { ODDropdownData, ODMessageBuildResult, ODMessageBuildSentResult, ODModal
|
|
|
11
11
|
*
|
|
12
12
|
* This class can't be used stand-alone & needs to be extended from!
|
|
13
13
|
*/
|
|
14
|
-
export declare class ODResponderImplementation<Instance, Origin extends string, Params, WorkerIds extends string = string> extends ODManagerData {
|
|
14
|
+
export declare abstract class ODResponderImplementation<Instance, Origin extends string, Params, WorkerIds extends string = string> extends ODManagerData {
|
|
15
15
|
/**The manager that has all workers of this implementation */
|
|
16
16
|
workers: ODWorkerManager<Instance, Origin, Params, WorkerIds>;
|
|
17
17
|
/**The `commandName` or `customId` needs to match this string or regex for this responder to be executed. */
|
|
18
18
|
match: string | RegExp;
|
|
19
19
|
constructor(id: ODValidId, match: string | RegExp, callback?: ODWorkerCallback<Instance, Origin, Params>, priority?: number, callbackId?: ODValidId);
|
|
20
20
|
/**Execute all workers & return the result. */
|
|
21
|
-
respond(instance: Instance, origin: Origin, params: Params): Promise<void>;
|
|
21
|
+
abstract respond(instance: Instance, origin: Origin, params: Params): Promise<void>;
|
|
22
22
|
}
|
|
23
23
|
/**## ODResponderTimeoutErrorCallback `type`
|
|
24
24
|
* This is the callback for the responder timeout function. It will be executed when something went wrong or the action takes too much time.
|
|
@@ -24,10 +24,6 @@ export class ODResponderImplementation extends ODManagerData {
|
|
|
24
24
|
if (callback)
|
|
25
25
|
this.workers.add(new ODWorker(callbackId ? callbackId : id, priority ?? 0, callback));
|
|
26
26
|
}
|
|
27
|
-
/**Execute all workers & return the result. */
|
|
28
|
-
async respond(instance, origin, params) {
|
|
29
|
-
throw new ODSystemError("Tried to build an unimplemented ODResponderImplementation");
|
|
30
|
-
}
|
|
31
27
|
}
|
|
32
28
|
/**## ODResponderManager `class`
|
|
33
29
|
* This is an Open Discord responder manager.
|
|
@@ -41,7 +41,7 @@ export type ODSessionTimeoutCallback = (id: string, timeout: "default" | "custom
|
|
|
41
41
|
/**## ODSession `class`
|
|
42
42
|
* This is an Open Discord session.
|
|
43
43
|
*
|
|
44
|
-
* It can be used to create
|
|
44
|
+
* It can be used to create unique user sessions with an ID. Each session can store additional data which isn't saved to the filesystem.
|
|
45
45
|
* You can almost compare it to the PHP session system.
|
|
46
46
|
*/
|
|
47
47
|
export declare class ODSession extends ODManagerData {
|
|
@@ -28,7 +28,7 @@ export class ODSessionManager extends ODManager {
|
|
|
28
28
|
/**## ODSession `class`
|
|
29
29
|
* This is an Open Discord session.
|
|
30
30
|
*
|
|
31
|
-
* It can be used to create
|
|
31
|
+
* It can be used to create unique user sessions with an ID. Each session can store additional data which isn't saved to the filesystem.
|
|
32
32
|
* You can almost compare it to the PHP session system.
|
|
33
33
|
*/
|
|
34
34
|
export class ODSession extends ODManagerData {
|
|
@@ -40,7 +40,7 @@ export declare class ODStartScreenManager<IdList extends ODStartScreenManagerIdC
|
|
|
40
40
|
*
|
|
41
41
|
* It's recommended to use pre-built components except if you really need a custom one.
|
|
42
42
|
*/
|
|
43
|
-
export declare class ODStartScreenComponent extends ODManagerData {
|
|
43
|
+
export declare abstract class ODStartScreenComponent extends ODManagerData {
|
|
44
44
|
/**The priority of this component. */
|
|
45
45
|
priority: number;
|
|
46
46
|
/**An optional render function which will be inserted before the default renderer. */
|
|
@@ -49,7 +49,7 @@ export declare class ODStartScreenComponent extends ODManagerData {
|
|
|
49
49
|
render: ODStartScreenComponentRenderCallback;
|
|
50
50
|
/**An optional render function which will be inserted behind the default renderer. */
|
|
51
51
|
renderAfter: ODStartScreenComponentRenderCallback | null;
|
|
52
|
-
constructor(id: ODValidId, priority: number, render: ODStartScreenComponentRenderCallback);
|
|
52
|
+
constructor(id: ODValidId, priority: number, render: ODStartScreenComponentRenderCallback, renderBefore?: ODStartScreenComponentRenderCallback, renderAfter?: ODStartScreenComponentRenderCallback);
|
|
53
53
|
/**Render this component and combine it with the `renderBefore` & `renderAfter` contents. */
|
|
54
54
|
renderAll(location: number): Promise<string>;
|
|
55
55
|
}
|
|
@@ -68,15 +68,17 @@ export class ODStartScreenComponent extends ODManagerData {
|
|
|
68
68
|
/**The priority of this component. */
|
|
69
69
|
priority;
|
|
70
70
|
/**An optional render function which will be inserted before the default renderer. */
|
|
71
|
-
renderBefore
|
|
71
|
+
renderBefore;
|
|
72
72
|
/**The render function which will render the contents of this component. */
|
|
73
73
|
render;
|
|
74
74
|
/**An optional render function which will be inserted behind the default renderer. */
|
|
75
|
-
renderAfter
|
|
76
|
-
constructor(id, priority, render) {
|
|
75
|
+
renderAfter;
|
|
76
|
+
constructor(id, priority, render, renderBefore, renderAfter) {
|
|
77
77
|
super(id);
|
|
78
78
|
this.priority = priority;
|
|
79
79
|
this.render = render;
|
|
80
|
+
this.renderBefore = renderBefore ?? null;
|
|
81
|
+
this.renderAfter = renderAfter ?? null;
|
|
80
82
|
}
|
|
81
83
|
/**Render this component and combine it with the `renderBefore` & `renderAfter` contents. */
|
|
82
84
|
async renderAll(location) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-discord-bots/framework",
|
|
3
3
|
"author": "DJj123dj",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
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",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"@types/terminal-kit": "^2.5.7",
|
|
17
17
|
"ansis": "^4.2.0",
|
|
18
18
|
"discord.js": "^14.26.3",
|
|
19
|
-
"formatted-json-stringify": "^1.3.
|
|
19
|
+
"formatted-json-stringify": "^1.3.1",
|
|
20
|
+
"jsonc": "^2.0.0",
|
|
20
21
|
"terminal-kit": "^3.1.2",
|
|
21
22
|
"typescript": "^6.0.3"
|
|
22
23
|
},
|
package/src/api/index.ts
CHANGED
|
@@ -2,28 +2,29 @@
|
|
|
2
2
|
export * from "./main.js"
|
|
3
3
|
|
|
4
4
|
//BASE MODULES
|
|
5
|
+
export * from "./modules/action.js"
|
|
5
6
|
export * from "./modules/base.js"
|
|
6
|
-
export * from "./modules/
|
|
7
|
+
export * from "./modules/builder.js"
|
|
8
|
+
export * from "./modules/checker.js"
|
|
9
|
+
export * from "./modules/client.js"
|
|
10
|
+
export * from "./modules/code.js"
|
|
11
|
+
export * from "./modules/component.js"
|
|
7
12
|
export * from "./modules/config.js"
|
|
13
|
+
export * from "./modules/console.js"
|
|
14
|
+
export * from "./modules/cooldown.js"
|
|
8
15
|
export * from "./modules/database.js"
|
|
9
|
-
export * from "./modules/
|
|
16
|
+
export * from "./modules/event.js"
|
|
10
17
|
export * from "./modules/flag.js"
|
|
11
|
-
export * from "./modules/console.js"
|
|
12
18
|
export * from "./modules/fuse.js"
|
|
19
|
+
export * from "./modules/helpmenu.js"
|
|
20
|
+
export * from "./modules/language.js"
|
|
21
|
+
export * from "./modules/permission.js"
|
|
13
22
|
export * from "./modules/plugin.js"
|
|
14
|
-
export * from "./modules/
|
|
15
|
-
export * from "./modules/
|
|
16
|
-
export * from "./modules/worker.js"
|
|
17
|
-
export * from "./modules/builder.js"
|
|
23
|
+
export * from "./modules/post.js"
|
|
24
|
+
export * from "./modules/progressbar.js"
|
|
18
25
|
export * from "./modules/responder.js"
|
|
19
|
-
export * from "./modules/action.js"
|
|
20
|
-
export * from "./modules/permission.js"
|
|
21
|
-
export * from "./modules/helpmenu.js"
|
|
22
26
|
export * from "./modules/session.js"
|
|
27
|
+
export * from "./modules/startscreen.js"
|
|
23
28
|
export * from "./modules/statistic.js"
|
|
24
|
-
export * from "./modules/code.js"
|
|
25
|
-
export * from "./modules/cooldown.js"
|
|
26
|
-
export * from "./modules/post.js"
|
|
27
29
|
export * from "./modules/verifybar.js"
|
|
28
|
-
export * from "./modules/
|
|
29
|
-
export * from "./modules/startscreen.js"
|
|
30
|
+
export * from "./modules/worker.js"
|