feat: Music support #62

Merged
Anri merged 43 commits from feat/music into main 2023-02-12 01:11:10 +01:00
2 changed files with 49 additions and 24 deletions
Showing only changes of commit bcd49c4d09 - Show all commits

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();
// 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 embed
.setTitle(data.title) .setTitle(data.title)
.setURL(data.url) .setURL(data.url)
.setAuthor({ .setAuthor({
name: data?.artist.name ?? "\u200b", name: data?.artist.name,
iconURL: data?.artist.image, iconURL: data?.artist.image,
url: data?.artist.url, url: data?.artist.url,
}) })
.setDescription(data.lyrics) .setDescription(lyrics)
.setThumbnail(data.thumbnail); .setThumbnail(data.thumbnail);
break;
embeds.push(embed);
} }
return await interaction.reply({ embeds }); 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;
} }
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",