dfx 0.126.1 → 1.0.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/.babel.cjs.json +11 -0
- package/.babel.mjs.json +10 -0
- package/.envrc +1 -0
- package/.gitmodules +3 -0
- package/.husky/pre-commit +2 -0
- package/.oxlintrc.json +72 -0
- package/.prettierignore +0 -0
- package/.prettierrc.json +5 -0
- package/.tool-versions +1 -0
- package/.vscode/debug.cjs +8 -0
- package/.vscode/launch.json +23 -0
- package/.vscode/settings.json +29 -0
- package/.vscode/tasks.json +44 -0
- package/AGENTS.md +15 -0
- package/CHANGELOG.md +1554 -0
- package/examples/.env.example +5 -0
- package/examples/interactions.ts +79 -0
- package/examples/readme.ts +56 -0
- package/examples/registry.ts +66 -0
- package/flake.lock +27 -0
- package/flake.nix +21 -0
- package/lerna.json +12 -0
- package/package.json +79 -36
- package/pnpm-workspace.yaml +7 -0
- package/scripts/generate-client.sh +10 -0
- package/scripts/worktree-setup.sh +8 -0
- package/src/Cache/memory.ts +5 -5
- package/src/Cache/memoryTTL.ts +11 -7
- package/src/Cache/prelude.ts +10 -8
- package/src/Cache.ts +31 -35
- package/src/DiscordConfig.ts +12 -16
- package/src/DiscordGateway/DiscordWS.ts +58 -32
- package/src/DiscordGateway/Messaging.ts +13 -15
- package/src/DiscordGateway/Shard/StateStore.ts +30 -25
- package/src/DiscordGateway/Shard/heartbeats.ts +25 -28
- package/src/DiscordGateway/Shard/identify.ts +11 -6
- package/src/DiscordGateway/Shard/sendEvents.ts +1 -1
- package/src/DiscordGateway/Shard/utils.ts +1 -1
- package/src/DiscordGateway/Shard.ts +39 -35
- package/src/DiscordGateway/ShardStore.ts +6 -7
- package/src/DiscordGateway/Sharder.ts +31 -29
- package/src/DiscordGateway.ts +15 -14
- package/src/DiscordREST/Generated.ts +660 -341
- package/src/DiscordREST/utils.ts +6 -3
- package/src/DiscordREST.ts +37 -41
- package/src/Helpers/flags.ts +10 -5
- package/src/Helpers/intents.ts +2 -2
- package/src/Helpers/interactions.ts +16 -14
- package/src/Helpers/members.ts +3 -3
- package/src/Helpers/permissions.ts +5 -5
- package/src/Helpers/ui.ts +16 -16
- package/src/Interactions/builder.ts +10 -10
- package/src/Interactions/commandHelper.ts +18 -29
- package/src/Interactions/context.ts +51 -65
- package/src/Interactions/definitions.ts +3 -3
- package/src/Interactions/gateway.ts +33 -45
- package/src/Interactions/handlers.ts +8 -5
- package/src/Interactions/index.ts +5 -5
- package/src/Interactions/utils.ts +6 -6
- package/src/Interactions/webhook.ts +31 -38
- package/src/RateLimit/memory.ts +3 -3
- package/src/RateLimit.ts +18 -15
- package/src/gateway.ts +21 -21
- package/src/index.ts +17 -17
- package/src/types.ts +18 -16
- package/src/utils/Effect.ts +38 -27
- package/src/webhooks.ts +7 -7
- package/test/index.test.ts +5 -0
- package/tsconfig.base.json +12 -6
- package/tsconfig.examples.json +0 -1
- package/vitest.config.ts +22 -0
- package/Cache/driver.d.ts +0 -24
- package/Cache/driver.d.ts.map +0 -1
- package/Cache/driver.js +0 -11
- package/Cache/driver.js.map +0 -1
- package/Cache/memory.d.ts +0 -5
- package/Cache/memory.d.ts.map +0 -1
- package/Cache/memory.js +0 -57
- package/Cache/memory.js.map +0 -1
- package/Cache/memoryTTL.d.ts +0 -23
- package/Cache/memoryTTL.d.ts.map +0 -1
- package/Cache/memoryTTL.js +0 -128
- package/Cache/memoryTTL.js.map +0 -1
- package/Cache/prelude.d.ts +0 -32
- package/Cache/prelude.d.ts.map +0 -1
- package/Cache/prelude.js +0 -143
- package/Cache/prelude.js.map +0 -1
- package/Cache.d.ts +0 -82
- package/Cache.d.ts.map +0 -1
- package/Cache.js +0 -144
- package/Cache.js.map +0 -1
- package/DiscordConfig.d.ts +0 -35
- package/DiscordConfig.d.ts.map +0 -1
- package/DiscordConfig.js +0 -42
- package/DiscordConfig.js.map +0 -1
- package/DiscordGateway/DiscordWS.d.ts +0 -37
- package/DiscordGateway/DiscordWS.d.ts.map +0 -1
- package/DiscordGateway/DiscordWS.js +0 -73
- package/DiscordGateway/DiscordWS.js.map +0 -1
- package/DiscordGateway/Messaging.d.ts +0 -393
- package/DiscordGateway/Messaging.d.ts.map +0 -1
- package/DiscordGateway/Messaging.js +0 -40
- package/DiscordGateway/Messaging.js.map +0 -1
- package/DiscordGateway/Shard/StateStore.d.ts +0 -24
- package/DiscordGateway/Shard/StateStore.d.ts.map +0 -1
- package/DiscordGateway/Shard/StateStore.js +0 -48
- package/DiscordGateway/Shard/StateStore.js.map +0 -1
- package/DiscordGateway/Shard/heartbeats.d.ts +0 -8
- package/DiscordGateway/Shard/heartbeats.d.ts.map +0 -1
- package/DiscordGateway/Shard/heartbeats.js +0 -28
- package/DiscordGateway/Shard/heartbeats.js.map +0 -1
- package/DiscordGateway/Shard/identify.d.ts +0 -12
- package/DiscordGateway/Shard/identify.d.ts.map +0 -1
- package/DiscordGateway/Shard/identify.js +0 -38
- package/DiscordGateway/Shard/identify.js.map +0 -1
- package/DiscordGateway/Shard/sendEvents.d.ts +0 -8
- package/DiscordGateway/Shard/sendEvents.d.ts.map +0 -1
- package/DiscordGateway/Shard/sendEvents.js +0 -39
- package/DiscordGateway/Shard/sendEvents.js.map +0 -1
- package/DiscordGateway/Shard/utils.d.ts +0 -6
- package/DiscordGateway/Shard/utils.d.ts.map +0 -1
- package/DiscordGateway/Shard/utils.js +0 -11
- package/DiscordGateway/Shard/utils.js.map +0 -1
- package/DiscordGateway/Shard.d.ts +0 -28
- package/DiscordGateway/Shard.d.ts.map +0 -1
- package/DiscordGateway/Shard.js +0 -149
- package/DiscordGateway/Shard.js.map +0 -1
- package/DiscordGateway/ShardStore.d.ts +0 -18
- package/DiscordGateway/ShardStore.d.ts.map +0 -1
- package/DiscordGateway/ShardStore.js +0 -31
- package/DiscordGateway/ShardStore.js.map +0 -1
- package/DiscordGateway/Sharder.d.ts +0 -13
- package/DiscordGateway/Sharder.d.ts.map +0 -1
- package/DiscordGateway/Sharder.js +0 -73
- package/DiscordGateway/Sharder.js.map +0 -1
- package/DiscordGateway.d.ts +0 -32
- package/DiscordGateway.d.ts.map +0 -1
- package/DiscordGateway.js +0 -28
- package/DiscordGateway.js.map +0 -1
- package/DiscordREST/Generated.d.ts +0 -5399
- package/DiscordREST/Generated.d.ts.map +0 -1
- package/DiscordREST/Generated.js +0 -2405
- package/DiscordREST/Generated.js.map +0 -1
- package/DiscordREST/utils.d.ts +0 -14
- package/DiscordREST/utils.d.ts.map +0 -1
- package/DiscordREST/utils.js +0 -31
- package/DiscordREST/utils.js.map +0 -1
- package/DiscordREST.d.ts +0 -23
- package/DiscordREST.d.ts.map +0 -1
- package/DiscordREST.js +0 -132
- package/DiscordREST.js.map +0 -1
- package/Helpers/flags.d.ts +0 -28
- package/Helpers/flags.d.ts.map +0 -1
- package/Helpers/flags.js +0 -48
- package/Helpers/flags.js.map +0 -1
- package/Helpers/intents.d.ts +0 -25
- package/Helpers/intents.d.ts.map +0 -1
- package/Helpers/intents.js +0 -34
- package/Helpers/intents.js.map +0 -1
- package/Helpers/interactions.d.ts +0 -116
- package/Helpers/interactions.d.ts.map +0 -1
- package/Helpers/interactions.js +0 -143
- package/Helpers/interactions.js.map +0 -1
- package/Helpers/members.d.ts +0 -10
- package/Helpers/members.d.ts.map +0 -1
- package/Helpers/members.js +0 -17
- package/Helpers/members.js.map +0 -1
- package/Helpers/permissions.d.ts +0 -42
- package/Helpers/permissions.d.ts.map +0 -1
- package/Helpers/permissions.js +0 -97
- package/Helpers/permissions.js.map +0 -1
- package/Helpers/ui.d.ts +0 -105
- package/Helpers/ui.d.ts.map +0 -1
- package/Helpers/ui.js +0 -162
- package/Helpers/ui.js.map +0 -1
- package/Interactions/builder.d.ts +0 -48
- package/Interactions/builder.d.ts.map +0 -1
- package/Interactions/builder.js +0 -64
- package/Interactions/builder.js.map +0 -1
- package/Interactions/commandHelper.d.ts +0 -99
- package/Interactions/commandHelper.d.ts.map +0 -1
- package/Interactions/commandHelper.js +0 -53
- package/Interactions/commandHelper.js.map +0 -1
- package/Interactions/context.d.ts +0 -54
- package/Interactions/context.d.ts.map +0 -1
- package/Interactions/context.js +0 -42
- package/Interactions/context.js.map +0 -1
- package/Interactions/definitions.d.ts +0 -44
- package/Interactions/definitions.d.ts.map +0 -1
- package/Interactions/definitions.js +0 -67
- package/Interactions/definitions.js.map +0 -1
- package/Interactions/error.d.ts +0 -2
- package/Interactions/error.d.ts.map +0 -1
- package/Interactions/error.js +0 -8
- package/Interactions/error.js.map +0 -1
- package/Interactions/gateway.d.ts +0 -21
- package/Interactions/gateway.d.ts.map +0 -1
- package/Interactions/gateway.js +0 -90
- package/Interactions/gateway.js.map +0 -1
- package/Interactions/handlers.d.ts +0 -15
- package/Interactions/handlers.d.ts.map +0 -1
- package/Interactions/handlers.js +0 -72
- package/Interactions/handlers.js.map +0 -1
- package/Interactions/index.d.ts +0 -16
- package/Interactions/index.d.ts.map +0 -1
- package/Interactions/index.js +0 -94
- package/Interactions/index.js.map +0 -1
- package/Interactions/utils.d.ts +0 -61
- package/Interactions/utils.d.ts.map +0 -1
- package/Interactions/utils.js +0 -35
- package/Interactions/utils.js.map +0 -1
- package/Interactions/webhook.d.ts +0 -73
- package/Interactions/webhook.d.ts.map +0 -1
- package/Interactions/webhook.js +0 -89
- package/Interactions/webhook.js.map +0 -1
- package/RateLimit/memory.d.ts +0 -3
- package/RateLimit/memory.d.ts.map +0 -1
- package/RateLimit/memory.js +0 -47
- package/RateLimit/memory.js.map +0 -1
- package/RateLimit/utils.d.ts +0 -3
- package/RateLimit/utils.d.ts.map +0 -1
- package/RateLimit/utils.js +0 -25
- package/RateLimit/utils.js.map +0 -1
- package/RateLimit.d.ts +0 -30
- package/RateLimit.d.ts.map +0 -1
- package/RateLimit.js +0 -35
- package/RateLimit.js.map +0 -1
- package/gateway.d.ts +0 -19
- package/gateway.d.ts.map +0 -1
- package/gateway.js +0 -72
- package/gateway.js.map +0 -1
- package/index.d.ts +0 -18
- package/index.d.ts.map +0 -1
- package/index.js +0 -71
- package/index.js.map +0 -1
- package/mjs/Cache/driver.mjs +0 -3
- package/mjs/Cache/driver.mjs.map +0 -1
- package/mjs/Cache/memory.mjs +0 -48
- package/mjs/Cache/memory.mjs.map +0 -1
- package/mjs/Cache/memoryTTL.mjs +0 -119
- package/mjs/Cache/memoryTTL.mjs.map +0 -1
- package/mjs/Cache/prelude.mjs +0 -131
- package/mjs/Cache/prelude.mjs.map +0 -1
- package/mjs/Cache.mjs +0 -89
- package/mjs/Cache.mjs.map +0 -1
- package/mjs/DiscordConfig.mjs +0 -32
- package/mjs/DiscordConfig.mjs.map +0 -1
- package/mjs/DiscordGateway/DiscordWS.mjs +0 -66
- package/mjs/DiscordGateway/DiscordWS.mjs.map +0 -1
- package/mjs/DiscordGateway/Messaging.mjs +0 -33
- package/mjs/DiscordGateway/Messaging.mjs.map +0 -1
- package/mjs/DiscordGateway/Shard/StateStore.mjs +0 -40
- package/mjs/DiscordGateway/Shard/StateStore.mjs.map +0 -1
- package/mjs/DiscordGateway/Shard/heartbeats.mjs +0 -20
- package/mjs/DiscordGateway/Shard/heartbeats.mjs.map +0 -1
- package/mjs/DiscordGateway/Shard/identify.mjs +0 -30
- package/mjs/DiscordGateway/Shard/identify.mjs.map +0 -1
- package/mjs/DiscordGateway/Shard/sendEvents.mjs +0 -26
- package/mjs/DiscordGateway/Shard/sendEvents.mjs.map +0 -1
- package/mjs/DiscordGateway/Shard/utils.mjs +0 -3
- package/mjs/DiscordGateway/Shard/utils.mjs.map +0 -1
- package/mjs/DiscordGateway/Shard.mjs +0 -142
- package/mjs/DiscordGateway/Shard.mjs.map +0 -1
- package/mjs/DiscordGateway/ShardStore.mjs +0 -24
- package/mjs/DiscordGateway/ShardStore.mjs.map +0 -1
- package/mjs/DiscordGateway/Sharder.mjs +0 -66
- package/mjs/DiscordGateway/Sharder.mjs.map +0 -1
- package/mjs/DiscordGateway.mjs +0 -21
- package/mjs/DiscordGateway.mjs.map +0 -1
- package/mjs/DiscordREST/Generated.mjs +0 -2396
- package/mjs/DiscordREST/Generated.mjs.map +0 -1
- package/mjs/DiscordREST/utils.mjs +0 -20
- package/mjs/DiscordREST/utils.mjs.map +0 -1
- package/mjs/DiscordREST.mjs +0 -124
- package/mjs/DiscordREST.mjs.map +0 -1
- package/mjs/Helpers/flags.mjs +0 -36
- package/mjs/Helpers/flags.mjs.map +0 -1
- package/mjs/Helpers/intents.mjs +0 -27
- package/mjs/Helpers/intents.mjs.map +0 -1
- package/mjs/Helpers/interactions.mjs +0 -115
- package/mjs/Helpers/interactions.mjs.map +0 -1
- package/mjs/Helpers/members.mjs +0 -9
- package/mjs/Helpers/members.mjs.map +0 -1
- package/mjs/Helpers/permissions.mjs +0 -84
- package/mjs/Helpers/permissions.mjs.map +0 -1
- package/mjs/Helpers/ui.mjs +0 -137
- package/mjs/Helpers/ui.mjs.map +0 -1
- package/mjs/Interactions/builder.mjs +0 -56
- package/mjs/Interactions/builder.mjs.map +0 -1
- package/mjs/Interactions/commandHelper.mjs +0 -45
- package/mjs/Interactions/commandHelper.mjs.map +0 -1
- package/mjs/Interactions/context.mjs +0 -29
- package/mjs/Interactions/context.mjs.map +0 -1
- package/mjs/Interactions/definitions.mjs +0 -51
- package/mjs/Interactions/definitions.mjs.map +0 -1
- package/mjs/Interactions/error.mjs +0 -2
- package/mjs/Interactions/error.mjs.map +0 -1
- package/mjs/Interactions/gateway.mjs +0 -81
- package/mjs/Interactions/gateway.mjs.map +0 -1
- package/mjs/Interactions/handlers.mjs +0 -63
- package/mjs/Interactions/handlers.mjs.map +0 -1
- package/mjs/Interactions/index.mjs +0 -11
- package/mjs/Interactions/index.mjs.map +0 -1
- package/mjs/Interactions/utils.mjs +0 -26
- package/mjs/Interactions/utils.mjs.map +0 -1
- package/mjs/Interactions/webhook.mjs +0 -76
- package/mjs/Interactions/webhook.mjs.map +0 -1
- package/mjs/RateLimit/memory.mjs +0 -39
- package/mjs/RateLimit/memory.mjs.map +0 -1
- package/mjs/RateLimit/utils.mjs +0 -18
- package/mjs/RateLimit/utils.mjs.map +0 -1
- package/mjs/RateLimit.mjs +0 -28
- package/mjs/RateLimit.mjs.map +0 -1
- package/mjs/gateway.mjs +0 -19
- package/mjs/gateway.mjs.map +0 -1
- package/mjs/index.mjs +0 -18
- package/mjs/index.mjs.map +0 -1
- package/mjs/types.mjs +0 -356
- package/mjs/types.mjs.map +0 -1
- package/mjs/utils/Effect.mjs +0 -18
- package/mjs/utils/Effect.mjs.map +0 -1
- package/mjs/version.mjs +0 -2
- package/mjs/version.mjs.map +0 -1
- package/mjs/webhooks.mjs +0 -6
- package/mjs/webhooks.mjs.map +0 -1
- package/src/version.ts +0 -1
- package/types.d.ts +0 -2457
- package/types.d.ts.map +0 -1
- package/types.js +0 -408
- package/types.js.map +0 -1
- package/utils/Effect.d.ts +0 -5
- package/utils/Effect.d.ts.map +0 -1
- package/utils/Effect.js +0 -27
- package/utils/Effect.js.map +0 -1
- package/version.d.ts +0 -2
- package/version.d.ts.map +0 -1
- package/version.js +0 -8
- package/version.js.map +0 -1
- package/webhooks.d.ts +0 -8
- package/webhooks.d.ts.map +0 -1
- package/webhooks.js +0 -55
- package/webhooks.js.map +0 -1
|
@@ -1,75 +1,56 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import type { NoSuchElementException } from "effect/Cause"
|
|
6
|
-
import { GenericTag } from "effect/Context"
|
|
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"
|
|
7
5
|
import * as Effect from "effect/Effect"
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
-
import * as Types from "effect/Types"
|
|
6
|
+
import * as ServiceMap from "effect/ServiceMap"
|
|
11
7
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
export const Interaction = GenericTag<
|
|
16
|
-
DiscordInteraction,
|
|
8
|
+
export class Interaction extends ServiceMap.Service<
|
|
9
|
+
Interaction,
|
|
17
10
|
Discord.APIInteraction
|
|
18
|
-
>("dfx/Interactions/Interaction")
|
|
11
|
+
>()("dfx/Interactions/Interaction") {}
|
|
12
|
+
export type DiscordInteraction = Interaction
|
|
19
13
|
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
export const ApplicationCommand = GenericTag<
|
|
24
|
-
DiscordApplicationCommand,
|
|
14
|
+
export class ApplicationCommand extends ServiceMap.Service<
|
|
15
|
+
ApplicationCommand,
|
|
25
16
|
Discord.APIApplicationCommandInteraction["data"]
|
|
26
|
-
>("dfx/Interactions/ApplicationCommand")
|
|
17
|
+
>()("dfx/Interactions/ApplicationCommand") {}
|
|
18
|
+
export type DiscordApplicationCommand = ApplicationCommand
|
|
27
19
|
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
export const MessageComponentData = GenericTag<
|
|
32
|
-
DiscordMessageComponent,
|
|
20
|
+
export class MessageComponentData extends ServiceMap.Service<
|
|
21
|
+
MessageComponentData,
|
|
33
22
|
Discord.APIMessageComponentInteractionData
|
|
34
|
-
>("dfx/Interactions/MessageComponentData")
|
|
23
|
+
>()("dfx/Interactions/MessageComponentData") {}
|
|
24
|
+
export type DiscordMessageComponent = MessageComponentData
|
|
35
25
|
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
export const ModalSubmitData = GenericTag<
|
|
40
|
-
DiscordModalSubmit,
|
|
26
|
+
export class ModalSubmitData extends ServiceMap.Service<
|
|
27
|
+
ModalSubmitData,
|
|
41
28
|
Discord.APIModalSubmission
|
|
42
|
-
>("dfx/Interactions/ModalSubmitData")
|
|
29
|
+
>()("dfx/Interactions/ModalSubmitData") {}
|
|
30
|
+
export type DiscordModalSubmit = ModalSubmitData
|
|
43
31
|
|
|
44
|
-
export
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
export const FocusedOptionContext = GenericTag<
|
|
48
|
-
DiscordFocusedOption,
|
|
32
|
+
export class FocusedOptionContext extends ServiceMap.Service<
|
|
33
|
+
FocusedOptionContext,
|
|
49
34
|
Discord.APIApplicationCommandInteractionDataOption
|
|
50
|
-
>("dfx/Interactions/FocusedOptionContext")
|
|
35
|
+
>()("dfx/Interactions/FocusedOptionContext") {}
|
|
36
|
+
export type DiscordFocusedOption = FocusedOptionContext
|
|
51
37
|
|
|
52
|
-
export interface
|
|
53
|
-
readonly _: unique symbol
|
|
54
|
-
}
|
|
55
|
-
export interface SubCommandContext {
|
|
38
|
+
export interface SubCommandContextData {
|
|
56
39
|
readonly command: Discord.APIApplicationCommandInteractionDataSubcommandOption
|
|
57
40
|
}
|
|
58
|
-
export
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
>("dfx/Interactions/SubCommandContext")
|
|
41
|
+
export class SubCommandContext extends ServiceMap.Service<
|
|
42
|
+
SubCommandContext,
|
|
43
|
+
SubCommandContextData
|
|
44
|
+
>()("dfx/Interactions/SubCommandContext") {}
|
|
45
|
+
export type DiscordSubCommand = SubCommandContext
|
|
62
46
|
|
|
63
47
|
export const resolvedValues = <A>(
|
|
64
48
|
f: (
|
|
65
49
|
id: Discord.Snowflake,
|
|
66
50
|
data: Discord.InteractionDataResolved,
|
|
67
51
|
) => A | undefined,
|
|
68
|
-
): Effect.Effect<
|
|
69
|
-
|
|
70
|
-
NoSuchElementException,
|
|
71
|
-
DiscordInteraction
|
|
72
|
-
> => Effect.flatMap(Interaction, ix => IxHelpers.resolveValues(f)(ix))
|
|
52
|
+
): Effect.Effect<ReadonlyArray<A>, NoSuchElementError, DiscordInteraction> =>
|
|
53
|
+
Interaction.use(ix => Effect.fromOption(IxHelpers.resolveValues(f)(ix)))
|
|
73
54
|
|
|
74
55
|
export const resolved = <A>(
|
|
75
56
|
name: string,
|
|
@@ -77,17 +58,16 @@ export const resolved = <A>(
|
|
|
77
58
|
id: Discord.Snowflake,
|
|
78
59
|
data: Discord.InteractionDataResolved,
|
|
79
60
|
) => A | undefined,
|
|
80
|
-
): Effect.Effect<A,
|
|
81
|
-
|
|
61
|
+
): Effect.Effect<A, NoSuchElementError, DiscordInteraction> =>
|
|
62
|
+
Interaction.use(ix =>
|
|
63
|
+
Effect.fromOption(IxHelpers.resolveOptionValue(name, f)(ix)),
|
|
64
|
+
)
|
|
82
65
|
|
|
83
|
-
export const focusedOptionValue =
|
|
84
|
-
"value" in _ ? _.value : "",
|
|
66
|
+
export const focusedOptionValue = FocusedOptionContext.use(_ =>
|
|
67
|
+
Effect.succeed("value" in _ ? _.value : ""),
|
|
85
68
|
)
|
|
86
69
|
|
|
87
|
-
export class SubCommandNotFound extends
|
|
88
|
-
InteractionsErrorTypeId,
|
|
89
|
-
"SubCommandNotFound",
|
|
90
|
-
)<{
|
|
70
|
+
export class SubCommandNotFound extends Data.TaggedError("SubCommandNotFound")<{
|
|
91
71
|
data: Discord.APIApplicationCommandInteraction["data"]
|
|
92
72
|
}> {}
|
|
93
73
|
|
|
@@ -95,7 +75,7 @@ export const currentSubCommand: Effect.Effect<
|
|
|
95
75
|
Discord.APIApplicationCommandInteractionDataSubcommandOption,
|
|
96
76
|
never,
|
|
97
77
|
DiscordSubCommand
|
|
98
|
-
> =
|
|
78
|
+
> = SubCommandContext.use(_ => Effect.succeed(_.command))
|
|
99
79
|
|
|
100
80
|
export class RequiredOptionNotFound {
|
|
101
81
|
readonly _tag = "RequiredOptionNotFound"
|
|
@@ -107,12 +87,18 @@ export class RequiredOptionNotFound {
|
|
|
107
87
|
) {}
|
|
108
88
|
}
|
|
109
89
|
|
|
110
|
-
export const modalValues =
|
|
90
|
+
export const modalValues = ModalSubmitData.use(data =>
|
|
91
|
+
Effect.succeed(IxHelpers.componentsMap(data)),
|
|
92
|
+
)
|
|
111
93
|
|
|
112
94
|
export const modalValueOption = (name: string) =>
|
|
113
|
-
|
|
95
|
+
ModalSubmitData.use(data =>
|
|
96
|
+
Effect.succeed(IxHelpers.componentValue(name)(data)),
|
|
97
|
+
)
|
|
114
98
|
|
|
115
99
|
export const modalValue = (
|
|
116
100
|
name: string,
|
|
117
|
-
): Effect.Effect<string,
|
|
118
|
-
|
|
101
|
+
): Effect.Effect<string, NoSuchElementError, DiscordModalSubmit> =>
|
|
102
|
+
ModalSubmitData.use(data =>
|
|
103
|
+
Effect.fromOption(IxHelpers.componentValue(name)(data)),
|
|
104
|
+
)
|
|
@@ -5,10 +5,10 @@ import type {
|
|
|
5
5
|
DiscordInteraction,
|
|
6
6
|
DiscordMessageComponent,
|
|
7
7
|
DiscordModalSubmit,
|
|
8
|
-
} from "
|
|
9
|
-
import type * as Discord from "
|
|
8
|
+
} from "./context.ts"
|
|
9
|
+
import type * as Discord from "../types.ts"
|
|
10
10
|
import type { Scope } from "effect/Scope"
|
|
11
|
-
import type { CommandHelper } from "./commandHelper"
|
|
11
|
+
import type { CommandHelper } from "./commandHelper.ts"
|
|
12
12
|
|
|
13
13
|
export type InteractionDefinition<R, E> =
|
|
14
14
|
| GlobalApplicationCommand<R, E>
|
|
@@ -1,40 +1,37 @@
|
|
|
1
|
+
import * as Arr from "effect/Array"
|
|
1
2
|
import * as Chunk from "effect/Chunk"
|
|
2
|
-
import type { Tag } from "effect/Context"
|
|
3
|
-
import { GenericTag } from "effect/Context"
|
|
4
3
|
import * as Duration from "effect/Duration"
|
|
5
|
-
import { pipe } from "effect/Function"
|
|
6
4
|
import * as Effect from "effect/Effect"
|
|
5
|
+
import { pipe } from "effect/Function"
|
|
7
6
|
import * as Layer from "effect/Layer"
|
|
8
7
|
import * as Queue from "effect/Queue"
|
|
9
8
|
import * as Ref from "effect/Ref"
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
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"
|
|
13
15
|
import type {
|
|
14
16
|
GlobalApplicationCommand,
|
|
15
17
|
GuildApplicationCommand,
|
|
16
|
-
} from "
|
|
17
|
-
import type { DefinitionNotFound } from "
|
|
18
|
-
import { handlers } from "
|
|
19
|
-
import type {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from "dfx/Interactions/index"
|
|
23
|
-
import { builder, Interaction } from "dfx/Interactions/index"
|
|
24
|
-
import * as EffectUtils from "dfx/utils/Effect"
|
|
25
|
-
import * as Schedule from "effect/Schedule"
|
|
26
|
-
import { globalValue } from "effect/GlobalValue"
|
|
27
|
-
import * as FiberRef from "effect/FiberRef"
|
|
28
|
-
import type { ListMyGuilds200, MyGuildResponse } from "dfx/types"
|
|
29
|
-
import * as Arr from "effect/Array"
|
|
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"
|
|
30
24
|
|
|
31
|
-
export const interactionsSync
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
25
|
+
export const interactionsSync = ServiceMap.Reference("dfx/Interactions/sync", {
|
|
26
|
+
defaultValue: () => true,
|
|
27
|
+
})
|
|
35
28
|
|
|
36
29
|
export const setInteractionsSync = (enabled: boolean) =>
|
|
37
|
-
Layer.
|
|
30
|
+
Layer.provide(Layer.succeed(interactionsSync, enabled))
|
|
31
|
+
|
|
32
|
+
const retryPolicy = Schedule.exponential("1 seconds").pipe(
|
|
33
|
+
Schedule.either(Schedule.spaced("20 seconds")),
|
|
34
|
+
)
|
|
38
35
|
|
|
39
36
|
export const run =
|
|
40
37
|
<R, R2, E, TE, E2>(
|
|
@@ -89,7 +86,7 @@ export const run =
|
|
|
89
86
|
const next: ListMyGuilds200 = yield* rest.listMyGuilds({
|
|
90
87
|
after: results && Arr.lastNonEmpty(results).id,
|
|
91
88
|
})
|
|
92
|
-
if (!Arr.
|
|
89
|
+
if (!Arr.isReadonlyArrayNonEmpty(next)) break
|
|
93
90
|
results = next
|
|
94
91
|
yield* Effect.forEach(
|
|
95
92
|
results!,
|
|
@@ -125,7 +122,7 @@ export const run =
|
|
|
125
122
|
return hasFiles ? rest.withFiles(r.files as any)(effect) : effect
|
|
126
123
|
})
|
|
127
124
|
|
|
128
|
-
const
|
|
125
|
+
const interactionRun = gateway.handleDispatch("INTERACTION_CREATE", i =>
|
|
129
126
|
Effect.withSpan(
|
|
130
127
|
Effect.provideService(postHandler(handle[i.type](i)), Interaction, i),
|
|
131
128
|
"dfx.Interaction",
|
|
@@ -133,16 +130,16 @@ export const run =
|
|
|
133
130
|
),
|
|
134
131
|
)
|
|
135
132
|
|
|
136
|
-
const sync = yield*
|
|
133
|
+
const sync = yield* interactionsSync
|
|
137
134
|
|
|
138
135
|
return yield* sync
|
|
139
136
|
? Effect.forever(
|
|
140
|
-
Effect.all([
|
|
137
|
+
Effect.all([interactionRun, globalSync, guildSync], {
|
|
141
138
|
concurrency: "unbounded",
|
|
142
139
|
discard: true,
|
|
143
140
|
}),
|
|
144
141
|
)
|
|
145
|
-
:
|
|
142
|
+
: interactionRun
|
|
146
143
|
})
|
|
147
144
|
|
|
148
145
|
const makeRegistry = Effect.gen(function* () {
|
|
@@ -160,16 +157,12 @@ const makeRegistry = Effect.gen(function* () {
|
|
|
160
157
|
yield* EffectUtils.foreverSwitch(Queue.take(queue), ix =>
|
|
161
158
|
pipe(
|
|
162
159
|
ix,
|
|
163
|
-
run(Effect.
|
|
160
|
+
run(Effect.catchCause(_ => Effect.logError("unhandled error", _))),
|
|
164
161
|
Effect.delay(Duration.seconds(5)),
|
|
165
162
|
),
|
|
166
163
|
).pipe(
|
|
167
|
-
Effect.
|
|
168
|
-
Effect.retry(
|
|
169
|
-
Schedule.exponential("1 seconds").pipe(
|
|
170
|
-
Schedule.union(Schedule.spaced("20 seconds")),
|
|
171
|
-
),
|
|
172
|
-
),
|
|
164
|
+
Effect.tapCause(_ => Effect.logError("registry error", _)),
|
|
165
|
+
Effect.retry(retryPolicy),
|
|
173
166
|
Effect.forkScoped,
|
|
174
167
|
Effect.interruptible,
|
|
175
168
|
)
|
|
@@ -187,19 +180,14 @@ export interface InteractionsRegistryService {
|
|
|
187
180
|
ix: InteractionBuilder<never, E, never>,
|
|
188
181
|
) => Effect.Effect<void>
|
|
189
182
|
}
|
|
190
|
-
export interface InteractionsRegistry {
|
|
191
|
-
readonly _: unique symbol
|
|
192
|
-
}
|
|
193
183
|
|
|
194
|
-
export
|
|
184
|
+
export class InteractionsRegistry extends ServiceMap.Service<
|
|
195
185
|
InteractionsRegistry,
|
|
196
186
|
InteractionsRegistryService
|
|
197
|
-
>
|
|
198
|
-
"dfx/Interactions/InteractionsRegistry",
|
|
199
|
-
)
|
|
187
|
+
>()("dfx/Interactions/InteractionsRegistry") {}
|
|
200
188
|
|
|
201
189
|
export const InteractionsRegistryLive: Layer.Layer<
|
|
202
190
|
InteractionsRegistry,
|
|
203
191
|
never,
|
|
204
192
|
DiscordREST | DiscordGateway
|
|
205
|
-
> = Layer.
|
|
193
|
+
> = Layer.effect(InteractionsRegistry, makeRegistry)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type * as Chunk from "effect/Chunk"
|
|
2
2
|
import * as Effect from "effect/Effect"
|
|
3
|
-
import * as IxHelpers from "
|
|
4
|
-
import * as Ctx from "
|
|
5
|
-
import type * as D from "
|
|
6
|
-
import { flattenDefinitions, splitDefinitions } from "
|
|
7
|
-
import * as Discord from "
|
|
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
8
|
import type { Scope } from "effect/Scope"
|
|
9
9
|
|
|
10
10
|
export class DefinitionNotFound {
|
|
@@ -58,6 +58,9 @@ export const handlers = <R, E, TE, A, B>(
|
|
|
58
58
|
) as Handler<Exclude<R, Scope>, E, B>
|
|
59
59
|
},
|
|
60
60
|
|
|
61
|
+
[Discord.InteractionTypes.SOCIAL_LAYER_SKU_PURCHASE_ELIGIBILITY]: i =>
|
|
62
|
+
Effect.fail(new DefinitionNotFound(i)),
|
|
63
|
+
|
|
61
64
|
[Discord.InteractionTypes.MODAL_SUBMIT]: i => {
|
|
62
65
|
const data = i.data as Discord.APIModalSubmission
|
|
63
66
|
const match = ModalSubmit.find(_ => _.predicate(data.custom_id))
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export { response } from "
|
|
2
|
-
export * from "
|
|
3
|
-
export * from "
|
|
1
|
+
export { response } from "../Helpers/interactions.ts"
|
|
2
|
+
export * from "./builder.ts"
|
|
3
|
+
export * from "./context.ts"
|
|
4
|
+
export type { InteractionDefinition } from "./definitions.ts"
|
|
4
5
|
export {
|
|
5
6
|
autocomplete,
|
|
6
7
|
global,
|
|
7
8
|
guild,
|
|
8
|
-
InteractionDefinition,
|
|
9
9
|
messageComponent,
|
|
10
10
|
modalSubmit,
|
|
11
|
-
} from "
|
|
11
|
+
} from "./definitions.ts"
|
|
12
12
|
|
|
13
13
|
// Filters
|
|
14
14
|
export const id = (query: string) => (customId: string) => query === customId
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as Chunk from "effect/Chunk"
|
|
2
2
|
import * as Effect from "effect/Effect"
|
|
3
|
-
import type * as D from "
|
|
4
|
-
import type * as Discord from "
|
|
3
|
+
import type * as D from "./definitions.ts"
|
|
4
|
+
import type * as Discord from "../types.ts"
|
|
5
5
|
import * as Array from "effect/Array"
|
|
6
|
-
import { CommandHelper } from "
|
|
6
|
+
import { CommandHelper } from "./commandHelper.ts"
|
|
7
7
|
|
|
8
8
|
export type DefinitionFlattened<R, E, TE, A> =
|
|
9
|
-
D.InteractionDefinition<R, E> extends infer
|
|
9
|
+
D.InteractionDefinition<R, E> extends infer Def
|
|
10
10
|
? {
|
|
11
|
-
[K in keyof
|
|
11
|
+
[K in keyof Def]: K extends "handle"
|
|
12
12
|
? (_: Discord.APIInteraction) => Effect.Effect<A, TE, R>
|
|
13
|
-
:
|
|
13
|
+
: Def[K]
|
|
14
14
|
}
|
|
15
15
|
: never
|
|
16
16
|
|
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
import * as Chunk from "effect/Chunk"
|
|
2
|
-
import { GenericTag } from "effect/Context"
|
|
3
2
|
import { identity } from "effect/Function"
|
|
4
3
|
import * as Option from "effect/Option"
|
|
5
4
|
import type * as Cause from "effect/Cause"
|
|
6
5
|
import type * as Config from "effect/Config"
|
|
7
|
-
import type * as ConfigError from "effect/ConfigError"
|
|
8
6
|
import * as Redacted from "effect/Redacted"
|
|
9
7
|
import * as Effect from "effect/Effect"
|
|
10
8
|
import * as Layer from "effect/Layer"
|
|
11
|
-
import
|
|
12
|
-
import type
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import { Interaction } from "dfx/Interactions/index"
|
|
19
|
-
import type * as Discord from "dfx/types"
|
|
9
|
+
import * as ServiceMap from "effect/ServiceMap"
|
|
10
|
+
import type * as D from "./definitions.ts"
|
|
11
|
+
import type { DefinitionNotFound } from "./handlers.ts"
|
|
12
|
+
import { handlers } from "./handlers.ts"
|
|
13
|
+
import type { DiscordInteraction, InteractionBuilder } from "./index.ts"
|
|
14
|
+
import { Interaction } from "./index.ts"
|
|
15
|
+
import type * as Discord from "../types.ts"
|
|
20
16
|
import * as Verify from "discord-verify"
|
|
21
|
-
import
|
|
22
|
-
import { InteractionsErrorTypeId } from "dfx/Interactions/error"
|
|
17
|
+
import * as Data from "effect/Data"
|
|
23
18
|
|
|
24
19
|
export class BadWebhookSignature {
|
|
25
20
|
readonly _tag = "BadWebhookSignature"
|
|
@@ -34,10 +29,12 @@ const checkSignature = (
|
|
|
34
29
|
crypto: SubtleCrypto,
|
|
35
30
|
algorithm: any,
|
|
36
31
|
) =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
Effect.fromOption(
|
|
33
|
+
Option.all({
|
|
34
|
+
signature: Option.fromNullishOr(headers["x-signature-ed25519"]),
|
|
35
|
+
timestamp: Option.fromNullishOr(headers["x-signature-timestamp"]),
|
|
36
|
+
}),
|
|
37
|
+
).pipe(
|
|
41
38
|
Effect.flatMap(_ =>
|
|
42
39
|
Effect.promise(() =>
|
|
43
40
|
Verify.verify(
|
|
@@ -51,7 +48,7 @@ const checkSignature = (
|
|
|
51
48
|
),
|
|
52
49
|
),
|
|
53
50
|
Effect.filterOrFail(identity, () => new BadWebhookSignature()),
|
|
54
|
-
Effect.
|
|
51
|
+
Effect.catchCause(() => Effect.fail(new BadWebhookSignature())),
|
|
55
52
|
Effect.asVoid,
|
|
56
53
|
)
|
|
57
54
|
|
|
@@ -73,37 +70,33 @@ const makeConfig = ({
|
|
|
73
70
|
algorithm: Verify.PlatformAlgorithm[algorithm],
|
|
74
71
|
})
|
|
75
72
|
|
|
76
|
-
export
|
|
77
|
-
readonly _: unique symbol
|
|
78
|
-
}
|
|
79
|
-
export const WebhookConfig = GenericTag<
|
|
73
|
+
export class WebhookConfig extends ServiceMap.Service<
|
|
80
74
|
WebhookConfig,
|
|
81
75
|
ReturnType<typeof makeConfig>
|
|
82
|
-
>("dfx/Interactions/WebhookConfig")
|
|
76
|
+
>()("dfx/Interactions/WebhookConfig") {}
|
|
83
77
|
|
|
84
78
|
export const layer = (opts: MakeConfigOpts) =>
|
|
85
79
|
Layer.succeed(WebhookConfig, makeConfig(opts))
|
|
86
80
|
|
|
87
81
|
export const layerConfig: (
|
|
88
82
|
config: Config.Config<MakeConfigOpts>,
|
|
89
|
-
) => Layer.Layer<WebhookConfig,
|
|
83
|
+
) => Layer.Layer<WebhookConfig, Config.ConfigError> = (
|
|
90
84
|
config: Config.Config<MakeConfigOpts>,
|
|
91
|
-
) => Layer.effect(WebhookConfig, Effect.map(config, makeConfig))
|
|
85
|
+
) => Layer.effect(WebhookConfig, Effect.map(config.asEffect(), makeConfig))
|
|
92
86
|
|
|
93
|
-
export class WebhookParseError extends
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
)<{ cause: unknown }> {}
|
|
87
|
+
export class WebhookParseError extends Data.TaggedError("WebhookParseError")<{
|
|
88
|
+
cause: unknown
|
|
89
|
+
}> {}
|
|
97
90
|
|
|
98
91
|
const fromHeadersAndBody = (headers: Headers, body: string) =>
|
|
99
|
-
|
|
100
|
-
checkSignature(publicKey, headers, body, crypto, algorithm)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
92
|
+
WebhookConfig.use(({ algorithm, crypto, publicKey }) =>
|
|
93
|
+
checkSignature(publicKey, headers, body, crypto, algorithm).pipe(
|
|
94
|
+
Effect.andThen(
|
|
95
|
+
Effect.try({
|
|
96
|
+
try: () => JSON.parse(body) as Discord.APIInteraction,
|
|
97
|
+
catch: cause => new WebhookParseError({ cause }),
|
|
98
|
+
}),
|
|
99
|
+
),
|
|
107
100
|
),
|
|
108
101
|
)
|
|
109
102
|
|
|
@@ -181,7 +174,7 @@ export const makeHandler = <R, E, TE>(
|
|
|
181
174
|
>): Effect.Effect<void, never, WebhookConfig> =>
|
|
182
175
|
handle(headers, body).pipe(
|
|
183
176
|
Effect.flatMap(success),
|
|
184
|
-
Effect.
|
|
177
|
+
Effect.catchCause(error),
|
|
185
178
|
)
|
|
186
179
|
}
|
|
187
180
|
|
package/src/RateLimit/memory.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Option from "effect/Option"
|
|
2
2
|
import * as Effect from "effect/Effect"
|
|
3
|
-
import type { BucketDetails, RateLimitStoreService } from "
|
|
3
|
+
import type { BucketDetails, RateLimitStoreService } from "../RateLimit.ts"
|
|
4
4
|
|
|
5
5
|
interface Counter {
|
|
6
6
|
count: number
|
|
@@ -14,12 +14,12 @@ export const make = (): RateLimitStoreService => {
|
|
|
14
14
|
|
|
15
15
|
const getCounter = (key: string) =>
|
|
16
16
|
Option.filter(
|
|
17
|
-
Option.
|
|
17
|
+
Option.fromNullishOr(counters.get(key)),
|
|
18
18
|
c => c.expires > Date.now(),
|
|
19
19
|
)
|
|
20
20
|
|
|
21
21
|
const getBucketForRoute = (route: string) =>
|
|
22
|
-
Effect.sync(() => Option.
|
|
22
|
+
Effect.sync(() => Option.fromNullishOr(buckets.get(routes.get(route)!)))
|
|
23
23
|
|
|
24
24
|
return {
|
|
25
25
|
hasBucket: key => Effect.sync(() => buckets.has(key)),
|
package/src/RateLimit.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { GenericTag } from "effect/Context"
|
|
2
1
|
import * as Duration from "effect/Duration"
|
|
3
2
|
import type * as Option from "effect/Option"
|
|
4
3
|
import * as Effect from "effect/Effect"
|
|
5
4
|
import * as Layer from "effect/Layer"
|
|
6
|
-
import * as Memory from "
|
|
7
|
-
import { delayFrom } from "
|
|
5
|
+
import * as Memory from "./RateLimit/memory.ts"
|
|
6
|
+
import { delayFrom } from "./RateLimit/utils.ts"
|
|
7
|
+
import * as ServiceMap from "effect/ServiceMap"
|
|
8
8
|
|
|
9
9
|
export type BucketDetails = {
|
|
10
10
|
key: "global" | string
|
|
@@ -35,13 +35,11 @@ export interface RateLimitStoreService {
|
|
|
35
35
|
readonly removeCounter: (key: string) => Effect.Effect<void>
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
export class RateLimitStore extends ServiceMap.Service<
|
|
39
|
+
RateLimitStore,
|
|
40
|
+
RateLimitStoreService
|
|
41
|
+
>()("dfx/RateLimit/RateLimitStore") {}
|
|
41
42
|
|
|
42
|
-
export const RateLimitStore = GenericTag<RateLimitStore, RateLimitStoreService>(
|
|
43
|
-
"dfx/RateLimit/RateLimitStore",
|
|
44
|
-
)
|
|
45
43
|
export const MemoryRateLimitStoreLive = Layer.sync(RateLimitStore, Memory.make)
|
|
46
44
|
|
|
47
45
|
const makeLimiter = Effect.gen(function* () {
|
|
@@ -77,11 +75,16 @@ const makeLimiter = Effect.gen(function* () {
|
|
|
77
75
|
return { maybeWait }
|
|
78
76
|
})
|
|
79
77
|
|
|
80
|
-
export
|
|
81
|
-
readonly _: unique symbol
|
|
82
|
-
}
|
|
83
|
-
export const RateLimiter = GenericTag<
|
|
78
|
+
export class RateLimiter extends ServiceMap.Service<
|
|
84
79
|
RateLimiter,
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
{
|
|
81
|
+
maybeWait: (
|
|
82
|
+
key: string,
|
|
83
|
+
window: Duration.Duration,
|
|
84
|
+
limit: number,
|
|
85
|
+
multiplier?: number,
|
|
86
|
+
) => Effect.Effect<void, never, never>
|
|
87
|
+
}
|
|
88
|
+
>()("dfx/RateLimit/RateLimiter") {}
|
|
89
|
+
|
|
87
90
|
export const RateLimiterLive = Layer.effect(RateLimiter, makeLimiter)
|
package/src/gateway.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import * as CachePrelude from "
|
|
2
|
-
import type { DiscordGateway } from "
|
|
3
|
-
import { DiscordGatewayLive } from "
|
|
4
|
-
import * as DiscordWS from "
|
|
5
|
-
import { JsonDiscordWSCodecLive } from "
|
|
6
|
-
import * as Shard from "
|
|
7
|
-
import { ShardStateStore } from "
|
|
8
|
-
import * as SendEvent from "
|
|
9
|
-
import * as ShardStore from "
|
|
10
|
-
import { MemoryShardStoreLive } from "
|
|
11
|
-
import type { DiscordREST } from "
|
|
12
|
-
import { DiscordRESTLive } from "
|
|
13
|
-
import type { InteractionsRegistry } from "
|
|
14
|
-
import { InteractionsRegistryLive } from "
|
|
15
|
-
import type { RateLimiter } from "
|
|
16
|
-
import { MemoryRateLimitStoreLive, RateLimiterLive } from "
|
|
1
|
+
import * as CachePrelude from "./Cache/prelude.ts"
|
|
2
|
+
import type { DiscordGateway } from "./DiscordGateway.ts"
|
|
3
|
+
import { DiscordGatewayLive } from "./DiscordGateway.ts"
|
|
4
|
+
import * as DiscordWS from "./DiscordGateway/DiscordWS.ts"
|
|
5
|
+
import { JsonDiscordWSCodecLive } from "./DiscordGateway/DiscordWS.ts"
|
|
6
|
+
import * as Shard from "./DiscordGateway/Shard.ts"
|
|
7
|
+
import { ShardStateStore } from "./DiscordGateway/Shard/StateStore.ts"
|
|
8
|
+
import * as SendEvent from "./DiscordGateway/Shard/sendEvents.ts"
|
|
9
|
+
import * as ShardStore from "./DiscordGateway/ShardStore.ts"
|
|
10
|
+
import { MemoryShardStoreLive } from "./DiscordGateway/ShardStore.ts"
|
|
11
|
+
import type { DiscordREST } from "./DiscordREST.ts"
|
|
12
|
+
import { DiscordRESTLive } from "./DiscordREST.ts"
|
|
13
|
+
import type { InteractionsRegistry } from "./Interactions/gateway.ts"
|
|
14
|
+
import { InteractionsRegistryLive } from "./Interactions/gateway.ts"
|
|
15
|
+
import type { RateLimiter } from "./RateLimit.ts"
|
|
16
|
+
import { MemoryRateLimitStoreLive, RateLimiterLive } from "./RateLimit.ts"
|
|
17
17
|
import * as Layer from "effect/Layer"
|
|
18
|
-
import type * as HttpClient from "
|
|
19
|
-
import type { DiscordConfig } from "
|
|
20
|
-
import type { WebSocketConstructor } from "
|
|
18
|
+
import type * as HttpClient from "effect/unstable/http/HttpClient"
|
|
19
|
+
import type { DiscordConfig } from "./DiscordConfig.ts"
|
|
20
|
+
import type { WebSocketConstructor } from "effect/unstable/socket/Socket"
|
|
21
21
|
|
|
22
|
-
export { DiscordGateway, DiscordGatewayLive } from "
|
|
22
|
+
export { DiscordGateway, DiscordGatewayLive } from "./DiscordGateway.ts"
|
|
23
23
|
|
|
24
24
|
export {
|
|
25
25
|
InteractionsRegistry,
|
|
@@ -27,7 +27,7 @@ export {
|
|
|
27
27
|
interactionsSync,
|
|
28
28
|
run as runIx,
|
|
29
29
|
setInteractionsSync,
|
|
30
|
-
} from "
|
|
30
|
+
} from "./Interactions/gateway.ts"
|
|
31
31
|
|
|
32
32
|
export { CachePrelude, DiscordWS, SendEvent, Shard, ShardStore }
|
|
33
33
|
|