cordo 2.13.2 → 2.14.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/package.json
CHANGED
|
@@ -3,8 +3,10 @@ import { ChannelType, ApplicationCommandOptionType, ApplicationCommandType, type
|
|
|
3
3
|
import type { LocalizedString } from '../../lib/localization'
|
|
4
4
|
import { CordoGateway } from '../gateway'
|
|
5
5
|
import { RoutingResolve } from '../routing/resolve'
|
|
6
|
+
import type { CordoInteraction } from '../interaction'
|
|
6
7
|
import type { CordoRoute } from './route'
|
|
7
8
|
|
|
9
|
+
|
|
8
10
|
type CommandOption = {
|
|
9
11
|
name: string | LocalizedString
|
|
10
12
|
description: string | LocalizedString
|
|
@@ -61,10 +63,9 @@ type CommandInput = {
|
|
|
61
63
|
nsfw?: boolean
|
|
62
64
|
limitInstallTypes?: Array<'guild' | 'user'>
|
|
63
65
|
limitContexts?: Array<'guild' | 'dm' | 'group'>
|
|
64
|
-
|
|
65
|
-
options: CommandOption[]
|
|
66
|
-
|
|
66
|
+
options?: CommandOption[]
|
|
67
67
|
route: CordoRoute | 'launch_activity'
|
|
68
|
+
private?: boolean | ((r: CordoInteraction) => boolean)
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
export type CordoCommand = {
|
package/src/core/files/route.ts
CHANGED
|
@@ -117,7 +117,7 @@ export type RouteRequest = {
|
|
|
117
117
|
rawEntitlements: APIEntitlement[]
|
|
118
118
|
|
|
119
119
|
/** acknowledge the request but only provide a reply later */
|
|
120
|
-
ack: (
|
|
120
|
+
ack: () => void
|
|
121
121
|
/** render the provided components */
|
|
122
122
|
render: (...response: RouteResponse) => void
|
|
123
123
|
/** open a modal with the provided components */
|
package/src/core/gateway.ts
CHANGED
|
@@ -72,9 +72,18 @@ export namespace CordoGateway {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/** if the payload is null the interaction will be defered if not done already */
|
|
75
|
-
export async function respondTo(i: CordoInteraction, payload: Record<string, any> | null, opts
|
|
75
|
+
export async function respondTo(i: CordoInteraction, payload: Record<string, any> | null, opts: { ephemeral?: boolean } = {}) {
|
|
76
76
|
payload = await Hooks.callHook('onBeforeRespond', payload, { interaction: i })
|
|
77
77
|
|
|
78
|
+
// if not specifically set, check if it's triggered by a command and if so -> is that command private?
|
|
79
|
+
if (opts?.ephemeral === undefined) {
|
|
80
|
+
const isPrivate = InteractionInternals.get(i).commandEntrypoint?.private
|
|
81
|
+
if (typeof isPrivate === 'boolean')
|
|
82
|
+
opts.ephemeral = isPrivate
|
|
83
|
+
else if (typeof isPrivate === 'function')
|
|
84
|
+
opts.ephemeral = isPrivate(i)
|
|
85
|
+
}
|
|
86
|
+
|
|
78
87
|
const internals = InteractionInternals.get(i)
|
|
79
88
|
if (internals.httpCallback && !internals.answered) {
|
|
80
89
|
internals.answered = true
|
|
@@ -162,7 +171,11 @@ export namespace CordoGateway {
|
|
|
162
171
|
}
|
|
163
172
|
|
|
164
173
|
const { route, path } = RoutingResolve.getRouteForCommand(name, 'slash')
|
|
174
|
+
|
|
165
175
|
CordoMagic.setCwd(path)
|
|
176
|
+
if (CordoMagic.getLockfile()?.$runtime.registeredCommands.has(route.routeId))
|
|
177
|
+
InteractionInternals.get(i).commandEntrypoint = CordoMagic.getLockfile()!.$runtime.registeredCommands.get(route.routeId)!
|
|
178
|
+
|
|
166
179
|
return RoutingRespond.callRoute(route.routeId, route.args, i)
|
|
167
180
|
}
|
|
168
181
|
|
|
@@ -172,7 +185,11 @@ export namespace CordoGateway {
|
|
|
172
185
|
i.data.name,
|
|
173
186
|
i.data.type === ApplicationCommandType.Message ? 'message' : 'user'
|
|
174
187
|
)
|
|
188
|
+
|
|
175
189
|
CordoMagic.setCwd(path)
|
|
190
|
+
if (CordoMagic.getLockfile()?.$runtime.registeredCommands.has(route.routeId))
|
|
191
|
+
InteractionInternals.get(i).commandEntrypoint = CordoMagic.getLockfile()!.$runtime.registeredCommands.get(route.routeId)!
|
|
192
|
+
|
|
176
193
|
return RoutingRespond.callRoute(route.routeId, route.args, i)
|
|
177
194
|
}
|
|
178
195
|
}
|
package/src/core/interaction.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { APIInteraction } from "discord-api-types/v10"
|
|
2
|
+
import type { CordoCommand } from "./files/command"
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
const CordoInteractionSymbol = Symbol.for('CordoInteraction')
|
|
@@ -7,6 +8,8 @@ export type CordoInteraction = {
|
|
|
7
8
|
[CordoInteractionSymbol]: {
|
|
8
9
|
answered: boolean
|
|
9
10
|
httpCallback: ((payload: any) => any) | null
|
|
11
|
+
// will be set to the command linked to this interaction if it was triggered by a command, otherwise null
|
|
12
|
+
commandEntrypoint: CordoCommand | null
|
|
10
13
|
}
|
|
11
14
|
locals: Record<string, any>
|
|
12
15
|
} & APIInteraction
|
|
@@ -29,7 +32,8 @@ export namespace InteractionInternals {
|
|
|
29
32
|
locals: {},
|
|
30
33
|
[CordoInteractionSymbol]: {
|
|
31
34
|
answered: false,
|
|
32
|
-
httpCallback: null
|
|
35
|
+
httpCallback: null,
|
|
36
|
+
commandEntrypoint: null
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
}
|
|
@@ -145,8 +145,8 @@ export namespace RoutingRespond {
|
|
|
145
145
|
has: (key: string) => key in interaction.locals
|
|
146
146
|
},
|
|
147
147
|
|
|
148
|
-
ack: opts.disableRendering ? noOp : (
|
|
149
|
-
CordoGateway.respondTo(interaction, null
|
|
148
|
+
ack: opts.disableRendering ? noOp : () => {
|
|
149
|
+
CordoGateway.respondTo(interaction, null)
|
|
150
150
|
},
|
|
151
151
|
render: opts.disableRendering ? noOp : (...response) => {
|
|
152
152
|
const rendered = renderRouteResponse(response, interaction, opts)
|