diff --git a/src/commands/music/lyrics.ts b/src/commands/music/lyrics.ts index c89c64c..639ee59 100644 --- a/src/commands/music/lyrics.ts +++ b/src/commands/music/lyrics.ts @@ -56,6 +56,15 @@ export default { .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(); const player = useMainPlayer() as Player; + const queue = useQueue(interaction.guildId ?? ""); if (request) { if ( interaction.options.getSubcommand() == @@ -88,22 +98,50 @@ export default { } catch { return await interaction.followUp(`❌ | ${loc.get("c_lyrics2")} \`${request}\``); } - } else { - const queue = useQueue(interaction.guildId ?? ""); - if (queue) { - const track = queue.history.currentTrack; - if (track) { - try { - data = await player.lyrics.search({ - q: track.cleanTitle + " " + queue.history.currentTrack?.author, - }); - } catch { - return await interaction.followUp(`❌ | ${loc.get("c_lyrics2")} \`${track.title}\``); - } + } else if (queue) { + const track = queue.history.currentTrack; + if (track) { + try { + data = await player.lyrics.search({ + q: track.cleanTitle + " " + queue.history.currentTrack?.author, + }); + } 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) { const title = data[0]; const limit_desc = 4096; diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 1a1a03c..69a1a9b 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -134,10 +134,14 @@ "c_lyrics_name": "lyrics", "c_lyrics_desc": "Displays the lyrics of a song", + "c_lyrics_sub3_name": "synced", + "c_lyrics_sub3_desc": "Synchronized lyrics search (updates in live)", "c_lyrics_opt1_name": "song", "c_lyrics_opt1_desc": "Wanted song", "c_lyrics1": "The bot is not playing anything at the moment and no songs are specified.", "c_lyrics2": "Unable to find the lyrics for", + "c_lyrics3": "Impossible to find synchronized lyrics for", + "c_lyrics4": "It's karaoke time!", "c_repeat_name": "repeat", "c_repeat_desc": "Command for the type of music repetition", diff --git a/src/locales/fr.json b/src/locales/fr.json index a466e6f..f17ecf8 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -141,10 +141,14 @@ "c_lyrics_sub1_desc": "Recherche de paroles", "c_lyrics_sub2_name": "romanized", "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_desc": "Chanson recherché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_lyrics3": "Impossible de trouver les paroles synchronisées pour", + "c_lyrics4": "C'est parti !", "c_repeat_name": "repeat", "c_repeat_desc": "Commande relative à la répétition des musiques",