dfx 0.44.0 → 0.45.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/Interactions/builder.d.ts +48 -0
- package/Interactions/builder.js +68 -0
- package/Interactions/builder.js.map +1 -0
- package/Interactions/definitions.d.ts +2 -2
- package/Interactions/gateway.d.ts +4 -4
- package/Interactions/gateway.js +19 -15
- package/Interactions/gateway.js.map +1 -1
- package/Interactions/handlers.d.ts +3 -3
- package/Interactions/handlers.js +15 -28
- package/Interactions/handlers.js.map +1 -1
- package/Interactions/index.d.ts +1 -35
- package/Interactions/index.js +1 -57
- package/Interactions/index.js.map +1 -1
- package/Interactions/utils.d.ts +75 -7
- package/Interactions/utils.js +28 -15
- package/Interactions/utils.js.map +1 -1
- package/Interactions/webhook.d.ts +4 -4
- package/Interactions/webhook.js +6 -6
- package/Interactions/webhook.js.map +1 -1
- package/package.json +2 -2
- package/src/Interactions/builder.ts +156 -0
- package/src/Interactions/definitions.ts +2 -2
- package/src/Interactions/gateway.ts +49 -26
- package/src/Interactions/handlers.ts +59 -80
- package/src/Interactions/index.ts +1 -142
- package/src/Interactions/utils.ts +72 -29
- package/src/Interactions/webhook.ts +28 -10
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Chunk, Cause } from "dfx/_common";
|
|
2
|
+
import * as Http from "@effect-http/client";
|
|
3
|
+
import { DiscordREST } from "dfx";
|
|
4
|
+
import { Discord, Effect } from "dfx/_common";
|
|
5
|
+
import * as D from "./definitions.js";
|
|
6
|
+
type ExtractTag<A> = A extends {
|
|
7
|
+
_tag: infer Tag;
|
|
8
|
+
} ? Tag extends string ? Tag : never : never;
|
|
9
|
+
/**
|
|
10
|
+
* @tsplus type dfx/InteractionBuilder
|
|
11
|
+
*/
|
|
12
|
+
export declare class InteractionBuilder<R, E, TE> {
|
|
13
|
+
readonly definitions: Chunk<readonly [
|
|
14
|
+
handler: D.InteractionDefinition<R, E>,
|
|
15
|
+
transform: (self: Effect<any, any, any>) => Effect<R, TE, void>
|
|
16
|
+
]>;
|
|
17
|
+
readonly transform: (self: Effect<any, any, any>) => Effect<R, TE, void>;
|
|
18
|
+
constructor(definitions: Chunk<readonly [
|
|
19
|
+
handler: D.InteractionDefinition<R, E>,
|
|
20
|
+
transform: (self: Effect<any, any, any>) => Effect<R, TE, void>
|
|
21
|
+
]>, transform: (self: Effect<any, any, any>) => Effect<R, TE, void>);
|
|
22
|
+
add<R1, E1>(definition: D.InteractionDefinition<R1, E1>): InteractionBuilder<R | R1, E | E1, TE | E1>;
|
|
23
|
+
concat<R1, E1, TE1>(builder: InteractionBuilder<R1, E1, TE1>): InteractionBuilder<R | R1, E | E1, TE | TE1>;
|
|
24
|
+
private transformTransform;
|
|
25
|
+
private transformHandlers;
|
|
26
|
+
catchAllCause<R1, E1>(f: (cause: Cause<TE>) => Effect<R1, E1, void>): InteractionBuilder<R | R1, E, E1>;
|
|
27
|
+
catchAllCauseRespond<R1, E1>(f: (cause: Cause<E>) => Effect<R1, E1, Discord.InteractionResponse>): InteractionBuilder<R | R1, E1, Exclude<TE, Exclude<E, E1>> | Exclude<E1, E>>;
|
|
28
|
+
catchAll<R1, E1>(f: (error: TE) => Effect<R1, E1, void>): InteractionBuilder<R | R1, E, E1>;
|
|
29
|
+
catchAllRespond<R1, E1>(f: (error: E) => Effect<R1, E1, Discord.InteractionResponse>): InteractionBuilder<R | R1, E1, Exclude<TE, Exclude<E, E1>> | Exclude<E1, E>>;
|
|
30
|
+
catchTag<T extends ExtractTag<E>, R1, E1>(tag: T, f: (error: Extract<TE, {
|
|
31
|
+
_tag: T;
|
|
32
|
+
}>) => Effect<R1, E1, void>): InteractionBuilder<R | R1, E, E1 | Exclude<TE, {
|
|
33
|
+
_tag: T;
|
|
34
|
+
}>>;
|
|
35
|
+
catchTagRespond<T extends ExtractTag<E>, R1, E1>(tag: T, f: (error: Extract<E, {
|
|
36
|
+
_tag: T;
|
|
37
|
+
}>) => Effect<R1, E1, Discord.InteractionResponse>): InteractionBuilder<R | R1, E1 | Exclude<E, {
|
|
38
|
+
_tag: T;
|
|
39
|
+
}>, Exclude<TE, Exclude<E, E1 | Exclude<E, {
|
|
40
|
+
_tag: T;
|
|
41
|
+
}>>> | Exclude<E1, E> | Exclude<Exclude<E, {
|
|
42
|
+
_tag: T;
|
|
43
|
+
}>, E>>;
|
|
44
|
+
get syncGlobal(): Effect<DiscordREST, import("../DiscordREST.js").DiscordRESTError | Http.ResponseDecodeError, import("../DiscordREST/types.js").ResponseWithData<Discord.ApplicationCommand[]>>;
|
|
45
|
+
syncGuild(appId: Discord.Snowflake, guildId: Discord.Snowflake): Effect<DiscordREST, import("../DiscordREST.js").DiscordRESTError, import("../DiscordREST/types.js").ResponseWithData<Discord.ApplicationCommand[]>>;
|
|
46
|
+
}
|
|
47
|
+
export declare const builder: InteractionBuilder<never, never, never>;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "@effect/data/Chunk";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/io/Effect";
|
|
3
|
+
import * as tsplus_module_3 from "@effect/data/Function";
|
|
4
|
+
import * as Http from "@effect-http/client";
|
|
5
|
+
import { catchTag } from "@effect/io/Effect";
|
|
6
|
+
import { DiscordREST } from "dfx";
|
|
7
|
+
/**
|
|
8
|
+
* @tsplus type dfx/InteractionBuilder
|
|
9
|
+
*/
|
|
10
|
+
export class InteractionBuilder {
|
|
11
|
+
definitions;
|
|
12
|
+
transform;
|
|
13
|
+
constructor(definitions, transform) {
|
|
14
|
+
this.definitions = definitions;
|
|
15
|
+
this.transform = transform;
|
|
16
|
+
}
|
|
17
|
+
add(definition) {
|
|
18
|
+
return new InteractionBuilder(tsplus_module_1.append(this.definitions, [definition, this.transform]), this.transform);
|
|
19
|
+
}
|
|
20
|
+
concat(builder) {
|
|
21
|
+
return new InteractionBuilder(tsplus_module_1.concat(this.definitions, builder.definitions), this.transform);
|
|
22
|
+
}
|
|
23
|
+
transformTransform(f) {
|
|
24
|
+
return new InteractionBuilder(tsplus_module_1.map(this.definitions, ([d, t]) => [d, _ => f(t(_))]), _ => f(this.transform(_)));
|
|
25
|
+
}
|
|
26
|
+
transformHandlers(f) {
|
|
27
|
+
return new InteractionBuilder(tsplus_module_1.map(this.definitions, ([d, t]) => [
|
|
28
|
+
{
|
|
29
|
+
...d,
|
|
30
|
+
handle: tsplus_module_2.isEffect(d.handle)
|
|
31
|
+
? f(d.handle)
|
|
32
|
+
: (_) => f(d.handle(_)),
|
|
33
|
+
},
|
|
34
|
+
t,
|
|
35
|
+
]), this.transform);
|
|
36
|
+
}
|
|
37
|
+
catchAllCause(f) {
|
|
38
|
+
return this.transformTransform(_ => tsplus_module_2.catchAllCause(_, f));
|
|
39
|
+
}
|
|
40
|
+
catchAllCauseRespond(f) {
|
|
41
|
+
return this.transformHandlers(_ => tsplus_module_2.catchAllCause(_, f));
|
|
42
|
+
}
|
|
43
|
+
catchAll(f) {
|
|
44
|
+
return this.transformTransform(_ => tsplus_module_2.catchAll(_, f));
|
|
45
|
+
}
|
|
46
|
+
catchAllRespond(f) {
|
|
47
|
+
return this.transformHandlers(_ => tsplus_module_2.catchAll(_, f));
|
|
48
|
+
}
|
|
49
|
+
catchTag(tag, f) {
|
|
50
|
+
return this.transformTransform(_ => catchTag(_, tag, f));
|
|
51
|
+
}
|
|
52
|
+
catchTagRespond(tag, f) {
|
|
53
|
+
return this.transformHandlers(_ => catchTag(_, tag, f));
|
|
54
|
+
}
|
|
55
|
+
get syncGlobal() {
|
|
56
|
+
const commands = tsplus_module_1.map(tsplus_module_1.filter(tsplus_module_1.map(this.definitions, ([d, _]) => d), (c) => c._tag === "GlobalApplicationCommand"), c => c.command);
|
|
57
|
+
return tsplus_module_2.flatMap(DiscordREST, rest => tsplus_module_2.flatMap(tsplus_module_2.flatMap(rest
|
|
58
|
+
.getCurrentBotApplicationInformation(), r => r.json), app => rest.bulkOverwriteGlobalApplicationCommands(app.id, {
|
|
59
|
+
body: Http.body.json(commands),
|
|
60
|
+
})));
|
|
61
|
+
}
|
|
62
|
+
syncGuild(appId, guildId) {
|
|
63
|
+
const commands = tsplus_module_1.map(tsplus_module_1.filter(tsplus_module_1.map(this.definitions, ([d, _]) => d), (c) => c._tag === "GuildApplicationCommand"), c => c.command);
|
|
64
|
+
return tsplus_module_2.flatMap(DiscordREST, rest => rest.bulkOverwriteGuildApplicationCommands(appId, guildId, commands));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export const builder = new InteractionBuilder(tsplus_module_1.empty(), tsplus_module_3.identity);
|
|
68
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/Interactions/builder.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,KAAK,CAAA;AAUjC;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAElB;IAMA;IAPX,YACW,WAKR,EACQ,SAA+D;QAN/D,gBAAW,GAAX,WAAW,CAKnB;QACQ,cAAS,GAAT,SAAS,CAAsD;IACvE,CAAC;IAEJ,GAAG,CAAS,UAA2C;QACrD,OAAO,IAAI,kBAAkB,CAC3B,uBAAA,IAAI,CAAC,WAAW,EAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAU,CAAC,EAC9D,IAAI,CAAC,SAAS,CACf,CAAA;IACH,CAAC;IAED,MAAM,CAAc,OAAwC;QAC1D,OAAO,IAAI,kBAAkB,CAC3B,uBAAA,IAAI,CAAC,WAAW,EAAQ,OAAO,CAAC,WAAW,CAAC,EAC5C,IAAI,CAAC,SAAS,CACf,CAAA;IACH,CAAC;IAEO,kBAAkB,CACxB,CAAsD;QAEtD,OAAO,IAAI,kBAAkB,CAC3B,oBAAA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AAC,CAAC,CAAC,EAEjB,CAAC,CAAC,EAAwC,EAAE,CAC1C,CAAC,CAAC,IAAI,KAAK,yBAAyB,CACvC,EACI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;QAEtB,OAAO,wBAAA,WAAW,EAAS,IAAI,CAAC,EAAE,CAChC,IAAI,CAAC,qCAAqC,CACxC,KAAK,EACL,OAAO,EACP,QAAe,CAChB,CACF,CAAA;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAC3C,uBAAa,EACb,gBAAA,QAAe,CAChB,CAAA"}
|
|
@@ -48,7 +48,7 @@ interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {
|
|
|
48
48
|
type DeepReadonlyObject<T> = {
|
|
49
49
|
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
|
50
50
|
};
|
|
51
|
-
type CommandHandler<R, E, A = any> = Effect<R, E, Discord.InteractionResponse> | CommandHandlerFn<R, E, A>;
|
|
51
|
+
export type CommandHandler<R, E, A = any> = Effect<R, E, Discord.InteractionResponse> | CommandHandlerFn<R, E, A>;
|
|
52
52
|
export interface CommandHelper<A> {
|
|
53
53
|
resolve: <T>(name: AllResolvables<A>["name"], f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => T | undefined) => Effect<Discord.Interaction, ResolvedDataNotFound, T>;
|
|
54
54
|
option: (name: AllCommandOptions<A>["name"]) => Effect<Discord.ApplicationCommandDatum, never, Maybe<Discord.ApplicationCommandInteractionDataOption>>;
|
|
@@ -70,7 +70,7 @@ export interface CommandHelper<A> {
|
|
|
70
70
|
};
|
|
71
71
|
}] ? E : never, Discord.InteractionResponse>;
|
|
72
72
|
}
|
|
73
|
-
type CommandHandlerFn<R, E, A> = (i: CommandHelper<A>) => Effect<R, E, Discord.InteractionResponse>;
|
|
73
|
+
export type CommandHandlerFn<R, E, A> = (i: CommandHelper<A>) => Effect<R, E, Discord.InteractionResponse>;
|
|
74
74
|
interface CommandOption {
|
|
75
75
|
readonly type: any;
|
|
76
76
|
readonly name: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Discord } from "dfx/_common";
|
|
1
|
+
import { Effect, Discord, Cause } from "dfx/_common";
|
|
2
2
|
import * as Http from "@effect-http/client";
|
|
3
3
|
import { DiscordGateway } from "dfx/DiscordGateway";
|
|
4
4
|
import { DiscordREST, DiscordRESTError } from "dfx/DiscordREST";
|
|
@@ -11,10 +11,10 @@ export interface RunOpts {
|
|
|
11
11
|
* @tsplus pipeable dfx/InteractionBuilder runGateway
|
|
12
12
|
* @tsplus location "dfx/Interactions/gateway"
|
|
13
13
|
*/
|
|
14
|
-
export declare const run: <R, R2, E, E2>(postHandler: (effect: import("@effect/io/Effect").Effect<R | DiscordREST | import("../types.js").Interaction,
|
|
14
|
+
export declare const run: <R, R2, E, TE, E2>(postHandler: (effect: import("@effect/io/Effect").Effect<R | DiscordREST | import("../types.js").Interaction, TE | DiscordRESTError | DefinitionNotFound, void>) => import("@effect/io/Effect").Effect<R2, E2, void>, { sync }?: RunOpts) => (ix: InteractionBuilder<R, E, TE>) => import("@effect/io/Effect").Effect<DiscordREST | DiscordGateway | Exclude<R2, import("../types.js").Interaction>, E2 | DiscordRESTError | Http.ResponseDecodeError, never>;
|
|
15
15
|
export interface InteractionsRegistry {
|
|
16
|
-
readonly register: (ix: InteractionBuilder<never, never>) => Effect<never, never, void>;
|
|
17
|
-
readonly run: Effect<DiscordREST | DiscordGateway, DiscordRESTError | Http.ResponseDecodeError, never>;
|
|
16
|
+
readonly register: <E>(ix: InteractionBuilder<never, E, never>) => Effect<never, never, void>;
|
|
17
|
+
readonly run: <R, E>(onError: (_: Cause<DiscordRESTError | DefinitionNotFound>) => Effect<R, E, void>, opts?: RunOpts) => Effect<DiscordREST | DiscordGateway | Exclude<R, Discord.Interaction>, DiscordRESTError | Http.ResponseDecodeError | E, never>;
|
|
18
18
|
}
|
|
19
19
|
export declare const InteractionsRegistry: import("@effect/data/Context").Tag<InteractionsRegistry, InteractionsRegistry>;
|
|
20
20
|
export declare const InteractionsRegistryLive: import("@effect-http/client/_common").Layer<never, never, InteractionsRegistry>;
|
package/Interactions/gateway.js
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
1
|
import * as tsplus_module_1 from "@effect/io/Effect";
|
|
2
|
-
import * as tsplus_module_2 from "@effect/data/
|
|
3
|
-
import * as tsplus_module_3 from "
|
|
4
|
-
import * as tsplus_module_4 from "
|
|
2
|
+
import * as tsplus_module_2 from "@effect/data/Chunk";
|
|
3
|
+
import * as tsplus_module_3 from "dfx/utils/hub";
|
|
4
|
+
import * as tsplus_module_4 from "@effect/io/Ref";
|
|
5
|
+
import * as tsplus_module_5 from "@effect/io/Queue";
|
|
6
|
+
import * as tsplus_module_6 from "dfx/_common";
|
|
5
7
|
import * as Http from "@effect-http/client";
|
|
6
8
|
import { DiscordGateway } from "dfx/DiscordGateway";
|
|
7
9
|
import { DiscordREST } from "dfx/DiscordREST";
|
|
8
10
|
import { handlers } from "./handlers.js";
|
|
9
11
|
import { Interaction, builder } from "./index.js";
|
|
10
|
-
import { splitDefinitions } from "./utils.js";
|
|
11
12
|
/**
|
|
12
13
|
* @tsplus pipeable dfx/InteractionBuilder runGateway
|
|
13
14
|
*/
|
|
14
15
|
const run_1 = (postHandler, { sync = true } = {}) => (ix) => (() => {
|
|
15
|
-
const
|
|
16
|
+
const GlobalApplicationCommand = tsplus_module_2.toReadonlyArray(tsplus_module_2.filter(tsplus_module_2.map(ix.definitions, _ => _[0]), (_) => _._tag === "GlobalApplicationCommand"));
|
|
17
|
+
const GuildApplicationCommand = tsplus_module_2.toReadonlyArray(tsplus_module_2.filter(tsplus_module_2.map(ix.definitions, _ => _[0]), (_) => _._tag === "GuildApplicationCommand"));
|
|
16
18
|
return tsplus_module_1.flatMap(DiscordGateway, gateway => tsplus_module_1.flatMap(DiscordREST, rest => tsplus_module_1.flatMap(tsplus_module_1.flatMap(rest.getCurrentBotApplicationInformation(), a => a.json), application => {
|
|
17
|
-
const globalSync = rest.bulkOverwriteGlobalApplicationCommands(application.id, {
|
|
19
|
+
const globalSync = rest.bulkOverwriteGlobalApplicationCommands(application.id, {
|
|
20
|
+
body: Http.body.json(GlobalApplicationCommand.map(_ => _.command)),
|
|
21
|
+
});
|
|
18
22
|
const guildSync = GuildApplicationCommand.length
|
|
19
|
-
? gateway.handleDispatch("GUILD_CREATE", a => rest.bulkOverwriteGuildApplicationCommands(application.id, a.id, GuildApplicationCommand.map(
|
|
23
|
+
? gateway.handleDispatch("GUILD_CREATE", a => rest.bulkOverwriteGuildApplicationCommands(application.id, a.id, GuildApplicationCommand.map(_ => _.command)))
|
|
20
24
|
: tsplus_module_1.never();
|
|
21
|
-
const handle = handlers(ix.definitions);
|
|
22
|
-
const run = gateway.handleDispatch("INTERACTION_CREATE", i => tsplus_module_1.provideService(
|
|
23
|
-
.transformRespond(handle[i.type](i)), r => rest.createInteractionResponse(i.id, i.token, r)), ix.transform, postHandler), Interaction, i));
|
|
25
|
+
const handle = handlers(ix.definitions, (i, r) => rest.createInteractionResponse(i.id, i.token, r));
|
|
26
|
+
const run = gateway.handleDispatch("INTERACTION_CREATE", i => tsplus_module_1.provideService(postHandler(handle[i.type](i)), Interaction, i));
|
|
24
27
|
return sync ? tsplus_module_1.zipParRight(tsplus_module_1.zipParRight(run, globalSync), guildSync) : run;
|
|
25
28
|
})));
|
|
26
29
|
})();
|
|
27
30
|
export const run = run_1;
|
|
28
|
-
const makeRegistry = tsplus_module_1.
|
|
29
|
-
const register = (ix) =>
|
|
30
|
-
const run =
|
|
31
|
+
const makeRegistry = tsplus_module_1.flatMap(tsplus_module_4.make(builder), ref => tsplus_module_1.map(tsplus_module_5.unbounded(), queue => {
|
|
32
|
+
const register = (ix) => tsplus_module_1.flatMap(tsplus_module_4.updateAndGet(ref, _ => _.concat(ix)), _ => queue.offer(_));
|
|
33
|
+
const run = (onError, opts) => tsplus_module_3.foreverSwitch(queue
|
|
34
|
+
.take(), _ => run_1(_ => tsplus_module_1.catchAllCause(_, onError), opts)(_));
|
|
31
35
|
return { register, run };
|
|
32
|
-
});
|
|
33
|
-
export const InteractionsRegistry =
|
|
36
|
+
}));
|
|
37
|
+
export const InteractionsRegistry = tsplus_module_6.Tag();
|
|
34
38
|
export const InteractionsRegistryLive = tsplus_module_1.toLayer(makeRegistry, InteractionsRegistry);
|
|
35
39
|
//# sourceMappingURL=gateway.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/Interactions/gateway.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/Interactions/gateway.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAoB,MAAM,iBAAiB,CAAA;AAC/D,OAAO,EAAsB,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAsB,OAAO,EAAE,MAAM,YAAY,CAAA;AAUrE;;GAEG;AACI,MAAM,QACX,CACE,WAMyB,EACzB,EAAE,IAAI,GAAG,IAAI,KAAc,EAAE,EAC7B,EAAE,CACJ,CACE,EAAgC,EAKhC,EAAE;IAEA,MAAM,wBAAwB,mCAAG,uBAAA,oBAAA,EAAE,CAAC,WAAW,EACxC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAEb,CAAC,CAAC,EAAuC,EAAE,CACzC,CAAC,CAAC,IAAI,KAAK,0BAA0B,CACxC,CAAgB,CAAA;IACnB,MAAM,uBAAuB,mCAAG,uBAAA,oBAAA,EAAE,CAAC,WAAW,EACvC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAEb,CAAC,CAAC,EAAsC,EAAE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,CAAC,EAAa,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG;;IACxE,CAAA;aAjEO,GAAG;AAmEhB,MAAM,YAAY,2BACF,qBAAS,OAAO,CAAC,EAAzB,GAAG,wBACO,2BAA0D,EAApE,KAAK;IAEX,MAAM,QAAQ,GAAG,CAAI,EAAuC,EAAE,EAAE,CAC9D,wBAAA,6BAAA,GAAG,EAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAS,CAAC,CAAC,EAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAEzE,MAAM,GAAG,GAAG,CACV,OAEuB,EACvB,IAAc,EACd,EAAE,CACF,8BAAA,KAAK;SACF,IAAI,EAAE,EACQ,CAAC,CAAC,EAAE,CAAC,MAAa,CAAC,CAAC,EAAE,CAAC,8BAAA,CAAC,EAAe,OAAO,CAAC,EAAE,IAAI,EAAhD,CAAC,CAAgD,CAAC,CAAA;IAE1E,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAW,CAAA;GACjC,CAAA;AAmBF,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAA,GAAG,EAAwB,CAAA;AAC/D,MAAM,CAAC,MAAM,wBAAwB,GACnC,wBAAA,YAAY,EAAS,oBAAoB,CAAC,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Discord, Effect } from "dfx/_common";
|
|
1
|
+
import { Discord, Effect, Chunk } from "dfx/_common";
|
|
2
2
|
import * as D from "./definitions.js";
|
|
3
3
|
export declare class DefinitionNotFound {
|
|
4
4
|
readonly interaction: Discord.Interaction;
|
|
5
5
|
readonly _tag = "DefinitionNotFound";
|
|
6
6
|
constructor(interaction: Discord.Interaction);
|
|
7
7
|
}
|
|
8
|
-
type Handler<R, E> = Effect<R | Discord.Interaction, E | DefinitionNotFound,
|
|
9
|
-
export declare const handlers: <R, E>(definitions: D.InteractionDefinition<R, E>
|
|
8
|
+
type Handler<R, E, A> = Effect<R | Discord.Interaction, E | DefinitionNotFound, A>;
|
|
9
|
+
export declare const handlers: <R, E, TE, A, B>(definitions: import("../_common.js").Chunk<readonly [handler: D.InteractionDefinition<R, E>, transform: (self: import("@effect/io/Effect").Effect<R, E, A>) => import("@effect/io/Effect").Effect<R, TE, B>]>, handleResponse: (ix: Discord.Interaction, _: Discord.InteractionResponse) => import("@effect/io/Effect").Effect<R, E, A>) => Record<import("../types.js").InteractionType, (i: Discord.Interaction) => Handler<R, E, B>>;
|
|
10
10
|
export {};
|
package/Interactions/handlers.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import * as tsplus_module_1 from "dfx/_common";
|
|
2
2
|
import * as tsplus_module_2 from "@effect/io/Effect";
|
|
3
3
|
import * as tsplus_module_3 from "@effect/data/Option";
|
|
4
|
-
import * as tsplus_module_4 from "@effect/data/Function";
|
|
5
|
-
import * as Arr from "@effect/data/ReadonlyArray";
|
|
6
4
|
import * as IxHelpers from "dfx/Helpers/interactions";
|
|
7
5
|
import * as Ctx from "./context.js";
|
|
8
|
-
import { splitDefinitions } from "./utils.js";
|
|
6
|
+
import { flattenDefinitions, splitDefinitions } from "./utils.js";
|
|
9
7
|
export class DefinitionNotFound {
|
|
10
8
|
interaction;
|
|
11
9
|
_tag = "DefinitionNotFound";
|
|
@@ -13,45 +11,34 @@ export class DefinitionNotFound {
|
|
|
13
11
|
this.interaction = interaction;
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
optionValue: Ctx.optionValue,
|
|
20
|
-
optionValueOptional: Ctx.optionValueOptional,
|
|
21
|
-
subCommands: Ctx.handleSubCommands,
|
|
22
|
-
};
|
|
23
|
-
export const handlers = (definitions) => {
|
|
24
|
-
const { Commands, Autocomplete, MessageComponent, ModalSubmit } = splitDefinitions(definitions);
|
|
14
|
+
export const handlers = (definitions, handleResponse) => {
|
|
15
|
+
const flattened = flattenDefinitions(definitions, handleResponse);
|
|
16
|
+
const { Commands, Autocomplete, MessageComponent, ModalSubmit } = splitDefinitions(flattened);
|
|
25
17
|
return {
|
|
26
18
|
[1 /* Discord.InteractionType.PING */]: () => tsplus_module_2.succeed({
|
|
27
19
|
type: 1 /* Discord.InteractionCallbackType.PONG */,
|
|
28
20
|
}),
|
|
29
21
|
[2 /* Discord.InteractionType.APPLICATION_COMMAND */]: i => {
|
|
30
22
|
const data = i.data;
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
: command.handle(context)), Ctx.ApplicationCommand, data);
|
|
23
|
+
return tsplus_module_3.match(tsplus_module_3.fromNullable(Commands[data.name]), () => tsplus_module_2.fail(new DefinitionNotFound(i)), command => tsplus_module_2.provideService(command
|
|
24
|
+
.handle(i), Ctx.ApplicationCommand, data));
|
|
34
25
|
},
|
|
35
|
-
[5 /* Discord.InteractionType.MODAL_SUBMIT */]:
|
|
26
|
+
[5 /* Discord.InteractionType.MODAL_SUBMIT */]: i => {
|
|
36
27
|
const data = i.data;
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
match: a.predicate(data.custom_id),
|
|
40
|
-
})), _ => tsplus_module_2.provideService(tsplus_module_2.flatMap(tsplus_module_2.allPar(_), _ => tsplus_module_3.match(Arr.findFirst(_, _ => _.match), () => tsplus_module_2.fail(new DefinitionNotFound(i)), a => a.command.handle)), Ctx.ModalSubmitData, data));
|
|
28
|
+
return tsplus_module_2.flatMap(tsplus_module_2.find(ModalSubmit, _ => _.predicate(data.custom_id)), _ => tsplus_module_3.match(_, () => tsplus_module_2.fail(new DefinitionNotFound(i)), match => tsplus_module_2.provideService(match
|
|
29
|
+
.handle(i), Ctx.ModalSubmitData, data)));
|
|
41
30
|
},
|
|
42
31
|
[3 /* Discord.InteractionType.MESSAGE_COMPONENT */]: i => {
|
|
43
32
|
const data = i.data;
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
match: a.predicate(data.custom_id),
|
|
47
|
-
})), _ => tsplus_module_2.provideService(tsplus_module_2.flatMap(tsplus_module_2.allPar(_), commands => tsplus_module_3.match(Arr.findFirst(commands, _ => _.match), () => tsplus_module_2.fail(new DefinitionNotFound(i)), _ => _.command.handle)), Ctx.MessageComponentData, data));
|
|
33
|
+
return tsplus_module_2.flatMap(tsplus_module_2.find(MessageComponent, _ => _.predicate(data.custom_id)), _ => tsplus_module_3.match(_, () => tsplus_module_2.fail(new DefinitionNotFound(i)), match => tsplus_module_2.provideService(match
|
|
34
|
+
.handle(i), Ctx.MessageComponentData, data)));
|
|
48
35
|
},
|
|
49
36
|
[4 /* Discord.InteractionType.APPLICATION_COMMAND_AUTOCOMPLETE */]: i => {
|
|
50
37
|
const data = i.data;
|
|
51
|
-
return tsplus_module_3.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}))
|
|
38
|
+
return tsplus_module_3.match(IxHelpers.focusedOption(data), () => tsplus_module_2.fail(new DefinitionNotFound(i)), focusedOption => tsplus_module_2.flatMap(tsplus_module_2.find(Autocomplete, _ => _.predicate(data, focusedOption)), _ => tsplus_module_3.match(_, () => tsplus_module_2.fail(new DefinitionNotFound(i)), match => tsplus_module_2.provideService(tsplus_module_2.provideService(match
|
|
39
|
+
.handle(i), Ctx.ApplicationCommand, data), Ctx.FocusedOptionContext, {
|
|
40
|
+
focusedOption,
|
|
41
|
+
}))));
|
|
55
42
|
},
|
|
56
43
|
};
|
|
57
44
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/Interactions/handlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/Interactions/handlers.ts"],"names":[],"mappings":";;;AAAA,OAAO,KAAK,SAAS,MAAM,0BAA0B,CAAA;AACrD,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAEjE,MAAM,OAAO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AAA"}
|
package/Interactions/index.d.ts
CHANGED
|
@@ -1,42 +1,8 @@
|
|
|
1
|
-
import { Cause } from "dfx/_common";
|
|
2
|
-
import * as Http from "@effect-http/client";
|
|
3
|
-
import { DiscordREST } from "dfx";
|
|
4
1
|
import { Discord, Effect } from "dfx/_common";
|
|
5
|
-
import * as D from "./definitions.js";
|
|
6
2
|
export { response } from "../Helpers/interactions.js";
|
|
3
|
+
export * from "./builder.js";
|
|
7
4
|
export * from "./context.js";
|
|
8
5
|
export { InteractionDefinition, autocomplete, global, guild, messageComponent, modalSubmit, } from "./definitions.js";
|
|
9
|
-
type ExtractTag<A> = A extends {
|
|
10
|
-
_tag: infer Tag;
|
|
11
|
-
} ? Tag extends string ? Tag : never : never;
|
|
12
|
-
/**
|
|
13
|
-
* @tsplus type dfx/InteractionBuilder
|
|
14
|
-
*/
|
|
15
|
-
export declare class InteractionBuilder<R, E> {
|
|
16
|
-
readonly definitions: D.InteractionDefinition<R, E>[];
|
|
17
|
-
readonly transform: (self: Effect<any, any, any>) => Effect<R, E, void>;
|
|
18
|
-
readonly transformRespond: (self: Effect<any, any, Discord.InteractionResponse>) => Effect<R, E, Discord.InteractionResponse>;
|
|
19
|
-
constructor(definitions: D.InteractionDefinition<R, E>[], transform: (self: Effect<any, any, any>) => Effect<R, E, void>, transformRespond: (self: Effect<any, any, Discord.InteractionResponse>) => Effect<R, E, Discord.InteractionResponse>);
|
|
20
|
-
add<R1, E1>(definition: D.InteractionDefinition<R1, E1>): InteractionBuilder<R | R1, E | E1>;
|
|
21
|
-
concat<R1, E1>(builder: InteractionBuilder<R1, E1>): InteractionBuilder<R | R1, E | E1>;
|
|
22
|
-
catchAllCause<R1, E1>(f: (cause: Cause<E>) => Effect<R1, E1, void>): InteractionBuilder<R | R1, E1>;
|
|
23
|
-
catchAllCauseRespond<R1, E1>(f: (cause: Cause<E>) => Effect<R1, E1, Discord.InteractionResponse>): InteractionBuilder<R | R1, E1>;
|
|
24
|
-
catchAll<R1, E1>(f: (error: E) => Effect<R1, E1, void>): InteractionBuilder<R | R1, E1>;
|
|
25
|
-
catchAllRespond<R1, E1>(f: (error: E) => Effect<R1, E1, Discord.InteractionResponse>): InteractionBuilder<R | R1, E1>;
|
|
26
|
-
catchTag<T extends ExtractTag<E>, R1, E1>(tag: T, f: (error: Extract<E, {
|
|
27
|
-
_tag: T;
|
|
28
|
-
}>) => Effect<R1, E1, void>): InteractionBuilder<R | R1, E1 | Exclude<E, {
|
|
29
|
-
_tag: T;
|
|
30
|
-
}>>;
|
|
31
|
-
catchTagRespond<T extends ExtractTag<E>, R1, E1>(tag: T, f: (error: Extract<E, {
|
|
32
|
-
_tag: T;
|
|
33
|
-
}>) => Effect<R1, E1, Discord.InteractionResponse>): InteractionBuilder<R | R1, E1 | Exclude<E, {
|
|
34
|
-
_tag: T;
|
|
35
|
-
}>>;
|
|
36
|
-
get syncGlobal(): Effect<DiscordREST, import("../DiscordREST.js").DiscordRESTError | Http.ResponseDecodeError, import("../DiscordREST/types.js").ResponseWithData<Discord.ApplicationCommand[]>>;
|
|
37
|
-
syncGuild(appId: Discord.Snowflake, guildId: Discord.Snowflake): Effect<DiscordREST, import("../DiscordREST.js").DiscordRESTError, import("../DiscordREST/types.js").ResponseWithData<Discord.ApplicationCommand[]>>;
|
|
38
|
-
}
|
|
39
|
-
export declare const builder: InteractionBuilder<never, never>;
|
|
40
6
|
export declare const id: (query: string) => (customId: string) => Effect<never, never, boolean>;
|
|
41
7
|
export declare const idStartsWith: (query: string) => (customId: string) => Effect<never, never, boolean>;
|
|
42
8
|
export declare const idRegex: (query: RegExp) => (customId: string) => Effect<never, never, boolean>;
|
package/Interactions/index.js
CHANGED
|
@@ -1,64 +1,8 @@
|
|
|
1
1
|
import * as tsplus_module_1 from "@effect/io/Effect";
|
|
2
|
-
import * as tsplus_module_2 from "@effect/data/Function";
|
|
3
|
-
import * as Http from "@effect-http/client";
|
|
4
|
-
import { catchTag } from "@effect/io/Effect";
|
|
5
|
-
import { DiscordREST } from "dfx";
|
|
6
2
|
export { response } from "../Helpers/interactions.js";
|
|
3
|
+
export * from "./builder.js";
|
|
7
4
|
export * from "./context.js";
|
|
8
5
|
export { autocomplete, global, guild, messageComponent, modalSubmit, } from "./definitions.js";
|
|
9
|
-
/**
|
|
10
|
-
* @tsplus type dfx/InteractionBuilder
|
|
11
|
-
*/
|
|
12
|
-
export class InteractionBuilder {
|
|
13
|
-
definitions;
|
|
14
|
-
transform;
|
|
15
|
-
transformRespond;
|
|
16
|
-
constructor(definitions, transform, transformRespond) {
|
|
17
|
-
this.definitions = definitions;
|
|
18
|
-
this.transform = transform;
|
|
19
|
-
this.transformRespond = transformRespond;
|
|
20
|
-
}
|
|
21
|
-
add(definition) {
|
|
22
|
-
return new InteractionBuilder([...this.definitions, definition], this.transform, this.transformRespond);
|
|
23
|
-
}
|
|
24
|
-
concat(builder) {
|
|
25
|
-
return new InteractionBuilder([...this.definitions, ...builder.definitions], this.transform, this.transformRespond);
|
|
26
|
-
}
|
|
27
|
-
catchAllCause(f) {
|
|
28
|
-
return new InteractionBuilder(this.definitions, _ => tsplus_module_1.catchAllCause(this.transform(_), f), this.transformRespond);
|
|
29
|
-
}
|
|
30
|
-
catchAllCauseRespond(f) {
|
|
31
|
-
return new InteractionBuilder(this.definitions, this.transform, _ => tsplus_module_1.catchAllCause(this.transformRespond(_), f));
|
|
32
|
-
}
|
|
33
|
-
catchAll(f) {
|
|
34
|
-
return new InteractionBuilder(this.definitions, _ => tsplus_module_1.catchAll(this.transform(_), f), this.transformRespond);
|
|
35
|
-
}
|
|
36
|
-
catchAllRespond(f) {
|
|
37
|
-
return new InteractionBuilder(this.definitions, this.transform, _ => tsplus_module_1.catchAll(this.transformRespond(_), f));
|
|
38
|
-
}
|
|
39
|
-
catchTag(tag, f) {
|
|
40
|
-
return new InteractionBuilder(this.definitions, _ => catchTag(this.transform(_), tag, f), this.transformRespond);
|
|
41
|
-
}
|
|
42
|
-
catchTagRespond(tag, f) {
|
|
43
|
-
return new InteractionBuilder(this.definitions, this.transform, _ => catchTag(this.transformRespond(_), tag, f));
|
|
44
|
-
}
|
|
45
|
-
get syncGlobal() {
|
|
46
|
-
const commands = this.definitions
|
|
47
|
-
.filter((c) => c._tag === "GlobalApplicationCommand")
|
|
48
|
-
.map(c => c.command);
|
|
49
|
-
return tsplus_module_1.flatMap(DiscordREST, rest => tsplus_module_1.flatMap(tsplus_module_1.flatMap(rest
|
|
50
|
-
.getCurrentBotApplicationInformation(), r => r.json), app => rest.bulkOverwriteGlobalApplicationCommands(app.id, {
|
|
51
|
-
body: Http.body.json(commands),
|
|
52
|
-
})));
|
|
53
|
-
}
|
|
54
|
-
syncGuild(appId, guildId) {
|
|
55
|
-
const commands = this.definitions
|
|
56
|
-
.filter((c) => c._tag === "GuildApplicationCommand")
|
|
57
|
-
.map(c => c.command);
|
|
58
|
-
return tsplus_module_1.flatMap(DiscordREST, rest => rest.bulkOverwriteGuildApplicationCommands(appId, guildId, commands));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
export const builder = new InteractionBuilder([], tsplus_module_2.identity, tsplus_module_2.identity);
|
|
62
6
|
// Filters
|
|
63
7
|
export const id = (query) => (customId) => tsplus_module_1.succeed(query === customId);
|
|
64
8
|
export const idStartsWith = (query) => (customId) => tsplus_module_1.succeed(customId.startsWith(query));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/Interactions/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/Interactions/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,OAAO,EAEL,YAAY,EACZ,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,WAAW,GACZ,MAAM,kBAAkB,CAAA;AAEzB,UAAU;AACV,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,QAAgB,EAAE,EAAE,CACxD,wBAAe,KAAK,KAAK,QAAQ,CAAC,CAAA;AAEpC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,QAAgB,EAAE,EAAE,CAClE,wBAAe,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;AAE5C,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,QAAgB,EAAE,EAAE,CAC7D,wBAAe,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;AAEtC,MAAM,CAAC,MAAM,MAAM,GACjB,CAAC,OAAe,EAAE,UAAkB,EAAE,EAAE,CACxC,CACE,IAAmD,EACnD,aAGC,EACD,EAAE,CACF,wBAAe,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,aAAa,CAAC,IAAI,KAAK,UAAU,CAAC,CAAA;AAE9E,MAAM,CAAC,MAAM,UAAU,GACrB,CAAC,UAAkB,EAAE,EAAE,CACvB,CACE,CAAU,EACV,aAGC,EACD,EAAE,CACF,wBAAe,aAAa,CAAC,IAAI,KAAK,UAAU,CAAC,CAAA"}
|
package/Interactions/utils.d.ts
CHANGED
|
@@ -1,10 +1,78 @@
|
|
|
1
|
+
import { Discord, Effect, Chunk } from "dfx/_common";
|
|
1
2
|
import * as D from "./definitions.js";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export type DefinitionFlattened<R, E, TE, A> = D.InteractionDefinition<R, E> extends infer D ? {
|
|
4
|
+
[K in keyof D]: K extends "handle" ? (_: Discord.Interaction) => Effect<R, TE, A> : D[K];
|
|
5
|
+
} : never;
|
|
6
|
+
export type DefinitionFlattenedCommand<R, E, TE, A> = Extract<DefinitionFlattened<R, E, TE, A>, {
|
|
7
|
+
_tag: "GlobalApplicationCommand" | "GuildApplicationCommand";
|
|
8
|
+
}>;
|
|
9
|
+
export declare const flattenDefinitions: <R, E, TE, A, B>(definitions: import("../_common.js").Chunk<readonly [handler: D.InteractionDefinition<R, E>, transform: (self: import("@effect/io/Effect").Effect<R, E, A>) => import("@effect/io/Effect").Effect<R, TE, B>]>, handleResponse: (ix: Discord.Interaction, _: Discord.InteractionResponse) => import("@effect/io/Effect").Effect<R, E, A>) => import("../_common.js").Chunk<{
|
|
10
|
+
handle: (i: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, B>;
|
|
11
|
+
_tag: "GlobalApplicationCommand";
|
|
12
|
+
command: import("../types.js").CreateGlobalApplicationCommandParams;
|
|
13
|
+
} | {
|
|
14
|
+
handle: (i: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, B>;
|
|
15
|
+
_tag: "GuildApplicationCommand";
|
|
16
|
+
command: import("../types.js").CreateGuildApplicationCommandParams;
|
|
17
|
+
} | {
|
|
18
|
+
handle: (i: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, B>;
|
|
19
|
+
_tag: "MessageComponent";
|
|
20
|
+
predicate: (customId: string) => import("@effect/io/Effect").Effect<R, E, boolean>;
|
|
21
|
+
} | {
|
|
22
|
+
handle: (i: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, B>;
|
|
23
|
+
_tag: "ModalSubmit";
|
|
24
|
+
predicate: (customId: string) => import("@effect/io/Effect").Effect<R, E, boolean>;
|
|
25
|
+
} | {
|
|
26
|
+
handle: (i: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, B>;
|
|
27
|
+
_tag: "Autocomplete";
|
|
28
|
+
predicate: (data: import("../types.js").ApplicationCommandDatum, focusedOption: import("../types.js").ApplicationCommandInteractionDataOption) => import("@effect/io/Effect").Effect<R, E, boolean>;
|
|
29
|
+
}>;
|
|
30
|
+
export declare const splitDefinitions: <R, E, TE, A>(definitions: import("../_common.js").Chunk<{
|
|
31
|
+
readonly _tag: "GlobalApplicationCommand";
|
|
32
|
+
readonly command: import("../types.js").CreateGlobalApplicationCommandParams;
|
|
33
|
+
readonly handle: (_: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, A>;
|
|
34
|
+
} | {
|
|
35
|
+
readonly _tag: "GuildApplicationCommand";
|
|
36
|
+
readonly command: import("../types.js").CreateGuildApplicationCommandParams;
|
|
37
|
+
readonly handle: (_: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, A>;
|
|
38
|
+
} | {
|
|
39
|
+
readonly _tag: "MessageComponent";
|
|
40
|
+
readonly predicate: (customId: string) => import("@effect/io/Effect").Effect<R, E, boolean>;
|
|
41
|
+
readonly handle: (_: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, A>;
|
|
42
|
+
} | {
|
|
43
|
+
readonly _tag: "ModalSubmit";
|
|
44
|
+
readonly predicate: (customId: string) => import("@effect/io/Effect").Effect<R, E, boolean>;
|
|
45
|
+
readonly handle: (_: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, A>;
|
|
46
|
+
} | {
|
|
47
|
+
readonly _tag: "Autocomplete";
|
|
48
|
+
readonly predicate: (data: import("../types.js").ApplicationCommandDatum, focusedOption: import("../types.js").ApplicationCommandInteractionDataOption) => import("@effect/io/Effect").Effect<R, E, boolean>;
|
|
49
|
+
readonly handle: (_: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, A>;
|
|
50
|
+
}>) => {
|
|
51
|
+
Commands: Record<string, DefinitionFlattenedCommand<R, E, TE, A>>;
|
|
52
|
+
GlobalApplicationCommand: import("../_common.js").Chunk<{
|
|
53
|
+
readonly _tag: "GlobalApplicationCommand";
|
|
54
|
+
readonly command: import("../types.js").CreateGlobalApplicationCommandParams;
|
|
55
|
+
readonly handle: (_: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, A>;
|
|
56
|
+
}>;
|
|
57
|
+
GuildApplicationCommand: import("../_common.js").Chunk<{
|
|
58
|
+
readonly _tag: "GuildApplicationCommand";
|
|
59
|
+
readonly command: import("../types.js").CreateGuildApplicationCommandParams;
|
|
60
|
+
readonly handle: (_: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, A>;
|
|
61
|
+
}>;
|
|
62
|
+
MessageComponent: import("../_common.js").Chunk<{
|
|
63
|
+
readonly _tag: "MessageComponent";
|
|
64
|
+
readonly predicate: (customId: string) => import("@effect/io/Effect").Effect<R, E, boolean>;
|
|
65
|
+
readonly handle: (_: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, A>;
|
|
66
|
+
}>;
|
|
67
|
+
ModalSubmit: import("../_common.js").Chunk<{
|
|
68
|
+
readonly _tag: "ModalSubmit";
|
|
69
|
+
readonly predicate: (customId: string) => import("@effect/io/Effect").Effect<R, E, boolean>;
|
|
70
|
+
readonly handle: (_: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, A>;
|
|
71
|
+
}>;
|
|
72
|
+
Autocomplete: import("../_common.js").Chunk<{
|
|
73
|
+
readonly _tag: "Autocomplete";
|
|
74
|
+
readonly predicate: (data: import("../types.js").ApplicationCommandDatum, focusedOption: import("../types.js").ApplicationCommandInteractionDataOption) => import("@effect/io/Effect").Effect<R, E, boolean>;
|
|
75
|
+
readonly handle: (_: Discord.Interaction) => import("@effect/io/Effect").Effect<R, TE, A>;
|
|
76
|
+
}>;
|
|
9
77
|
};
|
|
10
78
|
export declare function fromHex(hexString: string): Uint8Array;
|
package/Interactions/utils.js
CHANGED
|
@@ -1,21 +1,34 @@
|
|
|
1
|
+
import * as tsplus_module_1 from "@effect/io/Effect";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/data/Chunk";
|
|
3
|
+
import * as Ctx from "./context.js";
|
|
4
|
+
const context = {
|
|
5
|
+
resolve: Ctx.resolved,
|
|
6
|
+
option: Ctx.option,
|
|
7
|
+
optionValue: Ctx.optionValue,
|
|
8
|
+
optionValueOptional: Ctx.optionValueOptional,
|
|
9
|
+
subCommands: Ctx.handleSubCommands,
|
|
10
|
+
};
|
|
11
|
+
export const flattenDefinitions = (definitions, handleResponse) => tsplus_module_2.map(definitions, ([definition, transform]) => ({
|
|
12
|
+
...definition,
|
|
13
|
+
handle: (i) => tsplus_module_1.isEffect(definition.handle)
|
|
14
|
+
? transform(tsplus_module_1.flatMap(definition.handle, _ => handleResponse(i, _)))
|
|
15
|
+
: transform(tsplus_module_1.flatMap(definition.handle(context), _ => handleResponse(i, _))),
|
|
16
|
+
}));
|
|
1
17
|
export const splitDefinitions = (definitions) => {
|
|
2
|
-
const grouped =
|
|
18
|
+
const grouped = tsplus_module_2.reduce(definitions, {
|
|
19
|
+
Autocomplete: tsplus_module_2.empty(),
|
|
20
|
+
GlobalApplicationCommand: tsplus_module_2.empty(),
|
|
21
|
+
GuildApplicationCommand: tsplus_module_2.empty(),
|
|
22
|
+
MessageComponent: tsplus_module_2.empty(),
|
|
23
|
+
ModalSubmit: tsplus_module_2.empty(),
|
|
24
|
+
}, (acc, d) => ({
|
|
3
25
|
...acc,
|
|
4
|
-
[
|
|
5
|
-
})
|
|
6
|
-
|
|
7
|
-
GlobalApplicationCommand: [],
|
|
8
|
-
GuildApplicationCommand: [],
|
|
9
|
-
MessageComponent: [],
|
|
10
|
-
ModalSubmit: [],
|
|
11
|
-
});
|
|
12
|
-
const Commands = [
|
|
13
|
-
...grouped.GlobalApplicationCommand,
|
|
14
|
-
...grouped.GuildApplicationCommand,
|
|
15
|
-
].reduce((acc, a) => ({
|
|
26
|
+
[d._tag]: tsplus_module_2.append(acc[d._tag], d),
|
|
27
|
+
}));
|
|
28
|
+
const Commands = tsplus_module_2.reduce(tsplus_module_2.concat(grouped.GlobalApplicationCommand, grouped.GuildApplicationCommand), {}, (acc, d) => ({
|
|
16
29
|
...acc,
|
|
17
|
-
[
|
|
18
|
-
})
|
|
30
|
+
[d.command.name]: d,
|
|
31
|
+
}));
|
|
19
32
|
return {
|
|
20
33
|
...grouped,
|
|
21
34
|
Commands,
|