const { SlashCommandBuilder, EmbedBuilder } = require("discord.js"); module.exports = { data: new SlashCommandBuilder() .setName("profile") .setDescription("View your AeThex profile in Discord") .addUserOption(option => option.setName('user') .setDescription('User to view profile of') .setRequired(false) ), async execute(interaction, supabase) { if (!supabase) { return interaction.reply({ content: "This feature requires Supabase to be configured.", ephemeral: true }); } await interaction.deferReply(); const targetUser = interaction.options.getUser('user') || interaction.user; try { const { data: link } = await supabase .from("discord_links") .select("user_id, primary_arm") .eq("discord_id", targetUser.id) .single(); if (!link) { const embed = new EmbedBuilder() .setColor(0xff6b6b) .setTitle("โŒ Not Linked") .setThumbnail(targetUser.displayAvatarURL({ size: 256 })) .setDescription( targetUser.id === interaction.user.id ? "You must link your Discord account to AeThex first.\nUse `/verify` to get started." : `${targetUser.tag} hasn't linked their Discord account to AeThex yet.` ); return await interaction.editReply({ embeds: [embed] }); } const { data: profile } = await supabase .from("user_profiles") .select("*") .eq("id", link.user_id) .single(); if (!profile) { const embed = new EmbedBuilder() .setColor(0xff6b6b) .setTitle("โŒ Profile Not Found") .setDescription("The AeThex profile could not be found."); return await interaction.editReply({ embeds: [embed] }); } const armEmojis = { labs: "๐Ÿงช", gameforge: "๐ŸŽฎ", corp: "๐Ÿ’ผ", foundation: "๐Ÿค", devlink: "๐Ÿ’ป", }; const armColors = { labs: 0x22c55e, gameforge: 0xf97316, corp: 0x3b82f6, foundation: 0xec4899, devlink: 0x8b5cf6, }; const xp = profile.xp || 0; const prestige = profile.prestige_level || 0; const level = Math.floor(Math.sqrt(xp / 100)); const currentLevelXp = level * level * 100; const nextLevelXp = (level + 1) * (level + 1) * 100; const progressXp = xp - currentLevelXp; const neededXp = nextLevelXp - currentLevelXp; const progressPercent = Math.min(100, Math.floor((progressXp / neededXp) * 100)); const progressBar = createProgressBar(progressPercent); const prestigeInfo = getPrestigeInfo(prestige); const badges = profile.badges || []; const badgeDisplay = badges.length > 0 ? badges.map(b => getBadgeEmoji(b)).join(' ') : 'No badges yet'; // Validate avatar URL - must be http/https, not base64 let avatarUrl = targetUser.displayAvatarURL({ size: 256 }); if (profile.avatar_url && profile.avatar_url.startsWith('http')) { avatarUrl = profile.avatar_url; } const embed = new EmbedBuilder() .setColor(armColors[link.primary_arm] || 0x7c3aed) .setAuthor({ name: `${profile.full_name || profile.username || 'AeThex User'}`, iconURL: targetUser.displayAvatarURL({ size: 64 }) }) .setThumbnail(avatarUrl) .setDescription(profile.bio || '*No bio set*') .addFields( { name: "๐Ÿ‘ค Username", value: `\`${profile.username || 'N/A'}\``, inline: true, }, { name: `${armEmojis[link.primary_arm] || "โš”๏ธ"} Realm`, value: capitalizeFirst(link.primary_arm) || "Not set", inline: true, }, { name: "๐Ÿ“Š Role", value: formatRole(profile.user_type), inline: true, }, { name: `${prestigeInfo.icon} Prestige`, value: prestige > 0 ? `**${prestigeInfo.name}** (P${prestige}) +${prestige * 5}% XP` : 'Not prestiged', inline: true, }, { name: `๐Ÿ“ˆ Level ${level}`, value: `${progressBar}\n\`${xp.toLocaleString()}\` / \`${nextLevelXp.toLocaleString()}\` XP`, inline: false, }, { name: "๐Ÿ† Badges", value: badgeDisplay, inline: false, } ) .addFields({ name: "๐Ÿ”— Links", value: `[View Full Profile](https://aethex.dev/creators/${profile.username}) โ€ข [AeThex Platform](https://aethex.dev)`, }) .setFooter({ text: `AeThex | ${targetUser.tag}`, iconURL: 'https://aethex.dev/favicon.ico' }) .setTimestamp(); if (profile.banner_url) { embed.setImage(profile.banner_url); } await interaction.editReply({ embeds: [embed] }); } catch (error) { console.error("Profile command error:", error); const embed = new EmbedBuilder() .setColor(0xff0000) .setTitle("โŒ Error") .setDescription("Failed to fetch profile. Please try again."); await interaction.editReply({ embeds: [embed] }); } }, }; function createProgressBar(percent) { const filled = Math.floor(percent / 10); const empty = 10 - filled; return `${'โ–“'.repeat(filled)}${'โ–‘'.repeat(empty)} ${percent}%`; } function capitalizeFirst(str) { if (!str) return str; return str.charAt(0).toUpperCase() + str.slice(1); } function formatRole(role) { if (!role) return 'Member'; return role.split('_').map(capitalizeFirst).join(' '); } function getBadgeEmoji(badge) { const badgeMap = { 'verified': 'โœ…', 'founder': '๐Ÿ‘‘', 'early_adopter': '๐ŸŒŸ', 'contributor': '๐Ÿ’Ž', 'creator': '๐ŸŽจ', 'developer': '๐Ÿ’ป', 'moderator': '๐Ÿ›ก๏ธ', 'partner': '๐Ÿค', 'premium': '๐Ÿ’ซ', 'top_poster': '๐Ÿ“', 'helpful': 'โค๏ธ', 'bug_hunter': '๐Ÿ›', 'event_winner': '๐Ÿ†', }; return badgeMap[badge] || `[${badge}]`; } 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]; }