dfx 0.61.5 → 0.61.7

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