diff --git a/src/commands/music/lyrics.ts b/src/commands/music/lyrics.ts index a3f2202..d420d85 100644 --- a/src/commands/music/lyrics.ts +++ b/src/commands/music/lyrics.ts @@ -58,7 +58,7 @@ export default { ), ) - // Synced + // Synced start .addSubcommand((subcommand) => subcommand .setName(loc_default.get(`c_${filename}_sub3_name`)!.toLowerCase()) @@ -66,6 +66,15 @@ export default { .setNameLocalizations(getLocalizations(client, `c_${filename}_sub3_name`, true)) .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_sub3_desc`)), ) + + // Synced stop + .addSubcommand((subcommand) => + subcommand + .setName(loc_default.get(`c_${filename}_sub4_name`)!.toLowerCase()) + .setDescription(loc_default.get(`c_${filename}_sub4_desc`)!) + .setNameLocalizations(getLocalizations(client, `c_${filename}_sub4_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_sub4_desc`)), + ) ); }, @@ -124,9 +133,14 @@ export default { } // Load lyrics - const syncedLyrics = queue.syncedLyrics(data[0]); + if (queue.syncedLyricsMemory !== undefined) { + return await interaction.followUp(loc.get("c_lyrics9")); + } - let message: Message; + const syncedLyrics = queue.syncedLyrics(data[0]); + queue.syncedLyricsMemory = syncedLyrics; + + let message: Message; syncedLyrics?.onChange(async (lyrics) => { if (interaction.channel?.isSendable()) { if (message) { @@ -149,12 +163,39 @@ export default { // Live update syncedLyrics.subscribe(); + syncedLyrics.onUnsubscribe(() => { + queue.syncedLyricsMemory = undefined; + }); + return await interaction.followUp({ content: `đŸŽ€ | ${loc.get("c_lyrics4")}`, ephemeral: true, }); } + if ( + interaction.options.getSubcommand() === + loc_default?.get(`c_${filename}_sub4_name`)?.toLowerCase() + ) { + if (queue === null) { + return await interaction.followUp(`❌ | ${loc.get("c_lyrics1")}`); + } + + if (data === null || !data[0] || !data[0].syncedLyrics) { + return await interaction.followUp( + `❌ | ${loc.get("c_lyrics3")} \`${queue.currentTrack?.cleanTitle}\``, + ); + } + + // Load lyrics + if (queue.syncedLyricsMemory !== undefined && queue.syncedLyricsMemory.isSubscribed()) { + queue.syncedLyricsMemory.unsubscribe(); + return await interaction.followUp(loc.get("c_lyrics7")); + } + + return await interaction.followUp(loc.get("c_lyrics8")); + } + if (data && data.length > 0 && data[0].plainLyrics !== null) { const title = data[0]; const limit_desc = 4096; diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 192f7fb..a45ce2b 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -148,6 +148,8 @@ "c_lyrics_sub2_desc": "Search for romanized lyrics (e.g., hangul → Latin)", "c_lyrics_sub3_name": "synced", "c_lyrics_sub3_desc": "Synchronized lyrics search (updates in live)", + "c_lyrics_sub4_name": "stop-synced", + "c_lyrics_sub4_desc": "Stop Synchronized lyrics", "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.", @@ -156,6 +158,9 @@ "c_lyrics4": "It's karaoke time!", "c_lyrics5": "Unable to post the lyrics here.", "c_lyrics6": "More of :", + "c_lyrics7": "Stop synchronized lyrics.", + "c_lyrics8": "No synchronized lyrics currently posted.", + "c_lyrics9": "Synchronized lyrics currently posted.", "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 9780ec7..00316b0 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -148,6 +148,8 @@ "c_lyrics_sub2_desc": "Recherche de paroles romanisĂ©es (ex: hangul → latin)", "c_lyrics_sub3_name": "synced", "c_lyrics_sub3_desc": "Recherche de paroles synchronisĂ©es (se mettent Ă  jour avec la chanson en direct)", + "c_lyrics_sub4_name": "stop-synced", + "c_lyrics_sub4_desc": "ArrĂȘte les paroles synchronisĂ©es", "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.", @@ -156,6 +158,9 @@ "c_lyrics4": "C'est parti !", "c_lyrics5": "Impossible de poster les paroles ici.", "c_lyrics6": "Suite de :", + "c_lyrics7": "ArrĂȘt des paroles synchronisĂ©es.", + "c_lyrics8": "Pas de paroles synchronisĂ©es en cours.", + "c_lyrics9": "Paroles synchronisĂ©es dĂ©jĂ  en cours.", "c_repeat_name": "repeat", "c_repeat_desc": "Commande relative Ă  la rĂ©pĂ©tition des musiques", diff --git a/src/modules/player.ts b/src/modules/player.ts new file mode 100644 index 0000000..1fc72ac --- /dev/null +++ b/src/modules/player.ts @@ -0,0 +1,12 @@ +export {}; + +declare module "discord-player" { + export interface GuildQueue { + syncedLyricsMemory: + | { + isSubscribed: () => unknown; + unsubscribe: () => unknown; + } + | undefined; + } +}