@minesa-org/mini-interaction 0.2.9 → 0.2.10

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.
@@ -1303,6 +1303,8 @@ export class MiniInteraction {
1303
1303
  const interactionWithHelpers = createMessageContextMenuInteraction(commandInteraction, {
1304
1304
  onAck: (response) => ackResolver?.(response),
1305
1305
  sendFollowUp,
1306
+ canRespond: (id) => this.canRespond(id),
1307
+ trackResponse: (id, token, state) => this.trackInteractionState(id, token, state),
1306
1308
  });
1307
1309
  response = await command.handler(interactionWithHelpers);
1308
1310
  resolvedResponse =
@@ -28,8 +28,12 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
28
28
  return captureResponse({ type });
29
29
  }
30
30
  const reply = (data) => {
31
+ if (helpers?.canRespond && !helpers.canRespond(interaction.id)) {
32
+ throw new Error("[MiniInteraction] Interaction cannot respond: already responded or expired");
33
+ }
31
34
  const response = createMessageResponse(InteractionResponseType.ChannelMessageWithSource, data);
32
35
  hasResponded = true;
36
+ helpers?.trackResponse?.(interaction.id, interaction.token, 'responded');
33
37
  helpers?.onAck?.(response);
34
38
  return response;
35
39
  };
@@ -41,21 +45,31 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
41
45
  return response;
42
46
  };
43
47
  const editReply = async (data) => {
44
- const response = createMessageResponse(InteractionResponseType.UpdateMessage, data);
48
+ if (helpers?.canRespond && !helpers.canRespond(interaction.id)) {
49
+ throw new Error("[MiniInteraction] Interaction cannot edit reply: expired");
50
+ }
51
+ // Context menu commands (User/Message) MUST use ChannelMessageWithSource (4)
52
+ // for their initial response if it's the first response.
53
+ const response = createMessageResponse(InteractionResponseType.ChannelMessageWithSource, data);
45
54
  if (helpers?.sendFollowUp && (isDeferred || hasResponded)) {
46
55
  await helpers.sendFollowUp(interaction.token, response, '@original');
47
56
  return capturedResponse;
48
57
  }
49
58
  hasResponded = true;
59
+ helpers?.trackResponse?.(interaction.id, interaction.token, 'responded');
50
60
  return response;
51
61
  };
52
62
  const deferReply = (options = {}) => {
63
+ if (helpers?.canRespond && !helpers.canRespond(interaction.id)) {
64
+ throw new Error("[MiniInteraction] Interaction cannot defer: already responded or expired");
65
+ }
53
66
  const flags = normaliseMessageFlags(options.flags);
54
67
  const response = captureResponse({
55
68
  type: InteractionResponseType.DeferredChannelMessageWithSource,
56
69
  data: flags ? { flags } : undefined,
57
70
  });
58
71
  isDeferred = true;
72
+ helpers?.trackResponse?.(interaction.id, interaction.token, 'deferred');
59
73
  helpers?.onAck?.(response);
60
74
  return response;
61
75
  };
@@ -71,7 +85,7 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
71
85
  getResponse,
72
86
  reply,
73
87
  followUp,
74
- editReply,
88
+ editReply: editReply,
75
89
  deferReply,
76
90
  showModal,
77
91
  onAck: helpers?.onAck,
@@ -24,6 +24,9 @@ export function createMessageComponentInteraction(interaction, helpers) {
24
24
  return response;
25
25
  };
26
26
  const reply = async (data) => {
27
+ if (helpers?.canRespond && !helpers.canRespond(interaction.id)) {
28
+ throw new Error("[MiniInteraction] Interaction cannot respond: already responded or expired");
29
+ }
27
30
  const normalisedData = normaliseInteractionMessageData(data);
28
31
  if (!normalisedData) {
29
32
  throw new Error("[MiniInteraction] Component replies require response data to be provided.");
@@ -38,9 +41,13 @@ export function createMessageComponentInteraction(interaction, helpers) {
38
41
  else {
39
42
  helpers?.onAck?.(response);
40
43
  }
44
+ helpers?.trackResponse?.(interaction.id, interaction.token, 'responded');
41
45
  return response;
42
46
  };
43
47
  const deferReply = (options) => {
48
+ if (helpers?.canRespond && !helpers.canRespond(interaction.id)) {
49
+ throw new Error("[MiniInteraction] Interaction cannot defer: already responded or expired");
50
+ }
44
51
  const flags = normaliseMessageFlags(options?.flags);
45
52
  const response = flags !== undefined
46
53
  ? {
@@ -52,10 +59,14 @@ export function createMessageComponentInteraction(interaction, helpers) {
52
59
  };
53
60
  captureResponse(response);
54
61
  isDeferred = true;
62
+ helpers?.trackResponse?.(interaction.id, interaction.token, 'deferred');
55
63
  helpers?.onAck?.(response);
56
64
  return response;
57
65
  };
58
66
  const update = async (data) => {
67
+ if (helpers?.canRespond && !helpers.canRespond(interaction.id)) {
68
+ throw new Error("[MiniInteraction] Interaction cannot update: already responded or expired");
69
+ }
59
70
  const normalisedData = normaliseInteractionMessageData(data);
60
71
  const response = captureResponse(normalisedData
61
72
  ? {
@@ -71,13 +82,18 @@ export function createMessageComponentInteraction(interaction, helpers) {
71
82
  else {
72
83
  helpers?.onAck?.(response);
73
84
  }
85
+ helpers?.trackResponse?.(interaction.id, interaction.token, 'responded');
74
86
  return response;
75
87
  };
76
88
  const deferUpdate = () => {
89
+ if (helpers?.canRespond && !helpers.canRespond(interaction.id)) {
90
+ throw new Error("[MiniInteraction] Interaction cannot defer update: already responded or expired");
91
+ }
77
92
  const response = captureResponse({
78
93
  type: InteractionResponseType.DeferredMessageUpdate,
79
94
  });
80
95
  isDeferred = true;
96
+ helpers?.trackResponse?.(interaction.id, interaction.token, 'deferred');
81
97
  helpers?.onAck?.(response);
82
98
  return response;
83
99
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minesa-org/mini-interaction",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "Mini interaction, connecting your app with Discord via HTTP-interaction (Vercel support).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",