@minesa-org/mini-interaction 0.2.8 → 0.2.9
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.
|
@@ -1278,6 +1278,8 @@ export class MiniInteraction {
|
|
|
1278
1278
|
const interactionWithHelpers = createUserContextMenuInteraction(commandInteraction, {
|
|
1279
1279
|
onAck: (response) => ackResolver?.(response),
|
|
1280
1280
|
sendFollowUp,
|
|
1281
|
+
canRespond: (id) => this.canRespond(id),
|
|
1282
|
+
trackResponse: (id, token, state) => this.trackInteractionState(id, token, state),
|
|
1281
1283
|
});
|
|
1282
1284
|
response = await command.handler(interactionWithHelpers);
|
|
1283
1285
|
resolvedResponse =
|
|
@@ -1288,6 +1290,8 @@ export class MiniInteraction {
|
|
|
1288
1290
|
const interactionWithHelpers = createAppCommandInteraction(commandInteraction, {
|
|
1289
1291
|
onAck: (response) => ackResolver?.(response),
|
|
1290
1292
|
sendFollowUp,
|
|
1293
|
+
canRespond: (id) => this.canRespond(id),
|
|
1294
|
+
trackResponse: (id, token, state) => this.trackInteractionState(id, token, state),
|
|
1291
1295
|
});
|
|
1292
1296
|
response = await command.handler(interactionWithHelpers);
|
|
1293
1297
|
resolvedResponse =
|
|
@@ -146,7 +146,7 @@ export interface CommandInteraction extends Omit<APIChatInputApplicationCommandI
|
|
|
146
146
|
reply(data: InteractionMessageData): APIInteractionResponseChannelMessageWithSource;
|
|
147
147
|
followUp(data: InteractionMessageData): Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
148
148
|
edit(data?: InteractionMessageData): APIInteractionResponseUpdateMessage;
|
|
149
|
-
editReply(data?: InteractionMessageData): Promise<APIInteractionResponseUpdateMessage>;
|
|
149
|
+
editReply(data?: InteractionMessageData): Promise<APIInteractionResponseChannelMessageWithSource | APIInteractionResponseUpdateMessage>;
|
|
150
150
|
deferReply(options?: DeferReplyOptions): APIInteractionResponseDeferredChannelMessageWithSource;
|
|
151
151
|
showModal(data: APIModalInteractionResponseCallbackData | {
|
|
152
152
|
toJSON(): APIModalInteractionResponseCallbackData;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApplicationCommandOptionType, InteractionResponseType, } from "discord-api-types/v10";
|
|
1
|
+
import { ApplicationCommandOptionType, InteractionResponseType, InteractionType, } from "discord-api-types/v10";
|
|
2
2
|
import { normaliseInteractionMessageData, normaliseMessageFlags, } from "./interactionMessageHelpers.js";
|
|
3
3
|
export const ResolvedUserOption = {};
|
|
4
4
|
export const MentionableOption = {};
|
|
@@ -405,10 +405,24 @@ export function createCommandInteraction(interaction, helpers) {
|
|
|
405
405
|
if (!this.canRespond?.(this.id)) {
|
|
406
406
|
throw new Error('Interaction cannot edit reply: expired');
|
|
407
407
|
}
|
|
408
|
-
|
|
408
|
+
// Slash commands (type 2) MUST use ChannelMessageWithSource (type 4) for their initial response,
|
|
409
|
+
// or UpdateMessage (type 7) if they are updating a component interaction message.
|
|
410
|
+
// However, for as-yet-unresponded slash commands, we need type 4.
|
|
411
|
+
const interactionAny = interaction;
|
|
412
|
+
const isComponent = interactionAny.type === InteractionType.MessageComponent;
|
|
413
|
+
let response;
|
|
414
|
+
if (isComponent) {
|
|
415
|
+
response = createMessageResponse(InteractionResponseType.UpdateMessage, data);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
response = createMessageResponse(InteractionResponseType.ChannelMessageWithSource, data);
|
|
419
|
+
}
|
|
409
420
|
// If it's already deferred or responded, we MUST use a webhook
|
|
410
421
|
if (this.sendFollowUp && (isDeferred || hasResponded)) {
|
|
411
422
|
await this.sendFollowUp(this.token, response, '@original');
|
|
423
|
+
// If we already sent an ACK (like a DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE),
|
|
424
|
+
// we return the original captured response to avoid sending type 4/7 back to the initial POST.
|
|
425
|
+
return capturedResponse;
|
|
412
426
|
}
|
|
413
427
|
// Track response
|
|
414
428
|
this.trackResponse?.(this.id, this.token, 'responded');
|
|
@@ -14,6 +14,8 @@ export type ContextMenuInteractionHelpers = {
|
|
|
14
14
|
}) => APIModalInteractionResponse;
|
|
15
15
|
onAck?: (response: APIInteractionResponse) => void;
|
|
16
16
|
sendFollowUp?: (token: string, response: APIInteractionResponse, messageId?: string) => Promise<void>;
|
|
17
|
+
canRespond?: (interactionId: string) => boolean;
|
|
18
|
+
trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
|
|
17
19
|
};
|
|
18
20
|
/**
|
|
19
21
|
* User context menu interaction with helper methods.
|
|
@@ -46,6 +48,8 @@ export declare const AppCommandInteraction: {};
|
|
|
46
48
|
export declare function createUserContextMenuInteraction(interaction: APIUserApplicationCommandInteraction, helpers?: {
|
|
47
49
|
onAck?: (response: APIInteractionResponse) => void;
|
|
48
50
|
sendFollowUp?: (token: string, response: APIInteractionResponse, messageId?: string) => Promise<void>;
|
|
51
|
+
canRespond?: (interactionId: string) => boolean;
|
|
52
|
+
trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
|
|
49
53
|
}): UserContextMenuInteraction;
|
|
50
54
|
/**
|
|
51
55
|
* Wraps a raw message context menu interaction with helper methods.
|
|
@@ -57,6 +61,8 @@ export declare function createUserContextMenuInteraction(interaction: APIUserApp
|
|
|
57
61
|
export declare function createMessageContextMenuInteraction(interaction: APIMessageApplicationCommandInteraction, helpers?: {
|
|
58
62
|
onAck?: (response: APIInteractionResponse) => void;
|
|
59
63
|
sendFollowUp?: (token: string, response: APIInteractionResponse, messageId?: string) => Promise<void>;
|
|
64
|
+
canRespond?: (interactionId: string) => boolean;
|
|
65
|
+
trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
|
|
60
66
|
}): MessageContextMenuInteraction;
|
|
61
67
|
/**
|
|
62
68
|
* Wraps a raw primary entry point interaction with helper methods.
|
|
@@ -68,4 +74,6 @@ export declare function createMessageContextMenuInteraction(interaction: APIMess
|
|
|
68
74
|
export declare function createAppCommandInteraction(interaction: APIPrimaryEntryPointCommandInteraction, helpers?: {
|
|
69
75
|
onAck?: (response: APIInteractionResponse) => void;
|
|
70
76
|
sendFollowUp?: (token: string, response: APIInteractionResponse, messageId?: string) => Promise<void>;
|
|
77
|
+
canRespond?: (interactionId: string) => boolean;
|
|
78
|
+
trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
|
|
71
79
|
}): AppCommandInteraction;
|
|
@@ -44,6 +44,7 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
|
|
|
44
44
|
const response = createMessageResponse(InteractionResponseType.UpdateMessage, data);
|
|
45
45
|
if (helpers?.sendFollowUp && (isDeferred || hasResponded)) {
|
|
46
46
|
await helpers.sendFollowUp(interaction.token, response, '@original');
|
|
47
|
+
return capturedResponse;
|
|
47
48
|
}
|
|
48
49
|
hasResponded = true;
|
|
49
50
|
return response;
|
|
@@ -73,7 +74,10 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
|
|
|
73
74
|
editReply,
|
|
74
75
|
deferReply,
|
|
75
76
|
showModal,
|
|
77
|
+
onAck: helpers?.onAck,
|
|
76
78
|
sendFollowUp: helpers?.sendFollowUp,
|
|
79
|
+
canRespond: helpers?.canRespond,
|
|
80
|
+
trackResponse: helpers?.trackResponse,
|
|
77
81
|
};
|
|
78
82
|
}
|
|
79
83
|
/**
|
package/package.json
CHANGED