Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, AttachmentBuilder } = require("discord.js");
- const Canvas = require("canvas");
- const { convertTime } = require("../../../functions/timeFormat.js");
- module.exports = async (client, player, track) => {
- if (!player) return;
- const formatString = (str, maxLength) => (str.length > maxLength ? str.substr(0, maxLength - 3) + "..." : str);
- const trackTitle = formatString(track.title || "Unknown", 30).replace(/ - Topic$/, "");
- const trackAuthor = formatString(track.author || "Unknown", 25).replace(/ - Topic$/, "");
- const trackDuration = track.isStream ? "LIVE" : convertTime(track.duration);
- const createMusicCard = async () => {
- const canvas = Canvas.createCanvas(800, 300);
- const ctx = canvas.getContext("2d");
- const background = await Canvas.loadImage("https://i.imgur.com/IOGUfle.jpeg");
- ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
- ctx.fillStyle = "rgba(0, 0, 0, 0.6)";
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- ctx.fillStyle = "#FF7A00";
- ctx.font = "bold 35px 'Noto Color Emoji', Sans";
- ctx.fillText("🎶 Now Playing", 20, 50);
- ctx.font = "italic 28px 'Noto Color Emoji', Sans";
- ctx.fillStyle = "#FFFFFF";
- ctx.fillText(trackTitle, 20, 100);
- ctx.fillStyle = "#FFFF00";
- ctx.font = "24px 'Noto Color Emoji', Sans";
- ctx.fillText(`By: ${trackAuthor}`, 20, 150);
- const progress = player.position / track.duration;
- const progressBarX = 20;
- const progressBarY = 220;
- const progressBarWidth = 760;
- const progressBarHeight = 30;
- ctx.fillStyle = "#5F2D00";
- ctx.fillRect(progressBarX, progressBarY, progressBarWidth, progressBarHeight);
- ctx.fillStyle = "#FF7A00";
- ctx.fillRect(progressBarX, progressBarY, progressBarWidth * progress, progressBarHeight);
- ctx.strokeStyle = "#FFFFFF";
- ctx.lineWidth = 2;
- ctx.strokeRect(progressBarX, progressBarY, progressBarWidth, progressBarHeight);
- ctx.fillStyle = "#FFFFFF";
- ctx.font = "20px 'Noto Color Emoji', Sans";
- ctx.fillText("0:00", progressBarX, progressBarY + 50);
- ctx.fillText(track.isStream ? "LIVE" : convertTime(track.duration), progressBarX + progressBarWidth - 70, progressBarY + 50);
- const trackImage = await Canvas.loadImage(track.thumbnail || "https://via.placeholder.com/140");
- ctx.drawImage(trackImage, 650, 40, 140, 140);
- return canvas.toBuffer();
- };
- const musicCardBuffer = await createMusicCard();
- const attachment = new AttachmentBuilder(musicCardBuffer, { name: "musicard.png" });
- const embed = new EmbedBuilder()
- .setTitle("<:nmusic:1307807982284832870><:narrow:1302459790215086162>**__NoiseFX's Sound__**")
- .setColor(client.config.embedColor)
- .setDescription(`**[${trackTitle} - ${trackAuthor}](${track.uri})**`)
- .setImage("attachment://musicard.png")
- .addFields(
- { name: "<:narrow:1302459790215086162>Duration", value: `> ${trackDuration}`, inline: true },
- { name: "<:narrow:1302459790215086162>Requester", value: `> ${track.requester}`, inline: true },
- { name: "<:narrow:1302459790215086162>Source", value: `> ${track.source}`, inline: true }
- );
- const actionRow = new ActionRowBuilder().addComponents(
- new ButtonBuilder().setLabel("Pause").setStyle(ButtonStyle.Primary).setCustomId("pause"),
- new ButtonBuilder().setLabel("Skip").setStyle(ButtonStyle.Secondary).setCustomId("skip"),
- new ButtonBuilder().setLabel("Stop").setStyle(ButtonStyle.Danger).setCustomId("stop")
- );
- await player.textChannel.send({
- embeds: [embed],
- files: [attachment],
- components: [actionRow],
- });
- };
- module.exports.updateMusicCard = async (client, player, track) => {
- if (!player) return;
- const formatString = (str, maxLength) => (str.length > maxLength ? str.substr(0, maxLength - 3) + "..." : str);
- const trackTitle = formatString(track.title || "Unknown", 30).replace(/ - Topic$/, "");
- const trackAuthor = formatString(track.author || "Unknown", 25).replace(/ - Topic$/, "");
- const trackDuration = track.isStream ? "LIVE" : convertTime(track.duration);
- const createUpdatedMusicCard = async () => {
- const canvas = Canvas.createCanvas(800, 300);
- const ctx = canvas.getContext("2d");
- const background = await Canvas.loadImage("https://i.imgur.com/IOGUfle.jpeg");
- ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
- ctx.fillStyle = "rgba(0, 0, 0, 0.6)";
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- ctx.fillStyle = "#FF7A00";
- ctx.font = "bold 35px 'Noto Color Emoji', Sans";
- ctx.fillText("🎶 Now Playing", 20, 50);
- ctx.font = "italic 28px 'Noto Color Emoji', Sans";
- ctx.fillStyle = "#FFFFFF";
- ctx.fillText(trackTitle, 20, 100);
- ctx.fillStyle = "#FFFF00";
- ctx.font = "24px 'Noto Color Emoji', Sans";
- ctx.fillText(`By: ${trackAuthor}`, 20, 150);
- const progress = player.position / track.duration;
- const progressBarX = 20;
- const progressBarY = 220;
- const progressBarWidth = 760;
- const progressBarHeight = 30;
- ctx.fillStyle = "#5F2D00";
- ctx.fillRect(progressBarX, progressBarY, progressBarWidth, progressBarHeight);
- ctx.fillStyle = "#FF7A00";
- ctx.fillRect(progressBarX, progressBarY, progressBarWidth * progress, progressBarHeight);
- ctx.strokeStyle = "#FFFFFF";
- ctx.lineWidth = 2;
- ctx.strokeRect(progressBarX, progressBarY, progressBarWidth, progressBarHeight);
- ctx.fillStyle = "#FFFFFF";
- ctx.font = "20px 'Noto Color Emoji', Sans";
- ctx.fillText("0:00", progressBarX, progressBarY + 50);
- ctx.fillText(track.isStream ? "LIVE" : convertTime(track.duration), progressBarX + progressBarWidth - 70, progressBarY + 50);
- const trackImage = await Canvas.loadImage(track.thumbnail || "https://via.placeholder.com/140");
- ctx.drawImage(trackImage, 650, 40, 140, 140);
- return canvas.toBuffer();
- };
- const updatedMusicCardBuffer = await createUpdatedMusicCard();
- const updatedAttachment = new AttachmentBuilder(updatedMusicCardBuffer, { name: "updated-musicard.png" });
- const updatedEmbed = new EmbedBuilder()
- .setTitle("<:nmusic:1307807982284832870><:narrow:1302459790215086162>**__NoiseFX's Sound__**")
- .setColor(client.config.embedColor)
- .setDescription(`**[${trackTitle} - ${trackAuthor}](${track.uri})**`)
- .setImage("attachment://updated-musicard.png")
- .addFields(
- { name: "<:narrow:1302459790215086162>Duration", value: `> ${trackDuration}`, inline: true },
- { name: "<:narrow:1302459790215086162>Requester", value: `> ${track.requester}`, inline: true },
- { name: "<:narrow:1302459790215086162>Source", value: `> ${track.source}`, inline: true }
- );
- await player.textChannel.messages.fetch({ limit: 10 }).then(messages => {
- const trackMessage = messages.find(msg => msg.embeds.length && msg.embeds[0].title.includes("Now Playing"));
- if (trackMessage) {
- trackMessage.edit({
- embeds: [updatedEmbed],
- files: [updatedAttachment],
- });
- }
- });
- };
- // Made By ZayDocs || DO NOT REMOVE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement