dfx 0.110.1 → 0.111.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/DiscordGateway/Shard.d.ts +1 -1
- package/DiscordGateway/Sharder.d.ts +1 -1
- package/Helpers/interactions.d.ts +4 -0
- package/Helpers/interactions.d.ts.map +1 -1
- package/Helpers/interactions.js +13 -2
- package/Helpers/interactions.js.map +1 -1
- package/Interactions/commandHelper.d.ts +99 -0
- package/Interactions/commandHelper.d.ts.map +1 -0
- package/Interactions/commandHelper.js +54 -0
- package/Interactions/commandHelper.js.map +1 -0
- package/Interactions/context.d.ts +4 -18
- package/Interactions/context.d.ts.map +1 -1
- package/Interactions/context.js +1 -19
- package/Interactions/context.js.map +1 -1
- package/Interactions/definitions.d.ts +2 -79
- package/Interactions/definitions.d.ts.map +1 -1
- package/Interactions/definitions.js.map +1 -1
- package/Interactions/utils.d.ts.map +1 -1
- package/Interactions/utils.js +2 -9
- package/Interactions/utils.js.map +1 -1
- package/mjs/Helpers/interactions.mjs +10 -0
- package/mjs/Helpers/interactions.mjs.map +1 -1
- package/mjs/Interactions/commandHelper.mjs +45 -0
- package/mjs/Interactions/commandHelper.mjs.map +1 -0
- package/mjs/Interactions/context.mjs +0 -14
- package/mjs/Interactions/context.mjs.map +1 -1
- package/mjs/Interactions/definitions.mjs.map +1 -1
- package/mjs/Interactions/utils.mjs +2 -9
- package/mjs/Interactions/utils.mjs.map +1 -1
- package/mjs/version.mjs +1 -1
- package/package.json +2 -2
- package/src/Helpers/interactions.ts +22 -0
- package/src/Interactions/commandHelper.ts +236 -0
- package/src/Interactions/context.ts +3 -72
- package/src/Interactions/definitions.ts +1 -166
- package/src/Interactions/utils.ts +2 -10
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type * as Option from "effect/Option"
|
|
2
1
|
import type * as Effect from "effect/Effect"
|
|
3
2
|
import type {
|
|
4
3
|
DiscordApplicationCommand,
|
|
@@ -6,11 +5,10 @@ import type {
|
|
|
6
5
|
DiscordInteraction,
|
|
7
6
|
DiscordMessageComponent,
|
|
8
7
|
DiscordModalSubmit,
|
|
9
|
-
SubCommandContext,
|
|
10
8
|
} from "dfx/Interactions/context"
|
|
11
9
|
import type * as Discord from "dfx/types"
|
|
12
|
-
import type { NoSuchElementException } from "effect/Cause"
|
|
13
10
|
import type { Scope } from "effect/Scope"
|
|
11
|
+
import type { CommandHelper } from "./commandHelper"
|
|
14
12
|
|
|
15
13
|
export type InteractionDefinition<R, E> =
|
|
16
14
|
| GlobalApplicationCommand<R, E>
|
|
@@ -129,169 +127,6 @@ export type CommandHandler<R, E, A = any> =
|
|
|
129
127
|
| Effect.Effect<Discord.InteractionResponse, E, R>
|
|
130
128
|
| CommandHandlerFn<R, E, A>
|
|
131
129
|
|
|
132
|
-
export interface CommandHelper<A> {
|
|
133
|
-
resolve: <T>(
|
|
134
|
-
name: AllResolvables<A>["name"],
|
|
135
|
-
f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => T | undefined,
|
|
136
|
-
) => Effect.Effect<T, NoSuchElementException, DiscordInteraction>
|
|
137
|
-
|
|
138
|
-
option: (
|
|
139
|
-
name: AllCommandOptions<A>["name"],
|
|
140
|
-
) => Effect.Effect<
|
|
141
|
-
Option.Option<Discord.ApplicationCommandInteractionDataOption>,
|
|
142
|
-
never,
|
|
143
|
-
DiscordApplicationCommand
|
|
144
|
-
>
|
|
145
|
-
|
|
146
|
-
optionValue: <N extends AllRequiredCommandOptions<A>["name"]>(
|
|
147
|
-
name: N,
|
|
148
|
-
) => Effect.Effect<CommandValue<A, N>, never, DiscordApplicationCommand>
|
|
149
|
-
|
|
150
|
-
optionValueOptional: <N extends AllCommandOptions<A>["name"]>(
|
|
151
|
-
name: N,
|
|
152
|
-
) => Effect.Effect<
|
|
153
|
-
Option.Option<CommandValue<A, N>>,
|
|
154
|
-
never,
|
|
155
|
-
DiscordApplicationCommand
|
|
156
|
-
>
|
|
157
|
-
|
|
158
|
-
subCommands: <
|
|
159
|
-
NER extends SubCommandNames<A> extends never
|
|
160
|
-
? never
|
|
161
|
-
: Record<
|
|
162
|
-
SubCommandNames<A>,
|
|
163
|
-
Effect.Effect<Discord.InteractionResponse, any, any>
|
|
164
|
-
>,
|
|
165
|
-
>(
|
|
166
|
-
commands: NER,
|
|
167
|
-
) => Effect.Effect<
|
|
168
|
-
Discord.InteractionResponse,
|
|
169
|
-
[NER[keyof NER]] extends [
|
|
170
|
-
{ [Effect.EffectTypeId]: { _E: (_: never) => infer E } },
|
|
171
|
-
]
|
|
172
|
-
? E
|
|
173
|
-
: never,
|
|
174
|
-
| Exclude<
|
|
175
|
-
[NER[keyof NER]] extends [
|
|
176
|
-
{ [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
|
|
177
|
-
]
|
|
178
|
-
? R
|
|
179
|
-
: never,
|
|
180
|
-
SubCommandContext
|
|
181
|
-
>
|
|
182
|
-
| DiscordInteraction
|
|
183
|
-
| DiscordApplicationCommand
|
|
184
|
-
>
|
|
185
|
-
}
|
|
186
|
-
|
|
187
130
|
export type CommandHandlerFn<R, E, A> = (
|
|
188
131
|
i: CommandHelper<A>,
|
|
189
132
|
) => Effect.Effect<Discord.InteractionResponse, E, R>
|
|
190
|
-
|
|
191
|
-
interface CommandOption {
|
|
192
|
-
readonly type: any
|
|
193
|
-
readonly name: string
|
|
194
|
-
readonly options?: ReadonlyArray<CommandOption>
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// == Sub commands
|
|
198
|
-
type SubCommands<A> = A extends {
|
|
199
|
-
readonly type: Discord.ApplicationCommandOptionType.SUB_COMMAND
|
|
200
|
-
readonly options?: ReadonlyArray<CommandOption>
|
|
201
|
-
}
|
|
202
|
-
? A
|
|
203
|
-
: A extends { readonly options: ReadonlyArray<CommandOption> }
|
|
204
|
-
? SubCommands<A["options"][number]>
|
|
205
|
-
: never
|
|
206
|
-
|
|
207
|
-
type SubCommandNames<A> = Option<SubCommands<A>>["name"]
|
|
208
|
-
|
|
209
|
-
// == Command options
|
|
210
|
-
type CommandOptionType = Exclude<
|
|
211
|
-
Discord.ApplicationCommandOptionType,
|
|
212
|
-
| Discord.ApplicationCommandOptionType.SUB_COMMAND
|
|
213
|
-
| Discord.ApplicationCommandOptionType.SUB_COMMAND_GROUP
|
|
214
|
-
>
|
|
215
|
-
|
|
216
|
-
type CommandOptions<A> = OptionsWithLiteral<
|
|
217
|
-
A,
|
|
218
|
-
{
|
|
219
|
-
readonly type: CommandOptionType
|
|
220
|
-
}
|
|
221
|
-
>
|
|
222
|
-
|
|
223
|
-
type SubCommandOptions<A> = Extract<
|
|
224
|
-
Option<Exclude<SubCommands<A>["options"], undefined>[number]>,
|
|
225
|
-
{
|
|
226
|
-
readonly type: CommandOptionType
|
|
227
|
-
}
|
|
228
|
-
>
|
|
229
|
-
|
|
230
|
-
type AllCommandOptions<A> = CommandOptions<A> | SubCommandOptions<A>
|
|
231
|
-
|
|
232
|
-
type CommandWithName<A, N> = Extract<AllCommandOptions<A>, { readonly name: N }>
|
|
233
|
-
|
|
234
|
-
type OptionTypeValue = {
|
|
235
|
-
[Discord.ApplicationCommandOptionType.BOOLEAN]: boolean
|
|
236
|
-
[Discord.ApplicationCommandOptionType.INTEGER]: number
|
|
237
|
-
[Discord.ApplicationCommandOptionType.NUMBER]: number
|
|
238
|
-
}
|
|
239
|
-
type CommandValue<A, N> = CommandWithName<
|
|
240
|
-
A,
|
|
241
|
-
N
|
|
242
|
-
>["type"] extends keyof OptionTypeValue
|
|
243
|
-
? OptionTypeValue[CommandWithName<A, N>["type"]]
|
|
244
|
-
: string
|
|
245
|
-
|
|
246
|
-
// == Required options
|
|
247
|
-
type RequiredCommandOptions<A> = OptionsWithLiteral<
|
|
248
|
-
A,
|
|
249
|
-
{
|
|
250
|
-
readonly type: CommandOptionType
|
|
251
|
-
readonly required: true
|
|
252
|
-
}
|
|
253
|
-
>
|
|
254
|
-
|
|
255
|
-
type RequiredSubCommandOptions<A> = Extract<
|
|
256
|
-
SubCommandOptions<A>,
|
|
257
|
-
{ readonly required: true }
|
|
258
|
-
>
|
|
259
|
-
|
|
260
|
-
type AllRequiredCommandOptions<A> =
|
|
261
|
-
| RequiredCommandOptions<A>
|
|
262
|
-
| RequiredSubCommandOptions<A>
|
|
263
|
-
|
|
264
|
-
// == Resolveables
|
|
265
|
-
type ResolvableType =
|
|
266
|
-
| Discord.ApplicationCommandOptionType.ROLE
|
|
267
|
-
| Discord.ApplicationCommandOptionType.USER
|
|
268
|
-
| Discord.ApplicationCommandOptionType.MENTIONABLE
|
|
269
|
-
| Discord.ApplicationCommandOptionType.CHANNEL
|
|
270
|
-
|
|
271
|
-
type Resolvables<A> = OptionsWithLiteral<A, { readonly type: ResolvableType }>
|
|
272
|
-
type SubCommandResolvables<A> = Extract<
|
|
273
|
-
Option<Exclude<SubCommands<A>["options"], undefined>[number]>,
|
|
274
|
-
{
|
|
275
|
-
readonly type: ResolvableType
|
|
276
|
-
}
|
|
277
|
-
>
|
|
278
|
-
type AllResolvables<A> = Resolvables<A> | SubCommandResolvables<A>
|
|
279
|
-
|
|
280
|
-
// == Utilities
|
|
281
|
-
type StringLiteral<T> = T extends string
|
|
282
|
-
? string extends T
|
|
283
|
-
? never
|
|
284
|
-
: T
|
|
285
|
-
: never
|
|
286
|
-
|
|
287
|
-
type Option<A> = A extends { readonly name: infer N }
|
|
288
|
-
? N extends StringLiteral<N>
|
|
289
|
-
? A
|
|
290
|
-
: never
|
|
291
|
-
: never
|
|
292
|
-
|
|
293
|
-
type OptionsWithLiteral<A, T> = A extends {
|
|
294
|
-
readonly options: ReadonlyArray<CommandOption>
|
|
295
|
-
}
|
|
296
|
-
? Extract<A["options"][number], Option<A["options"][number]> & T>
|
|
297
|
-
: never
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as Chunk from "effect/Chunk"
|
|
2
2
|
import * as Effect from "effect/Effect"
|
|
3
|
-
import * as Ctx from "dfx/Interactions/context"
|
|
4
3
|
import type * as D from "dfx/Interactions/definitions"
|
|
5
4
|
import type * as Discord from "dfx/types"
|
|
6
5
|
import * as Array from "effect/Array"
|
|
6
|
+
import { CommandHelper } from "./commandHelper"
|
|
7
7
|
|
|
8
8
|
export type DefinitionFlattened<R, E, TE, A> =
|
|
9
9
|
D.InteractionDefinition<R, E> extends infer D
|
|
@@ -19,14 +19,6 @@ export type DefinitionFlattenedCommand<R, E, TE, A> = Extract<
|
|
|
19
19
|
{ _tag: "GlobalApplicationCommand" | "GuildApplicationCommand" }
|
|
20
20
|
>
|
|
21
21
|
|
|
22
|
-
const context: D.CommandHelper<any> = {
|
|
23
|
-
resolve: Ctx.resolved,
|
|
24
|
-
option: Ctx.option,
|
|
25
|
-
optionValue: Ctx.optionValue,
|
|
26
|
-
optionValueOptional: Ctx.optionValueOptional,
|
|
27
|
-
subCommands: Ctx.handleSubCommands,
|
|
28
|
-
} as any
|
|
29
|
-
|
|
30
22
|
export const flattenDefinitions = <R, E, TE, A, B>(
|
|
31
23
|
definitions: Chunk.Chunk<
|
|
32
24
|
readonly [
|
|
@@ -59,7 +51,7 @@ export const flattenDefinitions = <R, E, TE, A, B>(
|
|
|
59
51
|
definition.handle as (
|
|
60
52
|
_: any,
|
|
61
53
|
) => Effect.Effect<Discord.InteractionResponse>
|
|
62
|
-
)(
|
|
54
|
+
)(new CommandHelper(i)),
|
|
63
55
|
_ => handleResponse(i, _),
|
|
64
56
|
),
|
|
65
57
|
),
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "0.
|
|
1
|
+
export const LIB_VERSION = "0.111.0";
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const LIB_VERSION = "0.
|
|
1
|
+
export declare const LIB_VERSION = "0.111.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED