@minesa-org/mini-interaction 0.3.4 → 0.3.6

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.
@@ -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.
@@ -1,4 +1,4 @@
1
- import { ComponentType, InteractionResponseType, } from "discord-api-types/v10";
1
+ import { InteractionResponseType, } from "discord-api-types/v10";
2
2
  import { normaliseInteractionMessageData, normaliseMessageFlags, } from "./interactionMessageHelpers.js";
3
3
  export const ModalSubmitInteraction = {};
4
4
  /**
@@ -65,9 +65,11 @@ export function createModalSubmitInteraction(interaction, helpers) {
65
65
  const getTextFieldValue = (customId) => {
66
66
  for (const actionRow of interaction.data.components) {
67
67
  if ("components" in actionRow && Array.isArray(actionRow.components)) {
68
- for (const component of actionRow.components) {
69
- if (component.type === ComponentType.TextInput &&
70
- component.custom_id === customId) {
68
+ for (const rawComponent of actionRow.components) {
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ const component = rawComponent;
71
+ if (component.custom_id === customId &&
72
+ typeof component.value === "string") {
71
73
  return component.value;
72
74
  }
73
75
  }
@@ -75,12 +77,36 @@ export function createModalSubmitInteraction(interaction, helpers) {
75
77
  }
76
78
  return undefined;
77
79
  };
80
+ const getSelectMenuValues = (customId) => {
81
+ for (const actionRow of interaction.data.components) {
82
+ if ("components" in actionRow && Array.isArray(actionRow.components)) {
83
+ for (const rawComponent of actionRow.components) {
84
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
+ const component = rawComponent;
86
+ if (component.custom_id === customId &&
87
+ Array.isArray(component.values)) {
88
+ return component.values;
89
+ }
90
+ }
91
+ }
92
+ }
93
+ return undefined;
94
+ };
95
+ const getComponentValue = (customId) => {
96
+ const textValue = getTextFieldValue(customId);
97
+ if (textValue !== undefined) {
98
+ return textValue;
99
+ }
100
+ return getSelectMenuValues(customId);
101
+ };
78
102
  return Object.assign(interaction, {
79
103
  reply,
80
104
  deferReply,
81
105
  editReply,
82
106
  getResponse,
83
107
  getTextFieldValue,
108
+ getSelectMenuValues,
109
+ getComponentValue,
84
110
  sendFollowUp: helpers?.sendFollowUp,
85
111
  canRespond: helpers?.canRespond,
86
112
  trackResponse: helpers?.trackResponse,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minesa-org/mini-interaction",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
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",