dfx 1.0.5 → 1.0.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 (194) hide show
  1. package/dist/Cache/driver.d.ts.map +1 -1
  2. package/dist/Cache/memory.d.ts.map +1 -1
  3. package/dist/Cache/memoryTTL.d.ts.map +1 -1
  4. package/dist/Cache/prelude.d.ts.map +1 -1
  5. package/dist/Cache.d.ts.map +1 -1
  6. package/dist/DiscordConfig.d.ts.map +1 -1
  7. package/dist/DiscordGateway/DiscordWS.d.ts.map +1 -1
  8. package/dist/DiscordGateway/Messaging.d.ts.map +1 -1
  9. package/dist/DiscordGateway/Shard/StateStore.d.ts.map +1 -1
  10. package/dist/DiscordGateway/Shard/heartbeats.d.ts.map +1 -1
  11. package/dist/DiscordGateway/Shard/identify.d.ts.map +1 -1
  12. package/dist/DiscordGateway/Shard/sendEvents.d.ts.map +1 -1
  13. package/dist/DiscordGateway/Shard/utils.d.ts.map +1 -1
  14. package/dist/DiscordGateway/Shard.d.ts.map +1 -1
  15. package/dist/DiscordGateway/ShardStore.d.ts.map +1 -1
  16. package/dist/DiscordGateway/Sharder.d.ts +1 -1
  17. package/dist/DiscordGateway/Sharder.d.ts.map +1 -1
  18. package/dist/DiscordGateway.d.ts.map +1 -1
  19. package/dist/DiscordREST/Generated.d.ts.map +1 -1
  20. package/dist/DiscordREST/utils.d.ts.map +1 -1
  21. package/dist/DiscordREST.d.ts.map +1 -1
  22. package/dist/Helpers/flags.d.ts.map +1 -1
  23. package/dist/Helpers/intents.d.ts.map +1 -1
  24. package/dist/Helpers/interactions.d.ts.map +1 -1
  25. package/dist/Helpers/members.d.ts.map +1 -1
  26. package/dist/Helpers/permissions.d.ts.map +1 -1
  27. package/dist/Helpers/ui.d.ts.map +1 -1
  28. package/dist/Interactions/builder.d.ts.map +1 -1
  29. package/dist/Interactions/commandHelper.d.ts.map +1 -1
  30. package/dist/Interactions/context.d.ts.map +1 -1
  31. package/dist/Interactions/definitions.d.ts.map +1 -1
  32. package/dist/Interactions/error.d.ts.map +1 -1
  33. package/dist/Interactions/gateway.d.ts.map +1 -1
  34. package/dist/Interactions/handlers.d.ts.map +1 -1
  35. package/dist/Interactions/index.d.ts.map +1 -1
  36. package/dist/Interactions/utils.d.ts.map +1 -1
  37. package/dist/Interactions/webhook.d.ts.map +1 -1
  38. package/dist/RateLimit/memory.d.ts.map +1 -1
  39. package/dist/RateLimit/utils.d.ts.map +1 -1
  40. package/dist/RateLimit.d.ts.map +1 -1
  41. package/dist/gateway.d.ts.map +1 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/utils/Effect.d.ts.map +1 -1
  45. package/dist/version.d.ts +1 -1
  46. package/dist/version.d.ts.map +1 -1
  47. package/dist/version.js +1 -1
  48. package/dist/webhooks.d.ts.map +1 -1
  49. package/package.json +5 -5
  50. package/src/version.ts +1 -1
  51. package/dist/LICENSE +0 -21
  52. package/dist/README.md +0 -66
  53. package/dist/mjs/Cache/driver.mjs +0 -3
  54. package/dist/mjs/Cache/driver.mjs.map +0 -1
  55. package/dist/mjs/Cache/memory.mjs +0 -48
  56. package/dist/mjs/Cache/memory.mjs.map +0 -1
  57. package/dist/mjs/Cache/memoryTTL.mjs +0 -119
  58. package/dist/mjs/Cache/memoryTTL.mjs.map +0 -1
  59. package/dist/mjs/Cache/prelude.mjs +0 -131
  60. package/dist/mjs/Cache/prelude.mjs.map +0 -1
  61. package/dist/mjs/Cache.mjs +0 -90
  62. package/dist/mjs/Cache.mjs.map +0 -1
  63. package/dist/mjs/DiscordConfig.mjs +0 -32
  64. package/dist/mjs/DiscordConfig.mjs.map +0 -1
  65. package/dist/mjs/DiscordGateway/DiscordWS.mjs +0 -77
  66. package/dist/mjs/DiscordGateway/DiscordWS.mjs.map +0 -1
  67. package/dist/mjs/DiscordGateway/Messaging.mjs +0 -35
  68. package/dist/mjs/DiscordGateway/Messaging.mjs.map +0 -1
  69. package/dist/mjs/DiscordGateway/Shard/StateStore.mjs +0 -41
  70. package/dist/mjs/DiscordGateway/Shard/StateStore.mjs.map +0 -1
  71. package/dist/mjs/DiscordGateway/Shard/heartbeats.mjs +0 -25
  72. package/dist/mjs/DiscordGateway/Shard/heartbeats.mjs.map +0 -1
  73. package/dist/mjs/DiscordGateway/Shard/identify.mjs +0 -29
  74. package/dist/mjs/DiscordGateway/Shard/identify.mjs.map +0 -1
  75. package/dist/mjs/DiscordGateway/Shard/sendEvents.mjs +0 -26
  76. package/dist/mjs/DiscordGateway/Shard/sendEvents.mjs.map +0 -1
  77. package/dist/mjs/DiscordGateway/Shard/utils.mjs +0 -3
  78. package/dist/mjs/DiscordGateway/Shard/utils.mjs.map +0 -1
  79. package/dist/mjs/DiscordGateway/Shard.mjs +0 -147
  80. package/dist/mjs/DiscordGateway/Shard.mjs.map +0 -1
  81. package/dist/mjs/DiscordGateway/ShardStore.mjs +0 -24
  82. package/dist/mjs/DiscordGateway/ShardStore.mjs.map +0 -1
  83. package/dist/mjs/DiscordGateway/Sharder.mjs +0 -67
  84. package/dist/mjs/DiscordGateway/Sharder.mjs.map +0 -1
  85. package/dist/mjs/DiscordGateway.mjs +0 -21
  86. package/dist/mjs/DiscordGateway.mjs.map +0 -1
  87. package/dist/mjs/DiscordREST/Generated.mjs +0 -2471
  88. package/dist/mjs/DiscordREST/Generated.mjs.map +0 -1
  89. package/dist/mjs/DiscordREST/utils.mjs +0 -21
  90. package/dist/mjs/DiscordREST/utils.mjs.map +0 -1
  91. package/dist/mjs/DiscordREST.mjs +0 -119
  92. package/dist/mjs/DiscordREST.mjs.map +0 -1
  93. package/dist/mjs/Helpers/flags.mjs +0 -45
  94. package/dist/mjs/Helpers/flags.mjs.map +0 -1
  95. package/dist/mjs/Helpers/intents.mjs +0 -27
  96. package/dist/mjs/Helpers/intents.mjs.map +0 -1
  97. package/dist/mjs/Helpers/interactions.mjs +0 -115
  98. package/dist/mjs/Helpers/interactions.mjs.map +0 -1
  99. package/dist/mjs/Helpers/members.mjs +0 -9
  100. package/dist/mjs/Helpers/members.mjs.map +0 -1
  101. package/dist/mjs/Helpers/permissions.mjs +0 -84
  102. package/dist/mjs/Helpers/permissions.mjs.map +0 -1
  103. package/dist/mjs/Helpers/ui.mjs +0 -137
  104. package/dist/mjs/Helpers/ui.mjs.map +0 -1
  105. package/dist/mjs/Interactions/builder.mjs +0 -56
  106. package/dist/mjs/Interactions/builder.mjs.map +0 -1
  107. package/dist/mjs/Interactions/commandHelper.mjs +0 -49
  108. package/dist/mjs/Interactions/commandHelper.mjs.map +0 -1
  109. package/dist/mjs/Interactions/context.mjs +0 -28
  110. package/dist/mjs/Interactions/context.mjs.map +0 -1
  111. package/dist/mjs/Interactions/definitions.mjs +0 -51
  112. package/dist/mjs/Interactions/definitions.mjs.map +0 -1
  113. package/dist/mjs/Interactions/error.mjs +0 -2
  114. package/dist/mjs/Interactions/error.mjs.map +0 -1
  115. package/dist/mjs/Interactions/gateway.mjs +0 -82
  116. package/dist/mjs/Interactions/gateway.mjs.map +0 -1
  117. package/dist/mjs/Interactions/handlers.mjs +0 -64
  118. package/dist/mjs/Interactions/handlers.mjs.map +0 -1
  119. package/dist/mjs/Interactions/index.mjs +0 -11
  120. package/dist/mjs/Interactions/index.mjs.map +0 -1
  121. package/dist/mjs/Interactions/utils.mjs +0 -26
  122. package/dist/mjs/Interactions/utils.mjs.map +0 -1
  123. package/dist/mjs/Interactions/webhook.mjs +0 -75
  124. package/dist/mjs/Interactions/webhook.mjs.map +0 -1
  125. package/dist/mjs/RateLimit/memory.mjs +0 -39
  126. package/dist/mjs/RateLimit/memory.mjs.map +0 -1
  127. package/dist/mjs/RateLimit/utils.mjs +0 -18
  128. package/dist/mjs/RateLimit/utils.mjs.map +0 -1
  129. package/dist/mjs/RateLimit.mjs +0 -28
  130. package/dist/mjs/RateLimit.mjs.map +0 -1
  131. package/dist/mjs/gateway.mjs +0 -19
  132. package/dist/mjs/gateway.mjs.map +0 -1
  133. package/dist/mjs/index.mjs +0 -18
  134. package/dist/mjs/index.mjs.map +0 -1
  135. package/dist/mjs/types.mjs +0 -356
  136. package/dist/mjs/types.mjs.map +0 -1
  137. package/dist/mjs/utils/Effect.mjs +0 -44
  138. package/dist/mjs/utils/Effect.mjs.map +0 -1
  139. package/dist/mjs/version.mjs +0 -2
  140. package/dist/mjs/version.mjs.map +0 -1
  141. package/dist/mjs/webhooks.mjs +0 -6
  142. package/dist/mjs/webhooks.mjs.map +0 -1
  143. package/dist/package.json +0 -48
  144. package/dist/src/Cache/driver.ts +0 -37
  145. package/dist/src/Cache/memory.ts +0 -83
  146. package/dist/src/Cache/memoryTTL.ts +0 -225
  147. package/dist/src/Cache/prelude.ts +0 -279
  148. package/dist/src/Cache.ts +0 -261
  149. package/dist/src/DiscordConfig.ts +0 -67
  150. package/dist/src/DiscordGateway/DiscordWS.ts +0 -157
  151. package/dist/src/DiscordGateway/Messaging.ts +0 -71
  152. package/dist/src/DiscordGateway/Shard/StateStore.ts +0 -72
  153. package/dist/src/DiscordGateway/Shard/heartbeats.ts +0 -60
  154. package/dist/src/DiscordGateway/Shard/identify.ts +0 -50
  155. package/dist/src/DiscordGateway/Shard/sendEvents.ts +0 -43
  156. package/dist/src/DiscordGateway/Shard/utils.ts +0 -13
  157. package/dist/src/DiscordGateway/Shard.ts +0 -205
  158. package/dist/src/DiscordGateway/ShardStore.ts +0 -42
  159. package/dist/src/DiscordGateway/Sharder.ts +0 -118
  160. package/dist/src/DiscordGateway.ts +0 -79
  161. package/dist/src/DiscordREST/Generated.ts +0 -10832
  162. package/dist/src/DiscordREST/utils.ts +0 -42
  163. package/dist/src/DiscordREST.ts +0 -256
  164. package/dist/src/Helpers/flags.ts +0 -73
  165. package/dist/src/Helpers/intents.ts +0 -35
  166. package/dist/src/Helpers/interactions.ts +0 -317
  167. package/dist/src/Helpers/members.ts +0 -18
  168. package/dist/src/Helpers/permissions.ts +0 -145
  169. package/dist/src/Helpers/ui.ts +0 -253
  170. package/dist/src/Interactions/builder.ts +0 -171
  171. package/dist/src/Interactions/commandHelper.ts +0 -231
  172. package/dist/src/Interactions/context.ts +0 -104
  173. package/dist/src/Interactions/definitions.ts +0 -144
  174. package/dist/src/Interactions/error.ts +0 -3
  175. package/dist/src/Interactions/gateway.ts +0 -193
  176. package/dist/src/Interactions/handlers.ts +0 -108
  177. package/dist/src/Interactions/index.ts +0 -30
  178. package/dist/src/Interactions/utils.ts +0 -93
  179. package/dist/src/Interactions/webhook.ts +0 -204
  180. package/dist/src/RateLimit/memory.ts +0 -63
  181. package/dist/src/RateLimit/utils.ts +0 -28
  182. package/dist/src/RateLimit.ts +0 -90
  183. package/dist/src/gateway.ts +0 -50
  184. package/dist/src/index.ts +0 -44
  185. package/dist/src/types.ts +0 -3090
  186. package/dist/src/utils/Effect.ts +0 -65
  187. package/dist/src/version.ts +0 -1
  188. package/dist/src/webhooks.ts +0 -25
  189. package/dist/tsconfig.base.json +0 -54
  190. package/dist/tsconfig.build.json +0 -10
  191. package/dist/tsconfig.examples.json +0 -10
  192. package/dist/tsconfig.json +0 -14
  193. package/dist/tsconfig.madge.json +0 -12
  194. package/dist/tsconfig.test.json +0 -10
@@ -1,104 +0,0 @@
1
- import * as IxHelpers from "../Helpers/interactions.ts"
2
- import type * as Discord from "../types.ts"
3
- import type { NoSuchElementError } from "effect/Cause"
4
- import * as Data from "effect/Data"
5
- import * as Effect from "effect/Effect"
6
- import * as ServiceMap from "effect/ServiceMap"
7
-
8
- export class Interaction extends ServiceMap.Service<
9
- Interaction,
10
- Discord.APIInteraction
11
- >()("dfx/Interactions/Interaction") {}
12
- export type DiscordInteraction = Interaction
13
-
14
- export class ApplicationCommand extends ServiceMap.Service<
15
- ApplicationCommand,
16
- Discord.APIApplicationCommandInteraction["data"]
17
- >()("dfx/Interactions/ApplicationCommand") {}
18
- export type DiscordApplicationCommand = ApplicationCommand
19
-
20
- export class MessageComponentData extends ServiceMap.Service<
21
- MessageComponentData,
22
- Discord.APIMessageComponentInteractionData
23
- >()("dfx/Interactions/MessageComponentData") {}
24
- export type DiscordMessageComponent = MessageComponentData
25
-
26
- export class ModalSubmitData extends ServiceMap.Service<
27
- ModalSubmitData,
28
- Discord.APIModalSubmission
29
- >()("dfx/Interactions/ModalSubmitData") {}
30
- export type DiscordModalSubmit = ModalSubmitData
31
-
32
- export class FocusedOptionContext extends ServiceMap.Service<
33
- FocusedOptionContext,
34
- Discord.APIApplicationCommandInteractionDataOption
35
- >()("dfx/Interactions/FocusedOptionContext") {}
36
- export type DiscordFocusedOption = FocusedOptionContext
37
-
38
- export interface SubCommandContextData {
39
- readonly command: Discord.APIApplicationCommandInteractionDataSubcommandOption
40
- }
41
- export class SubCommandContext extends ServiceMap.Service<
42
- SubCommandContext,
43
- SubCommandContextData
44
- >()("dfx/Interactions/SubCommandContext") {}
45
- export type DiscordSubCommand = SubCommandContext
46
-
47
- export const resolvedValues = <A>(
48
- f: (
49
- id: Discord.Snowflake,
50
- data: Discord.InteractionDataResolved,
51
- ) => A | undefined,
52
- ): Effect.Effect<ReadonlyArray<A>, NoSuchElementError, DiscordInteraction> =>
53
- Interaction.use(ix => Effect.fromOption(IxHelpers.resolveValues(f)(ix)))
54
-
55
- export const resolved = <A>(
56
- name: string,
57
- f: (
58
- id: Discord.Snowflake,
59
- data: Discord.InteractionDataResolved,
60
- ) => A | undefined,
61
- ): Effect.Effect<A, NoSuchElementError, DiscordInteraction> =>
62
- Interaction.use(ix =>
63
- Effect.fromOption(IxHelpers.resolveOptionValue(name, f)(ix)),
64
- )
65
-
66
- export const focusedOptionValue = FocusedOptionContext.use(_ =>
67
- Effect.succeed("value" in _ ? _.value : ""),
68
- )
69
-
70
- export class SubCommandNotFound extends Data.TaggedError("SubCommandNotFound")<{
71
- data: Discord.APIApplicationCommandInteraction["data"]
72
- }> {}
73
-
74
- export const currentSubCommand: Effect.Effect<
75
- Discord.APIApplicationCommandInteractionDataSubcommandOption,
76
- never,
77
- DiscordSubCommand
78
- > = SubCommandContext.use(_ => Effect.succeed(_.command))
79
-
80
- export class RequiredOptionNotFound {
81
- readonly _tag = "RequiredOptionNotFound"
82
- constructor(
83
- readonly data:
84
- | Discord.APIApplicationCommandInteraction["data"]
85
- | Discord.APIApplicationCommandSubcommandOption,
86
- readonly name: string,
87
- ) {}
88
- }
89
-
90
- export const modalValues = ModalSubmitData.use(data =>
91
- Effect.succeed(IxHelpers.componentsMap(data)),
92
- )
93
-
94
- export const modalValueOption = (name: string) =>
95
- ModalSubmitData.use(data =>
96
- Effect.succeed(IxHelpers.componentValue(name)(data)),
97
- )
98
-
99
- export const modalValue = (
100
- name: string,
101
- ): Effect.Effect<string, NoSuchElementError, DiscordModalSubmit> =>
102
- ModalSubmitData.use(data =>
103
- Effect.fromOption(IxHelpers.componentValue(name)(data)),
104
- )
@@ -1,144 +0,0 @@
1
- import type * as Effect from "effect/Effect"
2
- import type {
3
- DiscordApplicationCommand,
4
- DiscordFocusedOption,
5
- DiscordInteraction,
6
- DiscordMessageComponent,
7
- DiscordModalSubmit,
8
- } from "./context.ts"
9
- import type * as Discord from "../types.ts"
10
- import type { Scope } from "effect/Scope"
11
- import type { CommandHelper } from "./commandHelper.ts"
12
-
13
- export type InteractionDefinition<R, E> =
14
- | GlobalApplicationCommand<R, E>
15
- | GuildApplicationCommand<R, E>
16
- | MessageComponent<R, E>
17
- | ModalSubmit<R, E>
18
- | Autocomplete<R, E>
19
-
20
- export class GlobalApplicationCommand<R, E> {
21
- readonly _tag = "GlobalApplicationCommand"
22
- constructor(
23
- readonly command: Discord.ApplicationCommandCreateRequest,
24
- readonly handle: CommandHandler<R, E>,
25
- ) {}
26
- }
27
-
28
- export const global = <
29
- R,
30
- E,
31
- const A extends Discord.ApplicationCommandCreateRequest,
32
- >(
33
- command: A,
34
- handle: CommandHandler<R, E, A>,
35
- ) =>
36
- new GlobalApplicationCommand<
37
- Exclude<R, DiscordInteraction | DiscordApplicationCommand | Scope>,
38
- E
39
- >(command as any, handle as any)
40
-
41
- export class GuildApplicationCommand<R, E> {
42
- readonly _tag = "GuildApplicationCommand"
43
- constructor(
44
- readonly command: Discord.ApplicationCommandCreateRequest,
45
- readonly handle: CommandHandler<R, E>,
46
- ) {}
47
- }
48
-
49
- export const guild = <
50
- R,
51
- E,
52
- const A extends Discord.ApplicationCommandCreateRequest,
53
- >(
54
- command: A,
55
- handle: CommandHandler<R, E, A>,
56
- ) =>
57
- new GuildApplicationCommand<
58
- Exclude<R, DiscordInteraction | DiscordApplicationCommand | Scope>,
59
- E
60
- >(command as any, handle as any)
61
-
62
- export class MessageComponent<R, E> {
63
- readonly _tag = "MessageComponent"
64
- constructor(
65
- readonly predicate: (customId: string) => boolean,
66
- readonly handle: Effect.Effect<
67
- Discord.CreateInteractionResponseRequest,
68
- E,
69
- R
70
- >,
71
- ) {}
72
- }
73
-
74
- export const messageComponent = <E, R>(
75
- pred: (customId: string) => boolean,
76
- handle: Effect.Effect<Discord.CreateInteractionResponseRequest, E, R>,
77
- ) =>
78
- new MessageComponent<
79
- Exclude<R, DiscordInteraction | DiscordMessageComponent | Scope>,
80
- E
81
- >(pred, handle as any)
82
-
83
- export class ModalSubmit<R, E> {
84
- readonly _tag = "ModalSubmit"
85
- constructor(
86
- readonly predicate: (customId: string) => boolean,
87
- readonly handle: Effect.Effect<
88
- Discord.CreateInteractionResponseRequest,
89
- E,
90
- R
91
- >,
92
- ) {}
93
- }
94
-
95
- export const modalSubmit = <R, E>(
96
- pred: (customId: string) => boolean,
97
- handle: Effect.Effect<Discord.CreateInteractionResponseRequest, E, R>,
98
- ) =>
99
- new ModalSubmit<
100
- Exclude<R, DiscordInteraction | DiscordModalSubmit | Scope>,
101
- E
102
- >(pred, handle as any)
103
-
104
- export class Autocomplete<R, E> {
105
- readonly _tag = "Autocomplete"
106
- constructor(
107
- readonly predicate: (
108
- data: Discord.APIApplicationCommandInteraction["data"],
109
- focusedOption: Discord.APIApplicationCommandInteractionDataOption,
110
- ) => boolean,
111
- readonly handle: Effect.Effect<
112
- Discord.CreateInteractionResponseRequest,
113
- E,
114
- R
115
- >,
116
- ) {}
117
- }
118
-
119
- export const autocomplete = <R, E>(
120
- pred: (
121
- data: Discord.APIApplicationCommandInteraction["data"],
122
- focusedOption: Discord.APIApplicationCommandInteractionDataOption,
123
- ) => boolean,
124
- handle: Effect.Effect<Discord.CreateInteractionResponseRequest, E, R>,
125
- ) =>
126
- new Autocomplete<
127
- Exclude<
128
- R,
129
- | DiscordInteraction
130
- | DiscordApplicationCommand
131
- | DiscordFocusedOption
132
- | Scope
133
- >,
134
- E
135
- >(pred, handle as any)
136
-
137
- // ==== Command handler helpers
138
- export type CommandHandler<R, E, A = any> =
139
- | Effect.Effect<Discord.CreateInteractionResponseRequest, E, R>
140
- | CommandHandlerFn<R, E, A>
141
-
142
- export type CommandHandlerFn<R, E, A> = (
143
- i: CommandHelper<A>,
144
- ) => Effect.Effect<Discord.CreateInteractionResponseRequest, E, R>
@@ -1,3 +0,0 @@
1
- export const InteractionsErrorTypeId = Symbol.for(
2
- "dfx/Interactions/InteractionsError",
3
- )
@@ -1,193 +0,0 @@
1
- import * as Arr from "effect/Array"
2
- import * as Chunk from "effect/Chunk"
3
- import * as Duration from "effect/Duration"
4
- import * as Effect from "effect/Effect"
5
- import { pipe } from "effect/Function"
6
- import * as Layer from "effect/Layer"
7
- import * as Queue from "effect/Queue"
8
- import * as Ref from "effect/Ref"
9
- import * as Schedule from "effect/Schedule"
10
- import * as ServiceMap from "effect/ServiceMap"
11
- import { DiscordGateway } from "../DiscordGateway.ts"
12
- import type { DiscordRESTError } from "../DiscordREST.ts"
13
- import { DiscordREST } from "../DiscordREST.ts"
14
- import type { ListMyGuilds200, MyGuildResponse } from "../types.ts"
15
- import type {
16
- GlobalApplicationCommand,
17
- GuildApplicationCommand,
18
- } from "./definitions.ts"
19
- import type { DefinitionNotFound } from "./handlers.ts"
20
- import { handlers } from "./handlers.ts"
21
- import type { DiscordInteraction, InteractionBuilder } from "./index.ts"
22
- import { builder, Interaction } from "./index.ts"
23
- import * as EffectUtils from "../utils/Effect.ts"
24
-
25
- export const interactionsSync = ServiceMap.Reference("dfx/Interactions/sync", {
26
- defaultValue: () => true,
27
- })
28
-
29
- export const setInteractionsSync = (enabled: boolean) =>
30
- Layer.provide(Layer.succeed(interactionsSync, enabled))
31
-
32
- const retryPolicy = Schedule.exponential("1 seconds").pipe(
33
- Schedule.either(Schedule.spaced("20 seconds")),
34
- )
35
-
36
- export const run =
37
- <R, R2, E, TE, E2>(
38
- postHandler: (
39
- effect: Effect.Effect<
40
- void,
41
- TE | DiscordRESTError | DefinitionNotFound,
42
- R | DiscordREST | DiscordInteraction
43
- >,
44
- ) => Effect.Effect<void, E2, R2>,
45
- ) =>
46
- (
47
- ix: InteractionBuilder<R, E, TE>,
48
- ): Effect.Effect<
49
- never,
50
- E2 | DiscordRESTError,
51
- DiscordREST | DiscordGateway | Exclude<R2, DiscordInteraction>
52
- > =>
53
- Effect.gen(function* () {
54
- const GlobalApplicationCommand = ix.definitions.pipe(
55
- Chunk.map(_ => _[0]),
56
- Chunk.filter(
57
- (_): _ is GlobalApplicationCommand<R, E> =>
58
- _._tag === "GlobalApplicationCommand",
59
- ),
60
- Chunk.toReadonlyArray,
61
- )
62
- const GuildApplicationCommand = ix.definitions.pipe(
63
- Chunk.map(_ => _[0]),
64
- Chunk.filter(
65
- (_): _ is GuildApplicationCommand<R, E> =>
66
- _._tag === "GuildApplicationCommand",
67
- ),
68
- Chunk.toReadonlyArray,
69
- )
70
-
71
- const gateway = yield* DiscordGateway
72
- const rest = yield* DiscordREST
73
-
74
- const application = yield* rest.getMyApplication()
75
-
76
- const globalSync = rest.bulkSetApplicationCommands(
77
- application.id,
78
- GlobalApplicationCommand.map(_ => _.command),
79
- )
80
-
81
- const runGuildSync = Effect.gen(function* () {
82
- const commands = GuildApplicationCommand.map(_ => _.command)
83
- let results: Arr.NonEmptyReadonlyArray<MyGuildResponse> | undefined =
84
- undefined
85
- while (true) {
86
- const next: ListMyGuilds200 = yield* rest.listMyGuilds({
87
- after: results && Arr.lastNonEmpty(results).id,
88
- })
89
- if (!Arr.isReadonlyArrayNonEmpty(next)) break
90
- results = next
91
- yield* Effect.forEach(
92
- results!,
93
- guild =>
94
- rest.bulkSetGuildApplicationCommands(
95
- application.id,
96
- guild.id,
97
- commands,
98
- ),
99
- { concurrency: "unbounded", discard: true },
100
- )
101
- }
102
-
103
- return yield* gateway.handleDispatch("GUILD_CREATE", a =>
104
- rest.bulkSetGuildApplicationCommands(
105
- application.id,
106
- a.id,
107
- GuildApplicationCommand.map(_ => _.command),
108
- ),
109
- )
110
- })
111
-
112
- const guildSync = GuildApplicationCommand.length
113
- ? runGuildSync
114
- : Effect.never
115
-
116
- const handle = handlers(ix.definitions, (i, r) => {
117
- const hasFiles = "files" in r
118
- const payload = hasFiles ? { ...r, files: undefined } : r
119
- const effect = rest.createInteractionResponse(i.id, i.token, {
120
- payload,
121
- })
122
- return hasFiles ? rest.withFiles(r.files as any)(effect) : effect
123
- })
124
-
125
- const interactionRun = gateway.handleDispatch("INTERACTION_CREATE", i =>
126
- Effect.withSpan(
127
- Effect.provideService(postHandler(handle[i.type](i)), Interaction, i),
128
- "dfx.Interaction",
129
- { attributes: { interactionId: i.id }, captureStackTrace: false },
130
- ),
131
- )
132
-
133
- const sync = yield* interactionsSync
134
-
135
- return yield* sync
136
- ? Effect.forever(
137
- Effect.all([interactionRun, globalSync, guildSync], {
138
- concurrency: "unbounded",
139
- discard: true,
140
- }),
141
- )
142
- : interactionRun
143
- })
144
-
145
- const makeRegistry = Effect.gen(function* () {
146
- const ref = yield* Ref.make(
147
- builder as InteractionBuilder<never, never, never>,
148
- )
149
- const queue = yield* Queue.sliding<InteractionBuilder<never, never, never>>(1)
150
-
151
- const register = <E>(ix: InteractionBuilder<never, E, never>) =>
152
- Effect.flatMap(
153
- Ref.updateAndGet(ref, _ => _.concat(ix as any)),
154
- _ => Queue.offer(queue, _),
155
- )
156
-
157
- yield* EffectUtils.foreverSwitch(Queue.take(queue), ix =>
158
- pipe(
159
- ix,
160
- run(Effect.catchCause(_ => Effect.logError("unhandled error", _))),
161
- Effect.delay(Duration.seconds(5)),
162
- ),
163
- ).pipe(
164
- Effect.tapCause(_ => Effect.logError("registry error", _)),
165
- Effect.retry(retryPolicy),
166
- Effect.forkScoped,
167
- Effect.interruptible,
168
- )
169
-
170
- return { register } as const
171
- }).pipe(
172
- Effect.annotateLogs({
173
- package: "dfx",
174
- service: "InteractionsRegistry",
175
- }),
176
- )
177
-
178
- export interface InteractionsRegistryService {
179
- readonly register: <E>(
180
- ix: InteractionBuilder<never, E, never>,
181
- ) => Effect.Effect<void>
182
- }
183
-
184
- export class InteractionsRegistry extends ServiceMap.Service<
185
- InteractionsRegistry,
186
- InteractionsRegistryService
187
- >()("dfx/Interactions/InteractionsRegistry") {}
188
-
189
- export const InteractionsRegistryLive: Layer.Layer<
190
- InteractionsRegistry,
191
- never,
192
- DiscordREST | DiscordGateway
193
- > = Layer.effect(InteractionsRegistry, makeRegistry)
@@ -1,108 +0,0 @@
1
- import type * as Chunk from "effect/Chunk"
2
- import * as Effect from "effect/Effect"
3
- import * as IxHelpers from "../Helpers/interactions.ts"
4
- import * as Ctx from "./context.ts"
5
- import type * as D from "./definitions.ts"
6
- import { flattenDefinitions, splitDefinitions } from "./utils.ts"
7
- import * as Discord from "../types.ts"
8
- import type { Scope } from "effect/Scope"
9
-
10
- export class DefinitionNotFound {
11
- readonly _tag = "DefinitionNotFound"
12
- constructor(readonly interaction: Discord.APIInteraction) {}
13
- }
14
-
15
- type Handler<R, E, A> = Effect.Effect<
16
- A,
17
- E | DefinitionNotFound,
18
- R | Ctx.DiscordInteraction
19
- >
20
-
21
- export const handlers = <R, E, TE, A, B>(
22
- definitions: Chunk.Chunk<
23
- readonly [
24
- handler: D.InteractionDefinition<R, E>,
25
- transform: (self: Effect.Effect<A, E, R>) => Effect.Effect<B, TE, R>,
26
- ]
27
- >,
28
- handleResponse: (
29
- ix: Discord.APIInteraction,
30
- _: Discord.CreateInteractionResponseRequest,
31
- ) => Effect.Effect<A, E, R>,
32
- ): Record<
33
- Discord.InteractionTypes,
34
- (i: Discord.APIInteraction) => Handler<Exclude<R, Scope>, E, B>
35
- > => {
36
- const flattened = flattenDefinitions(definitions, handleResponse)
37
-
38
- const { Autocomplete, Commands, MessageComponent, ModalSubmit } =
39
- splitDefinitions(flattened)
40
-
41
- return {
42
- [Discord.InteractionTypes.PING]: _ =>
43
- Effect.succeed({
44
- type: Discord.InteractionCallbackTypes.PONG,
45
- } as any),
46
-
47
- [Discord.InteractionTypes.APPLICATION_COMMAND]: i => {
48
- const data =
49
- i.data as Discord.APIChatInputApplicationCommandInteractionData
50
- const command = Commands[data.name]
51
- if (command === undefined) {
52
- return Effect.fail(new DefinitionNotFound(i))
53
- }
54
- return Effect.provideService(
55
- command.handle(i),
56
- Ctx.ApplicationCommand,
57
- data,
58
- ) as Handler<Exclude<R, Scope>, E, B>
59
- },
60
-
61
- [Discord.InteractionTypes.SOCIAL_LAYER_SKU_PURCHASE_ELIGIBILITY]: i =>
62
- Effect.fail(new DefinitionNotFound(i)),
63
-
64
- [Discord.InteractionTypes.MODAL_SUBMIT]: i => {
65
- const data = i.data as Discord.APIModalSubmission
66
- const match = ModalSubmit.find(_ => _.predicate(data.custom_id))
67
- if (match === undefined) {
68
- return Effect.fail(new DefinitionNotFound(i))
69
- }
70
- return Effect.provideService(
71
- match.handle(i),
72
- Ctx.ModalSubmitData,
73
- data,
74
- ) as Handler<Exclude<R, Scope>, E, B>
75
- },
76
-
77
- [Discord.InteractionTypes.MESSAGE_COMPONENT]: i => {
78
- const data = i.data as Discord.APIMessageComponentInteractionData
79
- const match = MessageComponent.find(_ => _.predicate(data.custom_id))
80
- if (match === undefined) {
81
- return Effect.fail(new DefinitionNotFound(i))
82
- }
83
- return Effect.provideService(
84
- match.handle(i),
85
- Ctx.MessageComponentData,
86
- data,
87
- ) as Handler<Exclude<R, Scope>, E, B>
88
- },
89
-
90
- [Discord.InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE]: i => {
91
- const data = i.data as Discord.APIApplicationCommandInteraction["data"]
92
- const option = IxHelpers.focusedOption(data as any)
93
- if (option._tag === "None") {
94
- return Effect.fail(new DefinitionNotFound(i))
95
- }
96
- const match = Autocomplete.find(_ => _.predicate(data, option.value))
97
- if (match === undefined) {
98
- return Effect.fail(new DefinitionNotFound(i))
99
- }
100
- return match
101
- .handle(i)
102
- .pipe(
103
- Effect.provideService(Ctx.ApplicationCommand, data),
104
- Effect.provideService(Ctx.FocusedOptionContext, option.value),
105
- ) as Handler<Exclude<R, Scope>, E, B>
106
- },
107
- }
108
- }
@@ -1,30 +0,0 @@
1
- export { response } from "../Helpers/interactions.ts"
2
- export * from "./builder.ts"
3
- export * from "./context.ts"
4
- export type { InteractionDefinition } from "./definitions.ts"
5
- export {
6
- autocomplete,
7
- global,
8
- guild,
9
- messageComponent,
10
- modalSubmit,
11
- } from "./definitions.ts"
12
-
13
- // Filters
14
- export const id = (query: string) => (customId: string) => query === customId
15
-
16
- export const idStartsWith = (query: string) => (customId: string) =>
17
- customId.startsWith(query)
18
-
19
- export const idRegex = (query: RegExp) => (customId: string) =>
20
- query.test(customId)
21
-
22
- export const option =
23
- (command: string, optionName: string) =>
24
- (data: { readonly name: string }, focusedOption: { readonly name: string }) =>
25
- data.name === command && focusedOption.name === optionName
26
-
27
- export const optionOnly =
28
- (optionName: string) =>
29
- (_: unknown, focusedOption: { readonly name: string }) =>
30
- focusedOption.name === optionName
@@ -1,93 +0,0 @@
1
- import * as Chunk from "effect/Chunk"
2
- import * as Effect from "effect/Effect"
3
- import type * as D from "./definitions.ts"
4
- import type * as Discord from "../types.ts"
5
- import * as Array from "effect/Array"
6
- import { CommandHelper } from "./commandHelper.ts"
7
-
8
- export type DefinitionFlattened<R, E, TE, A> =
9
- D.InteractionDefinition<R, E> extends infer Def
10
- ? {
11
- [K in keyof Def]: K extends "handle"
12
- ? (_: Discord.APIInteraction) => Effect.Effect<A, TE, R>
13
- : Def[K]
14
- }
15
- : never
16
-
17
- export type DefinitionFlattenedCommand<R, E, TE, A> = Extract<
18
- DefinitionFlattened<R, E, TE, A>,
19
- { _tag: "GlobalApplicationCommand" | "GuildApplicationCommand" }
20
- >
21
-
22
- export const flattenDefinitions = <R, E, TE, A, B>(
23
- definitions: Chunk.Chunk<
24
- readonly [
25
- handler: D.InteractionDefinition<R, E>,
26
- transform: (self: Effect.Effect<A, E, R>) => Effect.Effect<B, TE, R>,
27
- ]
28
- >,
29
- handleResponse: (
30
- ix: Discord.APIInteraction,
31
- _: Discord.CreateInteractionResponseRequest,
32
- ) => Effect.Effect<A, E, R>,
33
- ) =>
34
- Array.map(Chunk.toReadonlyArray(definitions), ([definition, transform]) => ({
35
- ...definition,
36
- handle: Effect.isEffect(definition.handle)
37
- ? (i: Discord.APIInteraction) =>
38
- Effect.scoped(
39
- transform(
40
- Effect.flatMap(
41
- definition.handle as Effect.Effect<Discord.CreateInteractionResponseRequest>,
42
- _ => handleResponse(i, _),
43
- ),
44
- ),
45
- )
46
- : (i: Discord.APIInteraction) =>
47
- Effect.scoped(
48
- transform(
49
- Effect.flatMap(
50
- (
51
- definition.handle as (
52
- _: any,
53
- ) => Effect.Effect<Discord.CreateInteractionResponseRequest>
54
- )(new CommandHelper(i)),
55
- _ => handleResponse(i, _),
56
- ),
57
- ),
58
- ),
59
- }))
60
-
61
- export const splitDefinitions = <R, E, TE, A>(
62
- definitions: ReadonlyArray<DefinitionFlattened<R, E, TE, A>>,
63
- ) => {
64
- const grouped = Array.reduce(
65
- definitions,
66
- {
67
- Autocomplete: [],
68
- GlobalApplicationCommand: [],
69
- GuildApplicationCommand: [],
70
- MessageComponent: [],
71
- ModalSubmit: [],
72
- Commands: {},
73
- } as {
74
- [K in D.InteractionDefinition<R, E>["_tag"]]: Array<
75
- Extract<DefinitionFlattened<R, E, TE, A>, { _tag: K }>
76
- >
77
- } & {
78
- readonly Commands: Record<string, DefinitionFlattenedCommand<R, E, TE, A>>
79
- },
80
- (acc, d) => {
81
- acc[d._tag].push(d as any)
82
- if (
83
- d._tag === "GlobalApplicationCommand" ||
84
- d._tag === "GuildApplicationCommand"
85
- ) {
86
- acc.Commands[d.command.name] = d as any
87
- }
88
- return acc
89
- },
90
- )
91
-
92
- return grouped
93
- }