const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); module.exports = { data: new SlashCommandBuilder() .setName('prestige') .setDescription('Prestige system - reset your level for permanent rewards') .addSubcommand(sub => sub.setName('view') .setDescription('View your prestige status and rewards') .addUserOption(opt => opt.setName('user') .setDescription('User to check') .setRequired(false) ) ) .addSubcommand(sub => sub.setName('up') .setDescription('Prestige up! Reset your XP for permanent rewards') ) .addSubcommand(sub => sub.setName('rewards') .setDescription('View all prestige rewards') ), async execute(interaction, supabase, client) { if (!supabase) { return interaction.reply({ content: 'Database not configured.', ephemeral: true }); } const sub = interaction.options.getSubcommand(); if (sub === 'view') { return viewPrestige(interaction, supabase); } else if (sub === 'up') { return prestigeUp(interaction, supabase, client); } else if (sub === 'rewards') { return viewRewards(interaction); } }, }; async function viewPrestige(interaction, supabase) { const target = interaction.options.getUser('user') || interaction.user; await interaction.deferReply(); try { const { data: link } = await supabase .from('discord_links') .select('user_id') .eq('discord_id', target.id) .single(); if (!link) { return interaction.editReply({ embeds: [ new EmbedBuilder() .setColor(0xff6b6b) .setDescription(`${target.id === interaction.user.id ? 'You are' : `${target.tag} is`} not linked to AeThex.`) ] }); } const { data: profile } = await supabase .from('user_profiles') .select('username, xp, prestige_level, total_xp_earned') .eq('id', link.user_id) .single(); const prestige = profile?.prestige_level || 0; const totalXpEarned = profile?.total_xp_earned || profile?.xp || 0; const currentXp = profile?.xp || 0; const level = Math.floor(Math.sqrt(currentXp / 100)); const prestigeInfo = getPrestigeInfo(prestige); const nextPrestigeReq = getPrestigeRequirement(prestige + 1); const canPrestige = level >= 50; const embed = new EmbedBuilder() .setColor(prestigeInfo.color) .setTitle(`${prestigeInfo.icon} ${profile?.username || target.tag}'s Prestige`) .setThumbnail(target.displayAvatarURL({ size: 256 })) .addFields( { name: 'Prestige Level', value: `**${prestigeInfo.name}** (${prestige})`, inline: true }, { name: 'XP Bonus', value: `+${prestige * 5}%`, inline: true }, { name: 'Current Level', value: `${level}`, inline: true }, { name: 'Total XP Earned', value: totalXpEarned.toLocaleString(), inline: true }, { name: 'Current XP', value: currentXp.toLocaleString(), inline: true }, { name: 'Can Prestige?', value: canPrestige ? 'āœ… Yes (Level 50+)' : `āŒ Need Level 50 (${level}/50)`, inline: true } ) .setFooter({ text: `Next prestige requirement: Level 50` }) .setTimestamp(); if (prestige > 0) { embed.addFields({ name: 'šŸ† Prestige Rewards Unlocked', value: getUnlockedRewards(prestige).join('\n') || 'None yet', inline: false }); } await interaction.editReply({ embeds: [embed] }); } catch (error) { console.error('Prestige view error:', error); await interaction.editReply({ content: 'Failed to fetch prestige data.' }); } } async function prestigeUp(interaction, supabase, client) { await interaction.deferReply(); try { const { data: link } = await supabase .from('discord_links') .select('user_id') .eq('discord_id', interaction.user.id) .single(); if (!link) { return interaction.editReply({ embeds: [ new EmbedBuilder() .setColor(0xff6b6b) .setDescription('You must link your Discord to AeThex first. Use `/verify` to link.') ] }); } const { data: profile } = await supabase .from('user_profiles') .select('username, xp, prestige_level, total_xp_earned') .eq('id', link.user_id) .single(); const currentXp = profile?.xp || 0; const level = Math.floor(Math.sqrt(currentXp / 100)); const prestige = profile?.prestige_level || 0; const totalEarned = profile?.total_xp_earned || currentXp; if (level < 50) { return interaction.editReply({ embeds: [ new EmbedBuilder() .setColor(0xff6b6b) .setTitle('āŒ Cannot Prestige') .setDescription(`You need to reach **Level 50** to prestige.\nCurrent level: **${level}**/50`) ] }); } if (prestige >= 10) { return interaction.editReply({ embeds: [ new EmbedBuilder() .setColor(0xffd700) .setTitle('šŸ‘‘ Maximum Prestige!') .setDescription('You have reached the maximum prestige level! You are a true legend.') ] }); } const newPrestige = prestige + 1; const newPrestigeInfo = getPrestigeInfo(newPrestige); const xpBonus = newPrestige * 5; const confirmEmbed = new EmbedBuilder() .setColor(0xf59e0b) .setTitle('āš ļø Confirm Prestige') .setDescription(`Are you sure you want to prestige?\n\n**What will happen:**\n• Your XP will reset to **0**\n• Your level will reset to **0**\n• You gain **Prestige ${newPrestige}** (${newPrestigeInfo.name})\n• You get a permanent **+${xpBonus}%** XP bonus\n• You unlock new **prestige rewards**\n\n**Current Stats:**\n• Level: ${level}\n• XP: ${currentXp.toLocaleString()}`) .setFooter({ text: 'This action cannot be undone!' }); const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setCustomId('prestige_confirm') .setLabel('✨ Prestige Up!') .setStyle(ButtonStyle.Success), new ButtonBuilder() .setCustomId('prestige_cancel') .setLabel('Cancel') .setStyle(ButtonStyle.Secondary) ); const response = await interaction.editReply({ embeds: [confirmEmbed], components: [row] }); try { const confirmation = await response.awaitMessageComponent({ filter: i => i.user.id === interaction.user.id, time: 60000 }); if (confirmation.customId === 'prestige_confirm') { const { error } = await supabase .from('user_profiles') .update({ xp: 0, prestige_level: newPrestige }) .eq('id', link.user_id); if (error) { console.error('Prestige update error:', error); return confirmation.update({ embeds: [ new EmbedBuilder() .setColor(0xff0000) .setDescription('Failed to prestige. Please try again.') ], components: [] }); } const successEmbed = new EmbedBuilder() .setColor(newPrestigeInfo.color) .setTitle(`${newPrestigeInfo.icon} Prestige ${newPrestige} Achieved!`) .setDescription(`Congratulations! You are now **${newPrestigeInfo.name}**!\n\n**Rewards Unlocked:**\n${getNewRewards(newPrestige).join('\n')}`) .addFields( { name: 'XP Bonus', value: `+${xpBonus}%`, inline: true }, { name: 'Total XP Earned (All Time)', value: totalEarned.toLocaleString(), inline: true } ) .setThumbnail(interaction.user.displayAvatarURL({ size: 256 })) .setTimestamp(); await confirmation.update({ embeds: [successEmbed], components: [] }); } else { await confirmation.update({ embeds: [ new EmbedBuilder() .setColor(0x6b7280) .setDescription('Prestige cancelled.') ], components: [] }); } } catch (e) { await interaction.editReply({ embeds: [ new EmbedBuilder() .setColor(0x6b7280) .setDescription('Prestige request timed out.') ], components: [] }); } } catch (error) { console.error('Prestige up error:', error); await interaction.editReply({ content: 'Failed to process prestige.' }); } } async function viewRewards(interaction) { const embed = new EmbedBuilder() .setColor(0x7c3aed) .setTitle('✨ Prestige Rewards') .setDescription('Each prestige level grants permanent rewards!\n\n**Requirements:** Level 50 to prestige') .addFields( { name: '⭐ Prestige 1 - Bronze', value: '+5% XP bonus\nšŸ·ļø Bronze Prestige badge', inline: true }, { name: '⭐ Prestige 2 - Silver', value: '+10% XP bonus\nšŸ·ļø Silver Prestige badge', inline: true }, { name: '⭐ Prestige 3 - Gold', value: '+15% XP bonus\nšŸ·ļø Gold Prestige badge', inline: true }, { name: 'šŸ’Ž Prestige 4 - Platinum', value: '+20% XP bonus\nšŸ·ļø Platinum badge\nšŸŽ Bonus daily XP', inline: true }, { name: 'šŸ’Ž Prestige 5 - Diamond', value: '+25% XP bonus\nšŸ·ļø Diamond badge\nā±ļø Reduced cooldowns', inline: true }, { name: 'šŸ”„ Prestige 6 - Master', value: '+30% XP bonus\nšŸ·ļø Master badge\nšŸŽÆ XP milestone rewards', inline: true }, { name: 'šŸ”„ Prestige 7 - Grandmaster', value: '+35% XP bonus\nšŸ·ļø Grandmaster badge\nšŸ’« Special profile effects', inline: true }, { name: 'šŸ‘‘ Prestige 8 - Champion', value: '+40% XP bonus\nšŸ·ļø Champion badge\nšŸ† Leaderboard priority', inline: true }, { name: 'šŸ‘‘ Prestige 9 - Legend', value: '+45% XP bonus\nšŸ·ļø Legend badge\n✨ Legendary profile aura', inline: true }, { name: '🌟 Prestige 10 - Mythic', value: '+50% XP bonus\nšŸ·ļø Mythic badge\n🌈 All prestige perks!', inline: true } ) .setFooter({ text: 'Use /prestige up when you reach Level 50!' }) .setTimestamp(); await interaction.reply({ embeds: [embed] }); } function getPrestigeInfo(level) { const prestiges = [ { name: 'Unprestiged', icon: '⚪', color: 0x6b7280 }, { name: 'Bronze', icon: 'šŸ„‰', color: 0xcd7f32 }, { name: 'Silver', icon: '🄈', color: 0xc0c0c0 }, { name: 'Gold', icon: 'šŸ„‡', color: 0xffd700 }, { name: 'Platinum', icon: 'šŸ’Ž', color: 0xe5e4e2 }, { name: 'Diamond', icon: 'šŸ’ ', color: 0xb9f2ff }, { name: 'Master', icon: 'šŸ”„', color: 0xff4500 }, { name: 'Grandmaster', icon: 'āš”ļø', color: 0x9400d3 }, { name: 'Champion', icon: 'šŸ‘‘', color: 0xffd700 }, { name: 'Legend', icon: '🌟', color: 0xff69b4 }, { name: 'Mythic', icon: '🌈', color: 0x7c3aed } ]; return prestiges[Math.min(level, 10)] || prestiges[0]; } function getPrestigeRequirement(level) { return 50; } function getUnlockedRewards(prestige) { const rewards = []; if (prestige >= 1) rewards.push('šŸ„‰ Bronze Prestige badge'); if (prestige >= 2) rewards.push('🄈 Silver Prestige badge'); if (prestige >= 3) rewards.push('šŸ„‡ Gold Prestige badge'); if (prestige >= 4) rewards.push('šŸ’Ž Platinum badge + Bonus daily XP'); if (prestige >= 5) rewards.push('šŸ’  Diamond badge + Reduced cooldowns'); if (prestige >= 6) rewards.push('šŸ”„ Master badge + XP milestones'); if (prestige >= 7) rewards.push('āš”ļø Grandmaster badge + Profile effects'); if (prestige >= 8) rewards.push('šŸ‘‘ Champion badge + Leaderboard priority'); if (prestige >= 9) rewards.push('🌟 Legend badge + Legendary aura'); if (prestige >= 10) rewards.push('🌈 Mythic badge + All perks unlocked'); return rewards; } function getNewRewards(prestige) { const rewardMap = { 1: ['šŸ„‰ Bronze Prestige badge', '+5% XP bonus on all XP gains'], 2: ['🄈 Silver Prestige badge', '+10% XP bonus on all XP gains'], 3: ['šŸ„‡ Gold Prestige badge', '+15% XP bonus on all XP gains'], 4: ['šŸ’Ž Platinum badge', '+20% XP bonus', 'šŸŽ +25 bonus daily XP'], 5: ['šŸ’  Diamond badge', '+25% XP bonus', 'ā±ļø 10% reduced XP cooldowns'], 6: ['šŸ”„ Master badge', '+30% XP bonus', 'šŸŽÆ XP milestone rewards'], 7: ['āš”ļø Grandmaster badge', '+35% XP bonus', 'šŸ’« Special profile effects'], 8: ['šŸ‘‘ Champion badge', '+40% XP bonus', 'šŸ† Leaderboard priority display'], 9: ['🌟 Legend badge', '+45% XP bonus', '✨ Legendary profile aura'], 10: ['🌈 Mythic badge', '+50% XP bonus', '🌟 All prestige perks unlocked!'] }; return rewardMap[prestige] || []; }