utils.selectionMessage: add support for multiple values

This commit is contained in:
Cynthia Foxwell 2022-04-24 12:42:53 -06:00
parent c48880ff4f
commit 306ad496fa

View file

@ -160,7 +160,13 @@ async function hastebin(body) {
} }
hf.selectionMessages = hf.selectionMessages || new Eris.Collection(); hf.selectionMessages = hf.selectionMessages || new Eris.Collection();
async function selectionMessage(msg, heading, options, timeout = 30000) { async function selectionMessage(
msg,
heading,
options,
timeout = 30000,
maxItems = 1
) {
const data = { const data = {
content: heading, content: heading,
allowedMentions: { allowedMentions: {
@ -177,6 +183,7 @@ async function selectionMessage(msg, heading, options, timeout = 30000) {
type: 3, type: 3,
custom_id: msg.id, custom_id: msg.id,
options: [], options: [],
max_values: maxItems,
}, },
], ],
}, },
@ -193,15 +200,15 @@ async function selectionMessage(msg, heading, options, timeout = 30000) {
}, },
], ],
}; };
options.slice(0, 20).forEach((value) => { options.slice(0, 25).forEach((value) => {
data.components[0].components[0].options.push({ data.components[0].components[0].options.push({
label: value.display, label: value.display,
value: value.key, value: value.key,
description: value.description, description: value.description,
}); });
}); });
if (options.length > 20) { if (options.length > 25) {
data.content += `\n\nDisplaying 20/${options.length} results`; data.content += `\n\nDisplaying 25/${options.length} results`;
} }
const displayMessage = await msg.channel.createMessage(data); const displayMessage = await msg.channel.createMessage(data);
@ -235,9 +242,17 @@ async function selectionMessage(msg, heading, options, timeout = 30000) {
displayMessage.delete(); displayMessage.delete();
const result = options.filter( let result;
(opt) => opt.key == interaction.data.values[0]
)[0].value; if (maxItems > 1) {
result = options
.filter((opt) => interaction.data.values.includes(opt.key))
.map((opt) => opt.value);
} else {
result = options.filter(
(opt) => opt.key == interaction.data.values[0]
)[0].value;
}
resolve(result); resolve(result);
} }