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.
- package/dist/Cache/driver.d.ts.map +1 -1
- package/dist/Cache/memory.d.ts.map +1 -1
- package/dist/Cache/memoryTTL.d.ts.map +1 -1
- package/dist/Cache/prelude.d.ts.map +1 -1
- package/dist/Cache.d.ts.map +1 -1
- package/dist/DiscordConfig.d.ts.map +1 -1
- package/dist/DiscordGateway/DiscordWS.d.ts.map +1 -1
- package/dist/DiscordGateway/Messaging.d.ts.map +1 -1
- package/dist/DiscordGateway/Shard/StateStore.d.ts.map +1 -1
- package/dist/DiscordGateway/Shard/heartbeats.d.ts.map +1 -1
- package/dist/DiscordGateway/Shard/identify.d.ts.map +1 -1
- package/dist/DiscordGateway/Shard/sendEvents.d.ts.map +1 -1
- package/dist/DiscordGateway/Shard/utils.d.ts.map +1 -1
- package/dist/DiscordGateway/Shard.d.ts.map +1 -1
- package/dist/DiscordGateway/ShardStore.d.ts.map +1 -1
- package/dist/DiscordGateway/Sharder.d.ts +1 -1
- package/dist/DiscordGateway/Sharder.d.ts.map +1 -1
- package/dist/DiscordGateway.d.ts.map +1 -1
- package/dist/DiscordREST/Generated.d.ts.map +1 -1
- package/dist/DiscordREST/utils.d.ts.map +1 -1
- package/dist/DiscordREST.d.ts.map +1 -1
- package/dist/Helpers/flags.d.ts.map +1 -1
- package/dist/Helpers/intents.d.ts.map +1 -1
- package/dist/Helpers/interactions.d.ts.map +1 -1
- package/dist/Helpers/members.d.ts.map +1 -1
- package/dist/Helpers/permissions.d.ts.map +1 -1
- package/dist/Helpers/ui.d.ts.map +1 -1
- package/dist/Interactions/builder.d.ts.map +1 -1
- package/dist/Interactions/commandHelper.d.ts.map +1 -1
- package/dist/Interactions/context.d.ts.map +1 -1
- package/dist/Interactions/definitions.d.ts.map +1 -1
- package/dist/Interactions/error.d.ts.map +1 -1
- package/dist/Interactions/gateway.d.ts.map +1 -1
- package/dist/Interactions/handlers.d.ts.map +1 -1
- package/dist/Interactions/index.d.ts.map +1 -1
- package/dist/Interactions/utils.d.ts.map +1 -1
- package/dist/Interactions/webhook.d.ts.map +1 -1
- package/dist/RateLimit/memory.d.ts.map +1 -1
- package/dist/RateLimit/utils.d.ts.map +1 -1
- package/dist/RateLimit.d.ts.map +1 -1
- package/dist/gateway.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/Effect.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/webhooks.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/version.ts +1 -1
- package/dist/LICENSE +0 -21
- package/dist/README.md +0 -66
- package/dist/mjs/Cache/driver.mjs +0 -3
- package/dist/mjs/Cache/driver.mjs.map +0 -1
- package/dist/mjs/Cache/memory.mjs +0 -48
- package/dist/mjs/Cache/memory.mjs.map +0 -1
- package/dist/mjs/Cache/memoryTTL.mjs +0 -119
- package/dist/mjs/Cache/memoryTTL.mjs.map +0 -1
- package/dist/mjs/Cache/prelude.mjs +0 -131
- package/dist/mjs/Cache/prelude.mjs.map +0 -1
- package/dist/mjs/Cache.mjs +0 -90
- package/dist/mjs/Cache.mjs.map +0 -1
- package/dist/mjs/DiscordConfig.mjs +0 -32
- package/dist/mjs/DiscordConfig.mjs.map +0 -1
- package/dist/mjs/DiscordGateway/DiscordWS.mjs +0 -77
- package/dist/mjs/DiscordGateway/DiscordWS.mjs.map +0 -1
- package/dist/mjs/DiscordGateway/Messaging.mjs +0 -35
- package/dist/mjs/DiscordGateway/Messaging.mjs.map +0 -1
- package/dist/mjs/DiscordGateway/Shard/StateStore.mjs +0 -41
- package/dist/mjs/DiscordGateway/Shard/StateStore.mjs.map +0 -1
- package/dist/mjs/DiscordGateway/Shard/heartbeats.mjs +0 -25
- package/dist/mjs/DiscordGateway/Shard/heartbeats.mjs.map +0 -1
- package/dist/mjs/DiscordGateway/Shard/identify.mjs +0 -29
- package/dist/mjs/DiscordGateway/Shard/identify.mjs.map +0 -1
- package/dist/mjs/DiscordGateway/Shard/sendEvents.mjs +0 -26
- package/dist/mjs/DiscordGateway/Shard/sendEvents.mjs.map +0 -1
- package/dist/mjs/DiscordGateway/Shard/utils.mjs +0 -3
- package/dist/mjs/DiscordGateway/Shard/utils.mjs.map +0 -1
- package/dist/mjs/DiscordGateway/Shard.mjs +0 -147
- package/dist/mjs/DiscordGateway/Shard.mjs.map +0 -1
- package/dist/mjs/DiscordGateway/ShardStore.mjs +0 -24
- package/dist/mjs/DiscordGateway/ShardStore.mjs.map +0 -1
- package/dist/mjs/DiscordGateway/Sharder.mjs +0 -67
- package/dist/mjs/DiscordGateway/Sharder.mjs.map +0 -1
- package/dist/mjs/DiscordGateway.mjs +0 -21
- package/dist/mjs/DiscordGateway.mjs.map +0 -1
- package/dist/mjs/DiscordREST/Generated.mjs +0 -2471
- package/dist/mjs/DiscordREST/Generated.mjs.map +0 -1
- package/dist/mjs/DiscordREST/utils.mjs +0 -21
- package/dist/mjs/DiscordREST/utils.mjs.map +0 -1
- package/dist/mjs/DiscordREST.mjs +0 -119
- package/dist/mjs/DiscordREST.mjs.map +0 -1
- package/dist/mjs/Helpers/flags.mjs +0 -45
- package/dist/mjs/Helpers/flags.mjs.map +0 -1
- package/dist/mjs/Helpers/intents.mjs +0 -27
- package/dist/mjs/Helpers/intents.mjs.map +0 -1
- package/dist/mjs/Helpers/interactions.mjs +0 -115
- package/dist/mjs/Helpers/interactions.mjs.map +0 -1
- package/dist/mjs/Helpers/members.mjs +0 -9
- package/dist/mjs/Helpers/members.mjs.map +0 -1
- package/dist/mjs/Helpers/permissions.mjs +0 -84
- package/dist/mjs/Helpers/permissions.mjs.map +0 -1
- package/dist/mjs/Helpers/ui.mjs +0 -137
- package/dist/mjs/Helpers/ui.mjs.map +0 -1
- package/dist/mjs/Interactions/builder.mjs +0 -56
- package/dist/mjs/Interactions/builder.mjs.map +0 -1
- package/dist/mjs/Interactions/commandHelper.mjs +0 -49
- package/dist/mjs/Interactions/commandHelper.mjs.map +0 -1
- package/dist/mjs/Interactions/context.mjs +0 -28
- package/dist/mjs/Interactions/context.mjs.map +0 -1
- package/dist/mjs/Interactions/definitions.mjs +0 -51
- package/dist/mjs/Interactions/definitions.mjs.map +0 -1
- package/dist/mjs/Interactions/error.mjs +0 -2
- package/dist/mjs/Interactions/error.mjs.map +0 -1
- package/dist/mjs/Interactions/gateway.mjs +0 -82
- package/dist/mjs/Interactions/gateway.mjs.map +0 -1
- package/dist/mjs/Interactions/handlers.mjs +0 -64
- package/dist/mjs/Interactions/handlers.mjs.map +0 -1
- package/dist/mjs/Interactions/index.mjs +0 -11
- package/dist/mjs/Interactions/index.mjs.map +0 -1
- package/dist/mjs/Interactions/utils.mjs +0 -26
- package/dist/mjs/Interactions/utils.mjs.map +0 -1
- package/dist/mjs/Interactions/webhook.mjs +0 -75
- package/dist/mjs/Interactions/webhook.mjs.map +0 -1
- package/dist/mjs/RateLimit/memory.mjs +0 -39
- package/dist/mjs/RateLimit/memory.mjs.map +0 -1
- package/dist/mjs/RateLimit/utils.mjs +0 -18
- package/dist/mjs/RateLimit/utils.mjs.map +0 -1
- package/dist/mjs/RateLimit.mjs +0 -28
- package/dist/mjs/RateLimit.mjs.map +0 -1
- package/dist/mjs/gateway.mjs +0 -19
- package/dist/mjs/gateway.mjs.map +0 -1
- package/dist/mjs/index.mjs +0 -18
- package/dist/mjs/index.mjs.map +0 -1
- package/dist/mjs/types.mjs +0 -356
- package/dist/mjs/types.mjs.map +0 -1
- package/dist/mjs/utils/Effect.mjs +0 -44
- package/dist/mjs/utils/Effect.mjs.map +0 -1
- package/dist/mjs/version.mjs +0 -2
- package/dist/mjs/version.mjs.map +0 -1
- package/dist/mjs/webhooks.mjs +0 -6
- package/dist/mjs/webhooks.mjs.map +0 -1
- package/dist/package.json +0 -48
- package/dist/src/Cache/driver.ts +0 -37
- package/dist/src/Cache/memory.ts +0 -83
- package/dist/src/Cache/memoryTTL.ts +0 -225
- package/dist/src/Cache/prelude.ts +0 -279
- package/dist/src/Cache.ts +0 -261
- package/dist/src/DiscordConfig.ts +0 -67
- package/dist/src/DiscordGateway/DiscordWS.ts +0 -157
- package/dist/src/DiscordGateway/Messaging.ts +0 -71
- package/dist/src/DiscordGateway/Shard/StateStore.ts +0 -72
- package/dist/src/DiscordGateway/Shard/heartbeats.ts +0 -60
- package/dist/src/DiscordGateway/Shard/identify.ts +0 -50
- package/dist/src/DiscordGateway/Shard/sendEvents.ts +0 -43
- package/dist/src/DiscordGateway/Shard/utils.ts +0 -13
- package/dist/src/DiscordGateway/Shard.ts +0 -205
- package/dist/src/DiscordGateway/ShardStore.ts +0 -42
- package/dist/src/DiscordGateway/Sharder.ts +0 -118
- package/dist/src/DiscordGateway.ts +0 -79
- package/dist/src/DiscordREST/Generated.ts +0 -10832
- package/dist/src/DiscordREST/utils.ts +0 -42
- package/dist/src/DiscordREST.ts +0 -256
- package/dist/src/Helpers/flags.ts +0 -73
- package/dist/src/Helpers/intents.ts +0 -35
- package/dist/src/Helpers/interactions.ts +0 -317
- package/dist/src/Helpers/members.ts +0 -18
- package/dist/src/Helpers/permissions.ts +0 -145
- package/dist/src/Helpers/ui.ts +0 -253
- package/dist/src/Interactions/builder.ts +0 -171
- package/dist/src/Interactions/commandHelper.ts +0 -231
- package/dist/src/Interactions/context.ts +0 -104
- package/dist/src/Interactions/definitions.ts +0 -144
- package/dist/src/Interactions/error.ts +0 -3
- package/dist/src/Interactions/gateway.ts +0 -193
- package/dist/src/Interactions/handlers.ts +0 -108
- package/dist/src/Interactions/index.ts +0 -30
- package/dist/src/Interactions/utils.ts +0 -93
- package/dist/src/Interactions/webhook.ts +0 -204
- package/dist/src/RateLimit/memory.ts +0 -63
- package/dist/src/RateLimit/utils.ts +0 -28
- package/dist/src/RateLimit.ts +0 -90
- package/dist/src/gateway.ts +0 -50
- package/dist/src/index.ts +0 -44
- package/dist/src/types.ts +0 -3090
- package/dist/src/utils/Effect.ts +0 -65
- package/dist/src/version.ts +0 -1
- package/dist/src/webhooks.ts +0 -25
- package/dist/tsconfig.base.json +0 -54
- package/dist/tsconfig.build.json +0 -10
- package/dist/tsconfig.examples.json +0 -10
- package/dist/tsconfig.json +0 -14
- package/dist/tsconfig.madge.json +0 -12
- package/dist/tsconfig.test.json +0 -10
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import * as Discord from "../types.ts"
|
|
2
|
-
import * as Arr from "effect/Array"
|
|
3
|
-
import { identity, pipe } from "effect/Function"
|
|
4
|
-
import * as HashMap from "effect/HashMap"
|
|
5
|
-
import * as Option from "effect/Option"
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Option find a sub-command within the interaction options.
|
|
9
|
-
*/
|
|
10
|
-
export const allSubCommands = (
|
|
11
|
-
interaction: Discord.APIApplicationCommandInteraction["data"],
|
|
12
|
-
) =>
|
|
13
|
-
pipe(
|
|
14
|
-
optionsWithNested(interaction as any),
|
|
15
|
-
Arr.filter(
|
|
16
|
-
o => o.type === Discord.ApplicationCommandOptionType.SUB_COMMAND,
|
|
17
|
-
),
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get the target for the application command data.
|
|
22
|
-
*/
|
|
23
|
-
export const target = (
|
|
24
|
-
interaction: Discord.APIApplicationCommandInteraction["data"],
|
|
25
|
-
):
|
|
26
|
-
| Discord.APIApplicationCommandInteraction["data"]
|
|
27
|
-
| Discord.UserResponse
|
|
28
|
-
| Discord.MessageResponse => targetTypes[interaction.type](interaction)
|
|
29
|
-
|
|
30
|
-
const targetTypes: Record<
|
|
31
|
-
Discord.ApplicationCommandType,
|
|
32
|
-
(
|
|
33
|
-
data: any,
|
|
34
|
-
) =>
|
|
35
|
-
| Discord.UserResponse
|
|
36
|
-
| Discord.MessageResponse
|
|
37
|
-
| Discord.APIApplicationCommandInteraction["data"]
|
|
38
|
-
> = {
|
|
39
|
-
[Discord.ApplicationCommandType.USER]: data =>
|
|
40
|
-
data.resolved.users![(data as any).target_id] as Discord.UserResponse,
|
|
41
|
-
[Discord.ApplicationCommandType.MESSAGE]: data =>
|
|
42
|
-
data.resolved.messages![data.target_id],
|
|
43
|
-
[Discord.ApplicationCommandType.CHAT]: data => data,
|
|
44
|
-
[Discord.ApplicationCommandType.PRIMARY_ENTRY_POINT]: data => data,
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Option find a sub-command within the interaction options.
|
|
49
|
-
*/
|
|
50
|
-
export const findSubCommand =
|
|
51
|
-
(name: string) =>
|
|
52
|
-
(interaction: Discord.APIApplicationCommandInteraction["data"]) =>
|
|
53
|
-
pipe(
|
|
54
|
-
optionsWithNested(interaction as any),
|
|
55
|
-
Arr.findFirst(
|
|
56
|
-
(
|
|
57
|
-
o,
|
|
58
|
-
): o is Discord.APIApplicationCommandInteractionDataSubcommandOption =>
|
|
59
|
-
o.type === Discord.ApplicationCommandOptionType.SUB_COMMAND &&
|
|
60
|
-
o.name === name,
|
|
61
|
-
),
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* If the sub-command exists return `true`, else `false`.
|
|
66
|
-
*/
|
|
67
|
-
export const isSubCommand =
|
|
68
|
-
(name: string) => (_: Discord.APIApplicationCommandInteraction["data"]) =>
|
|
69
|
-
Option.isSome(findSubCommand(name)(_))
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Option get the options for a sub-command
|
|
73
|
-
*/
|
|
74
|
-
export const subCommandOptions =
|
|
75
|
-
(name: string) => (_: Discord.APIApplicationCommandInteraction["data"]) =>
|
|
76
|
-
Option.flatMapNullishOr(findSubCommand(name)(_), o => o.options)
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* A lens for accessing nested options in a interaction.
|
|
80
|
-
*/
|
|
81
|
-
export const optionsWithNested = (data: {
|
|
82
|
-
readonly options?:
|
|
83
|
-
| ReadonlyArray<Discord.APIApplicationCommandInteractionDataOption>
|
|
84
|
-
| undefined
|
|
85
|
-
}): Array<Discord.APIApplicationCommandInteractionDataOption> => {
|
|
86
|
-
const optsFromOption = (opt: {
|
|
87
|
-
readonly options?: ReadonlyArray<Discord.APIApplicationCommandInteractionDataOption>
|
|
88
|
-
}): Array<Discord.APIApplicationCommandInteractionDataOption> =>
|
|
89
|
-
Option.fromNullishOr(opt.options).pipe(
|
|
90
|
-
Option.map(opts => [
|
|
91
|
-
...opts,
|
|
92
|
-
...opts.flatMap(_ => optsFromOption(_ as any)),
|
|
93
|
-
]),
|
|
94
|
-
Option.match({ onNone: () => [], onSome: identity }),
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
return Option.fromNullishOr(data.options).pipe(
|
|
98
|
-
Option.map(opts => [
|
|
99
|
-
...opts,
|
|
100
|
-
...opts.flatMap(_ => optsFromOption(_ as any)),
|
|
101
|
-
]),
|
|
102
|
-
Option.getOrElse(() => []),
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Return the interaction options as a name / value map.
|
|
108
|
-
*/
|
|
109
|
-
export const transformOptions = (
|
|
110
|
-
options: Array<Discord.APIApplicationCommandInteractionDataOption>,
|
|
111
|
-
) =>
|
|
112
|
-
options.reduce(
|
|
113
|
-
(map, option) => HashMap.set(map, option.name, (option as any).value),
|
|
114
|
-
HashMap.empty<string, string | number | boolean | undefined>(),
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Return the interaction options as a name / value map.
|
|
119
|
-
*/
|
|
120
|
-
export const optionsMap = (data: {
|
|
121
|
-
readonly options?:
|
|
122
|
-
| ReadonlyArray<Discord.APIApplicationCommandInteractionDataOption>
|
|
123
|
-
| undefined
|
|
124
|
-
}) => transformOptions(optionsWithNested(data))
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Try find a matching option from the interaction.
|
|
128
|
-
*/
|
|
129
|
-
export const getOption =
|
|
130
|
-
(name: string) =>
|
|
131
|
-
(data: {
|
|
132
|
-
readonly options?:
|
|
133
|
-
| ReadonlyArray<Discord.APIApplicationCommandInteractionDataOption>
|
|
134
|
-
| undefined
|
|
135
|
-
}) =>
|
|
136
|
-
Arr.findFirst(optionsWithNested(data), o => o.name === name)
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Try find a matching option from the interaction.
|
|
140
|
-
*/
|
|
141
|
-
export const focusedOption = (data: {
|
|
142
|
-
readonly options?:
|
|
143
|
-
| ReadonlyArray<Discord.APIApplicationCommandInteractionDataOption>
|
|
144
|
-
| undefined
|
|
145
|
-
}) =>
|
|
146
|
-
Arr.findFirst(
|
|
147
|
-
optionsWithNested(data),
|
|
148
|
-
o => "focused" in o && o.focused === true,
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Try find a matching option value from the interaction.
|
|
153
|
-
*/
|
|
154
|
-
export const optionValue =
|
|
155
|
-
(name: string) =>
|
|
156
|
-
(data: {
|
|
157
|
-
readonly options?:
|
|
158
|
-
| ReadonlyArray<Discord.APIApplicationCommandInteractionDataOption>
|
|
159
|
-
| undefined
|
|
160
|
-
}) =>
|
|
161
|
-
Option.flatMapNullishOr(getOption(name)(data), o =>
|
|
162
|
-
"value" in o ? o.value : undefined,
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Try extract resolved data
|
|
167
|
-
*/
|
|
168
|
-
export const resolved = (data: Discord.APIInteraction) =>
|
|
169
|
-
Option.flatMapNullishOr(Option.fromNullishOr(data.data), a =>
|
|
170
|
-
"resolved" in a
|
|
171
|
-
? (a.resolved as Discord.InteractionDataResolved)
|
|
172
|
-
: undefined,
|
|
173
|
-
)
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Try find a matching option value from the interaction.
|
|
177
|
-
*/
|
|
178
|
-
export const resolveOptionValue =
|
|
179
|
-
<T>(
|
|
180
|
-
name: string,
|
|
181
|
-
f: (
|
|
182
|
-
id: Discord.Snowflake,
|
|
183
|
-
data: Discord.InteractionDataResolved,
|
|
184
|
-
) => T | undefined,
|
|
185
|
-
) =>
|
|
186
|
-
(a: Discord.APIInteraction): Option.Option<T> =>
|
|
187
|
-
Option.Do.pipe(
|
|
188
|
-
Option.bind("data", () => Option.fromNullishOr(a.data as any)),
|
|
189
|
-
Option.bind("id", ({ data }) =>
|
|
190
|
-
Option.flatMapNullishOr(
|
|
191
|
-
getOption(name)(data) as Option.Option<{ value: Discord.Snowflake }>,
|
|
192
|
-
({ value }) => value,
|
|
193
|
-
),
|
|
194
|
-
),
|
|
195
|
-
Option.bind("r", () => resolved(a)),
|
|
196
|
-
Option.flatMapNullishOr(({ id, r }) => f(id, r)),
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Try find matching option values from the interaction.
|
|
201
|
-
*/
|
|
202
|
-
export const resolveValues =
|
|
203
|
-
<T>(
|
|
204
|
-
f: (
|
|
205
|
-
id: Discord.Snowflake,
|
|
206
|
-
data: Discord.InteractionDataResolved,
|
|
207
|
-
) => T | undefined,
|
|
208
|
-
) =>
|
|
209
|
-
(a: Discord.APIInteraction): Option.Option<ReadonlyArray<T>> =>
|
|
210
|
-
Option.Do.pipe(
|
|
211
|
-
Option.bind("values", () =>
|
|
212
|
-
Option.flatMapNullishOr(
|
|
213
|
-
Option.fromNullishOr(a.data as any),
|
|
214
|
-
data => data.values as unknown as Array<string>,
|
|
215
|
-
),
|
|
216
|
-
),
|
|
217
|
-
Option.bind("r", () => resolved(a)),
|
|
218
|
-
Option.map(({ r, values }) =>
|
|
219
|
-
Arr.getSomes(
|
|
220
|
-
values.map(value => Option.fromNullishOr(f(value as any, r))),
|
|
221
|
-
),
|
|
222
|
-
),
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
const extractComponents = (
|
|
226
|
-
c: Discord.AllComponents,
|
|
227
|
-
): Array<Discord.AllComponents> => {
|
|
228
|
-
if ("components" in c) {
|
|
229
|
-
return [...c.components!, ...c.components!.flatMap(extractComponents)]
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return []
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* A lens for accessing the components in a interaction.
|
|
237
|
-
*/
|
|
238
|
-
export const components = (
|
|
239
|
-
a: Discord.APIModalSubmission,
|
|
240
|
-
): Array<Discord.AllComponents> => [
|
|
241
|
-
...(a.components as any),
|
|
242
|
-
...a.components.flatMap(extractComponents as any),
|
|
243
|
-
]
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* A lens for accessing the components in a interaction.
|
|
247
|
-
*/
|
|
248
|
-
export const componentsWithValue = (data: Discord.APIModalSubmission) =>
|
|
249
|
-
Arr.filter(components(data), c => "value" in c && c.value !== undefined)
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Return the interaction components as an id / value map.
|
|
253
|
-
*/
|
|
254
|
-
export const transformComponents = (options: Array<Discord.AllComponents>) =>
|
|
255
|
-
(options as Array<Discord.TextInputComponentResponse>).reduce(
|
|
256
|
-
(map, c) => (c.custom_id ? HashMap.set(map, c.custom_id, c.value) : map),
|
|
257
|
-
HashMap.empty<string, string | undefined | null>(),
|
|
258
|
-
)
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Return the interaction components as an id / value map.
|
|
262
|
-
*/
|
|
263
|
-
export const componentsMap = (data: Discord.APIModalSubmission) =>
|
|
264
|
-
transformComponents(components(data))
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Try find a matching component from the interaction.
|
|
268
|
-
*/
|
|
269
|
-
export const getComponent =
|
|
270
|
-
(id: string) => (data: Discord.APIModalSubmission) =>
|
|
271
|
-
Arr.findFirst(
|
|
272
|
-
components(data),
|
|
273
|
-
o => (o as Discord.TextInputComponentResponse).custom_id === id,
|
|
274
|
-
)
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Try find a matching component value from the interaction.
|
|
278
|
-
*/
|
|
279
|
-
export const componentValue =
|
|
280
|
-
(id: string) => (data: Discord.APIModalSubmission) =>
|
|
281
|
-
Option.flatMapNullishOr(
|
|
282
|
-
getComponent(id)(data),
|
|
283
|
-
o => (o as Discord.TextInputComponentResponse).value,
|
|
284
|
-
)
|
|
285
|
-
|
|
286
|
-
export type InteractionResponse =
|
|
287
|
-
| {
|
|
288
|
-
type: typeof Discord.InteractionCallbackTypes.CHANNEL_MESSAGE_WITH_SOURCE
|
|
289
|
-
data: Discord.IncomingWebhookInteractionRequest
|
|
290
|
-
files?: ReadonlyArray<File>
|
|
291
|
-
}
|
|
292
|
-
| {
|
|
293
|
-
type: typeof Discord.InteractionCallbackTypes.UPDATE_MESSAGE
|
|
294
|
-
data: Discord.IncomingWebhookUpdateForInteractionCallbackRequestPartial
|
|
295
|
-
files?: ReadonlyArray<File>
|
|
296
|
-
}
|
|
297
|
-
| {
|
|
298
|
-
type: typeof Discord.InteractionCallbackTypes.MODAL
|
|
299
|
-
data: Discord.ModalInteractionCallbackRequestData
|
|
300
|
-
}
|
|
301
|
-
| {
|
|
302
|
-
type: typeof Discord.InteractionCallbackTypes.DEFERRED_UPDATE_MESSAGE
|
|
303
|
-
}
|
|
304
|
-
| {
|
|
305
|
-
type: typeof Discord.InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
|
|
306
|
-
}
|
|
307
|
-
| {
|
|
308
|
-
type: typeof Discord.InteractionCallbackTypes.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT
|
|
309
|
-
data: Discord.ApplicationCommandAutocompleteCallbackRequest["data"]
|
|
310
|
-
}
|
|
311
|
-
| {
|
|
312
|
-
type: typeof Discord.InteractionCallbackTypes.LAUNCH_ACTIVITY
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
export const response = (
|
|
316
|
-
r: InteractionResponse,
|
|
317
|
-
): Discord.CreateInteractionResponseRequest => r
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type * as Discord from "../types.ts"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* From a list of roles, filter out the ones the guild member has.
|
|
5
|
-
*/
|
|
6
|
-
export const roles =
|
|
7
|
-
(guildRoles: Array<Discord.GuildRoleResponse>) =>
|
|
8
|
-
(member: Discord.GuildMemberResponse) =>
|
|
9
|
-
guildRoles.filter(
|
|
10
|
-
role => member.roles.includes(role.id) || role.name === "@everyone",
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Type-guard function for checking if the object is a guild member
|
|
15
|
-
*/
|
|
16
|
-
export const is = (thing: unknown): thing is Discord.GuildMemberResponse =>
|
|
17
|
-
Object.prototype.hasOwnProperty.call(thing, "roles") &&
|
|
18
|
-
Object.prototype.hasOwnProperty.call(thing, "joined_at")
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { pipe } from "effect/Function"
|
|
2
|
-
import * as Effect from "effect/Effect"
|
|
3
|
-
import * as Flags from "./flags.ts"
|
|
4
|
-
import * as Members from "./members.ts"
|
|
5
|
-
import * as Discord from "../types.ts"
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A constant of all the permissions
|
|
9
|
-
*/
|
|
10
|
-
export const ALL = Flags.all(Discord.Permissions)
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Check if a flag exists in the permissions.
|
|
14
|
-
*/
|
|
15
|
-
export const has = Flags.hasBigInt
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Convert a permissions bitfield to a list of flag names.
|
|
19
|
-
*/
|
|
20
|
-
export const toList = Flags.toList(Discord.Permissions)
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Convert a list of flag names to a bitfield.
|
|
24
|
-
*/
|
|
25
|
-
export const fromList = Flags.fromListBigint(Discord.Permissions)
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Reduce a list of roles to a bitfield of all the permissions added together.
|
|
29
|
-
*/
|
|
30
|
-
export const forRoles = (roles: Array<Discord.GuildRoleResponse>) =>
|
|
31
|
-
roles.reduce(
|
|
32
|
-
(permissions, role) => permissions | BigInt(role.permissions),
|
|
33
|
-
BigInt(0),
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* From a list of roles, calculate the permissions bitfield for the member.
|
|
38
|
-
*/
|
|
39
|
-
export const forMember =
|
|
40
|
-
(roles: Array<Discord.GuildRoleResponse>) =>
|
|
41
|
-
(member: Discord.GuildMemberResponse) =>
|
|
42
|
-
pipe(Members.roles(roles)(member), forRoles)
|
|
43
|
-
|
|
44
|
-
const overwriteIsForMember =
|
|
45
|
-
(guildId?: string) =>
|
|
46
|
-
(member: Discord.GuildMemberResponse) =>
|
|
47
|
-
(overwrite: Discord.ChannelPermissionOverwriteResponse) => {
|
|
48
|
-
if (overwrite.type === 0) {
|
|
49
|
-
return overwrite.id === guildId || member.roles.includes(overwrite.id)
|
|
50
|
-
}
|
|
51
|
-
return overwrite.id === member.user?.id
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const overwriteIsForRole =
|
|
55
|
-
(guildId?: string) =>
|
|
56
|
-
(role: Discord.GuildRoleResponse) =>
|
|
57
|
-
(overwrite: Discord.ChannelPermissionOverwriteResponse) => {
|
|
58
|
-
if (overwrite.type === 0) {
|
|
59
|
-
return overwrite.id === guildId || overwrite.id === role.id
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return false
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* From a list of roles and a channel, calculate the permission bitfield for
|
|
67
|
-
* the guild member or role for that channel.
|
|
68
|
-
*/
|
|
69
|
-
export const forChannel =
|
|
70
|
-
(roles: Array<Discord.GuildRoleResponse>) =>
|
|
71
|
-
({ guild_id, permission_overwrites }: Discord.GuildChannelResponse) =>
|
|
72
|
-
(memberOrRole: Discord.GuildMemberResponse | Discord.GuildRoleResponse) => {
|
|
73
|
-
const overwrites = permission_overwrites || []
|
|
74
|
-
const hasAdmin = has(Discord.Permissions.Administrator)
|
|
75
|
-
let basePermissions: bigint
|
|
76
|
-
let filteredOverwrites: Array<Discord.ChannelPermissionOverwriteResponse>
|
|
77
|
-
|
|
78
|
-
if (Members.is(memberOrRole)) {
|
|
79
|
-
if ((memberOrRole as any).permissions)
|
|
80
|
-
return BigInt((memberOrRole as any).permissions)
|
|
81
|
-
|
|
82
|
-
const memberRoles = Members.roles(roles)(memberOrRole)
|
|
83
|
-
basePermissions = forRoles(memberRoles)
|
|
84
|
-
filteredOverwrites = overwrites.filter(
|
|
85
|
-
overwriteIsForMember(guild_id)(memberOrRole),
|
|
86
|
-
)
|
|
87
|
-
} else {
|
|
88
|
-
const everyone = roles.find(role => role.name === "@everyone")
|
|
89
|
-
|
|
90
|
-
basePermissions =
|
|
91
|
-
BigInt(everyone?.permissions || "0") | BigInt(memberOrRole.permissions)
|
|
92
|
-
filteredOverwrites = overwrites.filter(
|
|
93
|
-
overwriteIsForRole(guild_id)(memberOrRole),
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (hasAdmin(basePermissions)) {
|
|
98
|
-
return ALL
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return applyOverwrites(basePermissions)(filteredOverwrites)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Apply permission overwrites to a bitfield.
|
|
106
|
-
*/
|
|
107
|
-
export const applyOverwrites =
|
|
108
|
-
(permissions: bigint) =>
|
|
109
|
-
(overwrites: ReadonlyArray<Discord.ChannelPermissionOverwriteResponse>) =>
|
|
110
|
-
overwrites.reduce(
|
|
111
|
-
(current, overwrite) =>
|
|
112
|
-
(current & ~BigInt(overwrite.deny)) | BigInt(overwrite.allow),
|
|
113
|
-
permissions,
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
interface RolesCache<E> {
|
|
117
|
-
getForParent: (
|
|
118
|
-
parentId: string,
|
|
119
|
-
) => Effect.Effect<ReadonlyMap<string, Discord.GuildRoleResponse>, E>
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export const hasInChannel =
|
|
123
|
-
<E>(rolesCache: RolesCache<E>, permission: bigint) =>
|
|
124
|
-
(
|
|
125
|
-
channel: Discord.GuildChannelResponse,
|
|
126
|
-
memberOrRole: Discord.GuildMemberResponse | Discord.GuildRoleResponse,
|
|
127
|
-
) =>
|
|
128
|
-
Effect.map(rolesCache.getForParent(channel.guild_id!), roles => {
|
|
129
|
-
const channelPerms = forChannel([...roles.values()])(channel)(
|
|
130
|
-
memberOrRole,
|
|
131
|
-
)
|
|
132
|
-
return has(permission)(channelPerms)
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
export const hasInGuild =
|
|
136
|
-
<E>(rolesCache: RolesCache<E>, permission: bigint) =>
|
|
137
|
-
(guildId: Discord.Snowflake, member: Discord.GuildMemberResponse) =>
|
|
138
|
-
Effect.map(rolesCache.getForParent(guildId), roles => {
|
|
139
|
-
const hasPerm = has(permission)
|
|
140
|
-
|
|
141
|
-
return member.roles.some(id => {
|
|
142
|
-
const role = roles.get(id)
|
|
143
|
-
return role ? hasPerm(role.permissions) : false
|
|
144
|
-
})
|
|
145
|
-
})
|