Created At: 2026-11-18T04:43:54Z Completed At: 2026-11-18T04:43:54Z Command exited with code 0. Command output: const { Markup } = require('telegraf'); const { CREDIT_EMOJI } = require('../core/fonts'); const fs = require('fs'); function registerProfileCommand(bot, { pool, checkUserAccess, formatIST, sendMySubscriptionDetails }) { bot.command(['profile', 'Profile'], async (ctx) => { const userId = ctx.from.id; const access = await checkUserAccess(userId); // Fetch total searches done by this user let totalSearches = 0; if (pool) { try { const searchRes = await pool.query('SELECT COUNT(*) AS total FROM searches WHERE telegram_id = $1', [userId]); if (searchRes.rows.length > 0) { totalSearches = parseInt(searchRes.rows[0].total) || 0; } } catch (e) { console.error("Error fetching total searches:", e.message); } } else { if (fs.existsSync('searches.json')) { try { const searches = JSON.parse(fs.readFileSync('searches.json', 'utf8')); totalSearches = searches.filter(s => String(s.telegram_id) === String(userId)).length; } catch (e) {} } } // Determine User Status let userStatus = '⚡ Free Member'; if (access.role === 'owner' || access.isOwner) { userStatus = '👑 VIP Master Owner'; } else if (access.role === 'admin' || access.isAdmin) { userStatus = '🛡️ VIP Admin'; } else if (access.isUnlimited) { userStatus = '💎 VIP Active Member'; } else if (access.credits > 0) { userStatus = '🪙 Paid Credit Member'; } // Subscription Status let subStatus = 'Inactive ⚪ (Pay Per Search)'; if (access.role === 'owner' || access.isOwner) { subStatus = 'Active 🟢 (Master Owner VIP)'; } else if (access.role === 'admin' || access.isAdmin) { subStatus = 'Active 🟢 (Admin VIP)'; } else if (access.isUnlimited) { subStatus = 'Active 🟢'; } else if (access.planExpiresAt && access.planExpiresAt <= new Date()) { subStatus = 'Expired 🔴'; } const planBadge = access.isUnlimited ? 'UNLIMITED VIP' : `${access.credits} Credits`; const freeBadge = access.isUnlimited ? 'VIP Pass Active' : (access.hasFreeSearch ? 'Available (1/1)' : 'Used Today (Resets 12:00 AM IST)'); let datesText = ''; if (access.isUnlimited) { const startStr = formatIST(access.planStartedAt) || formatIST(access.createdAt) || 'Active'; const expStr = formatIST(access.planExpiresAt) || 'Lifetime'; datesText = `Start Date: ${startStr}\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + `Expiry Date: ${expStr}\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n`; } else { const startStr = formatIST(access.createdAt) || formatIST(new Date()); datesText = `Joined Date: ${startStr}\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n`; } const roleName = (access.role || (access.isAdmin ? 'admin' : 'user')).toUpperCase(); const roleBadge = roleName === 'OWNER' ? '👑 OWNER' : (roleName === 'ADMIN' ? '🛡️ ADMIN' : '👤 USER'); const profMsg = `USER PROFILE & ACCOUNT DETAILS\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + `Name: ${ctx.from.first_name || 'User'}\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + `User ID: ${userId}\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + `Account Role: ${roleBadge}\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + `User Status: ${userStatus}\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + `Total Searches Done: ${totalSearches} Searches\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + `Subscription Status: ${subStatus}\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + `Current Tier: ${planBadge}\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + `Wallet Balance: ${access.credits} Credits ${CREDIT_EMOJI}\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + `Daily Free Search: ${freeBadge}\n` + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + `${datesText}` + `Search Cost: 1 Search = 1 Credit ${CREDIT_EMOJI}`; return ctx.reply(profMsg, { parse_mode: 'HTML', ...Markup.inlineKeyboard([ [ { text: '📋 Subscription Details', callback_data: 'VIEW_MY_SUBSCRIPTION', style: 'primary' }, { text: '🛒 Buy Now', callback_data: 'BUY_CREDITS_MENU', style: 'primary' } ] ]) }); }); } module.exports = { registerProfileCommand };