Send multiples embed in case of long lyrics

This commit is contained in:
Mylloon 2023-02-11 16:19:39 +01:00
parent 8b606215ed
commit bcd49c4d09
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 49 additions and 24 deletions

View file

@ -47,7 +47,7 @@ export default {
try { try {
data = await client.player.lyrics.search(request); data = await client.player.lyrics.search(request);
} catch { } catch {
return await interaction.reply(loc.get("c_lyrics3") + ` \`${request}\``); return await interaction.reply(loc.get("c_lyrics2") + ` \`${request}\``);
} }
} else { } else {
const queue = client.player.queues.get(interaction.guildId ?? ""); const queue = client.player.queues.get(interaction.guildId ?? "");
@ -57,37 +57,63 @@ export default {
try { try {
data = await client.player.lyrics.search(title); data = await client.player.lyrics.search(title);
} catch { } catch {
return await interaction.reply(loc.get("c_lyrics3") + ` \`${title}\``); return await interaction.reply(loc.get("c_lyrics2") + ` \`${title}\``);
} }
} }
} }
} }
if (data) { if (data) {
if (data.lyrics.length > 4096 * 10) { const limit_desc = 4096;
// TODO: Pretty embed const nb_embed = Math.ceil(data.lyrics.length / limit_desc);
return await interaction.reply(loc.get("c_lyrics2") + " -> " + data.url);
}
// TODO: Take care of the desc char limit
const embeds = [];
{ // May send multiples message
const embed = new EmbedBuilder(); await interaction.deferReply();
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);
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")); return await interaction.reply(loc.get("c_lyrics1"));

View file

@ -114,8 +114,7 @@
"c_lyrics_opt1_name": "chanson", "c_lyrics_opt1_name": "chanson",
"c_lyrics_opt1_desc": "Chanson recherchée", "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_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_lyrics2": "Impossible de trouver les paroles pour",
"c_lyrics3": "Impossible de trouver les paroles pour",
"c_repeat_name": "repeat", "c_repeat_name": "repeat",
"c_repeat_desc": "Commande relative à la répétition des musiques", "c_repeat_desc": "Commande relative à la répétition des musiques",
"c_repeat_sub1_name": "stop", "c_repeat_sub1_name": "stop",