@minesa-org/mini-interaction 0.2.14 → 0.2.16
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/clients/MiniInteraction.js +8 -1
- package/dist/utils/CommandInteractionOptions.d.ts +1 -1
- package/dist/utils/CommandInteractionOptions.js +4 -2
- package/dist/utils/ContextMenuInteraction.d.ts +1 -1
- package/dist/utils/ContextMenuInteraction.js +11 -2
- package/dist/utils/MessageComponentInteraction.d.ts +4 -0
- package/dist/utils/MessageComponentInteraction.js +25 -1
- package/dist/utils/ModalSubmitInteraction.d.ts +4 -0
- package/dist/utils/ModalSubmitInteraction.js +16 -1
- package/package.json +1 -1
|
@@ -101,6 +101,10 @@ export class MiniInteraction {
|
|
|
101
101
|
this.trackInteractionState(interactionId, state.token, 'expired');
|
|
102
102
|
return false;
|
|
103
103
|
}
|
|
104
|
+
// Initial response only allowed once if not deferred
|
|
105
|
+
if (state.state === 'responded' && !state.token) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
104
108
|
return true;
|
|
105
109
|
}
|
|
106
110
|
/**
|
|
@@ -1391,7 +1395,10 @@ export class MiniInteraction {
|
|
|
1391
1395
|
}
|
|
1392
1396
|
if (!fetchResponse.ok) {
|
|
1393
1397
|
const errorBody = await fetchResponse.text();
|
|
1394
|
-
console.error(`[MiniInteraction] Failed to send follow-up response: [${fetchResponse.status}] ${errorBody}`);
|
|
1398
|
+
console.error(`[MiniInteraction] Failed to send follow-up response (id=${messageId || 'new'}): [${fetchResponse.status}] ${errorBody}`);
|
|
1399
|
+
if (fetchResponse.status === 404) {
|
|
1400
|
+
console.error("[MiniInteraction] Hint: Interaction token might have expired or the message was deleted.");
|
|
1401
|
+
}
|
|
1395
1402
|
}
|
|
1396
1403
|
}
|
|
1397
1404
|
catch (error) {
|
|
@@ -45,7 +45,7 @@ export interface CommandInteraction extends Omit<APIChatInputApplicationCommandI
|
|
|
45
45
|
};
|
|
46
46
|
options: CommandInteractionOptionResolver;
|
|
47
47
|
getResponse(): APIInteractionResponse | null;
|
|
48
|
-
reply(data: InteractionMessageData): APIInteractionResponseChannelMessageWithSource
|
|
48
|
+
reply(data: InteractionMessageData): Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
49
49
|
edit(data?: InteractionMessageData): APIInteractionResponseUpdateMessage;
|
|
50
50
|
followUp(data: InteractionMessageData): Promise<void>;
|
|
51
51
|
editReply(data?: InteractionMessageData): Promise<void>;
|
|
@@ -251,13 +251,13 @@ export function createCommandInteraction(interaction, helpers) {
|
|
|
251
251
|
getResponse() {
|
|
252
252
|
return capturedResponse;
|
|
253
253
|
},
|
|
254
|
-
reply(data) {
|
|
254
|
+
async reply(data) {
|
|
255
255
|
if (this.canRespond && !this.canRespond(this.id)) {
|
|
256
256
|
throw new Error('Interaction cannot respond: already responded or expired');
|
|
257
257
|
}
|
|
258
258
|
const response = createMessageResponse(InteractionResponseType.ChannelMessageWithSource, data);
|
|
259
259
|
if (isDeferred && this.sendFollowUp) {
|
|
260
|
-
this.sendFollowUp(this.token, response, '');
|
|
260
|
+
await this.sendFollowUp(this.token, response, '@original');
|
|
261
261
|
}
|
|
262
262
|
else {
|
|
263
263
|
this.onAck?.(response);
|
|
@@ -278,6 +278,8 @@ export function createCommandInteraction(interaction, helpers) {
|
|
|
278
278
|
if (this.sendFollowUp) {
|
|
279
279
|
await this.sendFollowUp(this.token, response, '');
|
|
280
280
|
}
|
|
281
|
+
this.trackResponse?.(this.id, this.token, 'responded');
|
|
282
|
+
hasResponded = true;
|
|
281
283
|
},
|
|
282
284
|
edit(data) {
|
|
283
285
|
return createMessageResponse(InteractionResponseType.UpdateMessage, data);
|
|
@@ -5,7 +5,7 @@ import { DeferReplyOptions, InteractionMessageData } from "./interactionMessageH
|
|
|
5
5
|
*/
|
|
6
6
|
export type ContextMenuInteractionHelpers = {
|
|
7
7
|
getResponse: () => APIInteractionResponse | null;
|
|
8
|
-
reply: (data: InteractionMessageData) => APIInteractionResponseChannelMessageWithSource
|
|
8
|
+
reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
9
9
|
followUp: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
10
10
|
editReply: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage>;
|
|
11
11
|
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
@@ -27,14 +27,19 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
|
|
|
27
27
|
}
|
|
28
28
|
return captureResponse({ type });
|
|
29
29
|
}
|
|
30
|
-
const reply = (data) => {
|
|
30
|
+
const reply = async (data) => {
|
|
31
31
|
if (helpers?.canRespond && !helpers.canRespond(interaction.id)) {
|
|
32
32
|
throw new Error("[MiniInteraction] Interaction cannot respond: already responded or expired");
|
|
33
33
|
}
|
|
34
34
|
const response = createMessageResponse(InteractionResponseType.ChannelMessageWithSource, data);
|
|
35
|
+
if (isDeferred && helpers?.sendFollowUp) {
|
|
36
|
+
await helpers.sendFollowUp(interaction.token, response, '@original');
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
helpers?.onAck?.(response);
|
|
40
|
+
}
|
|
35
41
|
hasResponded = true;
|
|
36
42
|
helpers?.trackResponse?.(interaction.id, interaction.token, 'responded');
|
|
37
|
-
helpers?.onAck?.(response);
|
|
38
43
|
return response;
|
|
39
44
|
};
|
|
40
45
|
const followUp = async (data) => {
|
|
@@ -42,6 +47,8 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
|
|
|
42
47
|
if (helpers?.sendFollowUp) {
|
|
43
48
|
await helpers.sendFollowUp(interaction.token, response, '');
|
|
44
49
|
}
|
|
50
|
+
hasResponded = true;
|
|
51
|
+
helpers?.trackResponse?.(interaction.id, interaction.token, 'responded');
|
|
45
52
|
return response;
|
|
46
53
|
};
|
|
47
54
|
const editReply = async (data) => {
|
|
@@ -55,6 +62,8 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
|
|
|
55
62
|
await helpers.sendFollowUp(interaction.token, response, '@original');
|
|
56
63
|
return capturedResponse;
|
|
57
64
|
}
|
|
65
|
+
captureResponse(response);
|
|
66
|
+
helpers?.onAck?.(response);
|
|
58
67
|
hasResponded = true;
|
|
59
68
|
helpers?.trackResponse?.(interaction.id, interaction.token, 'responded');
|
|
60
69
|
return response;
|
|
@@ -153,6 +153,10 @@ export type MessageComponentInteraction = APIMessageComponentInteraction & {
|
|
|
153
153
|
showModal: (data: APIModalInteractionResponseCallbackData | {
|
|
154
154
|
toJSON(): APIModalInteractionResponseCallbackData;
|
|
155
155
|
}) => APIModalInteractionResponse;
|
|
156
|
+
/**
|
|
157
|
+
* Edit the initial interaction response.
|
|
158
|
+
*/
|
|
159
|
+
editReply: (data?: InteractionMessageData) => Promise<APIInteractionResponseUpdateMessage | APIInteractionResponseChannelMessageWithSource>;
|
|
156
160
|
/**
|
|
157
161
|
* Finalise the interaction response via a webhook follow-up.
|
|
158
162
|
* This is automatically called by reply() and update() if the interaction is deferred.
|
|
@@ -36,7 +36,7 @@ export function createMessageComponentInteraction(interaction, helpers) {
|
|
|
36
36
|
data: normalisedData,
|
|
37
37
|
});
|
|
38
38
|
if (isDeferred && helpers?.sendFollowUp) {
|
|
39
|
-
await helpers.sendFollowUp(interaction.token, response, '');
|
|
39
|
+
await helpers.sendFollowUp(interaction.token, response, '@original');
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
42
|
helpers?.onAck?.(response);
|
|
@@ -108,6 +108,29 @@ export function createMessageComponentInteraction(interaction, helpers) {
|
|
|
108
108
|
data: resolvedData,
|
|
109
109
|
});
|
|
110
110
|
};
|
|
111
|
+
const editReply = async (data) => {
|
|
112
|
+
if (helpers?.canRespond && !helpers.canRespond(interaction.id)) {
|
|
113
|
+
throw new Error("[MiniInteraction] Interaction cannot edit reply: expired");
|
|
114
|
+
}
|
|
115
|
+
const normalisedData = normaliseInteractionMessageData(data);
|
|
116
|
+
const response = captureResponse(normalisedData
|
|
117
|
+
? {
|
|
118
|
+
type: InteractionResponseType.ChannelMessageWithSource,
|
|
119
|
+
data: normalisedData,
|
|
120
|
+
}
|
|
121
|
+
: {
|
|
122
|
+
type: InteractionResponseType.ChannelMessageWithSource,
|
|
123
|
+
data: { content: "" }
|
|
124
|
+
});
|
|
125
|
+
if (helpers?.sendFollowUp) {
|
|
126
|
+
await helpers.sendFollowUp(interaction.token, response, "@original");
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
helpers?.onAck?.(response);
|
|
130
|
+
}
|
|
131
|
+
helpers?.trackResponse?.(interaction.id, interaction.token, "responded");
|
|
132
|
+
return response;
|
|
133
|
+
};
|
|
111
134
|
const getResponse = () => capturedResponse;
|
|
112
135
|
// Extract values from select menu interactions
|
|
113
136
|
const values = "values" in interaction.data ? interaction.data.values : undefined;
|
|
@@ -210,6 +233,7 @@ export function createMessageComponentInteraction(interaction, helpers) {
|
|
|
210
233
|
update,
|
|
211
234
|
deferUpdate,
|
|
212
235
|
showModal,
|
|
236
|
+
editReply,
|
|
213
237
|
getResponse,
|
|
214
238
|
values,
|
|
215
239
|
getStringValues,
|
|
@@ -21,6 +21,10 @@ export type ModalSubmitInteraction = APIModalSubmitInteraction & {
|
|
|
21
21
|
*/
|
|
22
22
|
canRespond?: (interactionId: string) => boolean;
|
|
23
23
|
trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
|
|
24
|
+
/**
|
|
25
|
+
* Edit the initial interaction response.
|
|
26
|
+
*/
|
|
27
|
+
editReply: (data?: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
24
28
|
};
|
|
25
29
|
export declare const ModalSubmitInteraction: {};
|
|
26
30
|
/**
|
|
@@ -25,7 +25,21 @@ export function createModalSubmitInteraction(interaction, helpers) {
|
|
|
25
25
|
data: normalisedData,
|
|
26
26
|
});
|
|
27
27
|
if (isDeferred && helpers?.sendFollowUp) {
|
|
28
|
-
await helpers.sendFollowUp(interaction.token, response, '');
|
|
28
|
+
await helpers.sendFollowUp(interaction.token, response, '@original');
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
helpers?.onAck?.(response);
|
|
32
|
+
}
|
|
33
|
+
return response;
|
|
34
|
+
};
|
|
35
|
+
const editReply = async (data) => {
|
|
36
|
+
const normalisedData = normaliseInteractionMessageData(data);
|
|
37
|
+
const response = captureResponse({
|
|
38
|
+
type: InteractionResponseType.ChannelMessageWithSource,
|
|
39
|
+
data: normalisedData ?? { content: "" },
|
|
40
|
+
});
|
|
41
|
+
if (helpers?.sendFollowUp) {
|
|
42
|
+
await helpers.sendFollowUp(interaction.token, response, '@original');
|
|
29
43
|
}
|
|
30
44
|
else {
|
|
31
45
|
helpers?.onAck?.(response);
|
|
@@ -64,6 +78,7 @@ export function createModalSubmitInteraction(interaction, helpers) {
|
|
|
64
78
|
return Object.assign(interaction, {
|
|
65
79
|
reply,
|
|
66
80
|
deferReply,
|
|
81
|
+
editReply,
|
|
67
82
|
getResponse,
|
|
68
83
|
getTextFieldValue,
|
|
69
84
|
sendFollowUp: helpers?.sendFollowUp,
|
package/package.json
CHANGED