Send multiples embed in case of long lyrics
This commit is contained in:
parent
8b606215ed
commit
bcd49c4d09
2 changed files with 49 additions and 24 deletions
|
@ -47,7 +47,7 @@ export default {
|
|||
try {
|
||||
data = await client.player.lyrics.search(request);
|
||||
} catch {
|
||||
return await interaction.reply(loc.get("c_lyrics3") + ` \`${request}\``);
|
||||
return await interaction.reply(loc.get("c_lyrics2") + ` \`${request}\``);
|
||||
}
|
||||
} else {
|
||||
const queue = client.player.queues.get(interaction.guildId ?? "");
|
||||
|
@ -57,37 +57,63 @@ export default {
|
|||
try {
|
||||
data = await client.player.lyrics.search(title);
|
||||
} catch {
|
||||
return await interaction.reply(loc.get("c_lyrics3") + ` \`${title}\``);
|
||||
return await interaction.reply(loc.get("c_lyrics2") + ` \`${title}\``);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data) {
|
||||
if (data.lyrics.length > 4096 * 10) {
|
||||
// TODO: Pretty embed
|
||||
return await interaction.reply(loc.get("c_lyrics2") + " -> " + data.url);
|
||||
}
|
||||
// TODO: Take care of the desc char limit
|
||||
const embeds = [];
|
||||
const limit_desc = 4096;
|
||||
const nb_embed = Math.ceil(data.lyrics.length / limit_desc);
|
||||
|
||||
{
|
||||
const embed = new EmbedBuilder();
|
||||
embed
|
||||
.setTitle(data.title)
|
||||
.setURL(data.url)
|
||||
.setAuthor({
|
||||
name: data?.artist.name ?? "\u200b",
|
||||
iconURL: data?.artist.image,
|
||||
url: data?.artist.url,
|
||||
})
|
||||
.setDescription(data.lyrics)
|
||||
.setThumbnail(data.thumbnail);
|
||||
// May send multiples message
|
||||
await interaction.deferReply();
|
||||
|
||||
embeds.push(embed);
|
||||
// TODO: If lyrics < 6000, only send one message with multiples embed
|
||||
for (let i = 0, j = 0; i < nb_embed; i++, j += limit_desc) {
|
||||
// TODO: Better cut in lyrics
|
||||
const lyrics = data.lyrics.slice(j, j + limit_desc);
|
||||
|
||||
let embed;
|
||||
switch (i) {
|
||||
case 0: {
|
||||
// First embed
|
||||
embed = new EmbedBuilder();
|
||||
embed
|
||||
.setTitle(data.title)
|
||||
.setURL(data.url)
|
||||
.setAuthor({
|
||||
name: data?.artist.name,
|
||||
iconURL: data?.artist.image,
|
||||
url: data?.artist.url,
|
||||
})
|
||||
.setDescription(lyrics)
|
||||
.setThumbnail(data.thumbnail);
|
||||
break;
|
||||
}
|
||||
|
||||
case nb_embed - 1: {
|
||||
// Footer of last embed in case of multiple embed
|
||||
embed = new EmbedBuilder().setDescription(lyrics).setFooter({
|
||||
text: `${data?.artist.name} · ${data.title}`,
|
||||
iconURL: data?.artist.image,
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
// Embed with only lyrics in case of multiple embed
|
||||
embed = new EmbedBuilder().setDescription(lyrics);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Send embed
|
||||
await interaction.followUp({ embeds: [embed] });
|
||||
}
|
||||
|
||||
return await interaction.reply({ embeds });
|
||||
return;
|
||||
}
|
||||
|
||||
return await interaction.reply(loc.get("c_lyrics1"));
|
||||
|
|
|
@ -114,8 +114,7 @@
|
|||
"c_lyrics_opt1_name": "chanson",
|
||||
"c_lyrics_opt1_desc": "Chanson recherchée",
|
||||
"c_lyrics1": "Le bot ne joue rien en ce moment et aucune chanson n'est renseignée.",
|
||||
"c_lyrics2": "Paroles trop longues pour être affichées.",
|
||||
"c_lyrics3": "Impossible de trouver les paroles pour",
|
||||
"c_lyrics2": "Impossible de trouver les paroles pour",
|
||||
"c_repeat_name": "repeat",
|
||||
"c_repeat_desc": "Commande relative à la répétition des musiques",
|
||||
"c_repeat_sub1_name": "stop",
|
||||
|
|
Loading…
Reference in a new issue