@open-discord-bots/framework 0.3.7 → 0.3.9
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/builder.d.ts +2 -0
- package/dist/api/modules/builder.js +8 -0
- package/dist/api/modules/component.d.ts +90 -7
- package/dist/api/modules/component.js +143 -27
- package/dist/api/modules/fuse.d.ts +2 -0
- package/dist/api/modules/fuse.js +1 -0
- package/dist/api/modules/verifybar.d.ts +19 -48
- package/dist/api/modules/verifybar.js +12 -32
- package/dist/api/modules/worker.d.ts +2 -0
- package/dist/api/modules/worker.js +4 -0
- package/package.json +1 -1
- package/src/api/main.ts +1 -1
- package/src/api/modules/builder.ts +8 -0
- package/src/api/modules/component.ts +202 -31
- package/src/api/modules/fuse.ts +3 -0
- package/src/api/modules/verifybar.ts +23 -42
- package/src/api/modules/worker.ts +5 -0
|
@@ -1,68 +1,39 @@
|
|
|
1
1
|
import { ODManager, ODManagerData, ODNoGeneric, ODValidId } from "./base.js";
|
|
2
|
-
import { ODMessage } from "./builder.js";
|
|
3
2
|
import { ODDebugger } from "./console.js";
|
|
4
3
|
import { ODButtonResponderInstance } from "./responder.js";
|
|
5
|
-
import * as discord from "discord.js";
|
|
6
4
|
import { ODWorkerManager } from "./worker.js";
|
|
7
5
|
/**## ODVerifyBar `class`
|
|
8
|
-
* This is an Open Discord verifybar.
|
|
6
|
+
* This is an Open Discord verifybar responder.
|
|
9
7
|
*
|
|
10
|
-
* It
|
|
8
|
+
* It contain `ODWorkerManager`'s that will be fired when the continue/stop (✅ ❌) buttons are pressed.
|
|
11
9
|
*
|
|
12
|
-
*
|
|
10
|
+
* Verifybars don't automatically trigger these workers. The button responders of the verifybars should implement it manually.
|
|
13
11
|
*/
|
|
14
|
-
export declare class ODVerifyBar<
|
|
15
|
-
/**All workers that will run when the verifybar is
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
data: string | null;
|
|
23
|
-
verifybarMessage: discord.Message<boolean> | null;
|
|
24
|
-
}, FailureWorkerIds>;
|
|
25
|
-
/**The message that will be built wen activating this verifybar. */
|
|
26
|
-
message: ODMessage<"verifybar", {
|
|
27
|
-
guild: discord.Guild | null;
|
|
28
|
-
channel: discord.TextBasedChannel;
|
|
29
|
-
user: discord.User;
|
|
30
|
-
verifybar: ODVerifyBar;
|
|
31
|
-
originalMessage: discord.Message<boolean>;
|
|
32
|
-
}>;
|
|
33
|
-
/**When disabled, it will skip the verifybar and instantly fire the `success` workers. */
|
|
34
|
-
enabled: boolean;
|
|
35
|
-
constructor(id: ODValidId, message: ODMessage<"verifybar", {
|
|
36
|
-
guild: discord.Guild | null;
|
|
37
|
-
channel: discord.TextBasedChannel;
|
|
38
|
-
user: discord.User;
|
|
39
|
-
verifybar: ODVerifyBar;
|
|
40
|
-
originalMessage: discord.Message<boolean>;
|
|
41
|
-
}>, enabled?: boolean);
|
|
42
|
-
/**Build the message and reply to a button with this verifybar. */
|
|
43
|
-
activate(responder: ODButtonResponderInstance): Promise<void>;
|
|
12
|
+
export declare class ODVerifyBar<ButtonIds extends string, WorkerIds extends string = string> extends ODManagerData {
|
|
13
|
+
/**All workers that will run when a button in the verifybar is pressed. */
|
|
14
|
+
workers: ODWorkerManager<ODButtonResponderInstance, "verifybar", {
|
|
15
|
+
selectedButtonId: ButtonIds;
|
|
16
|
+
}, WorkerIds>;
|
|
17
|
+
constructor(id: ODValidId);
|
|
18
|
+
/**Activate the verifybar response to this button. */
|
|
19
|
+
activate(responder: ODButtonResponderInstance, selectedButtonId: ButtonIds): Promise<void>;
|
|
44
20
|
}
|
|
45
21
|
/**## ODVerifyBarManagerIdConstraint `type`
|
|
46
22
|
* The constraint/layout for id mappings/interfaces of the `ODVerifyBarManager` class.
|
|
47
23
|
*/
|
|
48
|
-
export type ODVerifyBarManagerIdConstraint = Record<string,
|
|
49
|
-
successWorkerIds: string;
|
|
50
|
-
failureWorkerIds: string;
|
|
51
|
-
}>;
|
|
24
|
+
export type ODVerifyBarManagerIdConstraint = Record<string, ODVerifyBar<string>>;
|
|
52
25
|
/**## ODVerifyBarManager `class`
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* It contains all (✅ ❌) verifybars in the bot.
|
|
26
|
+
* The Open Discord verifybar manager manages all responders for (✅ ❌) verifybars in the bot.
|
|
56
27
|
* The `ODVerifyBar` classes contain `ODWorkerManager`'s that will be fired when the continue/stop buttons are pressed.
|
|
57
28
|
*
|
|
58
|
-
*
|
|
29
|
+
* Verifybars don't automatically trigger these workers. The button responders of the verifybars should implement it manually.
|
|
59
30
|
*/
|
|
60
|
-
export declare class ODVerifyBarManager<IdList extends ODVerifyBarManagerIdConstraint = ODVerifyBarManagerIdConstraint> extends ODManager<ODVerifyBar
|
|
31
|
+
export declare class ODVerifyBarManager<IdList extends ODVerifyBarManagerIdConstraint = ODVerifyBarManagerIdConstraint> extends ODManager<ODVerifyBar<string>> {
|
|
61
32
|
constructor(debug: ODDebugger);
|
|
62
|
-
get<VerifyBarId extends keyof ODNoGeneric<IdList>>(id: VerifyBarId):
|
|
63
|
-
get(id: ODValidId): ODVerifyBar | null;
|
|
64
|
-
remove<VerifyBarId extends keyof ODNoGeneric<IdList>>(id: VerifyBarId):
|
|
65
|
-
remove(id: ODValidId): ODVerifyBar | null;
|
|
33
|
+
get<VerifyBarId extends keyof ODNoGeneric<IdList>>(id: VerifyBarId): IdList[VerifyBarId];
|
|
34
|
+
get(id: ODValidId): ODVerifyBar<string> | null;
|
|
35
|
+
remove<VerifyBarId extends keyof ODNoGeneric<IdList>>(id: VerifyBarId): IdList[VerifyBarId];
|
|
36
|
+
remove(id: ODValidId): ODVerifyBar<string> | null;
|
|
66
37
|
exists(id: keyof ODNoGeneric<IdList>): boolean;
|
|
67
38
|
exists(id: ODValidId): boolean;
|
|
68
39
|
}
|
|
@@ -4,49 +4,29 @@
|
|
|
4
4
|
import { ODManager, ODManagerData } from "./base.js";
|
|
5
5
|
import { ODWorkerManager } from "./worker.js";
|
|
6
6
|
/**## ODVerifyBar `class`
|
|
7
|
-
* This is an Open Discord verifybar.
|
|
7
|
+
* This is an Open Discord verifybar responder.
|
|
8
8
|
*
|
|
9
|
-
* It
|
|
9
|
+
* It contain `ODWorkerManager`'s that will be fired when the continue/stop (✅ ❌) buttons are pressed.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* Verifybars don't automatically trigger these workers. The button responders of the verifybars should implement it manually.
|
|
12
12
|
*/
|
|
13
13
|
export class ODVerifyBar extends ODManagerData {
|
|
14
|
-
/**All workers that will run when the verifybar is
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
failure;
|
|
18
|
-
/**The message that will be built wen activating this verifybar. */
|
|
19
|
-
message;
|
|
20
|
-
/**When disabled, it will skip the verifybar and instantly fire the `success` workers. */
|
|
21
|
-
enabled;
|
|
22
|
-
constructor(id, message, enabled) {
|
|
14
|
+
/**All workers that will run when a button in the verifybar is pressed. */
|
|
15
|
+
workers;
|
|
16
|
+
constructor(id) {
|
|
23
17
|
super(id);
|
|
24
|
-
this.
|
|
25
|
-
this.failure = new ODWorkerManager("descending");
|
|
26
|
-
this.message = message;
|
|
27
|
-
this.enabled = enabled ?? true;
|
|
18
|
+
this.workers = new ODWorkerManager("descending");
|
|
28
19
|
}
|
|
29
|
-
/**
|
|
30
|
-
async activate(responder) {
|
|
31
|
-
|
|
32
|
-
//show verifybar
|
|
33
|
-
const { guild, channel, user, message } = responder;
|
|
34
|
-
await responder.update(await this.message.build("verifybar", { guild, channel, user, verifybar: this, originalMessage: message }));
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
//instant success
|
|
38
|
-
if (this.success)
|
|
39
|
-
await this.success.executeWorkers(responder, "verifybar", { data: null, verifybarMessage: null });
|
|
40
|
-
}
|
|
20
|
+
/**Activate the verifybar response to this button. */
|
|
21
|
+
async activate(responder, selectedButtonId) {
|
|
22
|
+
await this.workers.executeWorkers(responder, "verifybar", { selectedButtonId });
|
|
41
23
|
}
|
|
42
24
|
}
|
|
43
25
|
/**## ODVerifyBarManager `class`
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* It contains all (✅ ❌) verifybars in the bot.
|
|
26
|
+
* The Open Discord verifybar manager manages all responders for (✅ ❌) verifybars in the bot.
|
|
47
27
|
* The `ODVerifyBar` classes contain `ODWorkerManager`'s that will be fired when the continue/stop buttons are pressed.
|
|
48
28
|
*
|
|
49
|
-
*
|
|
29
|
+
* Verifybars don't automatically trigger these workers. The button responders of the verifybars should implement it manually.
|
|
50
30
|
*/
|
|
51
31
|
export class ODVerifyBarManager extends ODManager {
|
|
52
32
|
constructor(debug) {
|
|
@@ -19,6 +19,8 @@ export declare class ODWorker<Instance, Origin extends string, Params> extends O
|
|
|
19
19
|
/**The main callback of this worker */
|
|
20
20
|
callback: ODWorkerCallback<Instance, Origin, Params>;
|
|
21
21
|
constructor(id: ODValidId, priority: number, callback: ODWorkerCallback<Instance, Origin, Params>);
|
|
22
|
+
/**Duplicate this worker. Warning: If the callback accesses external variables (outside parameters), the clone will still use those variables. This might result in unexpected behaviour! */
|
|
23
|
+
duplicate(newId?: ODValidId): ODWorker<Instance, Origin, Params>;
|
|
22
24
|
}
|
|
23
25
|
/**## ODWorker `class`
|
|
24
26
|
* This is an Open Discord worker manager.
|
|
@@ -22,6 +22,10 @@ export class ODWorker extends ODManagerData {
|
|
|
22
22
|
this.priority = priority;
|
|
23
23
|
this.callback = callback;
|
|
24
24
|
}
|
|
25
|
+
/**Duplicate this worker. Warning: If the callback accesses external variables (outside parameters), the clone will still use those variables. This might result in unexpected behaviour! */
|
|
26
|
+
duplicate(newId) {
|
|
27
|
+
return new ODWorker(newId ?? this.id.value, this.priority, this.callback);
|
|
28
|
+
}
|
|
25
29
|
}
|
|
26
30
|
/**## ODWorker `class`
|
|
27
31
|
* This is an Open Discord worker manager.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-discord-bots/framework",
|
|
3
3
|
"author": "DJj123dj",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.9",
|
|
5
5
|
"description": "The core framework of the popular open-source discord bots: Open Ticket & Open Moderation.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
package/src/api/main.ts
CHANGED
|
@@ -154,7 +154,7 @@ export abstract class ODMain implements ODMainManagers {
|
|
|
154
154
|
constructor(managers:ODMainManagers,project:ODProjectType){
|
|
155
155
|
this.project = project
|
|
156
156
|
this.versions = managers.versions
|
|
157
|
-
this.versions.add(ODVersion.fromString("opendiscord:api","v0.3.
|
|
157
|
+
this.versions.add(ODVersion.fromString("opendiscord:api","v0.3.9"))
|
|
158
158
|
this.versions.add(ODVersion.fromString("opendiscord:livestatus","v2.0.0"))
|
|
159
159
|
|
|
160
160
|
this.debugfile = managers.debugfile
|
|
@@ -1469,6 +1469,14 @@ export class ODMessage<Origin extends string,Params,WorkerIds extends string = s
|
|
|
1469
1469
|
this.didCache = true
|
|
1470
1470
|
return result
|
|
1471
1471
|
}
|
|
1472
|
+
/**Duplicate this message. Warning: If workers access external variables (outside parameters), the clone will still use those variables. This might result in unexpected behaviour! */
|
|
1473
|
+
duplicate(newId?:ODValidId): ODMessage<Origin,Params,WorkerIds> {
|
|
1474
|
+
const newMessage = new ODMessage<Origin,Params,WorkerIds>(newId ?? this.id.value)
|
|
1475
|
+
for (const worker of this.workers.getAll()){
|
|
1476
|
+
newMessage.workers.add(worker.duplicate())
|
|
1477
|
+
}
|
|
1478
|
+
return newMessage
|
|
1479
|
+
}
|
|
1472
1480
|
}
|
|
1473
1481
|
|
|
1474
1482
|
/**## ODQuickMessage `class`
|