dfx 0.8.3 → 0.9.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/Interactions/gateway.d.ts.map +1 -1
- package/dist/Interactions/gateway.js +5 -3
- package/dist/Interactions/gateway.js.map +1 -1
- package/dist/Interactions/handlers.js +5 -5
- package/dist/Interactions/handlers.js.map +1 -1
- package/dist/Interactions/index.d.ts +12 -3
- package/dist/Interactions/index.d.ts.map +1 -1
- package/dist/Interactions/index.js +24 -7
- package/dist/Interactions/index.js.map +1 -1
- package/dist/Interactions/utils.d.ts +6 -6
- package/dist/Interactions/utils.d.ts.map +1 -1
- package/dist/Interactions/utils.js +10 -12
- package/dist/Interactions/utils.js.map +1 -1
- package/package.json +8 -4
- package/src/Interactions/gateway.ts +12 -9
- package/src/Interactions/handlers.ts +5 -5
- package/src/Interactions/index.ts +59 -2
- package/src/Interactions/utils.ts +17 -27
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/Interactions/gateway.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAA;AAIrC,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED,eAAO,MAAM,GAAG,2QAKG,OAAO,+
|
|
1
|
+
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/Interactions/gateway.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAA;AAIrC,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED,eAAO,MAAM,GAAG,2QAKG,OAAO,+QAwCtB,CAAA"}
|
|
@@ -4,12 +4,14 @@ import * as tsplus_module_3 from "@fp-ts/data/Option";
|
|
|
4
4
|
import { handlers } from "./handlers.js";
|
|
5
5
|
import { splitDefinitions } from "./utils.js";
|
|
6
6
|
export const run = (definitions, catchAll, { sync = true } = {}) => (() => {
|
|
7
|
-
const {
|
|
7
|
+
const { GlobalApplicationCommand, GuildApplicationCommand } = splitDefinitions(definitions);
|
|
8
8
|
return tsplus_module_1.flatMap(application => {
|
|
9
9
|
const globalSync = tsplus_module_2.Rest.rest.bulkOverwriteGlobalApplicationCommands(application.id, {
|
|
10
|
-
body: JSON.stringify(
|
|
10
|
+
body: JSON.stringify(GlobalApplicationCommand.map((a) => a.command)),
|
|
11
11
|
});
|
|
12
|
-
const guildSync =
|
|
12
|
+
const guildSync = GuildApplicationCommand.length
|
|
13
|
+
? tsplus_module_2.Gateway.handleDispatch("GUILD_CREATE", (a) => tsplus_module_2.Rest.rest.bulkOverwriteGuildApplicationCommands(application.id, a.id, GuildApplicationCommand.map((a) => a.command)))
|
|
14
|
+
: tsplus_module_1.unit();
|
|
13
15
|
const handle = handlers(definitions);
|
|
14
16
|
const run = tsplus_module_2.Gateway.handleDispatch("INTERACTION_CREATE", (i) => tsplus_module_1.catchAll(catchAll)(tsplus_module_1.tap((r) => tsplus_module_3.match(tsplus_module_1.unit, (r) => tsplus_module_2.Rest.rest.createInteractionResponse(i.id, i.token, r))(r))(handle[i.type](i))));
|
|
15
17
|
return tsplus_module_1.map(() => void 0)(sync ? tsplus_module_1.zipPar(guildSync)(tsplus_module_1.zipPar(globalSync)(run)) : run);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../src/Interactions/gateway.ts"],"names":[],"mappings":";;;AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAM7C,MAAM,CAAC,MAAM,GAAG,GAAG,CACjB,WAA4C,EAC5C,QAEwB,EACxB,EAAE,IAAI,GAAG,IAAI,KAAc,EAAE,EAC7B,EAAE;IAEA,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../src/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,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,EADvD,CAAC,CAEA,EAJL,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAKd,CACkB,CACtB,CAAA;iDAEC,IAAI,CAAC,CAAC,CAAC,uBAA8B,SAAS,EAAvC,uBAAW,UAAU,EAArB,GAAG,CAAmB,CAAkB,CAAC,CAAC,CAAC,GAAG;OAhCrD,wBAAwD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAArE,gBAAA,IAAI,CAAC,IAAI,CAAC,mCAAmC,EAAE,CAAuB;IAiCxE,CAAA"}
|
|
@@ -14,32 +14,32 @@ export class InteractionNotFound {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
export const handlers = (definitions) => {
|
|
17
|
-
const {
|
|
17
|
+
const { Commands, Autocomplete, MessageComponent, ModalSubmit } = splitDefinitions(definitions);
|
|
18
18
|
return {
|
|
19
19
|
[tsplus_module_1.Discord.InteractionType.PING]: () => tsplus_module_2.asSome(tsplus_module_2.succeed({
|
|
20
20
|
type: tsplus_module_1.Discord.InteractionCallbackType.PONG,
|
|
21
21
|
})),
|
|
22
22
|
[tsplus_module_1.Discord.InteractionType.APPLICATION_COMMAND]: (i) => {
|
|
23
23
|
const data = i.data;
|
|
24
|
-
return tsplus_module_4.pipe(tsplus_module_3.match(() => tsplus_module_2.fail(new InteractionNotFound(i)), (command) => command.handle)(tsplus_module_3.fromNullable(
|
|
24
|
+
return tsplus_module_4.pipe(tsplus_module_3.match(() => tsplus_module_2.fail(new InteractionNotFound(i)), (command) => command.handle)(tsplus_module_3.fromNullable(Commands[data.name])), tsplus_module_2.provideService(Ctx.InteractionContext)(i), tsplus_module_2.provideService(Ctx.ApplicationCommandContext)(data));
|
|
25
25
|
},
|
|
26
26
|
[tsplus_module_1.Discord.InteractionType.MODAL_SUBMIT]: (i) => {
|
|
27
27
|
const data = i.data;
|
|
28
|
-
return tsplus_module_4.pipe(
|
|
28
|
+
return tsplus_module_4.pipe(ModalSubmit, Arr.map((a) => tsplus_module_2.struct({
|
|
29
29
|
command: tsplus_module_2.succeed(a),
|
|
30
30
|
match: a.predicate(data.custom_id),
|
|
31
31
|
})), (a) => tsplus_module_2.flatMap((a) => tsplus_module_3.match(() => tsplus_module_2.fail(new InteractionNotFound(i)), (a) => a.command.handle)(tsplus_module_5.findFirst((a) => a.match)(a)))(tsplus_module_2.collectAllPar(a)), tsplus_module_2.provideService(Ctx.InteractionContext)(i), tsplus_module_2.provideService(Ctx.ModalSubmitContext)(data));
|
|
32
32
|
},
|
|
33
33
|
[tsplus_module_1.Discord.InteractionType.MESSAGE_COMPONENT]: (i) => {
|
|
34
34
|
const data = i.data;
|
|
35
|
-
return tsplus_module_4.pipe(
|
|
35
|
+
return tsplus_module_4.pipe(MessageComponent, Arr.map((a) => tsplus_module_2.struct({
|
|
36
36
|
command: tsplus_module_2.succeed(a),
|
|
37
37
|
match: a.predicate(data.custom_id),
|
|
38
38
|
})), (a) => tsplus_module_2.flatMap((a) => tsplus_module_3.match(() => tsplus_module_2.fail(new InteractionNotFound(i)), (a) => a.command.handle)(tsplus_module_5.findFirst((a) => a.match)(a)))(tsplus_module_2.collectAllPar(a)), tsplus_module_2.provideService(Ctx.InteractionContext)(i), tsplus_module_2.provideService(Ctx.MessageComponentContext)(data));
|
|
39
39
|
},
|
|
40
40
|
[tsplus_module_1.Discord.InteractionType.APPLICATION_COMMAND_AUTOCOMPLETE]: (i) => {
|
|
41
41
|
const data = i.data;
|
|
42
|
-
return tsplus_module_3.getOrElse(() => tsplus_module_2.fail(new InteractionNotFound(i)))(tsplus_module_3.map((focusedOption) => tsplus_module_4.pipe(
|
|
42
|
+
return tsplus_module_3.getOrElse(() => tsplus_module_2.fail(new InteractionNotFound(i)))(tsplus_module_3.map((focusedOption) => tsplus_module_4.pipe(Autocomplete, Arr.map((a) => tsplus_module_2.struct({
|
|
43
43
|
command: tsplus_module_2.succeed(a),
|
|
44
44
|
match: a.predicate(focusedOption),
|
|
45
45
|
})), (a) => tsplus_module_2.flatMap((a) => tsplus_module_3.match(() => tsplus_module_2.fail(new InteractionNotFound(i)), (a) => a.command.handle)(tsplus_module_5.findFirst((a) => a.match)(a)))(tsplus_module_2.collectAllPar(a)), tsplus_module_2.provideService(Ctx.InteractionContext)(i), tsplus_module_2.provideService(Ctx.ApplicationCommandContext)(data), tsplus_module_2.provideService(Ctx.FocusedOptionContext)({ focusedOption })))(tsplus_module_1.IxHelpers.focusedOption(data)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/Interactions/handlers.ts"],"names":[],"mappings":";;;;;AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAEnC,OAAO,KAAK,GAAG,MAAM,2BAA2B,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,OAAO,mBAAmB;IAET;IADZ,IAAI,GAAG,qBAAqB,CAAA;IACrC,YAAqB,WAAgC;QAAhC,gBAAW,GAAX,WAAW,CAAqB;IAAG,CAAC;CAC1D;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,WAA4C,EAI5C,EAAE;IACF,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/Interactions/handlers.ts"],"names":[],"mappings":";;;;;AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAEnC,OAAO,KAAK,GAAG,MAAM,2BAA2B,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,OAAO,mBAAmB;IAET;IADZ,IAAI,GAAG,qBAAqB,CAAA;IACrC,YAAqB,WAAgC;QAAhC,gBAAW,GAAX,WAAW,CAAqB;IAAG,CAAC;CAC1D;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,WAA4C,EAI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,eAAe,CAAC,gCAAgC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;YAChE,MAAM,IAAI,GAAG,CAAC,CAAC,IAAuC,CAAA;YAEtD,OAAO,0BA6BM,GAAG,EAAE,CAAC,qBAAY,IAAI,mBAAmB,CAAC,CAAC,CAAC,CAAQ,EA7B1D,oBACA,CAAC,aAAa,EAAE,EAAE,CACrB,gBAAA,IAAI,CACF,YAAY,EACZ,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACZ,uBAAc;gBACZ,OAAO,EAAE,wBAAe,CAAC,CAAC;gBAC1B,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC;aAClC,CAAC,CACH,EACD,CAAC,CAAC,EAAE,EAAE,CACJ,wBAAwB,CAAC,CAAC,EAAE,EAAE,CAC5B,sBAGI,GAAG,EAAE,CACH,qBAAY,IAAI,mBAAmB,CAAC,CAAC,CAAC,CAIrC,EACH,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAT3B,0BACa,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAD3B,CAAC,CAC2B,CASzB,gCAXL,CAAC,EAYA,EACH,+BAAsB,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAChD,+BAAsB,GAAG,CAAC,yBAAyB,CAAC,CAAC,IAAI,CAAC,EAC1D,+BAAsB,GAAG,CAAC,oBAAoB,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CACnE,EA3BE,gBAAA,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,CA4BjC,CAC+D,CAAA;QACpE,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Discord, Effect, Cause, Http, Rest } from "dfx/common";
|
|
2
2
|
import * as D from "./definitions.js";
|
|
3
3
|
import * as Gateway from "./gateway.js";
|
|
4
4
|
import * as Webhook from "./webhook.js";
|
|
5
5
|
export * from "./context.js";
|
|
6
|
-
export { global, guild, messageComponent, modalSubmit, autocomplete, InteractionDefinition, } from "./definitions.js";
|
|
6
|
+
export { global, guild, messageComponent, modalSubmit, autocomplete, InteractionDefinition, InteractionResponse, } from "./definitions.js";
|
|
7
7
|
export { makeConfig as makeWebhookConfig, WebhookConfig, WebhookParseError, BadWebhookSignature, } from "./webhook.js";
|
|
8
|
+
export interface HandleWebhookOpts<E> {
|
|
9
|
+
headers: Webhook.Headers;
|
|
10
|
+
body: string;
|
|
11
|
+
success: (a: Discord.InteractionResponse) => Effect<never, never, void>;
|
|
12
|
+
error: (e: Cause<E>) => Effect<never, never, void>;
|
|
13
|
+
empty: Effect<never, never, void>;
|
|
14
|
+
}
|
|
8
15
|
declare class InteractionBuilder<R, E> {
|
|
9
16
|
readonly definitions: D.InteractionDefinition<R, E>[];
|
|
10
17
|
constructor(definitions: D.InteractionDefinition<R, E>[]);
|
|
11
18
|
add<R1, E1>(definition: D.InteractionDefinition<R1, E1>): InteractionBuilder<R | R1, E | E1>;
|
|
12
19
|
runGateway<R2, E2>(catchAll: (e: E | Http.FetchError | Http.StatusCodeError | Http.JsonParseError) => Effect<R2, E2, any>, opts?: Gateway.RunOpts): import("../common.js").Effect<import("../index.js").DiscordREST | import("../DiscordGateway/index.js").DiscordGateway | R | R2, import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError | E2, void>;
|
|
13
|
-
handleWebhook(headers: Webhook.
|
|
20
|
+
handleWebhook({ headers, body, success, empty, error, }: HandleWebhookOpts<E | Webhook.WebhookParseError | Webhook.BadWebhookSignature>): import("../common.js").Effect<Webhook.WebhookConfig | R, never, void>;
|
|
21
|
+
get syncGlobal(): import("../common.js").Effect<import("../index.js").DiscordREST, import("../Http/index.js").FetchError | import("../Http/index.js").StatusCodeError | import("../Http/index.js").JsonParseError, import("../DiscordREST/types.js").ResponseWithData<import("../types.js").ApplicationCommand[]>>;
|
|
22
|
+
syncGuild(appId: Discord.Snowflake, guildId: Discord.Snowflake): import("../DiscordREST/types.js").RestResponse<import("../types.js").ApplicationCommand[]>;
|
|
14
23
|
}
|
|
15
24
|
export declare const builder: InteractionBuilder<never, never>;
|
|
16
25
|
export declare const id: (query: string) => (customId: string) => import("../common.js").Effect<never, never, boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Interactions/index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,cAAc,cAAc,CAAA;AAE5B,OAAO,EACL,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Interactions/index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,cAAc,cAAc,CAAA;AAE5B,OAAO,EACL,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EACL,UAAU,IAAI,iBAAiB,EAC/B,aAAa,EACb,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,cAAc,CAAA;AAErB,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,mBAAmB,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,EAA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AAO,MAAM,KAAK,UAAW,MAAM,gBAAgB,MAAM,yDACnB,CAAA;AAEtC,eAAO,MAAM,MAAM,SACV,MAAM,qBACG,QAAQ,uCAAuC,yDAClB,CAAA"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import * as tsplus_module_1 from "@
|
|
1
|
+
import * as tsplus_module_1 from "@fp-ts/data/Option";
|
|
2
|
+
import * as tsplus_module_2 from "@effect/io/Effect";
|
|
3
|
+
import * as tsplus_module_3 from "dfx/common";
|
|
2
4
|
import * as Gateway from "./gateway.js";
|
|
3
5
|
import * as Webhook from "./webhook.js";
|
|
4
6
|
export * from "./context.js";
|
|
@@ -18,14 +20,29 @@ class InteractionBuilder {
|
|
|
18
20
|
runGateway(catchAll, opts = {}) {
|
|
19
21
|
return Gateway.run(this.definitions, catchAll, opts);
|
|
20
22
|
}
|
|
21
|
-
handleWebhook(headers,
|
|
22
|
-
return Webhook.run(this.definitions, headers,
|
|
23
|
+
handleWebhook({ headers, body, success, empty, error, }) {
|
|
24
|
+
return tsplus_module_2.catchAllCause(error)(tsplus_module_2.flatMap((o) => tsplus_module_1.match(() => empty, (a) => success(a))(o))(Webhook.run(this.definitions, headers, body)));
|
|
25
|
+
}
|
|
26
|
+
get syncGlobal() {
|
|
27
|
+
const commands = this.definitions
|
|
28
|
+
.filter((c) => c._tag === "GlobalApplicationCommand")
|
|
29
|
+
.map((c) => c.command);
|
|
30
|
+
return tsplus_module_2.flatMap((app) => tsplus_module_3.Rest.rest.bulkOverwriteGlobalApplicationCommands(app.id, {
|
|
31
|
+
body: JSON.stringify(commands),
|
|
32
|
+
}))(tsplus_module_2.flatMap((r) => r.json)(tsplus_module_3.Rest.rest
|
|
33
|
+
.getCurrentBotApplicationInformation()));
|
|
34
|
+
}
|
|
35
|
+
syncGuild(appId, guildId) {
|
|
36
|
+
const commands = this.definitions
|
|
37
|
+
.filter((c) => c._tag === "GuildApplicationCommand")
|
|
38
|
+
.map((c) => c.command);
|
|
39
|
+
return tsplus_module_3.Rest.rest.bulkOverwriteGuildApplicationCommands(appId, guildId, commands);
|
|
23
40
|
}
|
|
24
41
|
}
|
|
25
42
|
export const builder = new InteractionBuilder([]);
|
|
26
43
|
// Filters
|
|
27
|
-
export const id = (query) => (customId) =>
|
|
28
|
-
export const idStartsWith = (query) => (customId) =>
|
|
29
|
-
export const regex = (query) => (customId) =>
|
|
30
|
-
export const option = (name) => (focusedOption) =>
|
|
44
|
+
export const id = (query) => (customId) => tsplus_module_2.succeed(query === customId);
|
|
45
|
+
export const idStartsWith = (query) => (customId) => tsplus_module_2.succeed(customId.startsWith(query));
|
|
46
|
+
export const regex = (query) => (customId) => tsplus_module_2.succeed(query.test(customId));
|
|
47
|
+
export const option = (name) => (focusedOption) => tsplus_module_2.succeed(focusedOption.name === name);
|
|
31
48
|
//# sourceMappingURL=index.js.map
|
|
@@ -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":";;;AACA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,cAAc,cAAc,CAAA;AAE5B,OAAO,EACL,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,WAAW,EACX,YAAY,GAGb,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EACL,UAAU,IAAI,iBAAiB,EAC/B,aAAa,EACb,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,cAAc,CAAA;AAUrB,MAAM,kBAAkB;IACD;IAArB,YAAqB,WAA4C;QAA5C,gBAAW,GAAX,WAAW,CAAiC;IAAG,CAAC;IAErE,GAAG,CAAS,UAA2C;QACrD,OAAO,IAAI,kBAAkB,CAAiB;YAC5C,GAAG,IAAI,CAAC,WAAW;YACnB,UAAU;SACX,CAAC,CAAA;IACJ,CA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vC;aACA,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;QAExB,OAAO,gBAAA,IAAI,CAAC,IAAI,CAAC,qCAAqC,CACpD,KAAK,EACL,OAAO,EACP,QAAe,CAChB,CAAA;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAe,EAAE,CAAC,CAAA;AAE/D,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,KAAK,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,QAAgB,EAAE,EAAE,CAC3D,wBAAe,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;AAEtC,MAAM,CAAC,MAAM,MAAM,GACjB,CAAC,IAAY,EAAE,EAAE,CACjB,CAAC,aAA8D,EAAE,EAAE,CACjE,wBAAe,aAAa,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as D from "./definitions.js";
|
|
2
2
|
export declare const splitDefinitions: <R, E>(definitions: D.InteractionDefinition<R, E>[]) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
Commands: Record<string, D.GlobalApplicationCommand<R, E> | D.GuildApplicationCommand<R, E>>;
|
|
4
|
+
GlobalApplicationCommand: D.GlobalApplicationCommand<R, E>[];
|
|
5
|
+
GuildApplicationCommand: D.GuildApplicationCommand<R, E>[];
|
|
6
|
+
MessageComponent: D.MessageComponent<R, E>[];
|
|
7
|
+
ModalSubmit: D.ModalSubmit<R, E>[];
|
|
8
|
+
Autocomplete: D.Autocomplete<R, E>[];
|
|
9
9
|
};
|
|
10
10
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/Interactions/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAA;AAErC,eAAO,MAAM,gBAAgB;;;;;;;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/Interactions/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAA;AAErC,eAAO,MAAM,gBAAgB;;;;;;;CAkC5B,CAAA"}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
export const splitDefinitions = (definitions) => {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
2
|
+
const grouped = definitions.reduce((acc, a) => ({
|
|
3
|
+
...acc,
|
|
4
|
+
[a._tag]: [...(acc[a._tag] ?? []), a],
|
|
5
|
+
}), {});
|
|
6
|
+
const Commands = [
|
|
7
|
+
...grouped.GlobalApplicationCommand,
|
|
8
|
+
...grouped.GuildApplicationCommand,
|
|
9
|
+
].reduce((acc, a) => ({
|
|
8
10
|
...acc,
|
|
9
11
|
[a.command.name]: a,
|
|
10
12
|
}), {});
|
|
11
13
|
return {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
messageComponents,
|
|
15
|
-
modalSubmits,
|
|
16
|
-
autocompletes,
|
|
17
|
-
allCommands,
|
|
14
|
+
...grouped,
|
|
15
|
+
Commands,
|
|
18
16
|
};
|
|
19
17
|
};
|
|
20
18
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/Interactions/utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,WAA4C,EAC5C,EAAE;IACF,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/Interactions/utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,WAA4C,EAC5C,EAAE;IACF,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAMhC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACX,GAAG,GAAG;QACN,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;KACtC,CAAC,EACF,EAAS,CACV,CAAA;IAED,MAAM,QAAQ,GAAG;QACf,GAAG,OAAO,CAAC,wBAAwB;QACnC,GAAG,OAAO,CAAC,uBAAuB;KACnC,CAAC,MAAM,CACN,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACX,GAAG,GAAG;QACN,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;KACpB,CAAC,EACF,EAGC,CACF,CAAA;IAED,OAAO;QACL,GAAG,OAAO;QACV,QAAQ;KACT,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dfx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -23,17 +23,21 @@
|
|
|
23
23
|
"./*": "./dist/*.js"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"@effect/io": "^0.0.29",
|
|
27
|
+
"@fp-ts/data": "^0.0.19",
|
|
26
28
|
"@tim-smart/discord-api-docs-parser": "^0.4.1",
|
|
27
29
|
"@types/ws": "^8.5.3",
|
|
28
30
|
"lerna": "^4.0.0",
|
|
29
31
|
"typescript": "https://cdn.jsdelivr.net/npm/@tsplus/installer/compiler/typescript.tgz"
|
|
30
32
|
},
|
|
31
33
|
"dependencies": {
|
|
32
|
-
"@effect/io": "^0.0.29",
|
|
33
|
-
"@fp-ts/data": "^0.0.19",
|
|
34
34
|
"callbag-effect-ts": "1.0.0-alpha.17",
|
|
35
35
|
"isomorphic-ws": "^5.0.0"
|
|
36
36
|
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@effect/io": "*",
|
|
39
|
+
"@fp-ts/data": "*"
|
|
40
|
+
},
|
|
37
41
|
"optionalDependencies": {
|
|
38
42
|
"bufferutil": "^4.0.7",
|
|
39
43
|
"tweetnacl": "^1.0.3",
|
|
@@ -46,5 +50,5 @@
|
|
|
46
50
|
"@fp-ts/data": "^0.0.19"
|
|
47
51
|
}
|
|
48
52
|
},
|
|
49
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "e093d8df9e08c12f61c0c9046f1dcb8e0839eed3"
|
|
50
54
|
}
|
|
@@ -14,7 +14,8 @@ export const run = <R, R2, E, E2>(
|
|
|
14
14
|
{ sync = true }: RunOpts = {},
|
|
15
15
|
) =>
|
|
16
16
|
Do(($) => {
|
|
17
|
-
const {
|
|
17
|
+
const { GlobalApplicationCommand, GuildApplicationCommand } =
|
|
18
|
+
splitDefinitions(definitions)
|
|
18
19
|
|
|
19
20
|
const application = $(
|
|
20
21
|
Rest.rest.getCurrentBotApplicationInformation().flatMap((a) => a.json),
|
|
@@ -23,17 +24,19 @@ export const run = <R, R2, E, E2>(
|
|
|
23
24
|
const globalSync = Rest.rest.bulkOverwriteGlobalApplicationCommands(
|
|
24
25
|
application.id,
|
|
25
26
|
{
|
|
26
|
-
body: JSON.stringify(
|
|
27
|
+
body: JSON.stringify(GlobalApplicationCommand.map((a) => a.command)),
|
|
27
28
|
},
|
|
28
29
|
)
|
|
29
30
|
|
|
30
|
-
const guildSync =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
const guildSync = GuildApplicationCommand.length
|
|
32
|
+
? Gateway.handleDispatch("GUILD_CREATE", (a) =>
|
|
33
|
+
Rest.rest.bulkOverwriteGuildApplicationCommands(
|
|
34
|
+
application.id,
|
|
35
|
+
a.id,
|
|
36
|
+
GuildApplicationCommand.map((a) => a.command) as any,
|
|
37
|
+
),
|
|
38
|
+
)
|
|
39
|
+
: Effect.unit()
|
|
37
40
|
|
|
38
41
|
const handle = handlers(definitions)
|
|
39
42
|
|
|
@@ -14,7 +14,7 @@ export const handlers = <R, E>(
|
|
|
14
14
|
Discord.InteractionType,
|
|
15
15
|
(i: Discord.Interaction) => Effect<R, E, Maybe<Discord.InteractionResponse>>
|
|
16
16
|
> => {
|
|
17
|
-
const {
|
|
17
|
+
const { Commands, Autocomplete, MessageComponent, ModalSubmit } =
|
|
18
18
|
splitDefinitions(definitions)
|
|
19
19
|
|
|
20
20
|
return {
|
|
@@ -27,7 +27,7 @@ export const handlers = <R, E>(
|
|
|
27
27
|
const data = i.data as Discord.ApplicationCommandDatum
|
|
28
28
|
|
|
29
29
|
return pipe(
|
|
30
|
-
Maybe.fromNullable(
|
|
30
|
+
Maybe.fromNullable(Commands[data.name]).match(
|
|
31
31
|
() =>
|
|
32
32
|
Effect.fail(new InteractionNotFound(i)) as any as Effect<
|
|
33
33
|
R,
|
|
@@ -45,7 +45,7 @@ export const handlers = <R, E>(
|
|
|
45
45
|
const data = i.data as Discord.ModalSubmitDatum
|
|
46
46
|
|
|
47
47
|
return pipe(
|
|
48
|
-
|
|
48
|
+
ModalSubmit,
|
|
49
49
|
Arr.map((a) =>
|
|
50
50
|
Effect.struct({
|
|
51
51
|
command: Effect.succeed(a),
|
|
@@ -75,7 +75,7 @@ export const handlers = <R, E>(
|
|
|
75
75
|
const data = i.data as Discord.MessageComponentDatum
|
|
76
76
|
|
|
77
77
|
return pipe(
|
|
78
|
-
|
|
78
|
+
MessageComponent,
|
|
79
79
|
Arr.map((a) =>
|
|
80
80
|
Effect.struct({
|
|
81
81
|
command: Effect.succeed(a),
|
|
@@ -107,7 +107,7 @@ export const handlers = <R, E>(
|
|
|
107
107
|
return IxHelpers.focusedOption(data)
|
|
108
108
|
.map((focusedOption) =>
|
|
109
109
|
pipe(
|
|
110
|
-
|
|
110
|
+
Autocomplete,
|
|
111
111
|
Arr.map((a) =>
|
|
112
112
|
Effect.struct({
|
|
113
113
|
command: Effect.succeed(a),
|
|
@@ -11,6 +11,7 @@ export {
|
|
|
11
11
|
modalSubmit,
|
|
12
12
|
autocomplete,
|
|
13
13
|
InteractionDefinition,
|
|
14
|
+
InteractionResponse,
|
|
14
15
|
} from "./definitions.js"
|
|
15
16
|
|
|
16
17
|
export {
|
|
@@ -20,6 +21,14 @@ export {
|
|
|
20
21
|
BadWebhookSignature,
|
|
21
22
|
} from "./webhook.js"
|
|
22
23
|
|
|
24
|
+
export interface HandleWebhookOpts<E> {
|
|
25
|
+
headers: Webhook.Headers
|
|
26
|
+
body: string
|
|
27
|
+
success: (a: Discord.InteractionResponse) => Effect<never, never, void>
|
|
28
|
+
error: (e: Cause<E>) => Effect<never, never, void>
|
|
29
|
+
empty: Effect<never, never, void>
|
|
30
|
+
}
|
|
31
|
+
|
|
23
32
|
class InteractionBuilder<R, E> {
|
|
24
33
|
constructor(readonly definitions: D.InteractionDefinition<R, E>[]) {}
|
|
25
34
|
|
|
@@ -39,8 +48,56 @@ class InteractionBuilder<R, E> {
|
|
|
39
48
|
return Gateway.run<R, R2, E, E2>(this.definitions, catchAll, opts)
|
|
40
49
|
}
|
|
41
50
|
|
|
42
|
-
handleWebhook(
|
|
43
|
-
|
|
51
|
+
handleWebhook({
|
|
52
|
+
headers,
|
|
53
|
+
body,
|
|
54
|
+
success,
|
|
55
|
+
empty,
|
|
56
|
+
error,
|
|
57
|
+
}: HandleWebhookOpts<
|
|
58
|
+
E | Webhook.WebhookParseError | Webhook.BadWebhookSignature
|
|
59
|
+
>) {
|
|
60
|
+
return Webhook.run(this.definitions, headers, body)
|
|
61
|
+
.flatMap((o) =>
|
|
62
|
+
o.match(
|
|
63
|
+
() => empty,
|
|
64
|
+
(a) => success(a),
|
|
65
|
+
),
|
|
66
|
+
)
|
|
67
|
+
.catchAllCause(error)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get syncGlobal() {
|
|
71
|
+
const commands = this.definitions
|
|
72
|
+
.filter(
|
|
73
|
+
(c): c is D.GlobalApplicationCommand<R, E> =>
|
|
74
|
+
c._tag === "GlobalApplicationCommand",
|
|
75
|
+
)
|
|
76
|
+
.map((c) => c.command)
|
|
77
|
+
|
|
78
|
+
return Rest.rest
|
|
79
|
+
.getCurrentBotApplicationInformation()
|
|
80
|
+
.flatMap((r) => r.json)
|
|
81
|
+
.flatMap((app) =>
|
|
82
|
+
Rest.rest.bulkOverwriteGlobalApplicationCommands(app.id, {
|
|
83
|
+
body: JSON.stringify(commands),
|
|
84
|
+
}),
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
syncGuild(appId: Discord.Snowflake, guildId: Discord.Snowflake) {
|
|
89
|
+
const commands = this.definitions
|
|
90
|
+
.filter(
|
|
91
|
+
(c): c is D.GuildApplicationCommand<R, E> =>
|
|
92
|
+
c._tag === "GuildApplicationCommand",
|
|
93
|
+
)
|
|
94
|
+
.map((c) => c.command)
|
|
95
|
+
|
|
96
|
+
return Rest.rest.bulkOverwriteGuildApplicationCommands(
|
|
97
|
+
appId,
|
|
98
|
+
guildId,
|
|
99
|
+
commands as any,
|
|
100
|
+
)
|
|
44
101
|
}
|
|
45
102
|
}
|
|
46
103
|
|
|
@@ -3,29 +3,23 @@ import * as D from "./definitions.js"
|
|
|
3
3
|
export const splitDefinitions = <R, E>(
|
|
4
4
|
definitions: D.InteractionDefinition<R, E>[],
|
|
5
5
|
) => {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
(a)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
(a): a is D.MessageComponent<R, E> => a._tag === "MessageComponent",
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
const modalSubmits = definitions.filter(
|
|
21
|
-
(a): a is D.ModalSubmit<R, E> => a._tag === "ModalSubmit",
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
const autocompletes = definitions.filter(
|
|
25
|
-
(a): a is D.Autocomplete<R, E> => a._tag === "Autocomplete",
|
|
6
|
+
const grouped = definitions.reduce<{
|
|
7
|
+
[K in D.InteractionDefinition<R, E>["_tag"]]: Extract<
|
|
8
|
+
D.InteractionDefinition<R, E>,
|
|
9
|
+
{ _tag: K }
|
|
10
|
+
>[]
|
|
11
|
+
}>(
|
|
12
|
+
(acc, a) => ({
|
|
13
|
+
...acc,
|
|
14
|
+
[a._tag]: [...(acc[a._tag] ?? []), a],
|
|
15
|
+
}),
|
|
16
|
+
{} as any,
|
|
26
17
|
)
|
|
27
18
|
|
|
28
|
-
const
|
|
19
|
+
const Commands = [
|
|
20
|
+
...grouped.GlobalApplicationCommand,
|
|
21
|
+
...grouped.GuildApplicationCommand,
|
|
22
|
+
].reduce(
|
|
29
23
|
(acc, a) => ({
|
|
30
24
|
...acc,
|
|
31
25
|
[a.command.name]: a,
|
|
@@ -37,11 +31,7 @@ export const splitDefinitions = <R, E>(
|
|
|
37
31
|
)
|
|
38
32
|
|
|
39
33
|
return {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
messageComponents,
|
|
43
|
-
modalSubmits,
|
|
44
|
-
autocompletes,
|
|
45
|
-
allCommands,
|
|
34
|
+
...grouped,
|
|
35
|
+
Commands,
|
|
46
36
|
}
|
|
47
37
|
}
|