const { MessageEmbed } = require("discord.js");
const lyricsFinder = require('lyrics-finder');

exports.run = async(client, message, args) => {

    const serverQueue = client.player.getQueue(message.guild);

    if (!serverQueue) return message.channel.send("La file de musique du serveur est vide !");

    const track = serverQueue.tracks[0];

    const lyrics = await lyricsFinder(track.author, track.title) || "Not Found!";

    const lyricsSplit = lyrics.split("\n\n");

    var desc = "";

    const lyricsEmbed = new MessageEmbed()
    .setTitle(track.title)
    .setAuthor("Paroles");

    if (lyrics.length >= 2000) {
        for (const lyricsPart of lyricsSplit) {
            if (desc.length <= 1700) desc += `${lyricsPart}\n\n`;
            else {
                lyricsEmbed.setDescription(desc);
                message.channel.send(lyricsEmbed);
                lyricsEmbed.setTitle("").setAuthor("");
                    
                desc = `${lyricsPart}\n\n`;
            }
        }
    } else desc = lyrics;

    lyricsEmbed.setDescription(desc);
    message.channel.send({embeds: [lyricsEmbed]});
}

exports.config = {
    name: "lyrics",
    description: "[Musique] - Vous donne les paroles de la musique en cours de lecture pour transformer le vocal en un fantastique karaoké.",
    template: "lyrics",
    permission: "@everyone",
    aliases: ["parole"]
}