dfx 0.59.0 → 0.61.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/Cache/driver.d.ts +1 -1
- package/Cache/driver.d.ts.map +1 -1
- package/Cache/memory.js +2 -2
- package/Cache/memory.js.map +1 -1
- package/Cache/memoryTTL.d.ts.map +1 -1
- package/Cache/memoryTTL.js.map +1 -1
- package/Cache/prelude.d.ts.map +1 -1
- package/Cache/prelude.js.map +1 -1
- package/Cache.d.ts +1 -1
- package/Cache.d.ts.map +1 -1
- package/Cache.js +1 -1
- package/Cache.js.map +1 -1
- package/DiscordGateway/DiscordWS.d.ts +5 -5
- package/DiscordGateway/DiscordWS.d.ts.map +1 -1
- package/DiscordGateway/DiscordWS.js +2 -2
- package/DiscordGateway/DiscordWS.js.map +1 -1
- package/DiscordGateway/Shard/heartbeats.js.map +1 -1
- package/DiscordGateway/Shard/utils.d.ts +1 -1
- package/DiscordGateway/Shard/utils.d.ts.map +1 -1
- package/DiscordGateway/Shard/utils.js.map +1 -1
- package/DiscordGateway/Shard.d.ts +8 -8
- package/DiscordGateway/Shard.d.ts.map +1 -1
- package/DiscordGateway/Shard.js +11 -11
- package/DiscordGateway/Shard.js.map +1 -1
- package/DiscordGateway/ShardStore.d.ts +2 -2
- package/DiscordGateway/ShardStore.d.ts.map +1 -1
- package/DiscordGateway/ShardStore.js +2 -2
- package/DiscordGateway/ShardStore.js.map +1 -1
- package/DiscordGateway/Sharder.js.map +1 -1
- package/DiscordGateway/WS.d.ts +4 -4
- package/DiscordGateway/WS.d.ts.map +1 -1
- package/DiscordGateway/WS.js +6 -6
- package/DiscordGateway/WS.js.map +1 -1
- package/DiscordGateway.d.ts.map +1 -1
- package/DiscordGateway.js.map +1 -1
- package/DiscordREST/types.d.ts +1 -1
- package/DiscordREST/types.d.ts.map +1 -1
- package/DiscordREST/utils.d.ts +1 -1
- package/DiscordREST/utils.d.ts.map +1 -1
- package/DiscordREST/utils.js +1 -1
- package/DiscordREST/utils.js.map +1 -1
- package/DiscordREST.d.ts.map +1 -1
- package/DiscordREST.js.map +1 -1
- package/Helpers/flags.d.ts.map +1 -1
- package/Helpers/flags.js.map +1 -1
- package/Helpers/intents.d.ts.map +1 -1
- package/Helpers/intents.js.map +1 -1
- package/Helpers/interactions.d.ts +1 -1
- package/Helpers/interactions.d.ts.map +1 -1
- package/Helpers/interactions.js +2 -2
- package/Helpers/interactions.js.map +1 -1
- package/Helpers/members.d.ts.map +1 -1
- package/Helpers/members.js.map +1 -1
- package/Helpers/permissions.js.map +1 -1
- package/Interactions/builder.d.ts +1 -1
- package/Interactions/builder.d.ts.map +1 -1
- package/Interactions/builder.js.map +1 -1
- package/Interactions/context.d.ts.map +1 -1
- package/Interactions/context.js.map +1 -1
- package/Interactions/definitions.d.ts.map +1 -1
- package/Interactions/definitions.js.map +1 -1
- package/Interactions/gateway.d.ts.map +1 -1
- package/Interactions/gateway.js.map +1 -1
- package/Interactions/handlers.d.ts.map +1 -1
- package/Interactions/handlers.js.map +1 -1
- package/Interactions/index.d.ts +1 -1
- package/Interactions/index.d.ts.map +1 -1
- package/Interactions/index.js.map +1 -1
- package/Interactions/utils.d.ts.map +1 -1
- package/Interactions/utils.js.map +1 -1
- package/Interactions/webhook.d.ts.map +1 -1
- package/Interactions/webhook.js.map +1 -1
- package/LICENSE +21 -0
- package/Log.d.ts +1 -1
- package/Log.d.ts.map +1 -1
- package/Log.js +1 -1
- package/Log.js.map +1 -1
- package/RateLimit.d.ts +2 -2
- package/RateLimit.d.ts.map +1 -1
- package/RateLimit.js.map +1 -1
- package/gateway.d.ts +1 -1
- package/gateway.d.ts.map +1 -1
- package/gateway.js +1 -1
- package/gateway.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/mjs/Cache/memory.mjs +2 -2
- package/mjs/Cache/memory.mjs.map +1 -1
- package/mjs/Cache/memoryTTL.mjs.map +1 -1
- package/mjs/Cache/prelude.mjs.map +1 -1
- package/mjs/Cache.mjs +1 -1
- package/mjs/Cache.mjs.map +1 -1
- package/mjs/DiscordGateway/DiscordWS.mjs +2 -2
- package/mjs/DiscordGateway/DiscordWS.mjs.map +1 -1
- package/mjs/DiscordGateway/Shard/heartbeats.mjs.map +1 -1
- package/mjs/DiscordGateway/Shard/utils.mjs.map +1 -1
- package/mjs/DiscordGateway/Shard.mjs +11 -11
- package/mjs/DiscordGateway/Shard.mjs.map +1 -1
- package/mjs/DiscordGateway/ShardStore.mjs +2 -2
- package/mjs/DiscordGateway/ShardStore.mjs.map +1 -1
- package/mjs/DiscordGateway/Sharder.mjs.map +1 -1
- package/mjs/DiscordGateway/WS.mjs +5 -5
- package/mjs/DiscordGateway/WS.mjs.map +1 -1
- package/mjs/DiscordGateway.mjs.map +1 -1
- package/mjs/DiscordREST/utils.mjs +1 -1
- package/mjs/DiscordREST/utils.mjs.map +1 -1
- package/mjs/DiscordREST.mjs +1 -1
- package/mjs/DiscordREST.mjs.map +1 -1
- package/mjs/Helpers/flags.mjs.map +1 -1
- package/mjs/Helpers/intents.mjs.map +1 -1
- package/mjs/Helpers/interactions.mjs +2 -2
- package/mjs/Helpers/interactions.mjs.map +1 -1
- package/mjs/Helpers/members.mjs.map +1 -1
- package/mjs/Helpers/permissions.mjs.map +1 -1
- package/mjs/Interactions/builder.mjs.map +1 -1
- package/mjs/Interactions/context.mjs.map +1 -1
- package/mjs/Interactions/definitions.mjs.map +1 -1
- package/mjs/Interactions/gateway.mjs +1 -1
- package/mjs/Interactions/gateway.mjs.map +1 -1
- package/mjs/Interactions/handlers.mjs.map +1 -1
- package/mjs/Interactions/index.mjs.map +1 -1
- package/mjs/Interactions/utils.mjs.map +1 -1
- package/mjs/Interactions/webhook.mjs.map +1 -1
- package/mjs/Log.mjs +1 -1
- package/mjs/Log.mjs.map +1 -1
- package/mjs/RateLimit.mjs.map +1 -1
- package/mjs/gateway.mjs +1 -1
- package/mjs/gateway.mjs.map +1 -1
- package/mjs/index.mjs +1 -1
- package/mjs/index.mjs.map +1 -1
- package/mjs/types.mjs.map +1 -1
- package/mjs/utils/Effect.mjs +4 -4
- package/mjs/utils/Effect.mjs.map +1 -1
- package/mjs/version.mjs +1 -1
- package/mjs/webhooks.mjs +1 -1
- package/mjs/webhooks.mjs.map +1 -1
- package/package.json +32 -26
- package/src/Cache/driver.ts +1 -1
- package/src/Cache/memory.ts +2 -2
- package/src/Cache/memoryTTL.ts +6 -4
- package/src/Cache/prelude.ts +15 -13
- package/src/Cache.ts +3 -3
- package/src/DiscordGateway/DiscordWS.ts +9 -10
- package/src/DiscordGateway/Shard/heartbeats.ts +1 -1
- package/src/DiscordGateway/Shard/utils.ts +10 -12
- package/src/DiscordGateway/Shard.ts +23 -24
- package/src/DiscordGateway/ShardStore.ts +2 -2
- package/src/DiscordGateway/Sharder.ts +7 -7
- package/src/DiscordGateway/WS.ts +10 -10
- package/src/DiscordGateway.ts +8 -9
- package/src/DiscordREST/types.ts +1 -1
- package/src/DiscordREST/utils.ts +5 -3
- package/src/DiscordREST.ts +27 -24
- package/src/Helpers/flags.ts +2 -4
- package/src/Helpers/intents.ts +3 -4
- package/src/Helpers/interactions.ts +53 -56
- package/src/Helpers/members.ts +2 -2
- package/src/Helpers/permissions.ts +2 -2
- package/src/Interactions/builder.ts +21 -19
- package/src/Interactions/context.ts +16 -23
- package/src/Interactions/definitions.ts +27 -34
- package/src/Interactions/gateway.ts +80 -83
- package/src/Interactions/handlers.ts +34 -35
- package/src/Interactions/index.ts +17 -21
- package/src/Interactions/utils.ts +13 -17
- package/src/Interactions/webhook.ts +19 -15
- package/src/Log.ts +3 -3
- package/src/RateLimit.ts +5 -4
- package/src/gateway.ts +2 -2
- package/src/index.ts +1 -1
- package/src/types.ts +50 -26
- package/src/utils/Effect.ts +16 -17
- package/src/version.ts +1 -1
- package/src/webhooks.ts +2 -2
- package/types.d.ts.map +1 -1
- package/types.js.map +1 -1
- package/utils/Effect.d.ts.map +1 -1
- package/utils/Effect.js +4 -4
- package/utils/Effect.js.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/webhooks.d.ts +1 -1
- package/webhooks.d.ts.map +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { identity, pipe } from "@effect/data/Function"
|
|
2
|
+
import * as HashMap from "@effect/data/HashMap"
|
|
1
3
|
import * as Option from "@effect/data/Option"
|
|
2
4
|
import * as Arr from "@effect/data/ReadonlyArray"
|
|
3
5
|
import * as Discord from "dfx/types"
|
|
4
|
-
import { identity, pipe } from "@effect/data/Function"
|
|
5
|
-
import * as HashMap from "@effect/data/HashMap"
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Option find a sub-command within the interaction options.
|
|
@@ -24,8 +24,8 @@ export const findSubCommand =
|
|
|
24
24
|
optionsWithNested(interaction),
|
|
25
25
|
Arr.findFirst(
|
|
26
26
|
o =>
|
|
27
|
-
o.type === Discord.ApplicationCommandOptionType.SUB_COMMAND
|
|
28
|
-
o.name === name,
|
|
27
|
+
o.type === Discord.ApplicationCommandOptionType.SUB_COMMAND
|
|
28
|
+
&& o.name === name,
|
|
29
29
|
),
|
|
30
30
|
)
|
|
31
31
|
|
|
@@ -114,46 +114,42 @@ export const resolved = (data: Discord.Interaction) =>
|
|
|
114
114
|
/**
|
|
115
115
|
* Try find a matching option value from the interaction.
|
|
116
116
|
*/
|
|
117
|
-
export const resolveOptionValue =
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
Option.
|
|
124
|
-
Option.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
Option.flatMapNullable(({ id, r }) => f(id, r)),
|
|
135
|
-
)
|
|
117
|
+
export const resolveOptionValue = <T>(
|
|
118
|
+
name: string,
|
|
119
|
+
f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => T | undefined,
|
|
120
|
+
) =>
|
|
121
|
+
(a: Discord.Interaction): Option.Option<T> =>
|
|
122
|
+
Option.Do.pipe(
|
|
123
|
+
Option.bind("data", () =>
|
|
124
|
+
Option.fromNullable(a.data as Discord.ApplicationCommandDatum)),
|
|
125
|
+
Option.bind("id", ({ data }) =>
|
|
126
|
+
Option.flatMapNullable(
|
|
127
|
+
getOption(name)(data),
|
|
128
|
+
({ value }) =>
|
|
129
|
+
value as Discord.Snowflake,
|
|
130
|
+
)),
|
|
131
|
+
Option.bind("r", () => resolved(a)),
|
|
132
|
+
Option.flatMapNullable(({ id, r }) => f(id, r)),
|
|
133
|
+
)
|
|
136
134
|
|
|
137
135
|
/**
|
|
138
136
|
* Try find matching option values from the interaction.
|
|
139
137
|
*/
|
|
140
|
-
export const resolveValues =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
Option.
|
|
146
|
-
Option.
|
|
147
|
-
Option.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
),
|
|
156
|
-
)
|
|
138
|
+
export const resolveValues = <T>(
|
|
139
|
+
f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => T | undefined,
|
|
140
|
+
) =>
|
|
141
|
+
(a: Discord.Interaction): Option.Option<ReadonlyArray<T>> =>
|
|
142
|
+
Option.Do.pipe(
|
|
143
|
+
Option.bind("values", () =>
|
|
144
|
+
Option.flatMapNullable(
|
|
145
|
+
Option.fromNullable(a.data as Discord.MessageComponentDatum),
|
|
146
|
+
a => a.values as unknown as Array<string>,
|
|
147
|
+
)),
|
|
148
|
+
Option.bind("r", () => resolved(a)),
|
|
149
|
+
Option.map(({ r, values }) =>
|
|
150
|
+
Arr.compact(values.map(a => Option.fromNullable(f(a as any, r))))
|
|
151
|
+
),
|
|
152
|
+
)
|
|
157
153
|
|
|
158
154
|
const extractComponents = (c: Discord.Component): Array<Discord.Component> => {
|
|
159
155
|
if ("components" in c) {
|
|
@@ -215,26 +211,27 @@ export const componentValue =
|
|
|
215
211
|
|
|
216
212
|
export type InteractionResponse =
|
|
217
213
|
| {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
214
|
+
type: Discord.InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE
|
|
215
|
+
data: Discord.InteractionCallbackMessage
|
|
216
|
+
}
|
|
221
217
|
| {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
218
|
+
type: Discord.InteractionCallbackType.UPDATE_MESSAGE
|
|
219
|
+
data: Discord.InteractionCallbackMessage
|
|
220
|
+
}
|
|
225
221
|
| {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
222
|
+
type: Discord.InteractionCallbackType.MODAL
|
|
223
|
+
data: Discord.InteractionCallbackModal
|
|
224
|
+
}
|
|
229
225
|
| {
|
|
230
|
-
|
|
231
|
-
|
|
226
|
+
type: Discord.InteractionCallbackType.DEFERRED_UPDATE_MESSAGE
|
|
227
|
+
}
|
|
232
228
|
| {
|
|
233
|
-
|
|
234
|
-
|
|
229
|
+
type: Discord.InteractionCallbackType.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
|
|
230
|
+
}
|
|
235
231
|
| {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
232
|
+
type:
|
|
233
|
+
Discord.InteractionCallbackType.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT
|
|
234
|
+
data: Discord.InteractionCallbackAutocomplete
|
|
235
|
+
}
|
|
239
236
|
|
|
240
237
|
export const response = (r: InteractionResponse) => r
|
package/src/Helpers/members.ts
CHANGED
|
@@ -13,5 +13,5 @@ export const roles =
|
|
|
13
13
|
* Type-guard function for checking if the object is a guild member
|
|
14
14
|
*/
|
|
15
15
|
export const is = (thing: unknown): thing is Discord.GuildMember =>
|
|
16
|
-
Object.prototype.hasOwnProperty.call(thing, "roles")
|
|
17
|
-
Object.prototype.hasOwnProperty.call(thing, "joined_at")
|
|
16
|
+
Object.prototype.hasOwnProperty.call(thing, "roles")
|
|
17
|
+
&& Object.prototype.hasOwnProperty.call(thing, "joined_at")
|
|
@@ -84,8 +84,8 @@ export const forChannel =
|
|
|
84
84
|
} else {
|
|
85
85
|
const everyone = roles.find(role => role.name === "@everyone")
|
|
86
86
|
|
|
87
|
-
basePermissions =
|
|
88
|
-
|
|
87
|
+
basePermissions = BigInt(everyone?.permissions || "0")
|
|
88
|
+
| BigInt(memberOrRole.permissions)
|
|
89
89
|
filteredOverwrites = overwrites.filter(
|
|
90
90
|
overwriteIsForRole(guild_id)(memberOrRole),
|
|
91
91
|
)
|
|
@@ -5,13 +5,11 @@ import type * as Cause from "@effect/io/Cause"
|
|
|
5
5
|
import * as Effect from "@effect/io/Effect"
|
|
6
6
|
import { catchTag } from "@effect/io/Effect"
|
|
7
7
|
import { DiscordREST, type DiscordRESTError } from "dfx/DiscordREST"
|
|
8
|
-
import type * as Discord from "dfx/types"
|
|
9
8
|
import type * as D from "dfx/Interactions/definitions"
|
|
9
|
+
import type * as Discord from "dfx/types"
|
|
10
10
|
|
|
11
|
-
type ExtractTag<A> = A extends { _tag: infer Tag }
|
|
12
|
-
|
|
13
|
-
? Tag
|
|
14
|
-
: never
|
|
11
|
+
type ExtractTag<A> = A extends { _tag: infer Tag } ? Tag extends string ? Tag
|
|
12
|
+
: never
|
|
15
13
|
: never
|
|
16
14
|
|
|
17
15
|
/**
|
|
@@ -132,15 +130,17 @@ export class InteractionBuilder<R, E, TE> {
|
|
|
132
130
|
Chunk.map(c => c.command),
|
|
133
131
|
)
|
|
134
132
|
|
|
135
|
-
return Effect.flatMap(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
return Effect.flatMap(
|
|
134
|
+
DiscordREST,
|
|
135
|
+
rest =>
|
|
136
|
+
rest.getCurrentBotApplicationInformation().pipe(
|
|
137
|
+
Effect.flatMap(r => r.json),
|
|
138
|
+
Effect.flatMap(app =>
|
|
139
|
+
rest.bulkOverwriteGlobalApplicationCommands(app.id, {
|
|
140
|
+
body: Http.body.json(Chunk.toReadonlyArray(commands)),
|
|
141
|
+
})
|
|
142
|
+
),
|
|
142
143
|
),
|
|
143
|
-
),
|
|
144
144
|
)
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -154,12 +154,14 @@ export class InteractionBuilder<R, E, TE> {
|
|
|
154
154
|
Chunk.map(c => c.command),
|
|
155
155
|
)
|
|
156
156
|
|
|
157
|
-
return Effect.flatMap(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
return Effect.flatMap(
|
|
158
|
+
DiscordREST,
|
|
159
|
+
rest =>
|
|
160
|
+
rest.bulkOverwriteGuildApplicationCommands(
|
|
161
|
+
appId,
|
|
162
|
+
guildId,
|
|
163
|
+
Chunk.toReadonlyArray(commands) as any,
|
|
164
|
+
),
|
|
163
165
|
)
|
|
164
166
|
}
|
|
165
167
|
}
|
|
@@ -33,8 +33,7 @@ export const resolvedValues = <A>(
|
|
|
33
33
|
Effect.mapError(
|
|
34
34
|
IxHelpers.resolveValues(f)(ix),
|
|
35
35
|
() => new ResolvedDataNotFound(ix),
|
|
36
|
-
)
|
|
37
|
-
)
|
|
36
|
+
))
|
|
38
37
|
|
|
39
38
|
export const resolved = <A>(
|
|
40
39
|
name: string,
|
|
@@ -44,8 +43,7 @@ export const resolved = <A>(
|
|
|
44
43
|
Effect.mapError(
|
|
45
44
|
IxHelpers.resolveOptionValue(name, f)(ix),
|
|
46
45
|
() => new ResolvedDataNotFound(ix, name),
|
|
47
|
-
)
|
|
48
|
-
)
|
|
46
|
+
))
|
|
49
47
|
|
|
50
48
|
export const focusedOptionValue = Effect.map(
|
|
51
49
|
FocusedOptionContext,
|
|
@@ -66,20 +64,18 @@ export const handleSubCommands = <
|
|
|
66
64
|
commands: NER,
|
|
67
65
|
): Effect.Effect<
|
|
68
66
|
| Exclude<
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
>
|
|
67
|
+
[NER[keyof NER]] extends [
|
|
68
|
+
{ [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
|
|
69
|
+
] ? R
|
|
70
|
+
: never,
|
|
71
|
+
SubCommandContext
|
|
72
|
+
>
|
|
76
73
|
| Discord.Interaction
|
|
77
74
|
| Discord.ApplicationCommandDatum,
|
|
78
75
|
| ([NER[keyof NER]] extends [
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
: never)
|
|
76
|
+
{ [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
|
|
77
|
+
] ? E
|
|
78
|
+
: never)
|
|
83
79
|
| SubCommandNotFound,
|
|
84
80
|
Discord.InteractionResponse
|
|
85
81
|
> =>
|
|
@@ -88,12 +84,12 @@ export const handleSubCommands = <
|
|
|
88
84
|
Effect.mapError(
|
|
89
85
|
Arr.findFirst(IxHelpers.allSubCommands(data), _ => !!commands[_.name]),
|
|
90
86
|
() => new SubCommandNotFound(data),
|
|
91
|
-
)
|
|
87
|
+
)
|
|
92
88
|
),
|
|
93
89
|
Effect.flatMap(command =>
|
|
94
90
|
Effect.provideService(commands[command.name], SubCommandContext, {
|
|
95
91
|
command,
|
|
96
|
-
})
|
|
92
|
+
})
|
|
97
93
|
),
|
|
98
94
|
)
|
|
99
95
|
|
|
@@ -129,12 +125,10 @@ export const optionValue = (name: string) =>
|
|
|
129
125
|
{
|
|
130
126
|
onNone: () =>
|
|
131
127
|
Effect.flatMap(ApplicationCommand, data =>
|
|
132
|
-
Effect.fail(new RequiredOptionNotFound(data, name)),
|
|
133
|
-
),
|
|
128
|
+
Effect.fail(new RequiredOptionNotFound(data, name))),
|
|
134
129
|
onSome: Effect.succeed,
|
|
135
130
|
},
|
|
136
|
-
)
|
|
137
|
-
)
|
|
131
|
+
))
|
|
138
132
|
|
|
139
133
|
export const optionValueOptional = (name: string) =>
|
|
140
134
|
Effect.map(
|
|
@@ -157,5 +151,4 @@ export const modalValue = (name: string) =>
|
|
|
157
151
|
Effect.mapError(
|
|
158
152
|
IxHelpers.componentValue(name)(data),
|
|
159
153
|
() => new ModalValueNotFound(data, name),
|
|
160
|
-
)
|
|
161
|
-
)
|
|
154
|
+
))
|
|
@@ -25,7 +25,9 @@ export class GlobalApplicationCommand<R, E> {
|
|
|
25
25
|
export const global = <
|
|
26
26
|
R,
|
|
27
27
|
E,
|
|
28
|
-
const A extends DeepReadonlyObject<
|
|
28
|
+
const A extends DeepReadonlyObject<
|
|
29
|
+
Discord.CreateGlobalApplicationCommandParams
|
|
30
|
+
>,
|
|
29
31
|
>(
|
|
30
32
|
command: A,
|
|
31
33
|
handle: CommandHandler<R, E, A>,
|
|
@@ -46,7 +48,9 @@ export class GuildApplicationCommand<R, E> {
|
|
|
46
48
|
export const guild = <
|
|
47
49
|
R,
|
|
48
50
|
E,
|
|
49
|
-
const A extends DeepReadonlyObject<
|
|
51
|
+
const A extends DeepReadonlyObject<
|
|
52
|
+
Discord.CreateGuildApplicationCommandParams
|
|
53
|
+
>,
|
|
50
54
|
>(
|
|
51
55
|
command: A,
|
|
52
56
|
handle: CommandHandler<R, E, A>,
|
|
@@ -119,12 +123,9 @@ export const autocomplete = <R1, R2, E1, E2>(
|
|
|
119
123
|
>(pred as any, handle as any)
|
|
120
124
|
|
|
121
125
|
// ==== Command handler helpers
|
|
122
|
-
type DeepReadonly<T> = T extends Array<infer R>
|
|
123
|
-
?
|
|
124
|
-
: T extends
|
|
125
|
-
? T
|
|
126
|
-
: T extends object
|
|
127
|
-
? DeepReadonlyObject<T>
|
|
126
|
+
type DeepReadonly<T> = T extends Array<infer R> ? ReadonlyArray<DeepReadonly<R>>
|
|
127
|
+
: T extends Function ? T
|
|
128
|
+
: T extends object ? DeepReadonlyObject<T>
|
|
128
129
|
: T
|
|
129
130
|
type DeepReadonlyObject<T> = {
|
|
130
131
|
readonly [P in keyof T]: DeepReadonly<T[P]>
|
|
@@ -161,29 +162,26 @@ export interface CommandHelper<A> {
|
|
|
161
162
|
>
|
|
162
163
|
|
|
163
164
|
subCommands: <
|
|
164
|
-
NER extends SubCommandNames<A> extends never
|
|
165
|
-
? never
|
|
165
|
+
NER extends SubCommandNames<A> extends never ? never
|
|
166
166
|
: Record<
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
SubCommandNames<A>,
|
|
168
|
+
Effect.Effect<any, any, Discord.InteractionResponse>
|
|
169
|
+
>,
|
|
170
170
|
>(
|
|
171
171
|
commands: NER,
|
|
172
172
|
) => Effect.Effect<
|
|
173
173
|
| Exclude<
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
>
|
|
174
|
+
[NER[keyof NER]] extends [
|
|
175
|
+
{ [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
|
|
176
|
+
] ? R
|
|
177
|
+
: never,
|
|
178
|
+
SubCommandContext
|
|
179
|
+
>
|
|
181
180
|
| Discord.Interaction
|
|
182
181
|
| Discord.ApplicationCommandDatum,
|
|
183
182
|
[NER[keyof NER]] extends [
|
|
184
183
|
{ [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
|
|
185
|
-
]
|
|
186
|
-
? E
|
|
184
|
+
] ? E
|
|
187
185
|
: never,
|
|
188
186
|
Discord.InteractionResponse
|
|
189
187
|
>
|
|
@@ -203,10 +201,9 @@ interface CommandOption {
|
|
|
203
201
|
type SubCommands<A> = A extends {
|
|
204
202
|
readonly type: Discord.ApplicationCommandOptionType.SUB_COMMAND
|
|
205
203
|
readonly options?: ReadonlyArray<CommandOption>
|
|
206
|
-
}
|
|
207
|
-
? A
|
|
204
|
+
} ? A
|
|
208
205
|
: A extends { readonly options: ReadonlyArray<CommandOption> }
|
|
209
|
-
|
|
206
|
+
? SubCommands<A["options"][number]>
|
|
210
207
|
: never
|
|
211
208
|
|
|
212
209
|
type SubCommandNames<A> = Option<SubCommands<A>>["name"]
|
|
@@ -283,20 +280,16 @@ type SubCommandResolvables<A> = Extract<
|
|
|
283
280
|
type AllResolvables<A> = Resolvables<A> | SubCommandResolvables<A>
|
|
284
281
|
|
|
285
282
|
// == Utilities
|
|
286
|
-
type StringLiteral<T> = T extends string
|
|
287
|
-
|
|
288
|
-
? never
|
|
289
|
-
: T
|
|
283
|
+
type StringLiteral<T> = T extends string ? string extends T ? never
|
|
284
|
+
: T
|
|
290
285
|
: never
|
|
291
286
|
|
|
292
287
|
type Option<A> = A extends { readonly name: infer N }
|
|
293
|
-
? N extends StringLiteral<N>
|
|
294
|
-
|
|
295
|
-
: never
|
|
288
|
+
? N extends StringLiteral<N> ? A
|
|
289
|
+
: never
|
|
296
290
|
: never
|
|
297
291
|
|
|
298
292
|
type OptionsWithLiteral<A, T> = A extends {
|
|
299
293
|
readonly options: ReadonlyArray<CommandOption>
|
|
300
|
-
}
|
|
301
|
-
? Extract<A["options"][number], Option<A["options"][number]> & T>
|
|
294
|
+
} ? Extract<A["options"][number], Option<A["options"][number]> & T>
|
|
302
295
|
: never
|
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
import type { DefinitionNotFound } from "dfx/Interactions/handlers"
|
|
19
19
|
import { handlers } from "dfx/Interactions/handlers"
|
|
20
20
|
import type { InteractionBuilder } from "dfx/Interactions/index"
|
|
21
|
-
import {
|
|
21
|
+
import { builder, Interaction } from "dfx/Interactions/index"
|
|
22
22
|
import type * as Discord from "dfx/types"
|
|
23
23
|
import * as EffectUtils from "dfx/utils/Effect"
|
|
24
24
|
|
|
@@ -29,86 +29,84 @@ export interface RunOpts {
|
|
|
29
29
|
/**
|
|
30
30
|
* @tsplus pipeable dfx/InteractionBuilder runGateway
|
|
31
31
|
*/
|
|
32
|
-
export const run =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const makeRegistry = Effect.gen(function* (_) {
|
|
32
|
+
export const run = <R, R2, E, TE, E2>(
|
|
33
|
+
postHandler: (
|
|
34
|
+
effect: Effect.Effect<
|
|
35
|
+
R | DiscordREST | Discord.Interaction,
|
|
36
|
+
TE | DiscordRESTError | DefinitionNotFound,
|
|
37
|
+
void
|
|
38
|
+
>,
|
|
39
|
+
) => Effect.Effect<R2, E2, void>,
|
|
40
|
+
{ sync = true }: RunOpts = {},
|
|
41
|
+
) =>
|
|
42
|
+
(
|
|
43
|
+
ix: InteractionBuilder<R, E, TE>,
|
|
44
|
+
): Effect.Effect<
|
|
45
|
+
DiscordREST | DiscordGateway | Exclude<R2, Discord.Interaction>,
|
|
46
|
+
E2 | DiscordRESTError | Http.ResponseDecodeError,
|
|
47
|
+
never
|
|
48
|
+
> =>
|
|
49
|
+
Effect.gen(function*(_) {
|
|
50
|
+
const GlobalApplicationCommand = ix.definitions.pipe(
|
|
51
|
+
Chunk.map(_ => _[0]),
|
|
52
|
+
Chunk.filter(
|
|
53
|
+
(_): _ is GlobalApplicationCommand<R, E> =>
|
|
54
|
+
_._tag === "GlobalApplicationCommand",
|
|
55
|
+
),
|
|
56
|
+
Chunk.toReadonlyArray,
|
|
57
|
+
)
|
|
58
|
+
const GuildApplicationCommand = ix.definitions.pipe(
|
|
59
|
+
Chunk.map(_ => _[0]),
|
|
60
|
+
Chunk.filter(
|
|
61
|
+
(_): _ is GuildApplicationCommand<R, E> =>
|
|
62
|
+
_._tag === "GuildApplicationCommand",
|
|
63
|
+
),
|
|
64
|
+
Chunk.toReadonlyArray,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
const gateway = yield* _(DiscordGateway)
|
|
68
|
+
const rest = yield* _(DiscordREST)
|
|
69
|
+
|
|
70
|
+
const application = yield* _(
|
|
71
|
+
rest.getCurrentBotApplicationInformation(),
|
|
72
|
+
Effect.flatMap(a => a.json),
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
const globalSync = rest.bulkOverwriteGlobalApplicationCommands(
|
|
76
|
+
application.id,
|
|
77
|
+
{ body: Http.body.json(GlobalApplicationCommand.map(_ => _.command)) },
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
const guildSync = GuildApplicationCommand.length
|
|
81
|
+
? gateway.handleDispatch("GUILD_CREATE", a =>
|
|
82
|
+
rest.bulkOverwriteGuildApplicationCommands(
|
|
83
|
+
application.id,
|
|
84
|
+
a.id,
|
|
85
|
+
GuildApplicationCommand.map(_ =>
|
|
86
|
+
_.command
|
|
87
|
+
) as any,
|
|
88
|
+
))
|
|
89
|
+
: Effect.never
|
|
90
|
+
|
|
91
|
+
const handle = handlers(ix.definitions, (i, r) =>
|
|
92
|
+
rest.createInteractionResponse(i.id, i.token, r))
|
|
93
|
+
|
|
94
|
+
const run = gateway.handleDispatch("INTERACTION_CREATE", i =>
|
|
95
|
+
Effect.provideService(postHandler(handle[i.type](i)), Interaction, i))
|
|
96
|
+
|
|
97
|
+
return yield* _(
|
|
98
|
+
sync
|
|
99
|
+
? Effect.forever(
|
|
100
|
+
Effect.all([run, globalSync, guildSync], {
|
|
101
|
+
concurrency: "unbounded",
|
|
102
|
+
discard: true,
|
|
103
|
+
}),
|
|
104
|
+
)
|
|
105
|
+
: run,
|
|
106
|
+
)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const makeRegistry = Effect.gen(function*(_) {
|
|
112
110
|
const ref = yield* _(
|
|
113
111
|
Ref.make(builder as InteractionBuilder<never, never, never>),
|
|
114
112
|
)
|
|
@@ -132,8 +130,7 @@ const makeRegistry = Effect.gen(function* (_) {
|
|
|
132
130
|
Effect.delay(
|
|
133
131
|
pipe(ix, run(Effect.catchAllCause(onError), opts)),
|
|
134
132
|
Duration.seconds(0.1),
|
|
135
|
-
)
|
|
136
|
-
)
|
|
133
|
+
))
|
|
137
134
|
|
|
138
135
|
return { register, run: run_ } as const
|
|
139
136
|
})
|