Add support of synced lyrics

This commit is contained in:
Mylloon 2024-08-12 17:51:20 +02:00
parent 9d4da0db49
commit 2f8cb0f797
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 54 additions and 12 deletions

View file

@ -56,6 +56,15 @@ export default {
.setDescriptionLocalizations(getLocalizations(client, `c_${filename}_opt1_desc`)), .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_opt1_desc`)),
), ),
) )
// Synced
.addSubcommand((subcommand) =>
subcommand
.setName(loc_default.get(`c_${filename}_sub3_name`)?.toLowerCase() ?? "")
.setDescription(loc_default.get(`c_${filename}_sub3_desc`) ?? "")
.setNameLocalizations(getLocalizations(client, `c_${filename}_sub3_name`, true))
.setDescriptionLocalizations(getLocalizations(client, `c_${filename}_sub3_desc`)),
)
); );
}, },
@ -73,6 +82,7 @@ export default {
await interaction.deferReply(); await interaction.deferReply();
const player = useMainPlayer() as Player; const player = useMainPlayer() as Player;
const queue = useQueue(interaction.guildId ?? "");
if (request) { if (request) {
if ( if (
interaction.options.getSubcommand() == interaction.options.getSubcommand() ==
@ -88,22 +98,50 @@ export default {
} catch { } catch {
return await interaction.followUp(`❌ | ${loc.get("c_lyrics2")} \`${request}\``); return await interaction.followUp(`❌ | ${loc.get("c_lyrics2")} \`${request}\``);
} }
} else { } else if (queue) {
const queue = useQueue(interaction.guildId ?? ""); const track = queue.history.currentTrack;
if (queue) { if (track) {
const track = queue.history.currentTrack; try {
if (track) { data = await player.lyrics.search({
try { q: track.cleanTitle + " " + queue.history.currentTrack?.author,
data = await player.lyrics.search({ });
q: track.cleanTitle + " " + queue.history.currentTrack?.author, } catch {
}); return await interaction.followUp(`❌ | ${loc.get("c_lyrics2")} \`${track.title}\``);
} catch {
return await interaction.followUp(`❌ | ${loc.get("c_lyrics2")} \`${track.title}\``);
}
} }
} }
} }
if (
interaction.options.getSubcommand() ==
loc_default?.get(`c_${filename}_sub3_name`)?.toLowerCase() ??
""
) {
if (queue === null) {
return await interaction.followUp(`❌ | ${loc.get("c_lyrics1")}`);
}
if (data === null || !data[0].syncedLyrics) {
return await interaction.followUp(`❌ | ${loc.get("c_lyrics3")} \`${request}\``);
}
// Load lyrics
const syncedLyrics = queue?.syncedLyrics(data[0]);
syncedLyrics?.onChange(async (lyrics) => {
await interaction.channel?.send({
content: `[${data[0].trackName}]: ${lyrics}`,
});
});
// Live update
syncedLyrics.subscribe();
return await interaction.followUp({
content: `🎤 | ${loc.get("c_lyrics4")}`,
ephemeral: true,
});
}
if (data && data.length > 0) { if (data && data.length > 0) {
const title = data[0]; const title = data[0];
const limit_desc = 4096; const limit_desc = 4096;

View file

@ -141,10 +141,14 @@
"c_lyrics_sub1_desc": "Recherche de paroles", "c_lyrics_sub1_desc": "Recherche de paroles",
"c_lyrics_sub2_name": "romanized", "c_lyrics_sub2_name": "romanized",
"c_lyrics_sub2_desc": "Recherche de paroles romanisée (ex: hangul -> latin)", "c_lyrics_sub2_desc": "Recherche de paroles romanisée (ex: hangul -> latin)",
"c_lyrics_sub3_name": "synced",
"c_lyrics_sub3_desc": "Recherche de paroles synchronisée (se met à jour avec la chanson en direct)",
"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": "Impossible de trouver les paroles pour", "c_lyrics2": "Impossible de trouver les paroles pour",
"c_lyrics3": "Impossible de trouver les paroles synchronisées pour",
"c_lyrics4": "C'est parti !",
"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",