Advertisement
spiralvibes

Made By ZayDocs | CubeCloud Team

Nov 19th, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, AttachmentBuilder } = require("discord.js");
  2. const Canvas = require("canvas");
  3. const { convertTime } = require("../../../functions/timeFormat.js");
  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.  
  13.     const createMusicCard = async () => {
  14.         const canvas = Canvas.createCanvas(800, 300);
  15.         const ctx = canvas.getContext("2d");
  16.  
  17.         const background = await Canvas.loadImage("https://i.imgur.com/IOGUfle.jpeg");
  18.         ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
  19.  
  20.         ctx.fillStyle = "rgba(0, 0, 0, 0.6)";
  21.         ctx.fillRect(0, 0, canvas.width, canvas.height);
  22.  
  23.         ctx.fillStyle = "#FF7A00";
  24.         ctx.font = "bold 35px 'Noto Color Emoji', Sans";
  25.         ctx.fillText("🎶 Now Playing", 20, 50);
  26.  
  27.         ctx.font = "italic 28px 'Noto Color Emoji', Sans";
  28.         ctx.fillStyle = "#FFFFFF";
  29.         ctx.fillText(trackTitle, 20, 100);
  30.  
  31.         ctx.fillStyle = "#FFFF00";
  32.         ctx.font = "24px 'Noto Color Emoji', Sans";
  33.         ctx.fillText(`By: ${trackAuthor}`, 20, 150);
  34.  
  35.         const progress = player.position / track.duration;
  36.         const progressBarX = 20;
  37.         const progressBarY = 220;
  38.         const progressBarWidth = 760;
  39.         const progressBarHeight = 30;
  40.  
  41.         ctx.fillStyle = "#5F2D00";
  42.         ctx.fillRect(progressBarX, progressBarY, progressBarWidth, progressBarHeight);
  43.  
  44.         ctx.fillStyle = "#FF7A00";
  45.         ctx.fillRect(progressBarX, progressBarY, progressBarWidth * progress, progressBarHeight);
  46.  
  47.         ctx.strokeStyle = "#FFFFFF";
  48.         ctx.lineWidth = 2;
  49.         ctx.strokeRect(progressBarX, progressBarY, progressBarWidth, progressBarHeight);
  50.  
  51.         ctx.fillStyle = "#FFFFFF";
  52.         ctx.font = "20px 'Noto Color Emoji', Sans";
  53.         ctx.fillText("0:00", progressBarX, progressBarY + 50);
  54.         ctx.fillText(track.isStream ? "LIVE" : convertTime(track.duration), progressBarX + progressBarWidth - 70, progressBarY + 50);
  55.  
  56.         const trackImage = await Canvas.loadImage(track.thumbnail || "https://via.placeholder.com/140");
  57.         ctx.drawImage(trackImage, 650, 40, 140, 140);
  58.  
  59.         return canvas.toBuffer();
  60.     };
  61.  
  62.     const musicCardBuffer = await createMusicCard();
  63.     const attachment = new AttachmentBuilder(musicCardBuffer, { name: "musicard.png" });
  64.  
  65.     const embed = new EmbedBuilder()
  66.         .setTitle("<:nmusic:1307807982284832870><:narrow:1302459790215086162>**__NoiseFX's Sound__**")
  67.         .setColor(client.config.embedColor)
  68.         .setDescription(`**[${trackTitle} - ${trackAuthor}](${track.uri})**`)
  69.         .setImage("attachment://musicard.png")
  70.         .addFields(
  71.             { name: "<:narrow:1302459790215086162>Duration", value: `> ${trackDuration}`, inline: true },
  72.             { name: "<:narrow:1302459790215086162>Requester", value: `> ${track.requester}`, inline: true },
  73.             { name: "<:narrow:1302459790215086162>Source", value: `> ${track.source}`, inline: true }
  74.         );
  75.  
  76.     const actionRow = new ActionRowBuilder().addComponents(
  77.         new ButtonBuilder().setLabel("Pause").setStyle(ButtonStyle.Primary).setCustomId("pause"),
  78.         new ButtonBuilder().setLabel("Skip").setStyle(ButtonStyle.Secondary).setCustomId("skip"),
  79.         new ButtonBuilder().setLabel("Stop").setStyle(ButtonStyle.Danger).setCustomId("stop")
  80.     );
  81.  
  82.     await player.textChannel.send({
  83.         embeds: [embed],
  84.         files: [attachment],
  85.         components: [actionRow],
  86.     });
  87. };
  88.  
  89. module.exports.updateMusicCard = async (client, player, track) => {
  90.     if (!player) return;
  91.  
  92.     const formatString = (str, maxLength) => (str.length > maxLength ? str.substr(0, maxLength - 3) + "..." : str);
  93.     const trackTitle = formatString(track.title || "Unknown", 30).replace(/ - Topic$/, "");
  94.     const trackAuthor = formatString(track.author || "Unknown", 25).replace(/ - Topic$/, "");
  95.     const trackDuration = track.isStream ? "LIVE" : convertTime(track.duration);
  96.  
  97.     const createUpdatedMusicCard = async () => {
  98.         const canvas = Canvas.createCanvas(800, 300);
  99.         const ctx = canvas.getContext("2d");
  100.  
  101.         const background = await Canvas.loadImage("https://i.imgur.com/IOGUfle.jpeg");
  102.         ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
  103.  
  104.         ctx.fillStyle = "rgba(0, 0, 0, 0.6)";
  105.         ctx.fillRect(0, 0, canvas.width, canvas.height);
  106.  
  107.         ctx.fillStyle = "#FF7A00";
  108.         ctx.font = "bold 35px 'Noto Color Emoji', Sans";
  109.         ctx.fillText("🎶 Now Playing", 20, 50);
  110.  
  111.         ctx.font = "italic 28px 'Noto Color Emoji', Sans";
  112.         ctx.fillStyle = "#FFFFFF";
  113.         ctx.fillText(trackTitle, 20, 100);
  114.  
  115.         ctx.fillStyle = "#FFFF00";
  116.         ctx.font = "24px 'Noto Color Emoji', Sans";
  117.         ctx.fillText(`By: ${trackAuthor}`, 20, 150);
  118.  
  119.         const progress = player.position / track.duration;
  120.         const progressBarX = 20;
  121.         const progressBarY = 220;
  122.         const progressBarWidth = 760;
  123.         const progressBarHeight = 30;
  124.  
  125.         ctx.fillStyle = "#5F2D00";
  126.         ctx.fillRect(progressBarX, progressBarY, progressBarWidth, progressBarHeight);
  127.  
  128.         ctx.fillStyle = "#FF7A00";
  129.         ctx.fillRect(progressBarX, progressBarY, progressBarWidth * progress, progressBarHeight);
  130.  
  131.         ctx.strokeStyle = "#FFFFFF";
  132.         ctx.lineWidth = 2;
  133.         ctx.strokeRect(progressBarX, progressBarY, progressBarWidth, progressBarHeight);
  134.  
  135.         ctx.fillStyle = "#FFFFFF";
  136.         ctx.font = "20px 'Noto Color Emoji', Sans";
  137.         ctx.fillText("0:00", progressBarX, progressBarY + 50);
  138.         ctx.fillText(track.isStream ? "LIVE" : convertTime(track.duration), progressBarX + progressBarWidth - 70, progressBarY + 50);
  139.  
  140.         const trackImage = await Canvas.loadImage(track.thumbnail || "https://via.placeholder.com/140");
  141.         ctx.drawImage(trackImage, 650, 40, 140, 140);
  142.  
  143.         return canvas.toBuffer();
  144.     };
  145.  
  146.     const updatedMusicCardBuffer = await createUpdatedMusicCard();
  147.     const updatedAttachment = new AttachmentBuilder(updatedMusicCardBuffer, { name: "updated-musicard.png" });
  148.  
  149.     const updatedEmbed = new EmbedBuilder()
  150.         .setTitle("<:nmusic:1307807982284832870><:narrow:1302459790215086162>**__NoiseFX's Sound__**")
  151.         .setColor(client.config.embedColor)
  152.         .setDescription(`**[${trackTitle} - ${trackAuthor}](${track.uri})**`)
  153.         .setImage("attachment://updated-musicard.png")
  154.         .addFields(
  155.             { name: "<:narrow:1302459790215086162>Duration", value: `> ${trackDuration}`, inline: true },
  156.             { name: "<:narrow:1302459790215086162>Requester", value: `> ${track.requester}`, inline: true },
  157.             { name: "<:narrow:1302459790215086162>Source", value: `> ${track.source}`, inline: true }
  158.         );
  159.  
  160.     await player.textChannel.messages.fetch({ limit: 10 }).then(messages => {
  161.         const trackMessage = messages.find(msg => msg.embeds.length && msg.embeds[0].title.includes("Now Playing"));
  162.         if (trackMessage) {
  163.             trackMessage.edit({
  164.                 embeds: [updatedEmbed],
  165.                 files: [updatedAttachment],
  166.             });
  167.         }
  168.     });
  169. };
  170. // Made By ZayDocs || DO NOT REMOVE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement