diff --git a/src/buttons/music/queueList-next.ts b/src/buttons/music/queueList-next.ts index 7786e51..2b743db 100644 --- a/src/buttons/music/queueList-next.ts +++ b/src/buttons/music/queueList-next.ts @@ -36,7 +36,7 @@ export default { const rows = []; if (queue) { // Create the embed - embedListQueue(client, embed, queue.tracks, page, interaction.locale); + embedListQueue(client, embed, queue, page, interaction.locale); // Create buttons const idPrec = "queueList-prec_" + uuidv4(); diff --git a/src/buttons/music/queueList-prec.ts b/src/buttons/music/queueList-prec.ts index b13c456..5ca54b8 100644 --- a/src/buttons/music/queueList-prec.ts +++ b/src/buttons/music/queueList-prec.ts @@ -36,7 +36,7 @@ export default { const rows = []; if (queue) { // Create the embed - embedListQueue(client, embed, queue.tracks, page, interaction.locale); + embedListQueue(client, embed, queue, page, interaction.locale); // Create buttons const idPrec = "queueList-prec_" + uuidv4(); diff --git a/src/commands/music/queue.ts b/src/commands/music/queue.ts index e5c8a86..22db84e 100644 --- a/src/commands/music/queue.ts +++ b/src/commands/music/queue.ts @@ -107,7 +107,7 @@ export default { loc_default?.get(`c_${filename}_sub1_opt1_name`) as string ) ?? 1; - embedListQueue(client, embed, queue.tracks, page, interaction.locale); + embedListQueue(client, embed, queue, page, interaction.locale); const idPrec = "queueList-prec_" + uuidv4(); const idNext = "queueList-next_" + uuidv4(); diff --git a/src/locales/fr.json b/src/locales/fr.json index 70e3168..8e580dc 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -122,6 +122,8 @@ "c_queue8": "Précédent", "c_queue9": "Suivant", "c_queue10": "Désolé, une erreur est survenue.", + "c_queue11": "Actuellement", + "c_queue12": "À suivre", "c_skip_name": "skip", "c_skip_desc": "Passe la chanson en cours", diff --git a/src/utils/music.ts b/src/utils/music.ts index 1d5426d..f29b5d6 100644 --- a/src/utils/music.ts +++ b/src/utils/music.ts @@ -1,16 +1,20 @@ import { EmbedBuilder } from "@discordjs/builders"; -import { Track } from "discord-player"; +import { Queue, QueueRepeatMode, Track } from "discord-player"; import { Client } from "discord.js"; import { getLocale } from "./locales"; export const embedListQueue = ( client: Client, embed: EmbedBuilder, - tracks: Track[], + queue: Queue, page: number, local: string ) => { const loc = getLocale(client, local); + const tracks = queue.tracks.slice(); + + // Add the current song at the top of the list + tracks.unshift(queue.current as Track); // Limit of discord is 25 const limit_fields = 25; @@ -18,11 +22,33 @@ export const embedListQueue = ( const pageMax = Math.ceil(tracks.length / limit_fields); embed.setAuthor({ name: `${loc.get("c_queue1")} • ${loc.get("c_queue7")} ${page}/${pageMax}` }); + embed.setFooter({ text: `${printRepeatMode(queue.repeatMode, loc)}` }); - tracks.slice((page - 1) * limit_fields, page * limit_fields).forEach((t, idx) => + tracks.slice((page - 1) * limit_fields, page * limit_fields).forEach((t, idx) => { + const name = idx == 0 ? loc.get("c_queue11") : idx == 1 ? loc.get("c_queue12") : "\u200b"; + const idx_track = idx == 0 ? "" : `${idx * page}. `; embed.addFields({ - name: "\u200b", - value: `${(idx + 1) * page}. [${t.title}](${t.url}) (${t.duration})`, - }) - ); + name, + value: `${idx_track}[${t.title}](${t.url}) (${t.duration})`, + }); + }); +}; + +const printRepeatMode = (mode: QueueRepeatMode, loc: Map) => { + switch (mode) { + case QueueRepeatMode.OFF: + return loc.get("c_repeat2"); + + case QueueRepeatMode.QUEUE: + return loc.get("c_repeat3") + " " + loc.get("c_repeat6"); + + case QueueRepeatMode.AUTOPLAY: + return loc.get("c_repeat4") + " " + loc.get("c_repeat6"); + + case QueueRepeatMode.TRACK: + return loc.get("c_repeat5") + " " + loc.get("c_repeat6"); + + default: + break; + } };