chore: merge branch dev
to main
#200
1 changed files with 21 additions and 17 deletions
|
@ -193,6 +193,9 @@ export default {
|
|||
const query = interaction.options.getString(loc_default!.get(`c_${filename}_opt1_name`)!, true);
|
||||
|
||||
const limit_value_discord = 100;
|
||||
const limit_element_discord = 25;
|
||||
|
||||
const query_discord = query.slice(0, limit_value_discord);
|
||||
|
||||
if (query) {
|
||||
/* Since Discord wanna receive a response within 3 secs and results is async
|
||||
|
@ -208,7 +211,7 @@ export default {
|
|||
|
||||
/* Create a race between a timeout and the search
|
||||
* At the end, Discord will always receive a response */
|
||||
let tracks = await Promise.race([
|
||||
const tracks = await Promise.race([
|
||||
delay,
|
||||
player.search(query, {
|
||||
requestedBy: interaction.user,
|
||||
|
@ -225,17 +228,12 @@ export default {
|
|||
|
||||
// If tracks found
|
||||
if (tracks.length > 0) {
|
||||
if (tracks.length > 25) {
|
||||
tracks = tracks
|
||||
const payload = tracks
|
||||
// Assure that URL is under the limit of Discord
|
||||
.filter((v) => v.url.length < limit_value_discord)
|
||||
// Slice the list if needed to the 25 first results
|
||||
.slice(0, 25);
|
||||
}
|
||||
|
||||
// Returns a list of songs with their title and author
|
||||
return interaction.respond(
|
||||
tracks.map((t) => {
|
||||
// Slice the list to respect the limit of Discord
|
||||
.slice(0, limit_element_discord - 1)
|
||||
.map((t) => {
|
||||
let title = t.title;
|
||||
let author = t.author;
|
||||
let name = `${title} • ${author}`;
|
||||
|
@ -257,12 +255,18 @@ export default {
|
|||
name,
|
||||
value: t.url,
|
||||
};
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
payload.unshift({
|
||||
name: query_discord,
|
||||
value: query_discord,
|
||||
});
|
||||
|
||||
// Returns a list of songs with their title and author
|
||||
return interaction.respond(payload);
|
||||
}
|
||||
}
|
||||
return interaction.respond([
|
||||
{ name: loc.get("c_play9"), value: query.slice(0, limit_value_discord) },
|
||||
]);
|
||||
|
||||
return interaction.respond([{ name: loc.get("c_play9"), value: query_discord }]);
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue