@minesa-org/mini-interaction 0.3.10 → 0.3.13
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.
- package/dist/builders/ModalBuilder.js +2 -1
- package/dist/builders/ModalChannelSelectMenuBuilder.d.ts +10 -1
- package/dist/builders/ModalChannelSelectMenuBuilder.js +17 -0
- package/dist/utils/MessageComponentInteraction.d.ts +9 -1
- package/dist/utils/MessageComponentInteraction.js +17 -0
- package/dist/utils/ModalSubmitInteraction.d.ts +21 -4
- package/dist/utils/ModalSubmitInteraction.js +57 -0
- package/package.json +1 -1
|
@@ -74,7 +74,8 @@ export class ModalBuilder {
|
|
|
74
74
|
componentType === ComponentType.RoleSelect ||
|
|
75
75
|
componentType === ComponentType.MentionableSelect ||
|
|
76
76
|
componentType === ComponentType.ChannelSelect ||
|
|
77
|
-
componentType === ComponentType.FileUpload
|
|
77
|
+
componentType === ComponentType.FileUpload ||
|
|
78
|
+
componentType === ComponentType.Label) {
|
|
78
79
|
return {
|
|
79
80
|
type: ComponentType.ActionRow,
|
|
80
81
|
components: [resolved],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SelectMenuDefaultValueType, type APIChannelSelectComponent, type APISelectMenuDefaultValue } from "discord-api-types/v10";
|
|
1
|
+
import { SelectMenuDefaultValueType, type APIChannelSelectComponent, type APISelectMenuDefaultValue, ChannelType } from "discord-api-types/v10";
|
|
2
2
|
import type { JSONEncodable } from "./shared.js";
|
|
3
3
|
/** Shape describing initial modal channel select menu data accepted by the builder. */
|
|
4
4
|
export type ModalChannelSelectMenuBuilderData = {
|
|
@@ -8,6 +8,7 @@ export type ModalChannelSelectMenuBuilderData = {
|
|
|
8
8
|
maxValues?: number;
|
|
9
9
|
disabled?: boolean;
|
|
10
10
|
required?: boolean;
|
|
11
|
+
channelTypes?: ChannelType[];
|
|
11
12
|
defaultValues?: APISelectMenuDefaultValue<SelectMenuDefaultValueType.Channel>[];
|
|
12
13
|
};
|
|
13
14
|
/** Builder for Discord channel select menu components in modals. */
|
|
@@ -45,6 +46,14 @@ export declare class ModalChannelSelectMenuBuilder implements JSONEncodable<APIC
|
|
|
45
46
|
* Replaces the default channel selections displayed when the menu renders.
|
|
46
47
|
*/
|
|
47
48
|
setDefaultValues(defaultValues: Iterable<APISelectMenuDefaultValue<SelectMenuDefaultValueType.Channel>>): this;
|
|
49
|
+
/**
|
|
50
|
+
* Sets the channel types allowed in the select menu.
|
|
51
|
+
*/
|
|
52
|
+
setChannelTypes(...channelTypes: ChannelType[]): this;
|
|
53
|
+
/**
|
|
54
|
+
* Adds channel types allowed in the select menu.
|
|
55
|
+
*/
|
|
56
|
+
addChannelTypes(...channelTypes: ChannelType[]): this;
|
|
48
57
|
/**
|
|
49
58
|
* Serialises the builder into an API compatible channel select menu payload.
|
|
50
59
|
*/
|
|
@@ -13,6 +13,7 @@ export class ModalChannelSelectMenuBuilder {
|
|
|
13
13
|
maxValues: data.maxValues,
|
|
14
14
|
disabled: data.disabled,
|
|
15
15
|
required: data.required,
|
|
16
|
+
channelTypes: data.channelTypes,
|
|
16
17
|
defaultValues: data.defaultValues
|
|
17
18
|
? data.defaultValues.map((value) => ({
|
|
18
19
|
...value,
|
|
@@ -73,6 +74,21 @@ export class ModalChannelSelectMenuBuilder {
|
|
|
73
74
|
}));
|
|
74
75
|
return this;
|
|
75
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Sets the channel types allowed in the select menu.
|
|
79
|
+
*/
|
|
80
|
+
setChannelTypes(...channelTypes) {
|
|
81
|
+
this.data.channelTypes = channelTypes.flat();
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Adds channel types allowed in the select menu.
|
|
86
|
+
*/
|
|
87
|
+
addChannelTypes(...channelTypes) {
|
|
88
|
+
this.data.channelTypes ??= [];
|
|
89
|
+
this.data.channelTypes.push(...channelTypes.flat());
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
76
92
|
/**
|
|
77
93
|
* Serialises the builder into an API compatible channel select menu payload.
|
|
78
94
|
*/
|
|
@@ -89,6 +105,7 @@ export class ModalChannelSelectMenuBuilder {
|
|
|
89
105
|
max_values: this.data.maxValues,
|
|
90
106
|
disabled: this.data.disabled,
|
|
91
107
|
required: this.data.required,
|
|
108
|
+
channel_types: this.data.channelTypes,
|
|
92
109
|
default_values: this.data.defaultValues?.map((value) => ({
|
|
93
110
|
...value,
|
|
94
111
|
type: SelectMenuDefaultValueType.Channel,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type APIInteractionDataResolvedChannel, type APIInteractionDataResolvedGuildMember, type APIInteractionResponse, type APIInteractionResponseChannelMessageWithSource, type APIInteractionResponseDeferredChannelMessageWithSource, type APIInteractionResponseDeferredMessageUpdate, type APIInteractionResponseUpdateMessage, type APIMessageComponentInteraction, type APIMessageButtonInteractionData, type APIMessageChannelSelectInteractionData, type APIMessageMentionableSelectInteractionData, type APIMessageRoleSelectInteractionData, type APIMessageStringSelectInteractionData, type APIMessageUserSelectInteractionData, type APIModalInteractionResponse, type APIModalInteractionResponseCallbackData, type APIRole, type APIUser } from "discord-api-types/v10";
|
|
1
|
+
import { type APIInteractionDataResolvedChannel, type APIInteractionDataResolvedGuildMember, type APIInteractionResponse, type APIInteractionResponseChannelMessageWithSource, type APIInteractionResponseDeferredChannelMessageWithSource, type APIInteractionResponseDeferredMessageUpdate, type APIInteractionResponseUpdateMessage, type APIMessageComponentInteraction, type APIMessageButtonInteractionData, type APIMessageChannelSelectInteractionData, type APIMessageMentionableSelectInteractionData, type APIMessageRoleSelectInteractionData, type APIMessageStringSelectInteractionData, type APIMessageUserSelectInteractionData, type APIModalInteractionResponse, type APIModalInteractionResponseCallbackData, type APIRole, type APIUser, type APIAttachment } from "discord-api-types/v10";
|
|
2
2
|
import { DeferReplyOptions, InteractionMessageData } from "./interactionMessageHelpers.js";
|
|
3
3
|
/** Resolved user option including optional guild member data. */
|
|
4
4
|
export type ResolvedUserOption = {
|
|
@@ -183,21 +183,29 @@ export type MessageComponentInteraction = APIMessageComponentInteraction & {
|
|
|
183
183
|
* @returns Array of resolved role objects, or empty array if not a role select menu
|
|
184
184
|
*/
|
|
185
185
|
getRoles: () => APIRole[];
|
|
186
|
+
getRole: () => APIRole | undefined;
|
|
186
187
|
/**
|
|
187
188
|
* Helper method to get selected channels from a channel select menu.
|
|
188
189
|
* @returns Array of resolved channel objects, or empty array if not a channel select menu
|
|
189
190
|
*/
|
|
190
191
|
getChannels: () => APIInteractionDataResolvedChannel[];
|
|
192
|
+
getChannel: () => APIInteractionDataResolvedChannel | undefined;
|
|
191
193
|
/**
|
|
192
194
|
* Helper method to get selected users from a user select menu.
|
|
193
195
|
* @returns Array of resolved user objects (with optional member data), or empty array if not a user select menu
|
|
194
196
|
*/
|
|
195
197
|
getUsers: () => ResolvedUserOption[];
|
|
198
|
+
getUser: () => ResolvedUserOption | undefined;
|
|
196
199
|
/**
|
|
197
200
|
* Helper method to get selected mentionables from a mentionable select menu.
|
|
198
201
|
* @returns Array of resolved mentionable objects (users or roles), or empty array if not a mentionable select menu
|
|
199
202
|
*/
|
|
200
203
|
getMentionables: () => ResolvedMentionableOption[];
|
|
204
|
+
getMentionable: () => ResolvedMentionableOption | undefined;
|
|
205
|
+
/**
|
|
206
|
+
* Helper method to get an attachment value (if applicable).
|
|
207
|
+
*/
|
|
208
|
+
getAttachment: () => APIAttachment | undefined;
|
|
201
209
|
};
|
|
202
210
|
export declare const MessageComponentInteraction: {};
|
|
203
211
|
/**
|
|
@@ -160,6 +160,7 @@ export function createMessageComponentInteraction(interaction, helpers) {
|
|
|
160
160
|
}
|
|
161
161
|
return roles;
|
|
162
162
|
};
|
|
163
|
+
const getRole = () => getRoles()[0];
|
|
163
164
|
const getChannels = () => {
|
|
164
165
|
if (!values) {
|
|
165
166
|
return [];
|
|
@@ -180,6 +181,7 @@ export function createMessageComponentInteraction(interaction, helpers) {
|
|
|
180
181
|
}
|
|
181
182
|
return channels;
|
|
182
183
|
};
|
|
184
|
+
const getChannel = () => getChannels()[0];
|
|
183
185
|
const getUsers = () => {
|
|
184
186
|
if (!values) {
|
|
185
187
|
return [];
|
|
@@ -201,6 +203,7 @@ export function createMessageComponentInteraction(interaction, helpers) {
|
|
|
201
203
|
}
|
|
202
204
|
return users;
|
|
203
205
|
};
|
|
206
|
+
const getUser = () => getUsers()[0];
|
|
204
207
|
const getMentionables = () => {
|
|
205
208
|
if (!values) {
|
|
206
209
|
return [];
|
|
@@ -229,6 +232,15 @@ export function createMessageComponentInteraction(interaction, helpers) {
|
|
|
229
232
|
}
|
|
230
233
|
return mentionables;
|
|
231
234
|
};
|
|
235
|
+
const getMentionable = () => getMentionables()[0];
|
|
236
|
+
const getAttachment = () => {
|
|
237
|
+
if (!values || values.length === 0)
|
|
238
|
+
return undefined;
|
|
239
|
+
const resolved = "resolved" in interaction.data
|
|
240
|
+
? interaction.data.resolved
|
|
241
|
+
: undefined;
|
|
242
|
+
return resolved?.attachments?.[values[0]];
|
|
243
|
+
};
|
|
232
244
|
return Object.assign(interaction, {
|
|
233
245
|
reply,
|
|
234
246
|
deferReply,
|
|
@@ -240,9 +252,14 @@ export function createMessageComponentInteraction(interaction, helpers) {
|
|
|
240
252
|
values,
|
|
241
253
|
getStringValues,
|
|
242
254
|
getRoles,
|
|
255
|
+
getRole,
|
|
243
256
|
getChannels,
|
|
257
|
+
getChannel,
|
|
244
258
|
getUsers,
|
|
259
|
+
getUser,
|
|
245
260
|
getMentionables,
|
|
261
|
+
getMentionable,
|
|
262
|
+
getAttachment,
|
|
246
263
|
onAck: helpers?.onAck,
|
|
247
264
|
sendFollowUp: helpers?.sendFollowUp,
|
|
248
265
|
canRespond: helpers?.canRespond,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type APIInteractionResponse, type APIInteractionResponseChannelMessageWithSource, type APIInteractionResponseDeferredChannelMessageWithSource, type APIModalSubmitInteraction } from "discord-api-types/v10";
|
|
1
|
+
import { type APIInteractionResponse, type APIInteractionResponseChannelMessageWithSource, type APIInteractionResponseDeferredChannelMessageWithSource, type APIModalSubmitInteraction, type APIRole, type APIInteractionDataResolvedChannel, type APIAttachment } from "discord-api-types/v10";
|
|
2
2
|
import { DeferReplyOptions, InteractionMessageData } from "./interactionMessageHelpers.js";
|
|
3
|
+
import type { ResolvedUserOption } from "./MessageComponentInteraction.js";
|
|
3
4
|
/**
|
|
4
5
|
* Represents a modal submit interaction augmented with helper response methods.
|
|
5
6
|
*/
|
|
@@ -7,9 +8,6 @@ export type ModalSubmitInteraction = APIModalSubmitInteraction & {
|
|
|
7
8
|
getResponse: () => APIInteractionResponse | null;
|
|
8
9
|
reply: (data: InteractionMessageData) => Promise<APIInteractionResponseChannelMessageWithSource>;
|
|
9
10
|
deferReply: (options?: DeferReplyOptions) => APIInteractionResponseDeferredChannelMessageWithSource;
|
|
10
|
-
/**
|
|
11
|
-
* Helper method to get the value of a text input component by its custom ID.
|
|
12
|
-
*/
|
|
13
11
|
/**
|
|
14
12
|
* Helper method to get the value of a text input component by its custom ID.
|
|
15
13
|
*/
|
|
@@ -23,6 +21,25 @@ export type ModalSubmitInteraction = APIModalSubmitInteraction & {
|
|
|
23
21
|
* Returns string for text inputs, string[] for select menus, or undefined.
|
|
24
22
|
*/
|
|
25
23
|
getComponentValue: (customId: string) => string | string[] | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Helper method to get selected roles from a role select menu in the modal.
|
|
26
|
+
*/
|
|
27
|
+
getRoles: (customId: string) => APIRole[];
|
|
28
|
+
getRole: (customId: string) => APIRole | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Helper method to get selected users from a user select menu in the modal.
|
|
31
|
+
*/
|
|
32
|
+
getUsers: (customId: string) => ResolvedUserOption[];
|
|
33
|
+
getUser: (customId: string) => ResolvedUserOption | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Helper method to get selected channels from a channel select menu in the modal.
|
|
36
|
+
*/
|
|
37
|
+
getChannels: (customId: string) => APIInteractionDataResolvedChannel[];
|
|
38
|
+
getChannel: (customId: string) => APIInteractionDataResolvedChannel | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Helper method to get an attachment value (e.g. from FileUpload component).
|
|
41
|
+
*/
|
|
42
|
+
getAttachment: (customId: string) => APIAttachment | undefined;
|
|
26
43
|
/**
|
|
27
44
|
* Finalise the interaction response via a webhook follow-up.
|
|
28
45
|
* This is automatically called by reply() if the interaction is deferred.
|
|
@@ -137,6 +137,56 @@ export function createModalSubmitInteraction(interaction, helpers) {
|
|
|
137
137
|
}
|
|
138
138
|
return getSelectMenuValues(customId);
|
|
139
139
|
};
|
|
140
|
+
const getRoles = (customId) => {
|
|
141
|
+
const values = getSelectMenuValues(customId);
|
|
142
|
+
const resolved = interaction.data.resolved;
|
|
143
|
+
if (!values || !resolved?.roles)
|
|
144
|
+
return [];
|
|
145
|
+
const roles = [];
|
|
146
|
+
for (const id of values) {
|
|
147
|
+
const role = resolved.roles[id];
|
|
148
|
+
if (role)
|
|
149
|
+
roles.push(role);
|
|
150
|
+
}
|
|
151
|
+
return roles;
|
|
152
|
+
};
|
|
153
|
+
const getRole = (customId) => getRoles(customId)[0];
|
|
154
|
+
const getUsers = (customId) => {
|
|
155
|
+
const values = getSelectMenuValues(customId);
|
|
156
|
+
const resolved = interaction.data.resolved;
|
|
157
|
+
if (!values || !resolved?.users)
|
|
158
|
+
return [];
|
|
159
|
+
const users = [];
|
|
160
|
+
for (const id of values) {
|
|
161
|
+
const user = resolved.users[id];
|
|
162
|
+
if (user) {
|
|
163
|
+
const member = resolved.members?.[id];
|
|
164
|
+
users.push({ user, member });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return users;
|
|
168
|
+
};
|
|
169
|
+
const getUser = (customId) => getUsers(customId)[0];
|
|
170
|
+
const getChannels = (customId) => {
|
|
171
|
+
const values = getSelectMenuValues(customId);
|
|
172
|
+
const resolved = interaction.data.resolved;
|
|
173
|
+
if (!values || !resolved?.channels)
|
|
174
|
+
return [];
|
|
175
|
+
const channels = [];
|
|
176
|
+
for (const id of values) {
|
|
177
|
+
const channel = resolved.channels[id];
|
|
178
|
+
if (channel)
|
|
179
|
+
channels.push(channel);
|
|
180
|
+
}
|
|
181
|
+
return channels;
|
|
182
|
+
};
|
|
183
|
+
const getChannel = (customId) => getChannels(customId)[0];
|
|
184
|
+
const getAttachment = (customId) => {
|
|
185
|
+
const value = getComponentValue(customId);
|
|
186
|
+
if (!value || Array.isArray(value))
|
|
187
|
+
return undefined;
|
|
188
|
+
return interaction.data.resolved?.attachments?.[value];
|
|
189
|
+
};
|
|
140
190
|
return Object.assign(interaction, {
|
|
141
191
|
reply,
|
|
142
192
|
deferReply,
|
|
@@ -145,6 +195,13 @@ export function createModalSubmitInteraction(interaction, helpers) {
|
|
|
145
195
|
getTextFieldValue,
|
|
146
196
|
getSelectMenuValues,
|
|
147
197
|
getComponentValue,
|
|
198
|
+
getRoles,
|
|
199
|
+
getRole,
|
|
200
|
+
getUsers,
|
|
201
|
+
getUser,
|
|
202
|
+
getChannels,
|
|
203
|
+
getChannel,
|
|
204
|
+
getAttachment,
|
|
148
205
|
sendFollowUp: helpers?.sendFollowUp,
|
|
149
206
|
canRespond: helpers?.canRespond,
|
|
150
207
|
trackResponse: helpers?.trackResponse,
|
package/package.json
CHANGED