feat: synced lyrics (#142)
All checks were successful
Publish latest version / build (push) Successful in 2m10s

Close #134

Implement synced lyrics

Reviewed-on: #142
Co-authored-by: Mylloon <kennel.anri@tutanota.com>
Co-committed-by: Mylloon <kennel.anri@tutanota.com>
This commit is contained in:
Mylloon 2024-08-12 17:54:36 +02:00 committed by Mylloon
parent 9d4da0db49
commit 3e43eddc8e
Signed by: Forgejo
GPG key ID: E72245C752A07631
3 changed files with 58 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,9 +98,7 @@ 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 ?? "");
if (queue) {
const track = queue.history.currentTrack; const track = queue.history.currentTrack;
if (track) { if (track) {
try { try {
@ -102,6 +110,36 @@ export default {
} }
} }
} }
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) {

View file

@ -134,10 +134,14 @@
"c_lyrics_name": "lyrics", "c_lyrics_name": "lyrics",
"c_lyrics_desc": "Displays the lyrics of a song", "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_name": "song",
"c_lyrics_opt1_desc": "Wanted song", "c_lyrics_opt1_desc": "Wanted song",
"c_lyrics1": "The bot is not playing anything at the moment and no songs are specified.", "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_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_name": "repeat",
"c_repeat_desc": "Command for the type of music repetition", "c_repeat_desc": "Command for the type of music repetition",

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",