Resolve crash when data.name exceed the length limit (#104)
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
Reviewed-on: #104 Co-authored-by: Mylloon <kennel.anri@tutanota.com> Co-committed-by: Mylloon <kennel.anri@tutanota.com>
This commit is contained in:
parent
d039c064b7
commit
7595273822
1 changed files with 23 additions and 4 deletions
|
@ -196,10 +196,29 @@ export default {
|
||||||
|
|
||||||
// Returns a list of songs with their title and author
|
// Returns a list of songs with their title and author
|
||||||
return interaction.respond(
|
return interaction.respond(
|
||||||
tracks.map((t) => ({
|
tracks.map((t) => {
|
||||||
name: `${t.title} • ${t.author}`,
|
let title = t.title;
|
||||||
|
let author = t.author;
|
||||||
|
let name = `${title} • ${author}`;
|
||||||
|
|
||||||
|
// Slice returned data if needed to not exceed the length limit (100)
|
||||||
|
if (name.length > 100) {
|
||||||
|
const newTitle = title.substring(0, 40);
|
||||||
|
if (title.length != newTitle.length) {
|
||||||
|
title = `${newTitle}...`;
|
||||||
|
}
|
||||||
|
const newAuthor = author.substring(0, 40);
|
||||||
|
if (author.length != newAuthor.length) {
|
||||||
|
author = `${newAuthor}...`;
|
||||||
|
}
|
||||||
|
name = `${newTitle} • ${newAuthor}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
name,
|
||||||
value: t.url,
|
value: t.url,
|
||||||
}))
|
};
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue