Add ability to stop sync lyrics (fix #196)
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 30s

This commit is contained in:
Mylloon 2024-11-01 14:05:41 +01:00
parent 2fc39560f0
commit 1b11a3728f
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 66 additions and 3 deletions

View file

@ -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<boolean>;
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;

View file

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

View file

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

12
src/modules/player.ts Normal file
View file

@ -0,0 +1,12 @@
export {};
declare module "discord-player" {
export interface GuildQueue {
syncedLyricsMemory:
| {
isSubscribed: () => unknown;
unsubscribe: () => unknown;
}
| undefined;
}
}