@minesa-org/mini-interaction 0.2.1 → 0.2.3
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.
|
@@ -219,18 +219,6 @@ export class MiniInteraction {
|
|
|
219
219
|
data: normalizedData,
|
|
220
220
|
};
|
|
221
221
|
this.commands.set(commandName, normalizedCommand);
|
|
222
|
-
if (normalizedCommand.components &&
|
|
223
|
-
Array.isArray(normalizedCommand.components)) {
|
|
224
|
-
for (const component of normalizedCommand.components) {
|
|
225
|
-
this.useComponent(component);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (normalizedCommand.modals &&
|
|
229
|
-
Array.isArray(normalizedCommand.modals)) {
|
|
230
|
-
for (const modal of normalizedCommand.modals) {
|
|
231
|
-
this.useModal(modal);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
222
|
}
|
|
235
223
|
/**
|
|
236
224
|
* Registers a single command handler with the client.
|
|
@@ -961,7 +949,7 @@ export class MiniInteraction {
|
|
|
961
949
|
console.warn(`[MiniInteraction] Command module "${absolutePath}" does not export a command object. Skipping.`);
|
|
962
950
|
return null;
|
|
963
951
|
}
|
|
964
|
-
const { data, handler
|
|
952
|
+
const { data, handler } = candidate;
|
|
965
953
|
const normalizedData = this.normalizeCommandData(data);
|
|
966
954
|
if (!normalizedData || typeof normalizedData.name !== "string") {
|
|
967
955
|
console.warn(`[MiniInteraction] Command module "${absolutePath}" is missing "data.name". Skipping.`);
|
|
@@ -971,7 +959,7 @@ export class MiniInteraction {
|
|
|
971
959
|
console.warn(`[MiniInteraction] Command module "${absolutePath}" is missing a "handler" function. Skipping.`);
|
|
972
960
|
return null;
|
|
973
961
|
}
|
|
974
|
-
return { data: normalizedData, handler
|
|
962
|
+
return { data: normalizedData, handler };
|
|
975
963
|
}
|
|
976
964
|
catch (error) {
|
|
977
965
|
console.error(`[MiniInteraction] Failed to load command module "${absolutePath}":`, error);
|
package/dist/types/Commands.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { APIInteractionResponse, RESTPostAPIChatInputApplicationCommandsJSO
|
|
|
2
2
|
import type { CommandInteraction } from "../utils/CommandInteractionOptions.js";
|
|
3
3
|
import type { UserContextMenuInteraction, MessageContextMenuInteraction, AppCommandInteraction } from "../utils/ContextMenuInteraction.js";
|
|
4
4
|
import type { JSONEncodable } from "../builders/shared.js";
|
|
5
|
-
import type { ComponentCommand, ModalCommand } from "../clients/MiniInteraction.js";
|
|
6
5
|
import type { CommandBuilder } from "../commands/CommandBuilder.js";
|
|
7
6
|
import type { MessageCommandBuilder, UserCommandBuilder, AppCommandBuilder } from "../commands/ContextMenuCommandBuilder.js";
|
|
8
7
|
/** Handler signature for slash command executions within MiniInteraction. */
|
|
@@ -19,16 +18,6 @@ export type CommandHandler = SlashCommandHandler | UserCommandHandler | MessageC
|
|
|
19
18
|
export type InteractionCommand = {
|
|
20
19
|
data: RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody | RESTPostAPIPrimaryEntryPointApplicationCommandJSONBody | CommandBuilder | UserCommandBuilder | MessageCommandBuilder | AppCommandBuilder | JSONEncodable<RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody | RESTPostAPIPrimaryEntryPointApplicationCommandJSONBody>;
|
|
21
20
|
handler: CommandHandler;
|
|
22
|
-
/**
|
|
23
|
-
* Optional array of component handlers related to this command.
|
|
24
|
-
* These will be automatically registered when the command is loaded.
|
|
25
|
-
*/
|
|
26
|
-
components?: ComponentCommand[];
|
|
27
|
-
/**
|
|
28
|
-
* Optional array of modal handlers related to this command.
|
|
29
|
-
* These will be automatically registered when the command is loaded.
|
|
30
|
-
*/
|
|
31
|
-
modals?: ModalCommand[];
|
|
32
21
|
};
|
|
33
22
|
/** Map of command names to their registered MiniInteraction command definitions. */
|
|
34
23
|
export type InteractionCommandsMap = Map<string, InteractionCommand>;
|
|
@@ -18,6 +18,12 @@ export type ModalSubmitInteraction = APIModalSubmitInteraction & {
|
|
|
18
18
|
* @returns A map of custom_id to value for all text inputs
|
|
19
19
|
*/
|
|
20
20
|
getTextInputValues: () => Map<string, string>;
|
|
21
|
+
/**
|
|
22
|
+
* Helper method to get the selected values of a select menu component by custom_id.
|
|
23
|
+
* @param customId - The custom_id of the select menu component
|
|
24
|
+
* @returns The selected values of the select menu, or undefined if not found
|
|
25
|
+
*/
|
|
26
|
+
getSelectMenuValues: (customId: string) => string[] | undefined;
|
|
21
27
|
};
|
|
22
28
|
export declare const ModalSubmitInteraction: {};
|
|
23
29
|
/**
|
|
@@ -58,7 +58,30 @@ export function createModalSubmitInteraction(interaction) {
|
|
|
58
58
|
}
|
|
59
59
|
return textInputs;
|
|
60
60
|
};
|
|
61
|
+
// Helper to extract select menu values from modal components
|
|
62
|
+
const extractSelectMenuValues = () => {
|
|
63
|
+
const selectMenuValues = new Map();
|
|
64
|
+
for (const component of interaction.data.components) {
|
|
65
|
+
// Handle action rows
|
|
66
|
+
if ("components" in component && Array.isArray(component.components)) {
|
|
67
|
+
for (const child of component.components) {
|
|
68
|
+
if ("values" in child && "custom_id" in child && Array.isArray(child.values)) {
|
|
69
|
+
selectMenuValues.set(child.custom_id, child.values);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Handle labeled components (unlikely for select menus but good for completeness if spec allows)
|
|
74
|
+
else if ("component" in component) {
|
|
75
|
+
const labeledComponent = component.component; // Using any as ModalSubmitComponent might not cover select menus fully in types yet or strictness varies
|
|
76
|
+
if ("values" in labeledComponent && "custom_id" in labeledComponent && Array.isArray(labeledComponent.values)) {
|
|
77
|
+
selectMenuValues.set(labeledComponent.custom_id, labeledComponent.values);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return selectMenuValues;
|
|
82
|
+
};
|
|
61
83
|
const textInputValues = extractTextInputs();
|
|
84
|
+
const selectMenuValues = extractSelectMenuValues();
|
|
62
85
|
const getTextInputValue = (customId) => {
|
|
63
86
|
return textInputValues.get(customId);
|
|
64
87
|
};
|
|
@@ -71,5 +94,6 @@ export function createModalSubmitInteraction(interaction) {
|
|
|
71
94
|
getResponse,
|
|
72
95
|
getTextInputValue,
|
|
73
96
|
getTextInputValues,
|
|
97
|
+
getSelectMenuValues: (customId) => selectMenuValues.get(customId),
|
|
74
98
|
});
|
|
75
99
|
}
|
package/package.json
CHANGED