utils.selectionMessage: add support for multiple values
This commit is contained in:
parent
c48880ff4f
commit
306ad496fa
1 changed files with 22 additions and 7 deletions
|
@ -160,7 +160,13 @@ async function hastebin(body) {
|
|||
}
|
||||
|
||||
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 = {
|
||||
content: heading,
|
||||
allowedMentions: {
|
||||
|
@ -177,6 +183,7 @@ async function selectionMessage(msg, heading, options, timeout = 30000) {
|
|||
type: 3,
|
||||
custom_id: msg.id,
|
||||
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({
|
||||
label: value.display,
|
||||
value: value.key,
|
||||
description: value.description,
|
||||
});
|
||||
});
|
||||
if (options.length > 20) {
|
||||
data.content += `\n\nDisplaying 20/${options.length} results`;
|
||||
if (options.length > 25) {
|
||||
data.content += `\n\nDisplaying 25/${options.length} results`;
|
||||
}
|
||||
|
||||
const displayMessage = await msg.channel.createMessage(data);
|
||||
|
@ -235,9 +242,17 @@ async function selectionMessage(msg, heading, options, timeout = 30000) {
|
|||
|
||||
displayMessage.delete();
|
||||
|
||||
const result = options.filter(
|
||||
(opt) => opt.key == interaction.data.values[0]
|
||||
)[0].value;
|
||||
let result;
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue