Advertisement
spiralvibes

Made By ZayDocs | CubeCloud Team

Nov 23rd, 2024
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } = require("discord.js");
  2. const { convertTime } = require("../../../functions/timeFormat.js");
  3. const { Classic } = require("musicard");
  4.  
  5. module.exports = async (client, player, track) => {
  6.     if (!player) return;
  7.  
  8.     const formatString = (str, maxLength) => (str.length > maxLength ? str.substr(0, maxLength - 3) + "..." : str);
  9.     const trackTitle = formatString(track.title || "Unknown", 30).replace(/ - Topic$/, "");
  10.     const trackAuthor = formatString(track.author || "Unknown", 25).replace(/ - Topic$/, "");
  11.     const trackDuration = track.isStream ? "LIVE" : convertTime(track.duration);
  12.     const playerEmoji = client.emoji.player;
  13.  
  14.     const musicard = await Classic({
  15.         thumbnailImage: `https://img.youtube.com/vi/${track.identifier}/maxresdefault.jpg`,
  16.         backgroundColor: "#070707",
  17.         progress: 10,
  18.         progressBarColor: "#FF7A00",
  19.         progressColor: "#FF7A00",
  20.         name: trackTitle,
  21.         nameColor: "#FF7A00",
  22.         author: trackAuthor,
  23.         authorColor: "#FFFFFF",
  24.         startTime: "0:00",
  25.         endTime: track.isStream ? "LIVE" : convertTime(track.duration),
  26.         timeColor: "#FF7A00",
  27.     });
  28.  
  29.     const buffer = await musicard.build();
  30.     const attachment = new AttachmentBuilder(buffer, { name: `musicard.png` });
  31.  
  32.     const trackMsg = new EmbedBuilder()
  33.         .setAuthor({ name: player.paused ? "Song Paused" : "Now Playing", iconURL: client.user.displayAvatarURL() })
  34.         .setColor(client.config.embedColor)
  35.         .setDescription(`**[${trackTitle} - ${trackAuthor}](${track.uri})**`)
  36.         .setThumbnail(track.artworkUrl || `https://img.youtube.com/vi/${track.identifier}/maxresdefault.jpg`)
  37.         .addFields(
  38.             { name: "Duration", value: `\`${trackDuration}\``, inline: true },
  39.             { name: "Requester", value: `${track.requester}`, inline: true },
  40.             { name: "Source", value: `${capitalize(track.source)}`, inline: true }
  41.         )
  42.         .setImage("attachment://musicard.png");
  43.  
  44.     const button = new ActionRowBuilder().addComponents(
  45.         new ButtonBuilder()
  46.             .setCustomId("pause")
  47.             .setEmoji(player.paused ? playerEmoji.resume : playerEmoji.pause)
  48.             .setStyle(player.paused ? ButtonStyle.Primary : ButtonStyle.Secondary),
  49.         new ButtonBuilder().setCustomId("voldown").setEmoji(playerEmoji.voldown).setStyle(ButtonStyle.Secondary),
  50.         new ButtonBuilder().setCustomId("volup").setEmoji(playerEmoji.volup).setStyle(ButtonStyle.Secondary),
  51.         new ButtonBuilder().setCustomId("loop").setEmoji(playerEmoji.loop).setStyle(ButtonStyle.Secondary)
  52.     );
  53.  
  54.     const button2 = new ActionRowBuilder().addComponents(
  55.         new ButtonBuilder().setCustomId("shuffle").setEmoji(playerEmoji.shuffle).setStyle(ButtonStyle.Secondary),
  56.         new ButtonBuilder().setCustomId("prev").setEmoji(playerEmoji.previous).setStyle(ButtonStyle.Secondary),
  57.         new ButtonBuilder().setCustomId("skip").setEmoji(playerEmoji.skip).setStyle(ButtonStyle.Secondary),
  58.         new ButtonBuilder().setCustomId("stop").setEmoji(playerEmoji.stop).setStyle(ButtonStyle.Danger)
  59.     );
  60.  
  61.     const nplaying = await client.channels.cache
  62.         .get(player.textId)
  63.         .send({ embeds: [trackMsg], files: [attachment], components: [button, button2] });
  64.  
  65.     player.message = nplaying;
  66.  
  67.     const embed = new EmbedBuilder().setColor(client.config.embedColor);
  68.     const collector = nplaying.createMessageComponentCollector();
  69.  
  70.     collector.on("collect", async (interaction) => {
  71.         if (!player) return collector.stop();
  72.  
  73.         if (!interaction.member.voice.channel || player.voiceId !== interaction.member.voice.channelId) {
  74.             embed.setDescription(`You must be in the same voice channel as the bot.`);
  75.             return interaction.reply({ embeds: [embed], ephemeral: true });
  76.         }
  77.  
  78.         switch (interaction.customId) {
  79.             case "pause":
  80.                 player.paused ? player.resume() : player.pause();
  81.                 button.components[0]
  82.                     .setEmoji(player.paused ? playerEmoji.resume : playerEmoji.pause)
  83.                     .setStyle(player.paused ? ButtonStyle.Primary : ButtonStyle.Secondary);
  84.                 trackMsg.setAuthor({
  85.                     name: player.paused ? "Song Paused" : "Now Playing",
  86.                     iconURL: client.user.displayAvatarURL(),
  87.                 });
  88.                 await nplaying.edit({ embeds: [trackMsg], components: [button, button2] });
  89.                 interaction.deferUpdate();
  90.                 break;
  91.  
  92.             case "prev":
  93.                 if (!player.queue.previous.length) {
  94.                     embed.setDescription(`No previous song in the queue.`);
  95.                     return interaction.reply({ embeds: [embed], ephemeral: true });
  96.                 }
  97.                 player.previous();
  98.                 interaction.deferUpdate();
  99.                 break;
  100.  
  101.             case "skip":
  102.                 if (player.queue.isEmpty && !client.data.get("autoplay", player.guildId)) {
  103.                     embed.setDescription(`Queue is empty. Skip not possible.`);
  104.                     return interaction.reply({ embeds: [embed], ephemeral: true });
  105.                 }
  106.                 player.skip();
  107.                 interaction.deferUpdate();
  108.                 break;
  109.  
  110.             case "loop":
  111.                 const loopMode = player.loop === "none" ? "song" : player.loop === "song" ? "queue" : "none";
  112.                 player.setLoop(loopMode);
  113.                 embed.setDescription(`Loop mode has been set to \`${loopMode}\`.`);
  114.                 return interaction.reply({ embeds: [embed], ephemeral: true });
  115.  
  116.             case "shuffle":
  117.                 if (player.queue.isEmpty) {
  118.                     embed.setDescription(`Queue is empty. Shuffle not possible.`);
  119.                     return interaction.reply({ embeds: [embed], ephemeral: true });
  120.                 }
  121.                 player.queue.shuffle();
  122.                 embed.setDescription(`Queue has been shuffled.`);
  123.                 return interaction.reply({ embeds: [embed], ephemeral: true });
  124.  
  125.             case "voldown":
  126.                 if (player.volume <= client.config.minVolume) {
  127.                     embed.setDescription(`Volume cannot be lower than \`${client.config.minVolume}%\`.`);
  128.                     return interaction.reply({ embeds: [embed], ephemeral: true });
  129.                 }
  130.                 player.setVolume(player.volume - 10);
  131.                 embed.setDescription(`Volume has been decreased to \`${player.volume}%\`.`);
  132.                 return interaction.reply({ embeds: [embed], ephemeral: true });
  133.  
  134.             case "volup":
  135.                 if (player.volume >= client.config.maxVolume) {
  136.                     embed.setDescription(`Volume cannot be higher than \`${client.config.maxVolume}%\`.`);
  137.                     return interaction.reply({ embeds: [embed], ephemeral: true });
  138.                 }
  139.                 player.setVolume(player.volume + 10);
  140.                 embed.setDescription(`Volume has been increased to \`${player.volume}%\`.`);
  141.                 return interaction.reply({ embeds: [embed], ephemeral: true });
  142.  
  143.             case "stop":
  144.                 player.stop();
  145.                 interaction.deferUpdate();
  146.                 break;
  147.         }
  148.     });
  149. };
  150.  
  151. function capitalize(string) {
  152.     return string.charAt(0).toUpperCase() + string.slice(1);
  153. }
  154.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement