dfx 0.9.7 → 0.9.8
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/package.json +7 -6
- package/README.md +0 -41
- package/dist/DiscordConfig/index.d.ts +0 -40
- package/dist/DiscordConfig/index.d.ts.map +0 -1
- package/dist/DiscordConfig/index.js +0 -29
- package/dist/DiscordConfig/index.js.map +0 -1
- package/dist/DiscordGateway/DiscordWS/index.d.ts +0 -24
- package/dist/DiscordGateway/DiscordWS/index.d.ts.map +0 -1
- package/dist/DiscordGateway/DiscordWS/index.js +0 -26
- package/dist/DiscordGateway/DiscordWS/index.js.map +0 -1
- package/dist/DiscordGateway/Shard/heartbeats.d.ts +0 -4
- package/dist/DiscordGateway/Shard/heartbeats.d.ts.map +0 -1
- package/dist/DiscordGateway/Shard/heartbeats.js +0 -24
- package/dist/DiscordGateway/Shard/heartbeats.js.map +0 -1
- package/dist/DiscordGateway/Shard/identify.d.ts +0 -13
- package/dist/DiscordGateway/Shard/identify.d.ts.map +0 -1
- package/dist/DiscordGateway/Shard/identify.js +0 -30
- package/dist/DiscordGateway/Shard/identify.js.map +0 -1
- package/dist/DiscordGateway/Shard/index.d.ts +0 -10
- package/dist/DiscordGateway/Shard/index.d.ts.map +0 -1
- package/dist/DiscordGateway/Shard/index.js +0 -52
- package/dist/DiscordGateway/Shard/index.js.map +0 -1
- package/dist/DiscordGateway/Shard/invalidSession.d.ts +0 -4
- package/dist/DiscordGateway/Shard/invalidSession.d.ts.map +0 -1
- package/dist/DiscordGateway/Shard/invalidSession.js +0 -10
- package/dist/DiscordGateway/Shard/invalidSession.js.map +0 -1
- package/dist/DiscordGateway/Shard/sendEvents.d.ts +0 -8
- package/dist/DiscordGateway/Shard/sendEvents.d.ts.map +0 -1
- package/dist/DiscordGateway/Shard/sendEvents.js +0 -26
- package/dist/DiscordGateway/Shard/sendEvents.js.map +0 -1
- package/dist/DiscordGateway/Shard/utils.d.ts +0 -4
- package/dist/DiscordGateway/Shard/utils.d.ts.map +0 -1
- package/dist/DiscordGateway/Shard/utils.js +0 -9
- package/dist/DiscordGateway/Shard/utils.js.map +0 -1
- package/dist/DiscordGateway/ShardStore/index.d.ts +0 -13
- package/dist/DiscordGateway/ShardStore/index.d.ts.map +0 -1
- package/dist/DiscordGateway/ShardStore/index.js +0 -22
- package/dist/DiscordGateway/ShardStore/index.js.map +0 -1
- package/dist/DiscordGateway/Sharder/index.d.ts +0 -10
- package/dist/DiscordGateway/Sharder/index.d.ts.map +0 -1
- package/dist/DiscordGateway/Sharder/index.js +0 -61
- package/dist/DiscordGateway/Sharder/index.js.map +0 -1
- package/dist/DiscordGateway/WS/index.d.ts +0 -28
- package/dist/DiscordGateway/WS/index.d.ts.map +0 -1
- package/dist/DiscordGateway/WS/index.js +0 -82
- package/dist/DiscordGateway/WS/index.js.map +0 -1
- package/dist/DiscordGateway/index.d.ts +0 -21
- package/dist/DiscordGateway/index.d.ts.map +0 -1
- package/dist/DiscordGateway/index.js +0 -27
- package/dist/DiscordGateway/index.js.map +0 -1
- package/dist/DiscordREST/index.d.ts +0 -13
- package/dist/DiscordREST/index.d.ts.map +0 -1
- package/dist/DiscordREST/index.js +0 -85
- package/dist/DiscordREST/index.js.map +0 -1
- package/dist/DiscordREST/types.d.ts +0 -10
- package/dist/DiscordREST/types.d.ts.map +0 -1
- package/dist/DiscordREST/types.js +0 -2
- package/dist/DiscordREST/types.js.map +0 -1
- package/dist/DiscordREST/utils.d.ts +0 -11
- package/dist/DiscordREST/utils.d.ts.map +0 -1
- package/dist/DiscordREST/utils.js +0 -22
- package/dist/DiscordREST/utils.js.map +0 -1
- package/dist/Helpers/flags.d.ts +0 -28
- package/dist/Helpers/flags.d.ts.map +0 -1
- package/dist/Helpers/flags.js +0 -36
- package/dist/Helpers/flags.js.map +0 -1
- package/dist/Helpers/intents.d.ts +0 -25
- package/dist/Helpers/intents.d.ts.map +0 -1
- package/dist/Helpers/intents.js +0 -28
- package/dist/Helpers/intents.js.map +0 -1
- package/dist/Helpers/interactions.d.ts +0 -74
- package/dist/Helpers/interactions.d.ts.map +0 -1
- package/dist/Helpers/interactions.js +0 -93
- package/dist/Helpers/interactions.js.map +0 -1
- package/dist/Helpers/members.d.ts +0 -10
- package/dist/Helpers/members.d.ts.map +0 -1
- package/dist/Helpers/members.js +0 -10
- package/dist/Helpers/members.js.map +0 -1
- package/dist/Helpers/permissions.d.ts +0 -35
- package/dist/Helpers/permissions.d.ts.map +0 -1
- package/dist/Helpers/permissions.js +0 -69
- package/dist/Helpers/permissions.js.map +0 -1
- package/dist/Helpers/ui.d.ts +0 -48
- package/dist/Helpers/ui.d.ts.map +0 -1
- package/dist/Helpers/ui.js +0 -67
- package/dist/Helpers/ui.js.map +0 -1
- package/dist/Http/index.d.ts +0 -31
- package/dist/Http/index.d.ts.map +0 -1
- package/dist/Http/index.js +0 -53
- package/dist/Http/index.js.map +0 -1
- package/dist/Interactions/context.d.ts +0 -37
- package/dist/Interactions/context.d.ts.map +0 -1
- package/dist/Interactions/context.js +0 -34
- package/dist/Interactions/context.js.map +0 -1
- package/dist/Interactions/definitions.d.ts +0 -61
- package/dist/Interactions/definitions.d.ts.map +0 -1
- package/dist/Interactions/definitions.js +0 -52
- package/dist/Interactions/definitions.js.map +0 -1
- package/dist/Interactions/gateway.d.ts +0 -7
- package/dist/Interactions/gateway.d.ts.map +0 -1
- package/dist/Interactions/gateway.js +0 -21
- package/dist/Interactions/gateway.js.map +0 -1
- package/dist/Interactions/handlers.d.ts +0 -9
- package/dist/Interactions/handlers.d.ts.map +0 -1
- package/dist/Interactions/handlers.js +0 -49
- package/dist/Interactions/handlers.js.map +0 -1
- package/dist/Interactions/index.d.ts +0 -18
- package/dist/Interactions/index.d.ts.map +0 -1
- package/dist/Interactions/index.js +0 -39
- package/dist/Interactions/index.js.map +0 -1
- package/dist/Interactions/utils.d.ts +0 -11
- package/dist/Interactions/utils.d.ts.map +0 -1
- package/dist/Interactions/utils.js +0 -61
- package/dist/Interactions/utils.js.map +0 -1
- package/dist/Interactions/webhook.d.ts +0 -33
- package/dist/Interactions/webhook.d.ts.map +0 -1
- package/dist/Interactions/webhook.js +0 -42
- package/dist/Interactions/webhook.js.map +0 -1
- package/dist/Log/index.d.ts +0 -13
- package/dist/Log/index.d.ts.map +0 -1
- package/dist/Log/index.js +0 -19
- package/dist/Log/index.js.map +0 -1
- package/dist/RateLimitStore/index.d.ts +0 -25
- package/dist/RateLimitStore/index.d.ts.map +0 -1
- package/dist/RateLimitStore/index.js +0 -24
- package/dist/RateLimitStore/index.js.map +0 -1
- package/dist/RateLimitStore/memory.d.ts +0 -3
- package/dist/RateLimitStore/memory.d.ts.map +0 -1
- package/dist/RateLimitStore/memory.js +0 -31
- package/dist/RateLimitStore/memory.js.map +0 -1
- package/dist/RateLimitStore/utils.d.ts +0 -3
- package/dist/RateLimitStore/utils.d.ts.map +0 -1
- package/dist/RateLimitStore/utils.js +0 -18
- package/dist/RateLimitStore/utils.js.map +0 -1
- package/dist/common-gateway.d.ts +0 -6
- package/dist/common-gateway.d.ts.map +0 -1
- package/dist/common-gateway.js +0 -6
- package/dist/common-gateway.js.map +0 -1
- package/dist/common.d.ts +0 -29
- package/dist/common.d.ts.map +0 -1
- package/dist/common.js +0 -16
- package/dist/common.js.map +0 -1
- package/dist/global.d.ts +0 -18
- package/dist/global.d.ts.map +0 -1
- package/dist/global.js +0 -2
- package/dist/global.js.map +0 -1
- package/dist/index.d.ts +0 -22
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -29
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts +0 -4229
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -1796
- package/dist/types.js.map +0 -1
- package/dist/utils/effect.d.ts +0 -3
- package/dist/utils/effect.d.ts.map +0 -1
- package/dist/utils/effect.js +0 -2
- package/dist/utils/effect.js.map +0 -1
- package/dist/utils/tsplus.d.ts +0 -14
- package/dist/utils/tsplus.d.ts.map +0 -1
- package/dist/utils/tsplus.js +0 -2
- package/dist/utils/tsplus.js.map +0 -1
- package/dist/webhooks.d.ts +0 -16
- package/dist/webhooks.d.ts.map +0 -1
- package/dist/webhooks.js +0 -23
- package/dist/webhooks.js.map +0 -1
- package/src/DiscordConfig/index.ts +0 -52
- package/src/DiscordGateway/DiscordWS/index.ts +0 -50
- package/src/DiscordGateway/Shard/heartbeats.ts +0 -39
- package/src/DiscordGateway/Shard/identify.ts +0 -61
- package/src/DiscordGateway/Shard/index.ts +0 -90
- package/src/DiscordGateway/Shard/invalidSession.ts +0 -11
- package/src/DiscordGateway/Shard/sendEvents.ts +0 -35
- package/src/DiscordGateway/Shard/utils.ts +0 -14
- package/src/DiscordGateway/ShardStore/index.ts +0 -33
- package/src/DiscordGateway/Sharder/index.ts +0 -95
- package/src/DiscordGateway/WS/index.ts +0 -99
- package/src/DiscordGateway/index.ts +0 -55
- package/src/DiscordREST/index.ts +0 -132
- package/src/DiscordREST/types.ts +0 -14
- package/src/DiscordREST/utils.ts +0 -35
- package/src/Helpers/flags.ts +0 -68
- package/src/Helpers/intents.ts +0 -32
- package/src/Helpers/interactions.ts +0 -180
- package/src/Helpers/members.ts +0 -14
- package/src/Helpers/permissions.ts +0 -102
- package/src/Helpers/ui.ts +0 -103
- package/src/Http/index.ts +0 -65
- package/src/Interactions/context.ts +0 -100
- package/src/Interactions/definitions.ts +0 -144
- package/src/Interactions/gateway.ts +0 -55
- package/src/Interactions/handlers.ts +0 -139
- package/src/Interactions/index.ts +0 -83
- package/src/Interactions/utils.ts +0 -81
- package/src/Interactions/webhook.ts +0 -96
- package/src/Log/index.ts +0 -23
- package/src/RateLimitStore/index.ts +0 -65
- package/src/RateLimitStore/memory.ts +0 -48
- package/src/RateLimitStore/utils.ts +0 -27
- package/src/common-gateway.ts +0 -5
- package/src/common.ts +0 -30
- package/src/global.ts +0 -50
- package/src/index.ts +0 -36
- package/src/json.d.ts +0 -1
- package/src/types.ts +0 -6095
- package/src/utils/effect.ts +0 -7
- package/src/utils/tsplus.ts +0 -11
- package/src/webhooks.ts +0 -30
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import * as Arr from "@fp-ts/data/ReadonlyArray"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Maybe find a sub-command within the interaction options.
|
|
5
|
-
*/
|
|
6
|
-
export const allSubCommands = (interaction: Discord.ApplicationCommandDatum) =>
|
|
7
|
-
pipe(
|
|
8
|
-
optionsWithNested(interaction),
|
|
9
|
-
Arr.filter(
|
|
10
|
-
(o) => o.type === Discord.ApplicationCommandOptionType.SUB_COMMAND,
|
|
11
|
-
),
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Maybe find a sub-command within the interaction options.
|
|
16
|
-
*/
|
|
17
|
-
export const findSubCommand =
|
|
18
|
-
(name: string) => (interaction: Discord.ApplicationCommandDatum) =>
|
|
19
|
-
pipe(
|
|
20
|
-
optionsWithNested(interaction),
|
|
21
|
-
Arr.findFirst(
|
|
22
|
-
(o) =>
|
|
23
|
-
o.type === Discord.ApplicationCommandOptionType.SUB_COMMAND &&
|
|
24
|
-
o.name === name,
|
|
25
|
-
),
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* If the sub-command exists return `true`, else `false`.
|
|
30
|
-
*/
|
|
31
|
-
export const isSubCommand = (name: string) =>
|
|
32
|
-
flow(findSubCommand(name), (o) => o.isSome)
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Maybe get the options for a sub-command
|
|
36
|
-
*/
|
|
37
|
-
export const subCommandOptions = (name: string) =>
|
|
38
|
-
flow(findSubCommand(name), (o) => o.flatMapNullable((o) => o.options))
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* A lens for accessing nested options in a interaction.
|
|
42
|
-
*/
|
|
43
|
-
export const optionsWithNested = (
|
|
44
|
-
data: Pick<Discord.ApplicationCommandDatum, "options">,
|
|
45
|
-
): Discord.ApplicationCommandInteractionDataOption[] => {
|
|
46
|
-
const optsFromOption = (
|
|
47
|
-
opt: Discord.ApplicationCommandInteractionDataOption,
|
|
48
|
-
): Discord.ApplicationCommandInteractionDataOption[] =>
|
|
49
|
-
Maybe.fromNullable(opt.options)
|
|
50
|
-
.map((opts) => [...opts, ...opts.flatMap(optsFromOption)])
|
|
51
|
-
.match(() => [], identity)
|
|
52
|
-
|
|
53
|
-
return Maybe.fromNullable(data.options)
|
|
54
|
-
.map((opts) => [...opts, ...opts.flatMap(optsFromOption)])
|
|
55
|
-
.getOrElse(() => [])
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Return the interaction options as a name / value map.
|
|
60
|
-
*/
|
|
61
|
-
export const transformOptions = (
|
|
62
|
-
options: Discord.ApplicationCommandInteractionDataOption[],
|
|
63
|
-
) =>
|
|
64
|
-
options.reduce(
|
|
65
|
-
(map, option) => ({
|
|
66
|
-
...map,
|
|
67
|
-
[option.name]: option.value,
|
|
68
|
-
}),
|
|
69
|
-
{} as Record<string, string | undefined>,
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Return the interaction options as a name / value map.
|
|
74
|
-
*/
|
|
75
|
-
export const optionsMap = flow(optionsWithNested, transformOptions)
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Try find a matching option from the interaction.
|
|
79
|
-
*/
|
|
80
|
-
export const getOption = (name: string) =>
|
|
81
|
-
flow(
|
|
82
|
-
optionsWithNested,
|
|
83
|
-
Arr.findFirst((o) => o.name === name),
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Try find a matching option from the interaction.
|
|
88
|
-
*/
|
|
89
|
-
export const focusedOption = flow(
|
|
90
|
-
optionsWithNested,
|
|
91
|
-
Arr.findFirst((o) => o.focused === true),
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Try find a matching option value from the interaction.
|
|
96
|
-
*/
|
|
97
|
-
export const optionValue = (name: string) =>
|
|
98
|
-
flow(getOption(name), (o) => o.flatMapNullable((o) => o.value))
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Try extract resolved data
|
|
102
|
-
*/
|
|
103
|
-
export const resolved = (data: Discord.ApplicationCommandDatum) =>
|
|
104
|
-
Maybe.fromNullable(data.resolved)
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Try find a matching option value from the interaction.
|
|
108
|
-
*/
|
|
109
|
-
export const resolveOptionValue =
|
|
110
|
-
<T>(
|
|
111
|
-
name: string,
|
|
112
|
-
f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => T | undefined,
|
|
113
|
-
) =>
|
|
114
|
-
(a: Discord.ApplicationCommandDatum): Maybe<T> =>
|
|
115
|
-
Do(($) => {
|
|
116
|
-
const id = $(
|
|
117
|
-
getOption(name)(a).flatMapNullable(
|
|
118
|
-
({ value }) => value as Discord.Snowflake,
|
|
119
|
-
),
|
|
120
|
-
)
|
|
121
|
-
const data = $(resolved(a))
|
|
122
|
-
return $(Maybe.fromNullable(f(id, data)))
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
const extractComponents = (c: Discord.Component): Discord.Component[] => {
|
|
126
|
-
if ("components" in c) {
|
|
127
|
-
return [...c.components, ...c.components.flatMap(extractComponents)]
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return []
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* A lens for accessing the components in a interaction.
|
|
135
|
-
*/
|
|
136
|
-
export const components = (
|
|
137
|
-
a: Discord.ModalSubmitDatum,
|
|
138
|
-
): Discord.Component[] => [
|
|
139
|
-
...a.components,
|
|
140
|
-
...a.components.flatMap(extractComponents),
|
|
141
|
-
]
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* A lens for accessing the components in a interaction.
|
|
145
|
-
*/
|
|
146
|
-
export const componentsWithValue = flow(
|
|
147
|
-
components,
|
|
148
|
-
Arr.filter((c) => "value" in c && c.value !== undefined),
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Return the interaction components as an id / value map.
|
|
153
|
-
*/
|
|
154
|
-
export const transformComponents = (options: Discord.Component[]) =>
|
|
155
|
-
(options as Discord.TextInput[]).reduce(
|
|
156
|
-
(map, c) => (c.custom_id ? { ...map, [c.custom_id]: c.value } : map),
|
|
157
|
-
{} as Record<string, string | undefined>,
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Return the interaction components as an id / value map.
|
|
162
|
-
*/
|
|
163
|
-
export const componentsMap = flow(components, transformComponents)
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Try find a matching component from the interaction.
|
|
167
|
-
*/
|
|
168
|
-
export const getComponent = (id: string) =>
|
|
169
|
-
flow(
|
|
170
|
-
components,
|
|
171
|
-
Arr.findFirst((o) => (o as Discord.TextInput).custom_id === id),
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Try find a matching component value from the interaction.
|
|
176
|
-
*/
|
|
177
|
-
export const componentValue = (id: string) =>
|
|
178
|
-
flow(getComponent(id), (o) =>
|
|
179
|
-
o.flatMapNullable((o) => (o as Discord.TextInput).value),
|
|
180
|
-
)
|
package/src/Helpers/members.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* From a list of roles, filter out the ones the guild member has.
|
|
3
|
-
*/
|
|
4
|
-
export const roles = (roles: Discord.Role[]) => (member: Discord.GuildMember) =>
|
|
5
|
-
roles.filter(
|
|
6
|
-
(role) => member.roles.includes(role.id) || role.name === "@everyone",
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Type-guard function for checking if the object is a guild member
|
|
11
|
-
*/
|
|
12
|
-
export const is = (thing: unknown): thing is Discord.GuildMember =>
|
|
13
|
-
Object.prototype.hasOwnProperty.call(thing, "roles") &&
|
|
14
|
-
Object.prototype.hasOwnProperty.call(thing, "joined_at")
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A constant of all the permissions
|
|
3
|
-
*/
|
|
4
|
-
export const ALL = Flags.all(Discord.PermissionFlag)
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Check if a flag exists in the permissions.
|
|
8
|
-
*/
|
|
9
|
-
export const has = Flags.hasBigInt
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Convert a permissions bitfield to a list of flag names.
|
|
13
|
-
*/
|
|
14
|
-
export const toList = Flags.toList(Discord.PermissionFlag)
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Convert a list of flag names to a bitfield.
|
|
18
|
-
*/
|
|
19
|
-
export const fromList = Flags.fromListBigint(Discord.PermissionFlag)
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Reduce a list of roles to a bitfield of all the permissions added together.
|
|
23
|
-
*/
|
|
24
|
-
export const forRoles = (roles: Discord.Role[]) =>
|
|
25
|
-
roles.reduce(
|
|
26
|
-
(permissions, role) => permissions | BigInt(role.permissions),
|
|
27
|
-
BigInt(0),
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* From a list of roles, calculate the permissions bitfield for the member.
|
|
32
|
-
*/
|
|
33
|
-
export const forMember =
|
|
34
|
-
(roles: Discord.Role[]) => (member: Discord.GuildMember) =>
|
|
35
|
-
pipe(Members.roles(roles)(member), forRoles)
|
|
36
|
-
|
|
37
|
-
const overwriteIsForMember =
|
|
38
|
-
(guildId?: string) =>
|
|
39
|
-
(member: Discord.GuildMember) =>
|
|
40
|
-
(overwrite: Discord.Overwrite) => {
|
|
41
|
-
if (overwrite.type === 0) {
|
|
42
|
-
return overwrite.id === guildId || member.roles.includes(overwrite.id)
|
|
43
|
-
}
|
|
44
|
-
return overwrite.id === member.user?.id
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const overwriteIsForRole =
|
|
48
|
-
(guildId?: string) =>
|
|
49
|
-
(role: Discord.Role) =>
|
|
50
|
-
(overwrite: Discord.Overwrite) => {
|
|
51
|
-
if (overwrite.type === 0) {
|
|
52
|
-
return overwrite.id === guildId || overwrite.id === role.id
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return false
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* From a list of roles and a channel, calculate the permission bitfield for
|
|
60
|
-
* the guild member or role for that channel.
|
|
61
|
-
*/
|
|
62
|
-
export const forChannel =
|
|
63
|
-
(roles: Discord.Role[]) =>
|
|
64
|
-
({ guild_id, permission_overwrites: overwrites = [] }: Discord.Channel) =>
|
|
65
|
-
(memberOrRole: Discord.GuildMember | Discord.Role) => {
|
|
66
|
-
const hasAdmin = has(Discord.PermissionFlag.ADMINISTRATOR)
|
|
67
|
-
let basePermissions: bigint
|
|
68
|
-
let filteredOverwrites: Discord.Overwrite[]
|
|
69
|
-
|
|
70
|
-
if (Members.is(memberOrRole)) {
|
|
71
|
-
if (memberOrRole.permissions) return BigInt(memberOrRole.permissions)
|
|
72
|
-
|
|
73
|
-
const memberRoles = Members.roles(roles)(memberOrRole)
|
|
74
|
-
basePermissions = forRoles(memberRoles)
|
|
75
|
-
filteredOverwrites = overwrites.filter(
|
|
76
|
-
overwriteIsForMember(guild_id)(memberOrRole),
|
|
77
|
-
)
|
|
78
|
-
} else {
|
|
79
|
-
const everyone = roles.find((role) => role.name === "@everyone")
|
|
80
|
-
basePermissions =
|
|
81
|
-
BigInt(everyone?.permissions || "0") | BigInt(memberOrRole.permissions)
|
|
82
|
-
filteredOverwrites = overwrites.filter(
|
|
83
|
-
overwriteIsForRole(guild_id)(memberOrRole),
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (hasAdmin(basePermissions)) {
|
|
88
|
-
return ALL
|
|
89
|
-
}
|
|
90
|
-
return applyOverwrites(basePermissions)(filteredOverwrites)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Apply permission overwrites to a bitfield.
|
|
95
|
-
*/
|
|
96
|
-
export const applyOverwrites =
|
|
97
|
-
(permissions: bigint) => (overwrites: Discord.Overwrite[]) =>
|
|
98
|
-
overwrites.reduce(
|
|
99
|
-
(permissions, overwrite) =>
|
|
100
|
-
(permissions & ~BigInt(overwrite.deny)) | BigInt(overwrite.allow),
|
|
101
|
-
permissions,
|
|
102
|
-
)
|
package/src/Helpers/ui.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ActionRow,
|
|
3
|
-
Button,
|
|
4
|
-
ButtonStyle,
|
|
5
|
-
Component,
|
|
6
|
-
ComponentType,
|
|
7
|
-
SelectMenu,
|
|
8
|
-
SelectOption,
|
|
9
|
-
TextInput,
|
|
10
|
-
TextInputStyle,
|
|
11
|
-
} from "../types.js"
|
|
12
|
-
|
|
13
|
-
export type UIComponent = Exclude<Component, ActionRow>
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Helper to create an Action Row grid.
|
|
17
|
-
*/
|
|
18
|
-
export const grid = (items: UIComponent[][]): ActionRow[] =>
|
|
19
|
-
items.map(
|
|
20
|
-
(components): ActionRow => ({
|
|
21
|
-
type: ComponentType.ACTION_ROW,
|
|
22
|
-
components,
|
|
23
|
-
}),
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Helper to create a single column of components
|
|
28
|
-
*/
|
|
29
|
-
export const singleColumn = (items: UIComponent[]): ActionRow[] =>
|
|
30
|
-
items.map((c) => ({
|
|
31
|
-
type: ComponentType.ACTION_ROW,
|
|
32
|
-
components: [c],
|
|
33
|
-
}))
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Helper to create a button component.
|
|
37
|
-
*/
|
|
38
|
-
export const button = (button: Partial<Button>): Button => ({
|
|
39
|
-
type: ComponentType.BUTTON,
|
|
40
|
-
style: ButtonStyle.PRIMARY,
|
|
41
|
-
...button,
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
type BasicSelect = Omit<SelectMenu, "type" | "channel_types" | "options">
|
|
45
|
-
|
|
46
|
-
type StringSelect = BasicSelect & {
|
|
47
|
-
options: SelectOption[]
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
type ChannelSelect = Omit<SelectMenu, "type" | "options">
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Helper to create a select component.
|
|
54
|
-
*/
|
|
55
|
-
export const select = (select: StringSelect): SelectMenu => ({
|
|
56
|
-
type: ComponentType.STRING_SELECT,
|
|
57
|
-
...select,
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Helper to create a select component.
|
|
62
|
-
*/
|
|
63
|
-
export const userSelect = (select: BasicSelect): SelectMenu => ({
|
|
64
|
-
type: ComponentType.USER_SELECT,
|
|
65
|
-
...select,
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Helper to create a select component.
|
|
70
|
-
*/
|
|
71
|
-
export const roleSelect = (select: BasicSelect): SelectMenu => ({
|
|
72
|
-
type: ComponentType.ROLE_SELECT,
|
|
73
|
-
...select,
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Helper to create a select component.
|
|
78
|
-
*/
|
|
79
|
-
export const mentionableSelect = (select: BasicSelect): SelectMenu => ({
|
|
80
|
-
type: ComponentType.MENTIONABLE_SELECT,
|
|
81
|
-
...select,
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Helper to create a select component.
|
|
86
|
-
*/
|
|
87
|
-
export const channelSelect = (select: ChannelSelect): SelectMenu => ({
|
|
88
|
-
type: ComponentType.CHANNEL_SELECT,
|
|
89
|
-
...select,
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
type TextInputOpts = Omit<TextInput, "type" | "style"> & {
|
|
93
|
-
style?: TextInputStyle
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Helper to create a text input
|
|
98
|
-
*/
|
|
99
|
-
export const textInput = (input: TextInputOpts): TextInput => ({
|
|
100
|
-
type: ComponentType.TEXT_INPUT,
|
|
101
|
-
style: TextInputStyle.SHORT,
|
|
102
|
-
...input,
|
|
103
|
-
})
|
package/src/Http/index.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export class FetchError {
|
|
2
|
-
readonly _tag = "FetchError"
|
|
3
|
-
constructor(readonly reason: unknown) {}
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export class StatusCodeError {
|
|
7
|
-
readonly _tag = "StatusCodeError"
|
|
8
|
-
readonly code: number
|
|
9
|
-
constructor(readonly response: Response) {
|
|
10
|
-
this.code = response.status
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const request = (url: URL | string, init: RequestInit = {}) =>
|
|
15
|
-
Effect.asyncInterrupt<never, FetchError, Response>((resume) => {
|
|
16
|
-
const controller = new AbortController()
|
|
17
|
-
fetch(url, {
|
|
18
|
-
...init,
|
|
19
|
-
signal: controller.signal,
|
|
20
|
-
})
|
|
21
|
-
.then((a) => resume(Effect.succeed(a)))
|
|
22
|
-
.catch((e) => resume(Effect.fail(new FetchError(e))))
|
|
23
|
-
|
|
24
|
-
return Either.left(
|
|
25
|
-
Effect.sync(() => {
|
|
26
|
-
controller.abort()
|
|
27
|
-
}),
|
|
28
|
-
)
|
|
29
|
-
}).filterOrElseWith(
|
|
30
|
-
(r) => r.status < 300,
|
|
31
|
-
(r) => Effect.fail(new StatusCodeError(r)),
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
export class JsonParseError {
|
|
35
|
-
readonly _tag = "JsonParseError"
|
|
36
|
-
constructor(readonly reason: unknown) {}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const json = <A = unknown>(r: Response) =>
|
|
40
|
-
Effect.tryCatchPromise(
|
|
41
|
-
(): Promise<A> => r.json(),
|
|
42
|
-
(reason) => new JsonParseError(reason),
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
export class BlobError {
|
|
46
|
-
readonly _tag = "BlobError"
|
|
47
|
-
constructor(readonly reason: unknown) {}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export const blob = (r: Response) =>
|
|
51
|
-
Effect.tryCatchPromise(
|
|
52
|
-
() => r.blob(),
|
|
53
|
-
(reason) => new BlobError(reason),
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
export const requestWithJson = <A = unknown>(
|
|
57
|
-
url: URL | string,
|
|
58
|
-
init: RequestInit = {},
|
|
59
|
-
) =>
|
|
60
|
-
request(url, init).map((response) => ({
|
|
61
|
-
response,
|
|
62
|
-
json: json<A>(response),
|
|
63
|
-
blob: blob(response),
|
|
64
|
-
text: Effect.promise(() => response.text()),
|
|
65
|
-
}))
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { InteractionResponse } from "./definitions.js"
|
|
2
|
-
import { InteractionNotFound } from "./handlers.js"
|
|
3
|
-
import * as Arr from "@fp-ts/data/ReadonlyArray"
|
|
4
|
-
import { optionsMap } from "dfx/Helpers/interactions"
|
|
5
|
-
|
|
6
|
-
export const InteractionContext = Tag<Discord.Interaction>()
|
|
7
|
-
export const ApplicationCommandContext = Tag<Discord.ApplicationCommandDatum>()
|
|
8
|
-
export const MessageComponentContext = Tag<Discord.MessageComponentDatum>()
|
|
9
|
-
export const ModalSubmitContext = Tag<Discord.ModalSubmitDatum>()
|
|
10
|
-
|
|
11
|
-
export interface FocusedOptionContext {
|
|
12
|
-
readonly focusedOption: Discord.ApplicationCommandInteractionDataOption
|
|
13
|
-
}
|
|
14
|
-
export const FocusedOptionContext = Tag<FocusedOptionContext>()
|
|
15
|
-
|
|
16
|
-
export interface SubCommandContext {
|
|
17
|
-
readonly command: Discord.ApplicationCommandInteractionDataOption
|
|
18
|
-
}
|
|
19
|
-
export const SubCommandContext = Tag<SubCommandContext>()
|
|
20
|
-
|
|
21
|
-
export const getCommand = Effect.service(ApplicationCommandContext)
|
|
22
|
-
|
|
23
|
-
export class ResolvedDataNotFound {
|
|
24
|
-
readonly _tag = "ResolvedDataNotFound"
|
|
25
|
-
constructor(
|
|
26
|
-
readonly data: Discord.ApplicationCommandDatum,
|
|
27
|
-
readonly name: string,
|
|
28
|
-
) {}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const getResolved = <A>(
|
|
32
|
-
name: string,
|
|
33
|
-
f: (id: Discord.Snowflake, data: Discord.ResolvedDatum) => A | undefined,
|
|
34
|
-
) =>
|
|
35
|
-
Effect.serviceWithEffect(ApplicationCommandContext)((a) =>
|
|
36
|
-
IxHelpers.resolveOptionValue(
|
|
37
|
-
name,
|
|
38
|
-
f,
|
|
39
|
-
)(a).match(
|
|
40
|
-
() => Effect.fail(new ResolvedDataNotFound(a, name)),
|
|
41
|
-
Effect.succeed,
|
|
42
|
-
),
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
export const focusedOptionValue = Effect.serviceWith(FocusedOptionContext)(
|
|
46
|
-
(a) => a.focusedOption.value ?? "",
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
export const commandOptionsMap = Effect.serviceWith(ApplicationCommandContext)(
|
|
50
|
-
optionsMap,
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
export const handleSubCommands = <
|
|
54
|
-
NER extends Record<string, Effect<any, any, Maybe<InteractionResponse>>>,
|
|
55
|
-
>(
|
|
56
|
-
commands: NER,
|
|
57
|
-
): Effect<
|
|
58
|
-
| Exclude<
|
|
59
|
-
[NER[keyof NER]] extends [
|
|
60
|
-
{ [EffectTypeId]: { _R: (_: never) => infer R } },
|
|
61
|
-
]
|
|
62
|
-
? R
|
|
63
|
-
: never,
|
|
64
|
-
SubCommandContext
|
|
65
|
-
>
|
|
66
|
-
| Discord.Interaction
|
|
67
|
-
| Discord.ApplicationCommandDatum,
|
|
68
|
-
[NER[keyof NER]] extends [{ [EffectTypeId]: { _E: (_: never) => infer E } }]
|
|
69
|
-
? E
|
|
70
|
-
: never,
|
|
71
|
-
Maybe<InteractionResponse>
|
|
72
|
-
> =>
|
|
73
|
-
Effect.struct({
|
|
74
|
-
interaction: Effect.service(InteractionContext),
|
|
75
|
-
data: Effect.service(ApplicationCommandContext),
|
|
76
|
-
}).flatMap(({ interaction, data }) =>
|
|
77
|
-
pipe(
|
|
78
|
-
IxHelpers.allSubCommands(data),
|
|
79
|
-
Arr.findFirst((a) => !!commands[a.name]),
|
|
80
|
-
(o) => o.toEither(() => new InteractionNotFound(interaction)),
|
|
81
|
-
Effect.fromEither,
|
|
82
|
-
(a) =>
|
|
83
|
-
a.flatMap((command) =>
|
|
84
|
-
pipe(
|
|
85
|
-
commands[command.name],
|
|
86
|
-
Effect.provideService(SubCommandContext)({ command }),
|
|
87
|
-
),
|
|
88
|
-
),
|
|
89
|
-
),
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
export const getSubCommand = Effect.serviceWith(SubCommandContext)(
|
|
93
|
-
(a) => a.command,
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
export const subCommandOptionsMap = getSubCommand.map(IxHelpers.optionsMap)
|
|
97
|
-
|
|
98
|
-
export const modalValues = Effect.serviceWith(ModalSubmitContext)(
|
|
99
|
-
IxHelpers.componentsMap,
|
|
100
|
-
)
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
export type InteractionResponse =
|
|
2
|
-
| {
|
|
3
|
-
type: Discord.InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE
|
|
4
|
-
data: Discord.InteractionCallbackMessage
|
|
5
|
-
}
|
|
6
|
-
| {
|
|
7
|
-
type: Discord.InteractionCallbackType.UPDATE_MESSAGE
|
|
8
|
-
data: Discord.InteractionCallbackMessage
|
|
9
|
-
}
|
|
10
|
-
| {
|
|
11
|
-
type: Discord.InteractionCallbackType.MODAL
|
|
12
|
-
data: Discord.InteractionCallbackModal
|
|
13
|
-
}
|
|
14
|
-
| {
|
|
15
|
-
type: Discord.InteractionCallbackType.DEFERRED_UPDATE_MESSAGE
|
|
16
|
-
}
|
|
17
|
-
| {
|
|
18
|
-
type: Discord.InteractionCallbackType.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
|
|
19
|
-
}
|
|
20
|
-
| {
|
|
21
|
-
type: Discord.InteractionCallbackType.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT
|
|
22
|
-
data: Discord.InteractionCallbackAutocomplete
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type DescriptionMissing<A> = A extends {
|
|
26
|
-
type: Exclude<Discord.ApplicationCommandType, 1>
|
|
27
|
-
}
|
|
28
|
-
? false
|
|
29
|
-
: A extends { description: string }
|
|
30
|
-
? false
|
|
31
|
-
: true
|
|
32
|
-
|
|
33
|
-
export type InteractionDefinition<R, E> =
|
|
34
|
-
| GlobalApplicationCommand<R, E>
|
|
35
|
-
| GuildApplicationCommand<R, E>
|
|
36
|
-
| MessageComponent<R, E>
|
|
37
|
-
| ModalSubmit<R, E>
|
|
38
|
-
| Autocomplete<R, E>
|
|
39
|
-
|
|
40
|
-
export class GlobalApplicationCommand<R, E> {
|
|
41
|
-
readonly _tag = "GlobalApplicationCommand"
|
|
42
|
-
constructor(
|
|
43
|
-
readonly command: Discord.CreateGlobalApplicationCommandParams,
|
|
44
|
-
readonly handle: Effect<R, E, Maybe<InteractionResponse>>,
|
|
45
|
-
) {}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const global = <
|
|
49
|
-
R,
|
|
50
|
-
E,
|
|
51
|
-
A extends Discord.CreateGlobalApplicationCommandParams,
|
|
52
|
-
>(
|
|
53
|
-
command: A,
|
|
54
|
-
handle: DescriptionMissing<A> extends true
|
|
55
|
-
? "command description is missing"
|
|
56
|
-
: Effect<R, E, Maybe<InteractionResponse>>,
|
|
57
|
-
) =>
|
|
58
|
-
new GlobalApplicationCommand<
|
|
59
|
-
Exclude<R, Discord.Interaction | Discord.ApplicationCommandDatum>,
|
|
60
|
-
E
|
|
61
|
-
>(command, handle as any)
|
|
62
|
-
|
|
63
|
-
export class GuildApplicationCommand<R, E> {
|
|
64
|
-
readonly _tag = "GuildApplicationCommand"
|
|
65
|
-
constructor(
|
|
66
|
-
readonly command: Discord.CreateGuildApplicationCommandParams,
|
|
67
|
-
readonly handle: Effect<R, E, Maybe<InteractionResponse>>,
|
|
68
|
-
) {}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const guild = <
|
|
72
|
-
R,
|
|
73
|
-
E,
|
|
74
|
-
A extends Discord.CreateGuildApplicationCommandParams,
|
|
75
|
-
>(
|
|
76
|
-
command: A,
|
|
77
|
-
handle: DescriptionMissing<A> extends true
|
|
78
|
-
? "command description is missing"
|
|
79
|
-
: Effect<R, E, Maybe<InteractionResponse>>,
|
|
80
|
-
) =>
|
|
81
|
-
new GuildApplicationCommand<
|
|
82
|
-
Exclude<R, Discord.Interaction | Discord.ApplicationCommandDatum>,
|
|
83
|
-
E
|
|
84
|
-
>(command, handle as any)
|
|
85
|
-
|
|
86
|
-
export class MessageComponent<R, E> {
|
|
87
|
-
readonly _tag = "MessageComponent"
|
|
88
|
-
constructor(
|
|
89
|
-
readonly predicate: (customId: string) => Effect<R, E, boolean>,
|
|
90
|
-
readonly handle: Effect<R, E, Maybe<InteractionResponse>>,
|
|
91
|
-
) {}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export const messageComponent = <R1, R2, E1, E2>(
|
|
95
|
-
pred: (customId: string) => Effect<R1, E1, boolean>,
|
|
96
|
-
handle: Effect<R2, E2, Maybe<InteractionResponse>>,
|
|
97
|
-
) =>
|
|
98
|
-
new MessageComponent<
|
|
99
|
-
Exclude<R1 | R2, Discord.Interaction | Discord.MessageComponentDatum>,
|
|
100
|
-
E1 | E2
|
|
101
|
-
>(pred as any, handle as any)
|
|
102
|
-
|
|
103
|
-
export class ModalSubmit<R, E> {
|
|
104
|
-
readonly _tag = "ModalSubmit"
|
|
105
|
-
constructor(
|
|
106
|
-
readonly predicate: (customId: string) => Effect<R, E, boolean>,
|
|
107
|
-
readonly handle: Effect<R, E, Maybe<InteractionResponse>>,
|
|
108
|
-
) {}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export const modalSubmit = <R1, R2, E1, E2>(
|
|
112
|
-
pred: (customId: string) => Effect<R1, E1, boolean>,
|
|
113
|
-
handle: Effect<R2, E2, Maybe<InteractionResponse>>,
|
|
114
|
-
) =>
|
|
115
|
-
new ModalSubmit<
|
|
116
|
-
Exclude<R1 | R2, Discord.Interaction | Discord.ModalSubmitDatum>,
|
|
117
|
-
E1 | E2
|
|
118
|
-
>(pred as any, handle as any)
|
|
119
|
-
|
|
120
|
-
export class Autocomplete<R, E> {
|
|
121
|
-
readonly _tag = "Autocomplete"
|
|
122
|
-
constructor(
|
|
123
|
-
readonly predicate: (
|
|
124
|
-
focusedOption: Discord.ApplicationCommandInteractionDataOption,
|
|
125
|
-
) => Effect<R, E, boolean>,
|
|
126
|
-
readonly handle: Effect<R, E, Maybe<InteractionResponse>>,
|
|
127
|
-
) {}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export const autocomplete = <R1, R2, E1, E2>(
|
|
131
|
-
pred: (
|
|
132
|
-
focusedOption: Discord.ApplicationCommandInteractionDataOption,
|
|
133
|
-
) => Effect<R1, E1, boolean>,
|
|
134
|
-
handle: Effect<R2, E2, Maybe<InteractionResponse>>,
|
|
135
|
-
) =>
|
|
136
|
-
new Autocomplete<
|
|
137
|
-
Exclude<
|
|
138
|
-
R1 | R2,
|
|
139
|
-
| Discord.Interaction
|
|
140
|
-
| Discord.ApplicationCommandDatum
|
|
141
|
-
| Discord.ApplicationCommandInteractionDataOption
|
|
142
|
-
>,
|
|
143
|
-
E1 | E2
|
|
144
|
-
>(pred as any, handle as any)
|