@open-discord-bots/framework 0.3.0 → 0.3.1
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/main.js +1 -1
- package/dist/api/modules/base.d.ts +27 -9
- package/dist/api/modules/base.js +78 -80
- package/dist/api/modules/builder.d.ts +0 -9
- package/dist/api/modules/checker.d.ts +26 -5
- package/dist/api/modules/checker.js +31 -31
- package/dist/api/modules/client.d.ts +66 -14
- package/dist/api/modules/client.js +146 -132
- package/dist/api/modules/component.d.ts +8 -2
- package/dist/api/modules/component.js +8 -6
- package/dist/api/modules/config.d.ts +0 -1
- package/dist/api/modules/config.js +9 -7
- package/dist/api/modules/console.d.ts +16 -4
- package/dist/api/modules/console.js +25 -25
- package/dist/api/modules/event.d.ts +4 -2
- package/dist/api/modules/event.js +8 -10
- package/dist/api/modules/fuse.d.ts +1 -1
- package/dist/api/modules/helpmenu.d.ts +2 -2
- package/dist/api/modules/helpmenu.js +4 -7
- package/dist/api/modules/language.d.ts +2 -1
- package/dist/api/modules/language.js +6 -9
- package/dist/api/modules/permission.d.ts +10 -1
- package/dist/api/modules/permission.js +17 -20
- package/dist/api/modules/plugin.d.ts +2 -1
- package/dist/api/modules/plugin.js +2 -2
- package/dist/api/modules/post.d.ts +12 -4
- package/dist/api/modules/post.js +36 -10
- package/dist/api/modules/progressbar.d.ts +16 -5
- package/dist/api/modules/progressbar.js +34 -34
- package/dist/api/modules/responder.d.ts +95 -26
- package/dist/api/modules/responder.js +213 -172
- package/dist/api/modules/session.d.ts +10 -1
- package/dist/api/modules/session.js +15 -15
- package/dist/api/modules/startscreen.d.ts +0 -1
- package/dist/api/modules/startscreen.js +3 -6
- package/dist/api/modules/statistic.d.ts +2 -1
- package/dist/api/modules/statistic.js +4 -7
- package/dist/api/modules/worker.d.ts +2 -1
- package/dist/api/modules/worker.js +3 -3
- package/package.json +1 -1
- package/src/api/main.ts +1 -1
- package/src/api/modules/base.ts +75 -77
- package/src/api/modules/builder.ts +0 -10
- package/src/api/modules/checker.ts +31 -31
- package/src/api/modules/client.ts +144 -136
- package/src/api/modules/component.ts +11 -7
- package/src/api/modules/config.ts +8 -6
- package/src/api/modules/console.ts +25 -25
- package/src/api/modules/event.ts +6 -10
- package/src/api/modules/fuse.ts +1 -1
- package/src/api/modules/helpmenu.ts +4 -7
- package/src/api/modules/language.ts +6 -9
- package/src/api/modules/permission.ts +17 -20
- package/src/api/modules/plugin.ts +2 -2
- package/src/api/modules/post.ts +31 -10
- package/src/api/modules/progressbar.ts +34 -34
- package/src/api/modules/responder.ts +232 -181
- package/src/api/modules/session.ts +14 -14
- package/src/api/modules/startscreen.ts +3 -6
- package/src/api/modules/statistic.ts +4 -7
- package/src/api/modules/worker.ts +3 -3
|
@@ -9,7 +9,8 @@ import { ODDebugger } from "./console.js";
|
|
|
9
9
|
* This component can be used in another `ODComponentFactory` or rendered to a message/modal.
|
|
10
10
|
*/
|
|
11
11
|
export declare class ODComponentFactoryInstance<Component extends ODComponent<object, any>> {
|
|
12
|
-
|
|
12
|
+
/**The root component of this factory. */
|
|
13
|
+
private rootComponent;
|
|
13
14
|
/**The root component of this factory. */
|
|
14
15
|
getComponent(): Component | null;
|
|
15
16
|
/**Set the root component of this factory. */
|
|
@@ -161,7 +162,8 @@ export declare abstract class ODGroupComponent<Data extends object, ChildCompone
|
|
|
161
162
|
* `ODParentComponent` classes which represent the new Discord message/modal components.
|
|
162
163
|
*/
|
|
163
164
|
export declare abstract class ODParentComponent<Data extends object, ChildComponent extends ODComponent<object, any>, BuildResult> extends ODComponent<Data, BuildResult> {
|
|
164
|
-
|
|
165
|
+
/**The child component of this parent. */
|
|
166
|
+
private rawChild;
|
|
165
167
|
/**The child component of this parent. */
|
|
166
168
|
get child(): ChildComponent | null;
|
|
167
169
|
/**Set the child component of this parent. */
|
|
@@ -200,6 +202,8 @@ export interface ODMessageComponentBuildResult {
|
|
|
200
202
|
supressEmbeds: boolean;
|
|
201
203
|
/**Do not send notifications to mentioned users or roles. */
|
|
202
204
|
supressNotifications: boolean;
|
|
205
|
+
/**The id of the `ODMessageComponent` this message was built with. */
|
|
206
|
+
id: ODId;
|
|
203
207
|
}
|
|
204
208
|
/**## ODMessageComponent `class`
|
|
205
209
|
* A message builder with **components v2** support.
|
|
@@ -210,6 +214,7 @@ export interface ODMessageComponentBuildResult {
|
|
|
210
214
|
export declare class ODMessageComponent extends ODGroupComponent<ODMessageComponentData, ODValidMessageComponents, ODMessageComponentBuildResult> {
|
|
211
215
|
constructor(id: ODValidId, data?: Partial<ODMessageComponentData>);
|
|
212
216
|
build(): Promise<{
|
|
217
|
+
id: ODId;
|
|
213
218
|
msg: {
|
|
214
219
|
nonce?: string | number;
|
|
215
220
|
forward?: discord.ForwardOptions;
|
|
@@ -262,6 +267,7 @@ export type ODValidSimpleMessageComponents = ODContentComponent | ODEmbedCompone
|
|
|
262
267
|
export declare class ODSimpleMessageComponent extends ODGroupComponent<ODSimpleMessageComponentData, ODValidSimpleMessageComponents, ODMessageComponentBuildResult> {
|
|
263
268
|
constructor(id: ODValidId, data?: Partial<ODMessageComponentData>);
|
|
264
269
|
build(): Promise<{
|
|
270
|
+
id: ODId;
|
|
265
271
|
msg: {
|
|
266
272
|
nonce?: string | number;
|
|
267
273
|
forward?: discord.ForwardOptions;
|
|
@@ -12,14 +12,14 @@ import { ODWorkerManager, ODWorker } from "./worker.js";
|
|
|
12
12
|
*/
|
|
13
13
|
export class ODComponentFactoryInstance {
|
|
14
14
|
/**The root component of this factory. */
|
|
15
|
-
|
|
15
|
+
rootComponent = null;
|
|
16
16
|
/**The root component of this factory. */
|
|
17
17
|
getComponent() {
|
|
18
|
-
return this
|
|
18
|
+
return this.rootComponent;
|
|
19
19
|
}
|
|
20
20
|
/**Set the root component of this factory. */
|
|
21
21
|
setComponent(c) {
|
|
22
|
-
this
|
|
22
|
+
this.rootComponent = c;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
/**## ODComponentFactory `class`
|
|
@@ -218,14 +218,14 @@ export class ODGroupComponent extends ODComponent {
|
|
|
218
218
|
*/
|
|
219
219
|
export class ODParentComponent extends ODComponent {
|
|
220
220
|
/**The child component of this parent. */
|
|
221
|
-
|
|
221
|
+
rawChild = null;
|
|
222
222
|
/**The child component of this parent. */
|
|
223
223
|
get child() {
|
|
224
|
-
return this
|
|
224
|
+
return this.rawChild;
|
|
225
225
|
}
|
|
226
226
|
/**Set the child component of this parent. */
|
|
227
227
|
setComponent(c) {
|
|
228
|
-
this
|
|
228
|
+
this.rawChild = c;
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
/**## ODMessageComponent `class`
|
|
@@ -269,6 +269,7 @@ export class ODMessageComponent extends ODGroupComponent {
|
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
return {
|
|
272
|
+
id: new ODId(this.id),
|
|
272
273
|
msg: {
|
|
273
274
|
components,
|
|
274
275
|
files: attachments,
|
|
@@ -344,6 +345,7 @@ export class ODSimpleMessageComponent extends ODGroupComponent {
|
|
|
344
345
|
}
|
|
345
346
|
}
|
|
346
347
|
return {
|
|
348
|
+
id: new ODId(this.id),
|
|
347
349
|
msg: {
|
|
348
350
|
content,
|
|
349
351
|
embeds,
|
|
@@ -13,7 +13,6 @@ export type ODConfigManagerIdConstraint = Record<string, ODConfig<any>>;
|
|
|
13
13
|
* You can use this class to get/change/add a config file (`ODConfig`) in your plugin!
|
|
14
14
|
*/
|
|
15
15
|
export declare class ODConfigManager<IdList extends ODConfigManagerIdConstraint = ODConfigManagerIdConstraint> extends ODManager<ODConfig<any>> {
|
|
16
|
-
#private;
|
|
17
16
|
constructor(debug: ODDebugger);
|
|
18
17
|
add(data: ODConfig<any> | ODConfig<any>[], overwrite?: boolean): boolean;
|
|
19
18
|
/**Init all config files. */
|
|
@@ -14,17 +14,19 @@ import { jsonc } from "jsonc";
|
|
|
14
14
|
* You can use this class to get/change/add a config file (`ODConfig`) in your plugin!
|
|
15
15
|
*/
|
|
16
16
|
export class ODConfigManager extends ODManager {
|
|
17
|
-
/**Alias to Open Discord debugger. */
|
|
18
|
-
#debug;
|
|
19
17
|
constructor(debug) {
|
|
20
18
|
super(debug, "config");
|
|
21
|
-
this.#debug = debug;
|
|
22
19
|
}
|
|
23
20
|
add(data, overwrite) {
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
if (this.debug) {
|
|
22
|
+
if (Array.isArray(data)) {
|
|
23
|
+
for (const d of data) {
|
|
24
|
+
d.useDebug(this.debug);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
data.useDebug(this.debug);
|
|
29
|
+
}
|
|
28
30
|
return super.add(data, overwrite);
|
|
29
31
|
}
|
|
30
32
|
/**Init all config files. */
|
|
@@ -123,7 +123,6 @@ export type ODConsoleMessageTypes = "info" | "system" | "plugin" | "debug" | "wa
|
|
|
123
123
|
* The debug file (`debug.txt`) is handled in a sub-manager!
|
|
124
124
|
*/
|
|
125
125
|
export declare class ODConsoleManager {
|
|
126
|
-
#private;
|
|
127
126
|
/**The history of `ODConsoleMessage`'s and `ODError`'s since startup */
|
|
128
127
|
history: (ODConsoleMessage | ODError)[];
|
|
129
128
|
/**The max length of the history. The oldest messages will be removed when over the limit */
|
|
@@ -137,6 +136,8 @@ export declare class ODConsoleManager {
|
|
|
137
136
|
log(message: ODConsoleMessage): void;
|
|
138
137
|
log(message: ODError): void;
|
|
139
138
|
log(message: string, type?: ODConsoleMessageTypes, params?: ODConsoleMessageParam[]): void;
|
|
139
|
+
/**Shorten the history when it exceeds the max history length! */
|
|
140
|
+
protected purgeHistory(): void;
|
|
140
141
|
}
|
|
141
142
|
/**## ODDebugFileManager `class`
|
|
142
143
|
* This is the Open Discord debug file manager.
|
|
@@ -147,7 +148,6 @@ export declare class ODConsoleManager {
|
|
|
147
148
|
* Using this class, you can change the max length of this file and some other cool things!
|
|
148
149
|
*/
|
|
149
150
|
export declare class ODDebugFileManager {
|
|
150
|
-
#private;
|
|
151
151
|
/**The path to the debugfile (`./debug.txt` by default) */
|
|
152
152
|
path: string;
|
|
153
153
|
/**The filename of the debugfile (`debug.txt` by default) */
|
|
@@ -157,6 +157,16 @@ export declare class ODDebugFileManager {
|
|
|
157
157
|
/**The max length of the debug file. */
|
|
158
158
|
maxlines: number;
|
|
159
159
|
constructor(path: string, filename: string, maxlines: number, version: ODVersion);
|
|
160
|
+
/**Check if the debug file exists */
|
|
161
|
+
protected existsDebugFile(): boolean;
|
|
162
|
+
/**Read from the debug file */
|
|
163
|
+
protected readDebugFile(): string | false;
|
|
164
|
+
/**Write to the debug file and shorten it when needed. */
|
|
165
|
+
protected writeDebugFile(text: string): void;
|
|
166
|
+
/**Generate the statistics/header of the debug file (containing the version) */
|
|
167
|
+
protected createStatsText(): string;
|
|
168
|
+
/**Write the statistics/header to the debug file on startup */
|
|
169
|
+
protected writeStartupStats(): void;
|
|
160
170
|
/**Write an `ODConsoleMessage` to the debug file */
|
|
161
171
|
writeConsoleMessage(message: ODConsoleMessage): void;
|
|
162
172
|
/**Write an `ODError` to the debug file */
|
|
@@ -289,9 +299,10 @@ export type ODLiveStatusManagerIdConstraint = Record<string, ODLiveStatusSource>
|
|
|
289
299
|
* Access it in the global `opendiscord.startscreen.livestatus` variable!
|
|
290
300
|
*/
|
|
291
301
|
export declare class ODLiveStatusManager<IdList extends ODLiveStatusManagerIdConstraint = ODLiveStatusManagerIdConstraint> extends ODManager<ODLiveStatusSource> {
|
|
292
|
-
#private;
|
|
293
302
|
/**The class responsible for rendering the livestatus messages. */
|
|
294
303
|
renderer: ODLiveStatusRenderer;
|
|
304
|
+
/**A reference to the ODMain or "opendiscord" global variable */
|
|
305
|
+
protected main: ODMain | null;
|
|
295
306
|
constructor(debug: ODDebugger, console: ODConsoleManager);
|
|
296
307
|
/**Get the messages from all sources combined! */
|
|
297
308
|
getAllMessages(): Promise<ODLiveStatusSourceData[]>;
|
|
@@ -310,7 +321,8 @@ export declare class ODLiveStatusManager<IdList extends ODLiveStatusManagerIdCon
|
|
|
310
321
|
* It's responsible for rendering all LiveStatus messages to the console.
|
|
311
322
|
*/
|
|
312
323
|
export declare class ODLiveStatusRenderer {
|
|
313
|
-
|
|
324
|
+
/**A reference to the ODConsoleManager or "opendiscord.console" global variable */
|
|
325
|
+
protected console: ODConsoleManager;
|
|
314
326
|
constructor(console: ODConsoleManager);
|
|
315
327
|
/**Render all messages */
|
|
316
328
|
render(messages: ODLiveStatusSourceData[]): string;
|
|
@@ -252,10 +252,10 @@ export class ODConsoleManager {
|
|
|
252
252
|
this.debugfile.writeConsoleMessage(newMessage);
|
|
253
253
|
this.history.push(newMessage);
|
|
254
254
|
}
|
|
255
|
-
this
|
|
255
|
+
this.purgeHistory();
|
|
256
256
|
}
|
|
257
257
|
/**Shorten the history when it exceeds the max history length! */
|
|
258
|
-
|
|
258
|
+
purgeHistory() {
|
|
259
259
|
if (this.history.length > this.historylength)
|
|
260
260
|
this.history.shift();
|
|
261
261
|
}
|
|
@@ -282,15 +282,15 @@ export class ODDebugFileManager {
|
|
|
282
282
|
this.filename = filename;
|
|
283
283
|
this.version = version;
|
|
284
284
|
this.maxlines = maxlines;
|
|
285
|
-
this
|
|
285
|
+
this.writeStartupStats();
|
|
286
286
|
}
|
|
287
287
|
/**Check if the debug file exists */
|
|
288
|
-
|
|
288
|
+
existsDebugFile() {
|
|
289
289
|
return fs.existsSync(this.path);
|
|
290
290
|
}
|
|
291
291
|
/**Read from the debug file */
|
|
292
|
-
|
|
293
|
-
if (this
|
|
292
|
+
readDebugFile() {
|
|
293
|
+
if (this.existsDebugFile()) {
|
|
294
294
|
try {
|
|
295
295
|
return fs.readFileSync(this.path).toString();
|
|
296
296
|
}
|
|
@@ -303,8 +303,8 @@ export class ODDebugFileManager {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
/**Write to the debug file and shorten it when needed. */
|
|
306
|
-
|
|
307
|
-
const currenttext = this
|
|
306
|
+
writeDebugFile(text) {
|
|
307
|
+
const currenttext = this.readDebugFile();
|
|
308
308
|
if (currenttext) {
|
|
309
309
|
const splitted = currenttext.split("\n");
|
|
310
310
|
if (splitted.length + text.split("\n").length > this.maxlines) {
|
|
@@ -315,12 +315,12 @@ export class ODDebugFileManager {
|
|
|
315
315
|
}
|
|
316
316
|
else {
|
|
317
317
|
//write new file:
|
|
318
|
-
const newtext = this
|
|
318
|
+
const newtext = this.createStatsText() + text;
|
|
319
319
|
fs.writeFileSync(this.path, newtext);
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
/**Generate the statistics/header of the debug file (containing the version) */
|
|
323
|
-
|
|
323
|
+
createStatsText() {
|
|
324
324
|
const date = new Date();
|
|
325
325
|
const dstring = `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
|
|
326
326
|
return [
|
|
@@ -332,8 +332,8 @@ export class ODDebugFileManager {
|
|
|
332
332
|
].join("\n");
|
|
333
333
|
}
|
|
334
334
|
/**Write the statistics/header to the debug file on startup */
|
|
335
|
-
|
|
336
|
-
const currenttext = this
|
|
335
|
+
writeStartupStats() {
|
|
336
|
+
const currenttext = this.readDebugFile();
|
|
337
337
|
if (currenttext) {
|
|
338
338
|
//edit previous file:
|
|
339
339
|
const splitted = currenttext.split("\n");
|
|
@@ -341,31 +341,31 @@ export class ODDebugFileManager {
|
|
|
341
341
|
if (splitted.length + 11 > this.maxlines) {
|
|
342
342
|
splitted.splice(0, ((splitted.length + 11) - this.maxlines));
|
|
343
343
|
}
|
|
344
|
-
splitted.unshift(this
|
|
344
|
+
splitted.unshift(this.createStatsText());
|
|
345
345
|
splitted.push("\n---------------------------------------------------------------------\n---------------------------------------------------------------------\n");
|
|
346
346
|
fs.writeFileSync(this.path, splitted.join("\n"));
|
|
347
347
|
}
|
|
348
348
|
else {
|
|
349
349
|
//write new file:
|
|
350
|
-
const newtext = this
|
|
350
|
+
const newtext = this.createStatsText();
|
|
351
351
|
fs.writeFileSync(this.path, newtext);
|
|
352
352
|
}
|
|
353
353
|
}
|
|
354
354
|
/**Write an `ODConsoleMessage` to the debug file */
|
|
355
355
|
writeConsoleMessage(message) {
|
|
356
|
-
this
|
|
356
|
+
this.writeDebugFile(message.toDebugString());
|
|
357
357
|
}
|
|
358
358
|
/**Write an `ODError` to the debug file */
|
|
359
359
|
writeErrorMessage(error) {
|
|
360
|
-
this
|
|
360
|
+
this.writeDebugFile(error.toDebugString());
|
|
361
361
|
}
|
|
362
362
|
/**Write custom text to the debug file */
|
|
363
363
|
writeText(text) {
|
|
364
|
-
this
|
|
364
|
+
this.writeDebugFile(text);
|
|
365
365
|
}
|
|
366
366
|
/**Write a custom note to the debug file (starting with `[NOTE]:`) */
|
|
367
367
|
writeNote(text) {
|
|
368
|
-
this
|
|
368
|
+
this.writeDebugFile("[NOTE]: " + text);
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
/**## ODDebugger `class`
|
|
@@ -506,19 +506,19 @@ export class ODLiveStatusManager extends ODManager {
|
|
|
506
506
|
/**The class responsible for rendering the livestatus messages. */
|
|
507
507
|
renderer;
|
|
508
508
|
/**A reference to the ODMain or "opendiscord" global variable */
|
|
509
|
-
|
|
509
|
+
main = null;
|
|
510
510
|
constructor(debug, console) {
|
|
511
511
|
super(debug, "livestatus source");
|
|
512
512
|
this.renderer = new ODLiveStatusRenderer(console);
|
|
513
513
|
}
|
|
514
514
|
/**Get the messages from all sources combined! */
|
|
515
515
|
async getAllMessages() {
|
|
516
|
-
if (!this
|
|
516
|
+
if (!this.main)
|
|
517
517
|
throw new ODSystemError("ODLiveStatusManager:getAllMessages() --> Unable to get messages, 'opendiscord/ODMain' has not been connected!");
|
|
518
518
|
const messages = [];
|
|
519
519
|
for (const source of this.getAll()) {
|
|
520
520
|
try {
|
|
521
|
-
messages.push(...(await source.getMessages(this
|
|
521
|
+
messages.push(...(await source.getMessages(this.main)));
|
|
522
522
|
}
|
|
523
523
|
catch { }
|
|
524
524
|
}
|
|
@@ -526,7 +526,7 @@ export class ODLiveStatusManager extends ODManager {
|
|
|
526
526
|
}
|
|
527
527
|
/**Set the opendiscord `ODMain` class to use for fetching message filters. */
|
|
528
528
|
useMain(main) {
|
|
529
|
-
this
|
|
529
|
+
this.main = main;
|
|
530
530
|
}
|
|
531
531
|
get(id) {
|
|
532
532
|
return super.get(id);
|
|
@@ -545,9 +545,9 @@ export class ODLiveStatusManager extends ODManager {
|
|
|
545
545
|
*/
|
|
546
546
|
export class ODLiveStatusRenderer {
|
|
547
547
|
/**A reference to the ODConsoleManager or "opendiscord.console" global variable */
|
|
548
|
-
|
|
548
|
+
console;
|
|
549
549
|
constructor(console) {
|
|
550
|
-
this
|
|
550
|
+
this.console = console;
|
|
551
551
|
}
|
|
552
552
|
/**Render all messages */
|
|
553
553
|
render(messages) {
|
|
@@ -583,7 +583,7 @@ export class ODLiveStatusRenderer {
|
|
|
583
583
|
return final.join("\n");
|
|
584
584
|
}
|
|
585
585
|
catch {
|
|
586
|
-
this
|
|
586
|
+
this.console.log("Failed to render LiveStatus messages!", "error");
|
|
587
587
|
return "";
|
|
588
588
|
}
|
|
589
589
|
}
|
|
@@ -11,7 +11,8 @@ export type ODEventCallback = (...args: any) => ODPromiseVoid;
|
|
|
11
11
|
* The function of this specific class is to manage all listeners for a specifc event!
|
|
12
12
|
*/
|
|
13
13
|
export declare class ODEvent<Callback extends ODEventCallback = ODEventCallback> extends ODManagerData {
|
|
14
|
-
|
|
14
|
+
/**Alias to Open Discord debugger. */
|
|
15
|
+
protected debug?: ODDebugger;
|
|
15
16
|
/**The list of permanent listeners. */
|
|
16
17
|
listeners: Function[];
|
|
17
18
|
/**The list of one-time listeners. List is cleared every time the event is emitted. */
|
|
@@ -20,6 +21,8 @@ export declare class ODEvent<Callback extends ODEventCallback = ODEventCallback>
|
|
|
20
21
|
listenerLimit: number;
|
|
21
22
|
/**Use the Open Discord debugger in this manager for logs*/
|
|
22
23
|
useDebug(debug: ODDebugger | null): void;
|
|
24
|
+
/**Get a collection of listeners combined from both types. Also clears the one-time listeners array! */
|
|
25
|
+
protected getCurrentListeners(): Function[];
|
|
23
26
|
/**Edit the listener limit */
|
|
24
27
|
setListenerLimit(limit: number): void;
|
|
25
28
|
/**Add a permanent callback to this event. This will stay as long as the bot is running! */
|
|
@@ -44,7 +47,6 @@ export type ODEventManagerIdConstraint = Record<string, ODEvent>;
|
|
|
44
47
|
* All events are available in the `opendiscord.events` global!
|
|
45
48
|
*/
|
|
46
49
|
export declare class ODEventManager<IdList extends ODEventManagerIdConstraint = ODEventManagerIdConstraint> extends ODManager<ODEvent> {
|
|
47
|
-
#private;
|
|
48
50
|
constructor(debug: ODDebugger);
|
|
49
51
|
add(data: ODEvent, overwrite?: boolean): boolean;
|
|
50
52
|
get<EventId extends keyof ODNoGeneric<IdList>>(id: EventId): IdList[EventId];
|
|
@@ -11,7 +11,7 @@ import { ODWarningConsoleMessage } from "./console.js";
|
|
|
11
11
|
*/
|
|
12
12
|
export class ODEvent extends ODManagerData {
|
|
13
13
|
/**Alias to Open Discord debugger. */
|
|
14
|
-
|
|
14
|
+
debug;
|
|
15
15
|
/**The list of permanent listeners. */
|
|
16
16
|
listeners = [];
|
|
17
17
|
/**The list of one-time listeners. List is cleared every time the event is emitted. */
|
|
@@ -20,10 +20,10 @@ export class ODEvent extends ODManagerData {
|
|
|
20
20
|
listenerLimit = 25;
|
|
21
21
|
/**Use the Open Discord debugger in this manager for logs*/
|
|
22
22
|
useDebug(debug) {
|
|
23
|
-
this
|
|
23
|
+
this.debug = debug ?? undefined;
|
|
24
24
|
}
|
|
25
25
|
/**Get a collection of listeners combined from both types. Also clears the one-time listeners array! */
|
|
26
|
-
|
|
26
|
+
getCurrentListeners() {
|
|
27
27
|
const final = [];
|
|
28
28
|
this.oncelisteners.forEach((l) => final.push(l));
|
|
29
29
|
this.listeners.forEach((l) => final.push(l));
|
|
@@ -38,8 +38,8 @@ export class ODEvent extends ODManagerData {
|
|
|
38
38
|
listen(callback) {
|
|
39
39
|
this.listeners.push(callback);
|
|
40
40
|
if (this.listeners.length > this.listenerLimit) {
|
|
41
|
-
if (this
|
|
42
|
-
this
|
|
41
|
+
if (this.debug)
|
|
42
|
+
this.debug.console.log(new ODWarningConsoleMessage("Possible event memory leak detected!", [
|
|
43
43
|
{ key: "event", value: this.id.value },
|
|
44
44
|
{ key: "listeners", value: this.listeners.length.toString() }
|
|
45
45
|
]));
|
|
@@ -57,7 +57,7 @@ export class ODEvent extends ODManagerData {
|
|
|
57
57
|
}
|
|
58
58
|
/**Emit this event to all listeners. You are required to provide all parameters of the event! */
|
|
59
59
|
async emit(params) {
|
|
60
|
-
for (const listener of this
|
|
60
|
+
for (const listener of this.getCurrentListeners()) {
|
|
61
61
|
try {
|
|
62
62
|
await listener(...params);
|
|
63
63
|
}
|
|
@@ -76,14 +76,12 @@ export class ODEvent extends ODManagerData {
|
|
|
76
76
|
* All events are available in the `opendiscord.events` global!
|
|
77
77
|
*/
|
|
78
78
|
export class ODEventManager extends ODManager {
|
|
79
|
-
/**Reference to the Open Discord debugger */
|
|
80
|
-
#debug;
|
|
81
79
|
constructor(debug) {
|
|
82
80
|
super(debug, "event");
|
|
83
|
-
this.#debug = debug;
|
|
84
81
|
}
|
|
85
82
|
add(data, overwrite) {
|
|
86
|
-
|
|
83
|
+
if (this.debug)
|
|
84
|
+
data.useDebug(this.debug);
|
|
87
85
|
return super.add(data, overwrite);
|
|
88
86
|
}
|
|
89
87
|
get(id) {
|
|
@@ -36,7 +36,7 @@ export type ODFuseStringArray<FuseList extends object> = {
|
|
|
36
36
|
*/
|
|
37
37
|
export declare class ODFuseManager<FuseList extends object> {
|
|
38
38
|
/**A list of all the defaults */
|
|
39
|
-
|
|
39
|
+
protected fuses: FuseList;
|
|
40
40
|
constructor(fuses: FuseList);
|
|
41
41
|
/**Set a fuse to a specific value. Remember! All plugins can edit these values, so your value could be overwritten! */
|
|
42
42
|
setFuse<DefaultName extends keyof FuseList>(key: DefaultName, value: FuseList[DefaultName]): void;
|
|
@@ -55,11 +55,12 @@ export interface ODHelpMenuCommandComponentSettings {
|
|
|
55
55
|
* It contains a useful helper to render a command in the Open Discord help menu.
|
|
56
56
|
*/
|
|
57
57
|
export declare class ODHelpMenuCommandComponent extends ODHelpMenuComponent {
|
|
58
|
-
#private;
|
|
59
58
|
/**The settings for this help menu component. */
|
|
60
59
|
settings: ODHelpMenuCommandComponentSettings;
|
|
61
60
|
constructor(id: ODValidId, priority: number, settings: ODHelpMenuCommandComponentSettings);
|
|
62
61
|
render(page: number, category: number, location: number, mode: "slash" | "text"): string;
|
|
62
|
+
/**Utility function to render all command options. */
|
|
63
|
+
protected renderOptions(options: ODHelpMenuCommandComponentOption[]): string;
|
|
63
64
|
}
|
|
64
65
|
/**## ODHelpMenuCategoryIdConstraint `type`
|
|
65
66
|
* The constraint/layout for id mappings/interfaces of the `ODHelpMenuCategory` class.
|
|
@@ -112,7 +113,6 @@ export type ODHelpMenuManagerIdConstraint = Record<string, ODHelpMenuCategory>;
|
|
|
112
113
|
* Fewer Categories == More Clean Menu
|
|
113
114
|
*/
|
|
114
115
|
export declare class ODHelpMenuManager<IdList extends ODHelpMenuManagerIdConstraint = ODHelpMenuManagerIdConstraint> extends ODManager<ODHelpMenuCategory> {
|
|
115
|
-
#private;
|
|
116
116
|
/**The amount of categories per-page. */
|
|
117
117
|
categoriesPerPage: number;
|
|
118
118
|
constructor(debug: ODDebugger);
|
|
@@ -45,16 +45,16 @@ export class ODHelpMenuCommandComponent extends ODHelpMenuComponent {
|
|
|
45
45
|
}
|
|
46
46
|
render(page, category, location, mode) {
|
|
47
47
|
if (mode == "slash" && this.settings.slashName) {
|
|
48
|
-
return `\`${this.settings.slashName}${(this.settings.slashOptions) ? this
|
|
48
|
+
return `\`${this.settings.slashName}${(this.settings.slashOptions) ? this.renderOptions(this.settings.slashOptions) : ""}\` ➜ ${this.settings.slashDescription ?? ""}`;
|
|
49
49
|
}
|
|
50
50
|
else if (mode == "text" && this.settings.textName) {
|
|
51
|
-
return `\`${this.settings.textName}${(this.settings.textOptions) ? this
|
|
51
|
+
return `\`${this.settings.textName}${(this.settings.textOptions) ? this.renderOptions(this.settings.textOptions) : ""}\` ➜ ${this.settings.textDescription ?? ""}`;
|
|
52
52
|
}
|
|
53
53
|
else
|
|
54
54
|
return "";
|
|
55
55
|
}
|
|
56
56
|
/**Utility function to render all command options. */
|
|
57
|
-
|
|
57
|
+
renderOptions(options) {
|
|
58
58
|
return " " + options.map((opt) => (opt.optional) ? `[${opt.name}]` : `<${opt.name}>`).join(" ");
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -120,16 +120,13 @@ export class ODHelpMenuCategory extends ODManager {
|
|
|
120
120
|
* Fewer Categories == More Clean Menu
|
|
121
121
|
*/
|
|
122
122
|
export class ODHelpMenuManager extends ODManager {
|
|
123
|
-
/**Alias to Open Discord debugger. */
|
|
124
|
-
#debug;
|
|
125
123
|
/**The amount of categories per-page. */
|
|
126
124
|
categoriesPerPage = 3;
|
|
127
125
|
constructor(debug) {
|
|
128
126
|
super(debug, "help menu category");
|
|
129
|
-
this.#debug = debug;
|
|
130
127
|
}
|
|
131
128
|
add(data, overwrite) {
|
|
132
|
-
data.useDebug(this
|
|
129
|
+
data.useDebug(this.debug, "help menu component");
|
|
133
130
|
return super.add(data, overwrite);
|
|
134
131
|
}
|
|
135
132
|
/**Render this entire help menu & return a `ODHelpMenuRenderResult`. */
|
|
@@ -28,7 +28,6 @@ export type ODLanguageManagerIdConstraint = Record<string, ODLanguage>;
|
|
|
28
28
|
* Add new languages using the `ODlanguage` class in your plugin!
|
|
29
29
|
*/
|
|
30
30
|
export declare class ODLanguageManager<IdList extends ODLanguageManagerIdConstraint = ODLanguageManagerIdConstraint, TranslationIds extends string = string> extends ODManager<ODLanguage> {
|
|
31
|
-
#private;
|
|
32
31
|
/**The currently selected language. */
|
|
33
32
|
current: ODLanguage | null;
|
|
34
33
|
/**The currently selected backup language. (used when translation missing in current language) */
|
|
@@ -51,6 +50,8 @@ export declare class ODLanguageManager<IdList extends ODLanguageManagerIdConstra
|
|
|
51
50
|
/**Get a translation string by JSON location. (e.g. `"checker.system.typeError"`) */
|
|
52
51
|
getTranslation(id: TranslationIds): string;
|
|
53
52
|
getTranslation(id: string): string | null;
|
|
53
|
+
/**Get a backup translation string by JSON location. (system only) */
|
|
54
|
+
protected getBackupTranslation(id: string): string | null;
|
|
54
55
|
/**Get a backup translation string by JSON location and replace `{0}`,`{1}`,`{2}`,... with the provided parameters. */
|
|
55
56
|
getTranslationWithParams(id: TranslationIds, params: string[]): string;
|
|
56
57
|
getTranslationWithParams(id: string, params: string[]): string | null;
|
|
@@ -17,21 +17,18 @@ export class ODLanguageManager extends ODManager {
|
|
|
17
17
|
current = null;
|
|
18
18
|
/**The currently selected backup language. (used when translation missing in current language) */
|
|
19
19
|
backup = null;
|
|
20
|
-
/**An alias to Open Discord debugger. */
|
|
21
|
-
#debug;
|
|
22
20
|
constructor(debug, presets) {
|
|
23
21
|
super(debug, "language");
|
|
24
22
|
if (presets)
|
|
25
23
|
this.add(new ODJsonLanguage("english", "english.json"));
|
|
26
24
|
this.current = presets ? new ODJsonLanguage("english", "english.json") : null;
|
|
27
25
|
this.backup = presets ? new ODJsonLanguage("english", "english.json") : null;
|
|
28
|
-
this.#debug = debug;
|
|
29
26
|
}
|
|
30
27
|
setCurrentLanguage(id) {
|
|
31
28
|
this.current = this.get(id);
|
|
32
29
|
const languageId = this.current?.id.value ?? "<unknown-id>";
|
|
33
30
|
const languageAutomated = this.current?.metadata?.automated.toString() ?? "<unknown-metadata>";
|
|
34
|
-
this
|
|
31
|
+
this.debug?.debug("Selected current language", [
|
|
35
32
|
{ key: "id", value: languageId },
|
|
36
33
|
{ key: "automated", value: languageAutomated },
|
|
37
34
|
]);
|
|
@@ -44,7 +41,7 @@ export class ODLanguageManager extends ODManager {
|
|
|
44
41
|
this.backup = this.get(id);
|
|
45
42
|
const languageId = this.backup?.id.value ?? "<unknown-id>";
|
|
46
43
|
const languageAutomated = this.backup?.metadata?.automated.toString() ?? "<unknown-metadata>";
|
|
47
|
-
this
|
|
44
|
+
this.debug?.debug("Selected backup language", [
|
|
48
45
|
{ key: "id", value: languageId },
|
|
49
46
|
{ key: "automated", value: languageAutomated },
|
|
50
47
|
]);
|
|
@@ -65,7 +62,7 @@ export class ODLanguageManager extends ODManager {
|
|
|
65
62
|
}
|
|
66
63
|
getTranslation(id) {
|
|
67
64
|
if (!this.current)
|
|
68
|
-
return this
|
|
65
|
+
return this.getBackupTranslation(id);
|
|
69
66
|
const splitted = id.split(".");
|
|
70
67
|
let currentObject = this.current.data;
|
|
71
68
|
let result = false;
|
|
@@ -80,10 +77,10 @@ export class ODLanguageManager extends ODManager {
|
|
|
80
77
|
if (typeof result == "string")
|
|
81
78
|
return result;
|
|
82
79
|
else
|
|
83
|
-
return this
|
|
80
|
+
return this.getBackupTranslation(id);
|
|
84
81
|
}
|
|
85
|
-
/**Get a backup
|
|
86
|
-
|
|
82
|
+
/**Get a backup translation string by JSON location. (system only) */
|
|
83
|
+
getBackupTranslation(id) {
|
|
87
84
|
if (!this.backup)
|
|
88
85
|
return null;
|
|
89
86
|
const splitted = id.split(".");
|
|
@@ -108,7 +108,10 @@ export type ODPermissionManagerIdConstraint = Record<string, ODPermission>;
|
|
|
108
108
|
* Add new permissions using the `ODPermission` class in your plugin!
|
|
109
109
|
*/
|
|
110
110
|
export declare class ODPermissionManager<IdList extends ODPermissionManagerIdConstraint = ODPermissionManagerIdConstraint> extends ODManager<ODPermission> {
|
|
111
|
-
|
|
111
|
+
/**The function for calculating permissions in this manager. */
|
|
112
|
+
private calculation;
|
|
113
|
+
/**An alias to the Open Discord client manager. */
|
|
114
|
+
private client;
|
|
112
115
|
/**The result which is returned when no other permissions match. (`member` by default) */
|
|
113
116
|
defaultResult: ODPermissionResult;
|
|
114
117
|
constructor(debug: ODDebugger, client: ODClientManager, useDefaultCalculation?: boolean);
|
|
@@ -120,6 +123,12 @@ export declare class ODPermissionManager<IdList extends ODPermissionManagerIdCon
|
|
|
120
123
|
getPermissions(user: discord.User, channel?: discord.Channel | null, guild?: discord.Guild | null, settings?: ODPermissionSettings | null): Promise<ODPermissionResult>;
|
|
121
124
|
/**Simplifies the `ODPermissionResult` returned from `getPermissions()` and returns a boolean to check if the user matches the required permissions. */
|
|
122
125
|
hasPermissions(minimum: ODPermissionType, data: ODPermissionResult): boolean;
|
|
126
|
+
/**Check for permissions. (default calculation) */
|
|
127
|
+
private defaultCalculation;
|
|
128
|
+
/**Check for global permissions. Result will be compared with the channel perms in `#defaultCalculation()`. */
|
|
129
|
+
private defaultGlobalCalculation;
|
|
130
|
+
/**Check for channel permissions. Result will be compared with the global perms in `#defaultCalculation()`. */
|
|
131
|
+
private defaultChannelCalculation;
|
|
123
132
|
/**Check the permissions for a certain command of the bot. */
|
|
124
133
|
checkCommandPerms(permissionMode: string, requiredLevel: ODPermissionType, user: discord.User, member?: discord.GuildMember | null, channel?: discord.Channel | null, guild?: discord.Guild | null, settings?: ODPermissionSettings): Promise<ODPermissionCommandResult>;
|
|
125
134
|
get<PermissionId extends keyof ODNoGeneric<IdList>>(id: PermissionId): IdList[PermissionId];
|