@minesa-org/mini-interaction 0.3.7 → 0.3.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.
@@ -51,5 +51,6 @@ export declare const MiniPermFlags: {
51
51
  readonly SendPolls: bigint;
52
52
  readonly UseExternalApps: bigint;
53
53
  readonly PinMessages: bigint;
54
+ readonly BypassSlowmode: bigint;
54
55
  };
55
56
  export type MiniPermFlag = (typeof MiniPermFlags)[keyof typeof MiniPermFlags];
@@ -63,44 +63,71 @@ export function createModalSubmitInteraction(interaction, helpers) {
63
63
  };
64
64
  const getResponse = () => capturedResponse;
65
65
  const getTextFieldValue = (customId) => {
66
- for (const actionRow of interaction.data.components) {
67
- if ("components" in actionRow && Array.isArray(actionRow.components)) {
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") {
73
- return component.value;
74
- }
66
+ const findValue = (components) => {
67
+ for (const component of components) {
68
+ if (component?.custom_id === customId &&
69
+ typeof component.value === "string") {
70
+ return component.value;
75
71
  }
72
+ // Nested Label wrapper: single child in .component
73
+ if (component?.component) {
74
+ const found = findValue([component.component]);
75
+ if (found)
76
+ return found;
77
+ }
78
+ }
79
+ return undefined;
80
+ };
81
+ for (const top of interaction.data.components) {
82
+ if ("components" in top && Array.isArray(top.components)) {
83
+ const result = findValue(top.components);
84
+ if (result)
85
+ return result;
86
+ }
87
+ if ("component" in top && top.component) {
88
+ const result = findValue([top.component]);
89
+ if (result)
90
+ return result;
76
91
  }
77
92
  }
78
93
  return undefined;
79
94
  };
80
95
  /**
81
96
  * Helper method to get the value(s) of a select menu component by its custom ID.
82
- * Handles the nested structure of modal components (Action Rows -> Components).
97
+ * Handles the nested structure of modal components (Action Rows -> Components,
98
+ * and Label -> single component). Select menus in modals are typically inside
99
+ * Label components, not Action Rows.
83
100
  */
84
101
  const getSelectMenuValues = (customId) => {
85
- // 1. Access this.interaction.data.components (Array of Action Rows)
86
- for (const actionRow of interaction.data.components) {
87
- // 2. Iterate through these Action Rows
88
- if ("components" in actionRow && Array.isArray(actionRow.components)) {
89
- // 3. Inside each row, look for a component
90
- for (const rawComponent of actionRow.components) {
91
- // Cast to any to handle potential type definitions that might not fully support Select Menus in Modals yet
92
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
- const component = rawComponent;
94
- // 4. Match customId and check for 'values' property (specific to Select Menus)
95
- if (component.custom_id === customId &&
96
- Array.isArray(component.values)) {
97
- // 5. Return its values property
98
- return component.values;
99
- }
102
+ const findValues = (components) => {
103
+ for (const component of components) {
104
+ if (component?.custom_id === customId &&
105
+ Array.isArray(component.values)) {
106
+ return component.values;
100
107
  }
108
+ // Nested Label wrapper: single child in .component
109
+ if (component?.component) {
110
+ const found = findValues([component.component]);
111
+ if (found)
112
+ return found;
113
+ }
114
+ }
115
+ return undefined;
116
+ };
117
+ for (const top of interaction.data.components) {
118
+ // Action Row: multiple components in .components
119
+ if ("components" in top && Array.isArray(top.components)) {
120
+ const result = findValues(top.components);
121
+ if (result)
122
+ return result;
123
+ }
124
+ // Label: select menu (and other modal components) wrapped in .component
125
+ if ("component" in top && top.component) {
126
+ const result = findValues([top.component]);
127
+ if (result)
128
+ return result;
101
129
  }
102
130
  }
103
- // 6. If not found, return undefined
104
131
  return undefined;
105
132
  };
106
133
  const getComponentValue = (customId) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minesa-org/mini-interaction",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
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",