Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { AttachmentBuilder } = require('discord.js');
- const getProfile = require('../../managers/getProfile');
- const path = require('path');
- const fs = require('fs');
- module.exports = {
- name: 'nitro',
- aliases: ['n', 'nitr', 'mynitro'],
- description: 'Show Nitro subscription info',
- async execute(message) {
- const user = message.mentions.users.first() || message.author;
- if (user.bot)
- return message.reply({ content: 'Bots cannot have Nitro!', ephemeral: true });
- const profile = await getProfile(user.id);
- if (!profile || !profile.premium_since)
- return message.reply({ content: 'No Nitro subscription found.', ephemeral: true });
- const since = new Date(profile.premium_since);
- const now = Date.now();
- const levels = [
- { name: 'Normal', months: 0, file: 'beta-10.png' },
- { name: 'Bronze', months: 1, file: 'beta-11.png' },
- { name: 'Silver', months: 3, file: 'beta-12.png' },
- { name: 'Gold', months: 6, file: 'beta-13.png' },
- { name: 'Platinum', months: 12, file: 'beta-14.png' },
- { name: 'Diamond', months: 24, file: 'beta-15.png' },
- { name: 'Emerald', months: 36, file: 'beta-16.png' },
- { name: 'Ruby', months: 60, file: 'beta-17.png' },
- { name: 'Opal', months: 72, file: 'beta-18.png' },
- ];
- const nextIndex = levels.findIndex(l =>
- since.getTime() + l.months * 30 * 24 * 60 * 60 * 1000 > now
- );
- const isMax = nextIndex === -1;
- const currentIndex = isMax ? levels.length - 1 : Math.max(0, nextIndex - 1);
- const nextLevel = isMax ? null : levels[nextIndex];
- const currentLevel = levels[currentIndex];
- const cbadge = message.guild.emojis.cache.find(e =>
- currentLevel.months === 0
- ? e.name === 'premium'
- : e.name === `premium_tenure_${currentLevel.months}_month_v2`
- );
- const nbadge = nextLevel && message.guild.emojis.cache.find(e =>
- e.name === `premium_tenure_${nextLevel.months}_month_v2`
- );
- const relSince = Math.floor(since.getTime() / 1000);
- let desc = `${
- user.id === message.author.id ? 'You started' : `${profile.user.username} started`
- } Nitro <t:${relSince}:R> (Tier: ${currentLevel.name})`;
- if (!isMax && nextLevel) {
- const nextTs = Math.floor(
- since.getTime() + nextLevel.months * 30 * 24 * 60 * 60 * 1000
- ) / 1000;
- desc += `\nNext: ${nextLevel.name} ${nbadge} in <t:${Math.floor(nextTs)}:R>`;
- } else {
- desc += ' (Max tier)';
- }
- const imageFile = currentLevel.file;
- const imagePath = path.resolve(__dirname, '../../images', imageFile);
- if (!fs.existsSync(imagePath)) console.error('Missing image:', imagePath);
- const attachment = new AttachmentBuilder(imagePath, { name: imageFile });
- return message.reply({
- content: `${cbadge || ''} ${currentLevel.name}${isMax ? ' (Max)' : ''} ${cbadge || ''}`,
- embeds: [
- {
- title: profile.user.global_name || profile.user.username,
- description: desc,
- color: process.env.color,
- image: { url: `attachment://${imageFile}` },
- timestamp: new Date().toISOString(),
- footer: {
- text: message.guild.name,
- icon_url: message.guild.iconURL(),
- },
- },
- ],
- files: [attachment],
- });
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement