Advertisement
spiralvibes

Made By ZayDocs | Rivvix Team

Nov 23rd, 2024
183
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 musicardBuffer = 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 attachment = new AttachmentBuilder(musicardBuffer, { name: `musicard.png` });
  30.  
  31.     const trackMsg = new EmbedBuilder()
  32.         .setAuthor({ name: player.paused ? "Song Paused" : "Now Playing", iconURL: client.user.displayAvatarURL() })
  33.         .setColor(client.config.embedColor)
  34.         .setDescription(`**[${trackTitle} - ${trackAuthor}](${track.uri})**`)
  35.         .setThumbnail(track.artworkUrl || `https://img.youtube.com/vi/${track.identifier}/maxresdefault.jpg`)
  36.         .addFields(
  37.             { name: "Duration", value: `\`${trackDuration}\``, inline: true },
  38.             { name: "Requester", value: `${track.requester}`, inline: true },
  39.             { name: "Source", value: `${capitalize(track.source)}`, inline: true }
  40.         )
  41.         .setImage("attachment://musicard.png");
  42.  
  43.     const button = new ActionRowBuilder().addComponents(
  44.         new ButtonBuilder()
  45.             .setCustomId("pause")
  46.             .setEmoji(player.paused ? playerEmoji.resume : playerEmoji.pause)
  47.             .setStyle(player.paused ? ButtonStyle.Primary : ButtonStyle.Secondary),
  48.         new ButtonBuilder().setCustomId("voldown").setEmoji(playerEmoji.voldown).setStyle(ButtonStyle.Secondary),
  49.         new ButtonBuilder().setCustomId("volup").setEmoji(playerEmoji.volup).setStyle(ButtonStyle.Secondary),
  50.         new ButtonBuilder().setCustomId("loop").setEmoji(playerEmoji.loop).setStyle(ButtonStyle.Secondary)
  51.     );
  52.  
  53.     const button2 = new ActionRowBuilder().addComponents(
  54.         new ButtonBuilder().setCustomId("shuffle").setEmoji(playerEmoji.shuffle).setStyle(ButtonStyle.Secondary),
  55.         new ButtonBuilder().setCustomId("prev").setEmoji(playerEmoji.previous).setStyle(ButtonStyle.Secondary),
  56.         new ButtonBuilder().setCustomId("skip").setEmoji(playerEmoji.skip).setStyle(ButtonStyle.Secondary),
  57.         new ButtonBuilder().setCustomId("stop").setEmoji(playerEmoji.stop).setStyle(ButtonStyle.Danger)
  58.     );
  59.  
  60.     const nplaying = await client.channels.cache
  61.         .get(player.textId)
  62.         .send({ embeds: [trackMsg], files: [attachment], components: [button, button2] });
  63.  
  64.     player.message = nplaying;
  65.  
  66.     const embed = new EmbedBuilder().setColor(client.config.embedColor);
  67.     const collector = nplaying.createMessageComponentCollector();
  68.  
  69.     collector.on("collect", async (interaction) => {
  70.         if (!player) return collector.stop();
  71.  
  72.         if (!interaction.member.voice.channel || player.voiceId !== interaction.member.voice.channelId) {
  73.             embed.setDescription(`You must be in the same voice channel as the bot.`);
  74.             return interaction.reply({ embeds: [embed], ephemeral: true });
  75.         }
  76.  
  77.         switch (interaction.customId) {
  78.             case "pause":
  79.                 player.paused ? player.resume() : player.pause();
  80.                 button.components[0]
  81.                     .setEmoji(player.paused ? playerEmoji.resume : playerEmoji.pause)
  82.                     .setStyle(player.paused ? ButtonStyle.Primary : ButtonStyle.Secondary);
  83.                 trackMsg.setAuthor({
  84.                     name: player.paused ? "Song Paused" : "Now Playing",
  85.                     iconURL: client.user.displayAvatarURL(),
  86.                 });
  87.                 await nplaying.edit({ embeds: [trackMsg], components: [button, button2] });
  88.                 interaction.deferUpdate();
  89.                 break;
  90.  
  91.             case "prev":
  92.                 if (!player.queue.previous.length) {
  93.                     embed.setDescription(`No previous song in the queue.`);
  94.                     return interaction.reply({ embeds: [embed], ephemeral: true });
  95.                 }
  96.                 player.previous();
  97.                 interaction.deferUpdate();
  98.                 break;
  99.  
  100.             case "skip":
  101.                 if (player.queue.isEmpty && !client.data.get("autoplay", player.guildId)) {
  102.                     embed.setDescription(`Queue is empty. Skip not possible.`);
  103.                     return interaction.reply({ embeds: [embed], ephemeral: true });
  104.                 }
  105.                 player.skip();
  106.                 interaction.deferUpdate();
  107.                 break;
  108.  
  109.             case "loop":
  110.                 const loopMode = player.loop === "none" ? "song" : player.loop === "song" ? "queue" : "none";
  111.                 player.setLoop(loopMode);
  112.                 embed.setDescription(`Loop mode has been set to \`${loopMode}\`.`);
  113.                 return interaction.reply({ embeds: [embed], ephemeral: true });
  114.  
  115.             case "shuffle":
  116.                 if (player.queue.isEmpty) {
  117.                     embed.setDescription(`Queue is empty. Shuffle not possible.`);
  118.                     return interaction.reply({ embeds: [embed], ephemeral: true });
  119.                 }
  120.                 player.queue.shuffle();
  121.                 embed.setDescription(`Queue has been shuffled.`);
  122.                 return interaction.reply({ embeds: [embed], ephemeral: true });
  123.  
  124.             case "voldown":
  125.                 if (player.volume <= client.config.minVolume) {
  126.                     embed.setDescription(`Volume cannot be lower than \`${client.config.minVolume}%\`.`);
  127.                     return interaction.reply({ embeds: [embed], ephemeral: true });
  128.                 }
  129.                 player.setVolume(player.volume - 10);
  130.                 embed.setDescription(`Volume has been decreased to \`${player.volume}%\`.`);
  131.                 return interaction.reply({ embeds: [embed], ephemeral: true });
  132.  
  133.             case "volup":
  134.                 if (player.volume >= client.config.maxVolume) {
  135.                     embed.setDescription(`Volume cannot be higher than \`${client.config.maxVolume}%\`.`);
  136.                     return interaction.reply({ embeds: [embed], ephemeral: true });
  137.                 }
  138.                 player.setVolume(player.volume + 10);
  139.                 embed.setDescription(`Volume has been increased to \`${player.volume}%\`.`);
  140.                 return interaction.reply({ embeds: [embed], ephemeral: true });
  141.  
  142.             case "stop":
  143.                 player.stop();
  144.                 interaction.deferUpdate();
  145.                 break;
  146.         }
  147.     });
  148. };
  149.  
  150. function capitalize(string) {
  151.     return string.charAt(0).toUpperCase() + string.slice(1);
  152. }
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement