Advertisement
BETAlwrd

Untitled

Jun 28th, 2025
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require('axios');
  2. const { loadImage, createCanvas } = require('canvas');
  3. const getProfile = require('../../managers/getProfile');
  4. const drawCircle = require('../../managers/drawCircle');
  5. const { AttachmentBuilder } = require('discord.js');
  6. const path = require('path');
  7. const fs = require('fs');
  8.  
  9. module.exports = {
  10.     name: 'boost',
  11.     aliases: ['b', 'booster', 'myboost','بوست','بست','ب'],
  12.     description: 'Show your/someone\'s boost badge information',
  13.     async execute(message) {
  14.         const user = message.mentions.users.first() || message.author;
  15.  
  16.         if (user.bot) {
  17.             return message.reply({
  18.                 content: 'This command cannot work with bots!',
  19.                 ephemeral: true
  20.             });
  21.         }
  22.  
  23.         const profile = await getProfile(user.id);
  24.         if (!profile) {
  25.             return message.reply({
  26.                 content: 'Cannot find this user in my servers!',
  27.                 ephemeral: true
  28.             });
  29.         }
  30.  
  31.         if (!profile.premium_guild_since) {
  32.             return message.reply({
  33.                 content: 'This user doesn\'t have a boost badge!',
  34.                 ephemeral: true
  35.             });
  36.         }
  37.  
  38.         const guild = message.guild;
  39.         const date = new Date(profile.premium_guild_since);
  40.         const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  41.  
  42.         const getTimeAfterMonths = (monthsToAdd) => {
  43.             const currentDate = new Date(date.getTime());
  44.             currentDate.setMonth(currentDate.getMonth() + monthsToAdd);
  45.             return currentDate.getTime();
  46.         };
  47.  
  48.         const nextLevel =
  49.          getTimeAfterMonths(2) > Date.now()
  50.             ? 2
  51.             : getTimeAfterMonths(3) > Date.now()
  52.                 ? 3
  53.                 : getTimeAfterMonths(6) > Date.now()
  54.                     ? 4
  55.                     : getTimeAfterMonths(9) > Date.now()
  56.                         ? 5
  57.                         : getTimeAfterMonths(12) > Date.now()
  58.                             ? 6
  59.                             : getTimeAfterMonths(15) > Date.now()
  60.                                 ? 7
  61.                                 : getTimeAfterMonths(18) > Date.now()
  62.                                     ? 8
  63.                                     : getTimeAfterMonths(24) > Date.now()
  64.                                         ? 9
  65.                                         : null;
  66.  
  67.         const currentLevel = (nextLevel || 10) - 1;
  68.         const badges = ["", "", "", "", "", "", "", "", ""].map((_, index) => {
  69.             const emoji = guild.emojis.cache.find((emot) => emot.name == `guild_booster_lvl${index + 1}`);
  70.             return `<:${emoji.name}:${emoji.id}>`;
  71.         });
  72.  
  73.         const nextBadge = badges[(nextLevel || 10) - 1];
  74.         const currentBadge = badges[currentLevel - 1];
  75.  
  76.         let description = "";
  77.         let content = "";
  78.  
  79.         const levelsMonths = { 2: 2, 3: 3, 4: 6, 5: 9, 6: 12, 7: 15, 8: 18, 9: 24 };
  80.         const form = new FormData();
  81.  
  82.         if (currentLevel == 9) {
  83.             content = `${currentBadge} Level ${currentLevel} (Max) ${currentBadge}`;
  84.             description = `${user.id == message.author.id
  85.                 ? "**You**, have"
  86.                 : `**${profile.user.username}**, has`} level 9 (Max)\nBoosted: <t:${Math.floor(date.getTime() / 1000)}:R> | ${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
  87.             const bg = await loadImage(path.resolve(__dirname, '../../images', `9.png`));
  88.             const canvas = createCanvas(bg.width, bg.height);
  89.             const ctx = canvas.getContext("2d");
  90.             ctx.drawImage(bg, 0, 0, canvas.width, canvas.height);
  91.             ctx.font = "16px Arial";
  92.             ctx.fillStyle = "white";
  93.             ctx.fillText(user.username, 50, 202);
  94.             const avatarX = 30.5;
  95.             const avatarY = 188;
  96.             const avatarSize = 17;
  97.             const attachment = new AttachmentBuilder(canvas.toBuffer('image/png'), { name: 'boost.png' });
  98.  
  99.             await message.reply({
  100.                 content,
  101.                 embeds: [{
  102.                     title: `${profile.user.global_name || profile.user.username}`,
  103.                     description,
  104.                     color: process.env.color,
  105.                     image: { url: "attachment://boost.png" }
  106.                 }],
  107.                 files: [attachment]
  108.             });
  109.         } else {
  110.             content = `${currentBadge} Level ${currentLevel} ${currentBadge}`;
  111.             const nextTimestamp = getTimeAfterMonths(levelsMonths[nextLevel]);
  112.             const timestamp = nextTimestamp - Date.now();
  113.             const remainingTime = [
  114.                 Math.floor(timestamp / (1000 * 60 * 60 * 24)),
  115.                 Math.floor(timestamp / (1000 * 60 * 60)) % 24,
  116.                 Math.floor(timestamp / (1000 * 60)) % 60,
  117.                 Math.floor(timestamp / 1000) % 60
  118.             ].map((value, index) => `${value}${["d", "h", "m", "s"][index]}`)
  119.                 .join(', ');
  120.  
  121.             description = `${user.id == message.author.id
  122.                 ? "**You**, have"
  123.                 : `**${profile.user.username}**, has`} level ${currentLevel}.\nBoosted: <t:${Math.floor(date.getTime() / 1000)}:R> | ${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}\n${nextBadge} Next level ${nextBadge}\nRemaining time: <t:${Math.floor(nextTimestamp / 1000)}:R> | ${remainingTime}`;
  124.             const bgPath = path.resolve(__dirname, '../../images', `${currentLevel}.png`);
  125.             if (!fs.existsSync(bgPath)) return console.log('❌ الملف غير موجود:', bgPath);
  126.             const bg = await loadImage(bgPath);
  127.             const canvas = createCanvas(bg.width, bg.height);
  128.             const ctx = canvas.getContext("2d");
  129.             ctx.drawImage(bg, 0, 0, canvas.width, canvas.height);
  130.             ctx.font = "16px Arial";
  131.             ctx.fillStyle = "white";
  132.             ctx.fillText(profile.user.global_name || user.username, 50, 202);
  133.             const avatarX = 30.5;
  134.             const avatarY = 188;
  135.             const avatarSize = 17;
  136.             try {
  137.                 const avatar = await drawCircle({
  138.                     image: user.displayAvatarURL({ format: 'png', size: 4096 })
  139.                 });
  140.                 ctx.drawImage(avatar, avatarX, avatarY, avatarSize, avatarSize);
  141.             } catch (error) {}
  142.  
  143.             const attachment = new AttachmentBuilder(canvas.toBuffer('image/png'), { name: 'boost.png' });
  144.  
  145.             await message.reply({
  146.                 content,
  147.                 embeds: [{
  148.                     title: profile.user.global_name || profile.user.username,
  149.                     description,
  150.                     color: process.env.color,
  151.                     image: { url: "attachment://boost.png" }
  152.                 }],
  153.                 files: [attachment]
  154.             });
  155.  
  156.         }
  157.     }
  158. };
  159.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement