dfx 0.60.0 → 0.61.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.
Files changed (199) hide show
  1. package/Cache/driver.d.ts +1 -1
  2. package/Cache/driver.d.ts.map +1 -1
  3. package/Cache/memory.js +2 -2
  4. package/Cache/memory.js.map +1 -1
  5. package/Cache/memoryTTL.d.ts.map +1 -1
  6. package/Cache/memoryTTL.js.map +1 -1
  7. package/Cache/prelude.d.ts +7 -7
  8. package/Cache/prelude.d.ts.map +1 -1
  9. package/Cache/prelude.js.map +1 -1
  10. package/Cache.d.ts +1 -1
  11. package/Cache.d.ts.map +1 -1
  12. package/Cache.js +1 -1
  13. package/Cache.js.map +1 -1
  14. package/DiscordGateway/DiscordWS.d.ts +5 -5
  15. package/DiscordGateway/DiscordWS.d.ts.map +1 -1
  16. package/DiscordGateway/DiscordWS.js +2 -2
  17. package/DiscordGateway/DiscordWS.js.map +1 -1
  18. package/DiscordGateway/Shard/heartbeats.js.map +1 -1
  19. package/DiscordGateway/Shard/utils.d.ts +1 -1
  20. package/DiscordGateway/Shard/utils.d.ts.map +1 -1
  21. package/DiscordGateway/Shard/utils.js.map +1 -1
  22. package/DiscordGateway/Shard.d.ts +8 -8
  23. package/DiscordGateway/Shard.d.ts.map +1 -1
  24. package/DiscordGateway/Shard.js +11 -11
  25. package/DiscordGateway/Shard.js.map +1 -1
  26. package/DiscordGateway/ShardStore.d.ts +2 -2
  27. package/DiscordGateway/ShardStore.d.ts.map +1 -1
  28. package/DiscordGateway/ShardStore.js +2 -2
  29. package/DiscordGateway/ShardStore.js.map +1 -1
  30. package/DiscordGateway/Sharder.d.ts +2 -2
  31. package/DiscordGateway/Sharder.js.map +1 -1
  32. package/DiscordGateway/WS.d.ts +4 -4
  33. package/DiscordGateway/WS.d.ts.map +1 -1
  34. package/DiscordGateway/WS.js +6 -6
  35. package/DiscordGateway/WS.js.map +1 -1
  36. package/DiscordGateway.d.ts +1 -1
  37. package/DiscordGateway.d.ts.map +1 -1
  38. package/DiscordGateway.js.map +1 -1
  39. package/DiscordREST/types.d.ts +4 -4
  40. package/DiscordREST/types.d.ts.map +1 -1
  41. package/DiscordREST/utils.d.ts +5 -4
  42. package/DiscordREST/utils.d.ts.map +1 -1
  43. package/DiscordREST/utils.js +4 -3
  44. package/DiscordREST/utils.js.map +1 -1
  45. package/DiscordREST.d.ts +6 -7
  46. package/DiscordREST.d.ts.map +1 -1
  47. package/DiscordREST.js +12 -18
  48. package/DiscordREST.js.map +1 -1
  49. package/Helpers/flags.d.ts.map +1 -1
  50. package/Helpers/flags.js.map +1 -1
  51. package/Helpers/intents.d.ts.map +1 -1
  52. package/Helpers/intents.js.map +1 -1
  53. package/Helpers/interactions.d.ts +1 -1
  54. package/Helpers/interactions.d.ts.map +1 -1
  55. package/Helpers/interactions.js +2 -2
  56. package/Helpers/interactions.js.map +1 -1
  57. package/Helpers/members.d.ts.map +1 -1
  58. package/Helpers/members.js.map +1 -1
  59. package/Helpers/permissions.js.map +1 -1
  60. package/Interactions/builder.d.ts +3 -3
  61. package/Interactions/builder.d.ts.map +1 -1
  62. package/Interactions/builder.js +1 -1
  63. package/Interactions/builder.js.map +1 -1
  64. package/Interactions/context.d.ts +1 -1
  65. package/Interactions/context.d.ts.map +1 -1
  66. package/Interactions/context.js.map +1 -1
  67. package/Interactions/definitions.d.ts +3 -3
  68. package/Interactions/definitions.d.ts.map +1 -1
  69. package/Interactions/definitions.js.map +1 -1
  70. package/Interactions/gateway.d.ts +3 -3
  71. package/Interactions/gateway.d.ts.map +1 -1
  72. package/Interactions/gateway.js +1 -1
  73. package/Interactions/gateway.js.map +1 -1
  74. package/Interactions/handlers.d.ts.map +1 -1
  75. package/Interactions/handlers.js.map +1 -1
  76. package/Interactions/index.d.ts +1 -1
  77. package/Interactions/index.d.ts.map +1 -1
  78. package/Interactions/index.js.map +1 -1
  79. package/Interactions/utils.d.ts.map +1 -1
  80. package/Interactions/utils.js.map +1 -1
  81. package/Interactions/webhook.d.ts.map +1 -1
  82. package/Interactions/webhook.js.map +1 -1
  83. package/LICENSE +21 -0
  84. package/Log.d.ts +1 -1
  85. package/Log.d.ts.map +1 -1
  86. package/Log.js +1 -1
  87. package/Log.js.map +1 -1
  88. package/RateLimit.d.ts +2 -2
  89. package/RateLimit.d.ts.map +1 -1
  90. package/RateLimit.js.map +1 -1
  91. package/gateway.d.ts +2 -4
  92. package/gateway.d.ts.map +1 -1
  93. package/gateway.js +3 -6
  94. package/gateway.js.map +1 -1
  95. package/index.d.ts +2 -3
  96. package/index.d.ts.map +1 -1
  97. package/index.js +1 -3
  98. package/index.js.map +1 -1
  99. package/mjs/Cache/memory.mjs +2 -2
  100. package/mjs/Cache/memory.mjs.map +1 -1
  101. package/mjs/Cache/memoryTTL.mjs.map +1 -1
  102. package/mjs/Cache/prelude.mjs.map +1 -1
  103. package/mjs/Cache.mjs +1 -1
  104. package/mjs/Cache.mjs.map +1 -1
  105. package/mjs/DiscordGateway/DiscordWS.mjs +2 -2
  106. package/mjs/DiscordGateway/DiscordWS.mjs.map +1 -1
  107. package/mjs/DiscordGateway/Shard/heartbeats.mjs.map +1 -1
  108. package/mjs/DiscordGateway/Shard/utils.mjs.map +1 -1
  109. package/mjs/DiscordGateway/Shard.mjs +11 -11
  110. package/mjs/DiscordGateway/Shard.mjs.map +1 -1
  111. package/mjs/DiscordGateway/ShardStore.mjs +2 -2
  112. package/mjs/DiscordGateway/ShardStore.mjs.map +1 -1
  113. package/mjs/DiscordGateway/Sharder.mjs.map +1 -1
  114. package/mjs/DiscordGateway/WS.mjs +5 -5
  115. package/mjs/DiscordGateway/WS.mjs.map +1 -1
  116. package/mjs/DiscordGateway.mjs.map +1 -1
  117. package/mjs/DiscordREST/utils.mjs +4 -3
  118. package/mjs/DiscordREST/utils.mjs.map +1 -1
  119. package/mjs/DiscordREST.mjs +13 -14
  120. package/mjs/DiscordREST.mjs.map +1 -1
  121. package/mjs/Helpers/flags.mjs.map +1 -1
  122. package/mjs/Helpers/intents.mjs.map +1 -1
  123. package/mjs/Helpers/interactions.mjs +2 -2
  124. package/mjs/Helpers/interactions.mjs.map +1 -1
  125. package/mjs/Helpers/members.mjs.map +1 -1
  126. package/mjs/Helpers/permissions.mjs.map +1 -1
  127. package/mjs/Interactions/builder.mjs +1 -1
  128. package/mjs/Interactions/builder.mjs.map +1 -1
  129. package/mjs/Interactions/context.mjs.map +1 -1
  130. package/mjs/Interactions/definitions.mjs.map +1 -1
  131. package/mjs/Interactions/gateway.mjs +2 -2
  132. package/mjs/Interactions/gateway.mjs.map +1 -1
  133. package/mjs/Interactions/handlers.mjs.map +1 -1
  134. package/mjs/Interactions/index.mjs.map +1 -1
  135. package/mjs/Interactions/utils.mjs.map +1 -1
  136. package/mjs/Interactions/webhook.mjs.map +1 -1
  137. package/mjs/Log.mjs +1 -1
  138. package/mjs/Log.mjs.map +1 -1
  139. package/mjs/RateLimit.mjs.map +1 -1
  140. package/mjs/gateway.mjs +2 -4
  141. package/mjs/gateway.mjs.map +1 -1
  142. package/mjs/index.mjs +2 -3
  143. package/mjs/index.mjs.map +1 -1
  144. package/mjs/types.mjs.map +1 -1
  145. package/mjs/utils/Effect.mjs +4 -4
  146. package/mjs/utils/Effect.mjs.map +1 -1
  147. package/mjs/version.mjs +1 -1
  148. package/mjs/webhooks.mjs +3 -12
  149. package/mjs/webhooks.mjs.map +1 -1
  150. package/package.json +32 -26
  151. package/src/Cache/driver.ts +1 -1
  152. package/src/Cache/memory.ts +2 -2
  153. package/src/Cache/memoryTTL.ts +6 -4
  154. package/src/Cache/prelude.ts +15 -13
  155. package/src/Cache.ts +3 -3
  156. package/src/DiscordGateway/DiscordWS.ts +9 -10
  157. package/src/DiscordGateway/Shard/heartbeats.ts +1 -1
  158. package/src/DiscordGateway/Shard/utils.ts +10 -12
  159. package/src/DiscordGateway/Shard.ts +23 -24
  160. package/src/DiscordGateway/ShardStore.ts +2 -2
  161. package/src/DiscordGateway/Sharder.ts +7 -7
  162. package/src/DiscordGateway/WS.ts +10 -10
  163. package/src/DiscordGateway.ts +8 -9
  164. package/src/DiscordREST/types.ts +4 -4
  165. package/src/DiscordREST/utils.ts +12 -8
  166. package/src/DiscordREST.ts +60 -53
  167. package/src/Helpers/flags.ts +2 -4
  168. package/src/Helpers/intents.ts +3 -4
  169. package/src/Helpers/interactions.ts +53 -56
  170. package/src/Helpers/members.ts +2 -2
  171. package/src/Helpers/permissions.ts +2 -2
  172. package/src/Interactions/builder.ts +22 -20
  173. package/src/Interactions/context.ts +16 -23
  174. package/src/Interactions/definitions.ts +27 -34
  175. package/src/Interactions/gateway.ts +82 -85
  176. package/src/Interactions/handlers.ts +34 -35
  177. package/src/Interactions/index.ts +17 -21
  178. package/src/Interactions/utils.ts +13 -17
  179. package/src/Interactions/webhook.ts +19 -15
  180. package/src/Log.ts +3 -3
  181. package/src/RateLimit.ts +5 -4
  182. package/src/gateway.ts +4 -19
  183. package/src/index.ts +1 -3
  184. package/src/types.ts +50 -26
  185. package/src/utils/Effect.ts +16 -17
  186. package/src/version.ts +1 -1
  187. package/src/webhooks.ts +21 -34
  188. package/tsconfig.tsbuildinfo +1 -0
  189. package/types.d.ts.map +1 -1
  190. package/types.js.map +1 -1
  191. package/utils/Effect.d.ts.map +1 -1
  192. package/utils/Effect.js +4 -4
  193. package/utils/Effect.js.map +1 -1
  194. package/version.d.ts +1 -1
  195. package/version.js +1 -1
  196. package/webhooks.d.ts +3 -5
  197. package/webhooks.d.ts.map +1 -1
  198. package/webhooks.js +4 -14
  199. package/webhooks.js.map +1 -1
@@ -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<Discord.CreateGlobalApplicationCommandParams>,
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<Discord.CreateGuildApplicationCommandParams>,
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
- ? ReadonlyArray<DeepReadonly<R>>
124
- : T extends Function
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
- SubCommandNames<A>,
168
- Effect.Effect<any, any, Discord.InteractionResponse>
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
- [NER[keyof NER]] extends [
175
- { [Effect.EffectTypeId]: { _R: (_: never) => infer R } },
176
- ]
177
- ? R
178
- : never,
179
- SubCommandContext
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
- ? SubCommands<A["options"][number]>
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
- ? string extends T
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
- ? A
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
@@ -1,4 +1,3 @@
1
- import * as Http from "@effect-http/client"
2
1
  import * as Chunk from "@effect/data/Chunk"
3
2
  import { Tag } from "@effect/data/Context"
4
3
  import * as Duration from "@effect/data/Duration"
@@ -8,6 +7,7 @@ import * as Effect from "@effect/io/Effect"
8
7
  import * as Layer from "@effect/io/Layer"
9
8
  import * as Queue from "@effect/io/Queue"
10
9
  import * as Ref from "@effect/io/Ref"
10
+ import * as Http from "@effect/platform/HttpClient"
11
11
  import { DiscordGateway } from "dfx/DiscordGateway"
12
12
  import type { DiscordRESTError } from "dfx/DiscordREST"
13
13
  import { DiscordREST } from "dfx/DiscordREST"
@@ -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 { Interaction, builder } from "dfx/Interactions/index"
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
- <R, R2, E, TE, E2>(
34
- postHandler: (
35
- effect: Effect.Effect<
36
- R | DiscordREST | Discord.Interaction,
37
- TE | DiscordRESTError | DefinitionNotFound,
38
- void
39
- >,
40
- ) => Effect.Effect<R2, E2, void>,
41
- { sync = true }: RunOpts = {},
42
- ) =>
43
- (
44
- ix: InteractionBuilder<R, E, TE>,
45
- ): Effect.Effect<
46
- DiscordREST | DiscordGateway | Exclude<R2, Discord.Interaction>,
47
- E2 | DiscordRESTError | Http.ResponseDecodeError,
48
- never
49
- > =>
50
- Effect.gen(function* (_) {
51
- const GlobalApplicationCommand = ix.definitions.pipe(
52
- Chunk.map(_ => _[0]),
53
- Chunk.filter(
54
- (_): _ is GlobalApplicationCommand<R, E> =>
55
- _._tag === "GlobalApplicationCommand",
56
- ),
57
- Chunk.toReadonlyArray,
58
- )
59
- const GuildApplicationCommand = ix.definitions.pipe(
60
- Chunk.map(_ => _[0]),
61
- Chunk.filter(
62
- (_): _ is GuildApplicationCommand<R, E> =>
63
- _._tag === "GuildApplicationCommand",
64
- ),
65
- Chunk.toReadonlyArray,
66
- )
67
-
68
- const gateway = yield* _(DiscordGateway)
69
- const rest = yield* _(DiscordREST)
70
-
71
- const application = yield* _(
72
- rest.getCurrentBotApplicationInformation(),
73
- Effect.flatMap(a => a.json),
74
- )
75
-
76
- const globalSync = rest.bulkOverwriteGlobalApplicationCommands(
77
- application.id,
78
- { body: Http.body.json(GlobalApplicationCommand.map(_ => _.command)) },
79
- )
80
-
81
- const guildSync = GuildApplicationCommand.length
82
- ? gateway.handleDispatch("GUILD_CREATE", a =>
83
- rest.bulkOverwriteGuildApplicationCommands(
84
- application.id,
85
- a.id,
86
- GuildApplicationCommand.map(_ => _.command) as any,
87
- ),
88
- )
89
- : Effect.never
90
-
91
- const handle = handlers(ix.definitions, (i, r) =>
92
- rest.createInteractionResponse(i.id, i.token, r),
93
- )
94
-
95
- const run = gateway.handleDispatch("INTERACTION_CREATE", i =>
96
- Effect.provideService(postHandler(handle[i.type](i)), Interaction, i),
97
- )
98
-
99
- return yield* _(
100
- sync
101
- ? Effect.forever(
102
- Effect.all([run, globalSync, guildSync], {
103
- concurrency: "unbounded",
104
- discard: true,
105
- }),
106
- )
107
- : run,
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.error.ResponseError,
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
  })
@@ -150,7 +147,7 @@ export interface InteractionsRegistry {
150
147
  opts?: RunOpts,
151
148
  ) => Effect.Effect<
152
149
  DiscordREST | DiscordGateway | Exclude<R, Discord.Interaction>,
153
- DiscordRESTError | Http.ResponseDecodeError | E,
150
+ DiscordRESTError | Http.error.ResponseError | E,
154
151
  never
155
152
  >
156
153
  }
@@ -61,28 +61,28 @@ export const handlers = <R, E, TE, A, B>(
61
61
  [Discord.InteractionType.MODAL_SUBMIT]: i => {
62
62
  const data = i.data as Discord.ModalSubmitDatum
63
63
 
64
- return Effect.findFirst(ModalSubmit, _ =>
65
- _.predicate(data.custom_id),
66
- ).pipe(
67
- Effect.flatMap(
68
- Option.match({
69
- onNone: () => Effect.fail(new DefinitionNotFound(i)),
70
- onSome: match =>
71
- Effect.provideService(
72
- match.handle(i),
73
- Ctx.ModalSubmitData,
74
- data,
75
- ) as Handler<R, E, B>,
76
- }),
77
- ),
78
- )
64
+ return Effect.findFirst(ModalSubmit, _ => _.predicate(data.custom_id))
65
+ .pipe(
66
+ Effect.flatMap(
67
+ Option.match({
68
+ onNone: () => Effect.fail(new DefinitionNotFound(i)),
69
+ onSome: match =>
70
+ Effect.provideService(
71
+ match.handle(i),
72
+ Ctx.ModalSubmitData,
73
+ data,
74
+ ) as Handler<R, E, B>,
75
+ }),
76
+ ),
77
+ )
79
78
  },
80
79
 
81
80
  [Discord.InteractionType.MESSAGE_COMPONENT]: i => {
82
81
  const data = i.data as Discord.MessageComponentDatum
83
82
 
84
- return Effect.findFirst(MessageComponent, _ =>
85
- _.predicate(data.custom_id),
83
+ return Effect.findFirst(
84
+ MessageComponent,
85
+ _ => _.predicate(data.custom_id),
86
86
  ).pipe(
87
87
  Effect.flatMap(
88
88
  Option.match({
@@ -104,25 +104,24 @@ export const handlers = <R, E, TE, A, B>(
104
104
  return Option.match(IxHelpers.focusedOption(data), {
105
105
  onNone: () => Effect.fail(new DefinitionNotFound(i)),
106
106
  onSome: focusedOption =>
107
- Effect.findFirst(Autocomplete, _ =>
108
- _.predicate(data, focusedOption),
109
- ).pipe(
110
- Effect.flatMap(
111
- Option.match({
112
- onNone: () => Effect.fail(new DefinitionNotFound(i)),
113
- onSome: match =>
114
- Effect.provideService(
115
- match.handle(i),
116
- Ctx.ApplicationCommand,
117
- data,
118
- ).pipe(
119
- Effect.provideService(Ctx.FocusedOptionContext, {
120
- focusedOption,
121
- }),
122
- ) as Handler<R, E, B>,
123
- }),
107
+ Effect.findFirst(Autocomplete, _ => _.predicate(data, focusedOption))
108
+ .pipe(
109
+ Effect.flatMap(
110
+ Option.match({
111
+ onNone: () => Effect.fail(new DefinitionNotFound(i)),
112
+ onSome: match =>
113
+ Effect.provideService(
114
+ match.handle(i),
115
+ Ctx.ApplicationCommand,
116
+ data,
117
+ ).pipe(
118
+ Effect.provideService(Ctx.FocusedOptionContext, {
119
+ focusedOption,
120
+ }),
121
+ ) as Handler<R, E, B>,
122
+ }),
123
+ ),
124
124
  ),
125
- ),
126
125
  })
127
126
  },
128
127
  }
@@ -5,10 +5,10 @@ export { response } from "dfx/Helpers/interactions"
5
5
  export * from "dfx/Interactions/builder"
6
6
  export * from "dfx/Interactions/context"
7
7
  export {
8
- InteractionDefinition,
9
8
  autocomplete,
10
9
  global,
11
10
  guild,
11
+ InteractionDefinition,
12
12
  messageComponent,
13
13
  modalSubmit,
14
14
  } from "dfx/Interactions/definitions"
@@ -23,24 +23,20 @@ export const idStartsWith = (query: string) => (customId: string) =>
23
23
  export const idRegex = (query: RegExp) => (customId: string) =>
24
24
  Effect.succeed(query.test(customId))
25
25
 
26
- export const option =
27
- (command: string, optionName: string) =>
28
- (
29
- data: Pick<Discord.ApplicationCommandDatum, "name">,
30
- focusedOption: Pick<
31
- Discord.ApplicationCommandInteractionDataOption,
32
- "name"
33
- >,
34
- ) =>
35
- Effect.succeed(data.name === command && focusedOption.name === optionName)
26
+ export const option = (command: string, optionName: string) =>
27
+ (
28
+ data: Pick<Discord.ApplicationCommandDatum, "name">,
29
+ focusedOption: Pick<
30
+ Discord.ApplicationCommandInteractionDataOption,
31
+ "name"
32
+ >,
33
+ ) => Effect.succeed(data.name === command && focusedOption.name === optionName)
36
34
 
37
- export const optionOnly =
38
- (optionName: string) =>
39
- (
40
- _: unknown,
41
- focusedOption: Pick<
42
- Discord.ApplicationCommandInteractionDataOption,
43
- "name"
44
- >,
45
- ) =>
46
- Effect.succeed(focusedOption.name === optionName)
35
+ export const optionOnly = (optionName: string) =>
36
+ (
37
+ _: unknown,
38
+ focusedOption: Pick<
39
+ Discord.ApplicationCommandInteractionDataOption,
40
+ "name"
41
+ >,
42
+ ) => Effect.succeed(focusedOption.name === optionName)
@@ -7,12 +7,11 @@ import type * as Discord from "dfx/types"
7
7
  export type DefinitionFlattened<R, E, TE, A> = D.InteractionDefinition<
8
8
  R,
9
9
  E
10
- > extends infer D
11
- ? {
12
- [K in keyof D]: K extends "handle"
13
- ? (_: Discord.Interaction) => Effect.Effect<R, TE, A>
14
- : D[K]
15
- }
10
+ > extends infer D ? {
11
+ [K in keyof D]: K extends "handle"
12
+ ? (_: Discord.Interaction) => Effect.Effect<R, TE, A>
13
+ : D[K]
14
+ }
16
15
  : never
17
16
 
18
17
  export type DefinitionFlattenedCommand<R, E, TE, A> = Extract<
@@ -45,13 +44,11 @@ export const flattenDefinitions = <R, E, TE, A, B>(
45
44
  handle: (i: Discord.Interaction) =>
46
45
  Effect.isEffect(definition.handle)
47
46
  ? transform(
48
- Effect.flatMap(definition.handle, _ => handleResponse(i, _)),
49
- )
47
+ Effect.flatMap(definition.handle, _ => handleResponse(i, _)),
48
+ )
50
49
  : transform(
51
- Effect.flatMap(definition.handle(context), _ =>
52
- handleResponse(i, _),
53
- ),
54
- ),
50
+ Effect.flatMap(definition.handle(context), _ => handleResponse(i, _)),
51
+ ),
55
52
  }))
56
53
 
57
54
  export const splitDefinitions = <R, E, TE, A>(
@@ -82,11 +79,10 @@ export const splitDefinitions = <R, E, TE, A>(
82
79
  ).pipe(
83
80
  Chunk.reduce(
84
81
  {} as Record<string, DefinitionFlattenedCommand<R, E, TE, A>>,
85
- (acc, d) =>
86
- ({
87
- ...acc,
88
- [d.command.name]: d,
89
- } as any),
82
+ (acc, d) => ({
83
+ ...acc,
84
+ [d.command.name]: d,
85
+ } as any),
90
86
  ),
91
87
  )
92
88
 
@@ -42,8 +42,8 @@ const checkSignature = (
42
42
  publicKey,
43
43
  crypto,
44
44
  algorithm,
45
- ),
46
- ),
45
+ )
46
+ )
47
47
  ),
48
48
  Effect.filterOrFail(identity, () => new BadWebhookSignature()),
49
49
  Effect.catchAllCause(() => Effect.fail(new BadWebhookSignature())),
@@ -86,14 +86,16 @@ export class WebhookParseError {
86
86
  }
87
87
 
88
88
  const fromHeadersAndBody = (headers: Headers, body: string) =>
89
- Effect.tap(WebhookConfig, ({ algorithm, crypto, publicKey }) =>
90
- checkSignature(publicKey, headers, body, crypto, algorithm),
89
+ Effect.tap(
90
+ WebhookConfig,
91
+ ({ algorithm, crypto, publicKey }) =>
92
+ checkSignature(publicKey, headers, body, crypto, algorithm),
91
93
  ).pipe(
92
94
  Effect.flatMap(() =>
93
95
  Effect.try({
94
96
  try: () => JSON.parse(body) as Discord.Interaction,
95
97
  catch: reason => new WebhookParseError(reason),
96
- }),
98
+ })
97
99
  ),
98
100
  )
99
101
 
@@ -113,12 +115,14 @@ const run = <R, E>(
113
115
  ) => {
114
116
  const handler = handlers(definitions, handleResponse)
115
117
  return (headers: Headers, body: string) =>
116
- Effect.flatMap(fromHeadersAndBody(headers, body), interaction =>
117
- Effect.provideService(
118
- handler[interaction.type](interaction),
119
- Interaction,
120
- interaction,
121
- ),
118
+ Effect.flatMap(
119
+ fromHeadersAndBody(headers, body),
120
+ interaction =>
121
+ Effect.provideService(
122
+ handler[interaction.type](interaction),
123
+ Interaction,
124
+ interaction,
125
+ ),
122
126
  )
123
127
  }
124
128
 
@@ -134,14 +138,14 @@ export interface HandleWebhookOpts<E> {
134
138
  */
135
139
  export const makeHandler = <R, E, TE>(
136
140
  ix: InteractionBuilder<R, E, TE>,
137
- ): (({
141
+ ): ({
138
142
  body,
139
143
  error,
140
144
  headers,
141
145
  success,
142
146
  }: HandleWebhookOpts<
143
147
  E | WebhookParseError | BadWebhookSignature | DefinitionNotFound
144
- >) => Effect.Effect<WebhookConfig, never, void>) => {
148
+ >) => Effect.Effect<WebhookConfig, never, void> => {
145
149
  const handle = run(
146
150
  Chunk.map(ix.definitions, ([d]) => [d, identity] as any),
147
151
  (_i, r) => Effect.succeed(r),
@@ -166,7 +170,7 @@ export const makeHandler = <R, E, TE>(
166
170
  */
167
171
  export const makeSimpleHandler = <R, E, TE>(
168
172
  ix: InteractionBuilder<R, E, TE>,
169
- ): (({
173
+ ): ({
170
174
  body,
171
175
  headers,
172
176
  }: {
@@ -176,7 +180,7 @@ export const makeSimpleHandler = <R, E, TE>(
176
180
  WebhookConfig,
177
181
  BadWebhookSignature | WebhookParseError | DefinitionNotFound,
178
182
  Discord.InteractionResponse
179
- >) => {
183
+ > => {
180
184
  const handle = run(
181
185
  Chunk.map(ix.definitions, ([d]) => [d, identity] as any),
182
186
  (_i, r) => Effect.succeed(r),
package/src/Log.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import { Tag } from "@effect/data/Context"
1
2
  import * as Effect from "@effect/io/Effect"
2
3
  import * as Layer from "@effect/io/Layer"
3
- import { Tag } from "@effect/data/Context"
4
4
 
5
5
  const make = (debug = false) => ({
6
6
  info: (...args: Array<any>) =>
@@ -10,8 +10,8 @@ const make = (debug = false) => ({
10
10
  debug: (...args: Array<any>) =>
11
11
  debug
12
12
  ? Effect.sync(() => {
13
- console.error("DEBUG", ...args)
14
- })
13
+ console.error("DEBUG", ...args)
14
+ })
15
15
  : Effect.unit,
16
16
  })
17
17
 
package/src/RateLimit.ts CHANGED
@@ -43,7 +43,7 @@ export interface RateLimitStore {
43
43
  export const RateLimitStore = Tag<RateLimitStore>()
44
44
  export const LiveMemoryRateLimitStore = Layer.sync(RateLimitStore, Memory.make)
45
45
 
46
- const makeLimiter = Effect.gen(function* (_) {
46
+ const makeLimiter = Effect.gen(function*(_) {
47
47
  const store = yield* _(RateLimitStore)
48
48
  const log = yield* _(Log)
49
49
 
@@ -64,10 +64,10 @@ const makeLimiter = Effect.gen(function* (_) {
64
64
  windowMs,
65
65
  limit,
66
66
  delay: Duration.toMillis(d),
67
- }),
67
+ })
68
68
  ),
69
69
  Effect.tap(_ =>
70
- Duration.toMillis(_) === 0 ? Effect.unit : Effect.sleep(_),
70
+ Duration.toMillis(_) === 0 ? Effect.unit : Effect.sleep(_)
71
71
  ),
72
72
  Effect.asUnit,
73
73
  )
@@ -77,6 +77,7 @@ const makeLimiter = Effect.gen(function* (_) {
77
77
  })
78
78
 
79
79
  export interface RateLimiter
80
- extends Effect.Effect.Success<typeof makeLimiter> {}
80
+ extends Effect.Effect.Success<typeof makeLimiter>
81
+ {}
81
82
  export const RateLimiter = Tag<RateLimiter>()
82
83
  export const LiveRateLimiter = Layer.effect(RateLimiter, makeLimiter)