feat: Better message in music category #74

Merged
Anri merged 11 commits from prettify-music into main 2023-02-17 23:06:19 +01:00
5 changed files with 38 additions and 10 deletions
Showing only changes of commit 84df0d2395 - Show all commits

View file

@ -36,7 +36,7 @@ export default {
const rows = []; const rows = [];
if (queue) { if (queue) {
// Create the embed // Create the embed
embedListQueue(client, embed, queue.tracks, page, interaction.locale); embedListQueue(client, embed, queue, page, interaction.locale);
// Create buttons // Create buttons
const idPrec = "queueList-prec_" + uuidv4(); const idPrec = "queueList-prec_" + uuidv4();

View file

@ -36,7 +36,7 @@ export default {
const rows = []; const rows = [];
if (queue) { if (queue) {
// Create the embed // Create the embed
embedListQueue(client, embed, queue.tracks, page, interaction.locale); embedListQueue(client, embed, queue, page, interaction.locale);
// Create buttons // Create buttons
const idPrec = "queueList-prec_" + uuidv4(); const idPrec = "queueList-prec_" + uuidv4();

View file

@ -107,7 +107,7 @@ export default {
loc_default?.get(`c_${filename}_sub1_opt1_name`) as string loc_default?.get(`c_${filename}_sub1_opt1_name`) as string
) ?? 1; ) ?? 1;
embedListQueue(client, embed, queue.tracks, page, interaction.locale); embedListQueue(client, embed, queue, page, interaction.locale);
const idPrec = "queueList-prec_" + uuidv4(); const idPrec = "queueList-prec_" + uuidv4();
const idNext = "queueList-next_" + uuidv4(); const idNext = "queueList-next_" + uuidv4();

View file

@ -122,6 +122,8 @@
"c_queue8": "Précédent", "c_queue8": "Précédent",
"c_queue9": "Suivant", "c_queue9": "Suivant",
"c_queue10": "Désolé, une erreur est survenue.", "c_queue10": "Désolé, une erreur est survenue.",
"c_queue11": "Actuellement",
"c_queue12": "À suivre",
"c_skip_name": "skip", "c_skip_name": "skip",
"c_skip_desc": "Passe la chanson en cours", "c_skip_desc": "Passe la chanson en cours",

View file

@ -1,16 +1,20 @@
import { EmbedBuilder } from "@discordjs/builders"; import { EmbedBuilder } from "@discordjs/builders";
import { Track } from "discord-player"; import { Queue, QueueRepeatMode, Track } from "discord-player";
import { Client } from "discord.js"; import { Client } from "discord.js";
import { getLocale } from "./locales"; import { getLocale } from "./locales";
export const embedListQueue = ( export const embedListQueue = (
client: Client, client: Client,
embed: EmbedBuilder, embed: EmbedBuilder,
tracks: Track[], queue: Queue,
page: number, page: number,
local: string local: string
) => { ) => {
const loc = getLocale(client, local); 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 // Limit of discord is 25
const limit_fields = 25; const limit_fields = 25;
@ -18,11 +22,33 @@ export const embedListQueue = (
const pageMax = Math.ceil(tracks.length / limit_fields); const pageMax = Math.ceil(tracks.length / limit_fields);
embed.setAuthor({ name: `${loc.get("c_queue1")}${loc.get("c_queue7")} ${page}/${pageMax}` }); 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({ embed.addFields({
name: "\u200b", name,
value: `${(idx + 1) * page}. [${t.title}](${t.url}) (${t.duration})`, 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;
}
}; };