@minesa-org/mini-interaction 0.3.3 → 0.3.5

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.
@@ -325,10 +325,12 @@ export function createCommandInteraction(interaction, helpers) {
325
325
  typeof data.toJSON === "function"
326
326
  ? data.toJSON()
327
327
  : data;
328
- return captureResponse({
328
+ const response = captureResponse({
329
329
  type: InteractionResponseType.Modal,
330
330
  data: resolvedData,
331
331
  });
332
+ this.onAck?.(response);
333
+ return response;
332
334
  },
333
335
  async withTimeoutProtection(operation, deferOptions) {
334
336
  const startTime = Date.now();
@@ -84,10 +84,12 @@ function createContextMenuInteractionHelpers(interaction, helpers) {
84
84
  };
85
85
  const showModal = (data) => {
86
86
  const modalData = typeof data === "object" && "toJSON" in data ? data.toJSON() : data;
87
- return captureResponse({
87
+ const response = captureResponse({
88
88
  type: InteractionResponseType.Modal,
89
89
  data: modalData,
90
90
  });
91
+ helpers?.onAck?.(response);
92
+ return response;
91
93
  };
92
94
  const getResponse = () => capturedResponse;
93
95
  return {
@@ -103,10 +103,12 @@ export function createMessageComponentInteraction(interaction, helpers) {
103
103
  typeof data.toJSON === "function"
104
104
  ? data.toJSON()
105
105
  : data;
106
- return captureResponse({
106
+ const response = captureResponse({
107
107
  type: InteractionResponseType.Modal,
108
108
  data: resolvedData,
109
109
  });
110
+ helpers?.onAck?.(response);
111
+ return response;
110
112
  };
111
113
  const editReply = async (data) => {
112
114
  if (helpers?.canRespond && !helpers.canRespond(interaction.id)) {
@@ -7,10 +7,22 @@ export type ModalSubmitInteraction = APIModalSubmitInteraction & {
7
7
  getResponse: () => APIInteractionResponse | null;
8
8
  reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
9
9
  deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
10
+ /**
11
+ * Helper method to get the value of a text input component by its custom ID.
12
+ */
10
13
  /**
11
14
  * Helper method to get the value of a text input component by its custom ID.
12
15
  */
13
16
  getTextFieldValue: (customId: string) => string | undefined;
17
+ /**
18
+ * Helper method to get the value(s) of a select menu component by its custom ID.
19
+ */
20
+ getSelectMenuValues: (customId: string) => string[] | undefined;
21
+ /**
22
+ * Helper method to get the value of any component by its custom ID.
23
+ * Returns string for text inputs, string[] for select menus, or undefined.
24
+ */
25
+ getComponentValue: (customId: string) => string | string[] | undefined;
14
26
  /**
15
27
  * Finalise the interaction response via a webhook follow-up.
16
28
  * This is automatically called by reply() if the interaction is deferred.
@@ -75,12 +75,40 @@ export function createModalSubmitInteraction(interaction, helpers) {
75
75
  }
76
76
  return undefined;
77
77
  };
78
+ const getSelectMenuValues = (customId) => {
79
+ for (const actionRow of interaction.data.components) {
80
+ if ("components" in actionRow && Array.isArray(actionRow.components)) {
81
+ for (const rawComponent of actionRow.components) {
82
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
+ const component = rawComponent;
84
+ if ((component.type === ComponentType.StringSelect ||
85
+ component.type === ComponentType.UserSelect ||
86
+ component.type === ComponentType.RoleSelect ||
87
+ component.type === ComponentType.MentionableSelect ||
88
+ component.type === ComponentType.ChannelSelect) &&
89
+ component.custom_id === customId) {
90
+ return component.values;
91
+ }
92
+ }
93
+ }
94
+ }
95
+ return undefined;
96
+ };
97
+ const getComponentValue = (customId) => {
98
+ const textValue = getTextFieldValue(customId);
99
+ if (textValue !== undefined) {
100
+ return textValue;
101
+ }
102
+ return getSelectMenuValues(customId);
103
+ };
78
104
  return Object.assign(interaction, {
79
105
  reply,
80
106
  deferReply,
81
107
  editReply,
82
108
  getResponse,
83
109
  getTextFieldValue,
110
+ getSelectMenuValues,
111
+ getComponentValue,
84
112
  sendFollowUp: helpers?.sendFollowUp,
85
113
  canRespond: helpers?.canRespond,
86
114
  trackResponse: helpers?.trackResponse,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minesa-org/mini-interaction",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
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",