@minesa-org/mini-interaction 0.3.4 → 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.
|
@@ -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