Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require('axios');
- const { loadImage, createCanvas } = require('canvas');
- const getProfile = require('../../managers/getProfile');
- const drawCircle = require('../../managers/drawCircle');
- const { AttachmentBuilder } = require('discord.js');
- const path = require('path');
- const fs = require('fs');
- module.exports = {
- name: 'boost',
- aliases: ['b', 'booster', 'myboost','بوست','بست','ب'],
- description: 'Show your/someone\'s boost badge information',
- async execute(message) {
- const user = message.mentions.users.first() || message.author;
- if (user.bot) {
- return message.reply({
- content: 'This command cannot work with bots!',
- ephemeral: true
- });
- }
- const profile = await getProfile(user.id);
- if (!profile) {
- return message.reply({
- content: 'Cannot find this user in my servers!',
- ephemeral: true
- });
- }
- if (!profile.premium_guild_since) {
- return message.reply({
- content: 'This user doesn\'t have a boost badge!',
- ephemeral: true
- });
- }
- const guild = message.guild;
- const date = new Date(profile.premium_guild_since);
- const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
- const getTimeAfterMonths = (monthsToAdd) => {
- const currentDate = new Date(date.getTime());
- currentDate.setMonth(currentDate.getMonth() + monthsToAdd);
- return currentDate.getTime();
- };
- const nextLevel =
- getTimeAfterMonths(2) > Date.now()
- ? 2
- : getTimeAfterMonths(3) > Date.now()
- ? 3
- : getTimeAfterMonths(6) > Date.now()
- ? 4
- : getTimeAfterMonths(9) > Date.now()
- ? 5
- : getTimeAfterMonths(12) > Date.now()
- ? 6
- : getTimeAfterMonths(15) > Date.now()
- ? 7
- : getTimeAfterMonths(18) > Date.now()
- ? 8
- : getTimeAfterMonths(24) > Date.now()
- ? 9
- : null;
- const currentLevel = (nextLevel || 10) - 1;
- const badges = ["", "", "", "", "", "", "", "", ""].map((_, index) => {
- const emoji = guild.emojis.cache.find((emot) => emot.name == `guild_booster_lvl${index + 1}`);
- return `<:${emoji.name}:${emoji.id}>`;
- });
- const nextBadge = badges[(nextLevel || 10) - 1];
- const currentBadge = badges[currentLevel - 1];
- let description = "";
- let content = "";
- const levelsMonths = { 2: 2, 3: 3, 4: 6, 5: 9, 6: 12, 7: 15, 8: 18, 9: 24 };
- const form = new FormData();
- if (currentLevel == 9) {
- content = `${currentBadge} Level ${currentLevel} (Max) ${currentBadge}`;
- description = `${user.id == message.author.id
- ? "**You**, have"
- : `**${profile.user.username}**, has`} level 9 (Max)\nBoosted: <t:${Math.floor(date.getTime() / 1000)}:R> | ${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
- const bg = await loadImage(path.resolve(__dirname, '../../images', `9.png`));
- const canvas = createCanvas(bg.width, bg.height);
- const ctx = canvas.getContext("2d");
- ctx.drawImage(bg, 0, 0, canvas.width, canvas.height);
- ctx.font = "16px Arial";
- ctx.fillStyle = "white";
- ctx.fillText(user.username, 50, 202);
- const avatarX = 30.5;
- const avatarY = 188;
- const avatarSize = 17;
- const attachment = new AttachmentBuilder(canvas.toBuffer('image/png'), { name: 'boost.png' });
- await message.reply({
- content,
- embeds: [{
- title: `${profile.user.global_name || profile.user.username}`,
- description,
- color: process.env.color,
- image: { url: "attachment://boost.png" }
- }],
- files: [attachment]
- });
- } else {
- content = `${currentBadge} Level ${currentLevel} ${currentBadge}`;
- const nextTimestamp = getTimeAfterMonths(levelsMonths[nextLevel]);
- const timestamp = nextTimestamp - Date.now();
- const remainingTime = [
- Math.floor(timestamp / (1000 * 60 * 60 * 24)),
- Math.floor(timestamp / (1000 * 60 * 60)) % 24,
- Math.floor(timestamp / (1000 * 60)) % 60,
- Math.floor(timestamp / 1000) % 60
- ].map((value, index) => `${value}${["d", "h", "m", "s"][index]}`)
- .join(', ');
- description = `${user.id == message.author.id
- ? "**You**, have"
- : `**${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}`;
- const bgPath = path.resolve(__dirname, '../../images', `${currentLevel}.png`);
- if (!fs.existsSync(bgPath)) return console.log('❌ الملف غير موجود:', bgPath);
- const bg = await loadImage(bgPath);
- const canvas = createCanvas(bg.width, bg.height);
- const ctx = canvas.getContext("2d");
- ctx.drawImage(bg, 0, 0, canvas.width, canvas.height);
- ctx.font = "16px Arial";
- ctx.fillStyle = "white";
- ctx.fillText(profile.user.global_name || user.username, 50, 202);
- const avatarX = 30.5;
- const avatarY = 188;
- const avatarSize = 17;
- try {
- const avatar = await drawCircle({
- image: user.displayAvatarURL({ format: 'png', size: 4096 })
- });
- ctx.drawImage(avatar, avatarX, avatarY, avatarSize, avatarSize);
- } catch (error) {}
- const attachment = new AttachmentBuilder(canvas.toBuffer('image/png'), { name: 'boost.png' });
- await message.reply({
- content,
- embeds: [{
- title: profile.user.global_name || profile.user.username,
- description,
- color: process.env.color,
- image: { url: "attachment://boost.png" }
- }],
- files: [attachment]
- });
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement