feat: Better message in music category #74
5 changed files with 38 additions and 10 deletions
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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<string, string>) => {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue