The following changes were made by the replace_file_content tool to: /root/aadharbot/index.js. If relevant, proactively run terminal commands to execute this code for the USER. Don't ask for permission. [diff_block_start] @@ -640,52 +640,31 @@ return next(); }); -bot.command('start', async (ctx) => { - try { - const userId = ctx.chat.id; - const firstName = ctx.from?.first_name || 'User'; - - let referralCode = null; - if (ctx.message.text && ctx.message.text.includes('ref_')) { - referralCode = ctx.message.text.split('ref_')[1]; - } - - const isNew = await isUserNew(userId); - if (isNew) { - await registerNewUser(userId, firstName, referralCode); - } - - await getOrCreateUserThread(ctx, userId, firstName, ctx.from?.username || ''); - - const access = await checkUserAccess(userId); - await showAuthorizedWelcomeMenu(ctx, userId, firstName, isNew, access); - } catch (error) { - console.error("Start error:", error); - } -}); - -bot.command(['pricing', 'Pricing'], async (ctx) => { - const pricingMsg = `AADHAAR BOT PRICING\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Search Cost: 1 Search = 1 Credit ${CREDIT_EMOJI}\n` + - `Credit Rate: 1 Credit = ₹60\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `AVAILABLE PACKAGES:\n` + - `• 1 Credit = ₹60\n` + - `• 5 Credits = ₹300\n` + - `• 10 Credits = ₹600\n` + - `• 20 Credits = ₹1,200\n` + - `• 50 Credits = ₹3,000\n` + - `• 100 Credits = ₹6,000\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Credits will be automatically added immediately after payment.`; - - return ctx.reply(pricingMsg, { - parse_mode: 'HTML', - ...Markup.inlineKeyboard([ - [{ text: '🛒 Buy Credits Now', callback_data: 'BUY_CREDITS_MENU', style: 'primary' }] - ]) - }); +initCommandsModule(bot, { + pool, + checkUserAccess, + formatIST: (d) => { + if (!d) return null; + try { + return new Date(d).toLocaleString('en-IN', { + timeZone: 'Asia/Kolkata', + day: '2-digit', + month: '2-digit', + year: 'numeric', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false + }); + } catch (e) { + return null; + } + }, + isUserNew, + registerNewUser, + getOrCreateUserThread, + showAuthorizedWelcomeMenu, + sessions }); bot.command(['ping', 'Ping'], async (ctx) => { @@ -704,208 +704,6 @@ }); }); -async function sendMySubscriptionDetails(ctx) { - const userId = ctx.from.id; - const access = await checkUserAccess(userId); - - const formatIST = (d) => { - if (!d) return null; - try { - return new Date(d).toLocaleString('en-IN', { - timeZone: 'Asia/Kolkata', - day: '2-digit', - month: '2-digit', - year: 'numeric', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false - }); - } catch (e) { - return null; - } - }; - - let subRecord = null; - if (pool) { - try { - const subRes = await pool.query( - `SELECT * FROM user_subscriptions WHERE telegram_id = $1 ORDER BY id DESC LIMIT 1`, - [userId] - ); - if (subRes.rows.length > 0) { - subRecord = subRes.rows[0]; - } - } catch (e) { - console.error("Error fetching user_subscriptions:", e.message); - } - } - - let statusText = ''; - let planText = ''; - let durationText = ''; - let purchaseDateText = ''; - let expiryDateText = ''; - let paymentMethodText = ''; - let amountPaidText = ''; - let searchAccessText = ''; - let buttons = []; - - if (access.isAdmin) { - statusText = 'Active (VIP Master Pass)'; - planText = 'UNLIMITED VIP'; - durationText = 'Lifetime (No Expiry)'; - purchaseDateText = formatIST(access.planStartedAt) || 'Account Activation'; - expiryDateText = 'Lifetime Access (Never Expires)'; - paymentMethodText = '👑 Admin Master Access'; - amountPaidText = '₹0 (Master Key)'; - searchAccessText = 'Unlimited Searches (Zero Deduction)'; - buttons = [ - [{ text: '🛒 View Store', callback_data: 'BUY_CREDITS_MENU', style: 'primary' }] - ]; - } else if (access.isUnlimited) { - statusText = 'Active 🟢'; - planText = 'UNLIMITED VIP'; - durationText = access.subscriptionDuration || subRecord?.duration || 'Unlimited'; - purchaseDateText = formatIST(access.planStartedAt || subRecord?.started_at) || 'Active'; - expiryDateText = formatIST(access.planExpiresAt || subRecord?.expires_at) || 'Active'; - paymentMethodText = access.subscriptionPaymentMethod || subRecord?.payment_method || 'UPI (QR Code)'; - amountPaidText = access.subscriptionAmount || subRecord?.amount || 'Paid'; - searchAccessText = 'Unlimited Searches (Zero Deduction)'; - buttons = [ - [{ text: '🛒 Extend / Buy Plan', callback_data: 'BUY_UNLIMITED_PLANS', style: 'primary' }] - ]; - } else if (subRecord || (access.planExpiresAt && access.planExpiresAt <= new Date())) { - statusText = 'Expired 🔴'; - planText = subRecord?.plan_name || 'UNLIMITED VIP'; - durationText = access.subscriptionDuration || subRecord?.duration || 'Expired'; - purchaseDateText = formatIST(access.planStartedAt || subRecord?.started_at) || 'N/A'; - expiryDateText = formatIST(access.planExpiresAt || subRecord?.expires_at) || 'Expired'; - paymentMethodText = access.subscriptionPaymentMethod || subRecord?.payment_method || 'UPI (QR Code)'; - amountPaidText = access.subscriptionAmount || subRecord?.amount || 'Paid'; - searchAccessText = `${access.credits} Credits Available (Pay Per Search)`; - buttons = [ - [{ text: '💎 Renew VIP Plan', callback_data: 'BUY_UNLIMITED_PLANS', style: 'primary' }], - [{ text: '🪙 Buy Credits', callback_data: 'BUY_CUSTOM_CREDITS', style: 'primary' }] - ]; - } else { - statusText = 'No Active Subscription ⚪'; - planText = 'Free Tier (Pay Per Search)'; - durationText = 'N/A'; - purchaseDateText = 'N/A (No subscription purchased yet)'; - expiryDateText = 'N/A'; - paymentMethodText = 'N/A'; - amountPaidText = 'N/A'; - const freeBadge = access.hasFreeSearch ? 'Available (1/1)' : 'Used Today (Resets 12:00 AM IST)'; - searchAccessText = `Daily Free: ${freeBadge} | Wallet: ${access.credits} Credits`; - buttons = [ - [{ text: '💎 Buy Unlimited VIP Plan', callback_data: 'BUY_UNLIMITED_PLANS', style: 'primary' }], - [{ text: '🪙 Buy Credits', callback_data: 'BUY_CUSTOM_CREDITS', style: 'primary' }] - ]; - } - - const subMsg = `USER SUBSCRIPTION DETAILS\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Name: ${ctx.from.first_name || 'User'}\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `User ID: ${userId}\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Status: ${statusText}\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Plan: ${planText}\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Kitne Din Ka (Duration): ${durationText}\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Kab Kharida (Purchase Date): ${purchaseDateText}\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Expiry Date: ${expiryDateText}\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Payment Method: ${paymentMethodText}\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Amount Paid: ${amountPaidText}\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Search Access: ${searchAccessText}`; - - return ctx.reply(subMsg, { - parse_mode: 'HTML', - ...Markup.inlineKeyboard(buttons) - }); -} - -bot.command(['mysubscription', 'subscription', 'plan', 'myplan'], async (ctx) => { - await sendMySubscriptionDetails(ctx); -}); - -bot.action('VIEW_MY_SUBSCRIPTION', async (ctx) => { - ctx.answerCbQuery().catch(() => {}); - await sendMySubscriptionDetails(ctx); -}); - -bot.command(['profile', 'Profile'], async (ctx) => { - const userId = ctx.from.id; - const access = await checkUserAccess(userId); - - const formatIST = (d) => { - if (!d) return null; - try { - return new Date(d).toLocaleString('en-IN', { - timeZone: 'Asia/Kolkata', - day: '2-digit', - month: '2-digit', - year: 'numeric', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false - }); - } catch (e) { - return null; - } - }; - - const planBadge = access.isUnlimited ? 'UNLIMITED VIP' : `${access.credits} Credits`; - const freeBadge = access.isUnlimited ? 'VIP Pass Active' : (access.hasFreeSearch ? '1 Free Search Available' : '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 = `Start Date: ${startStr}\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Expiry Date: Lifetime (No Expiry)\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n`; - } - - const profMsg = `USER PROFILE\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Name: ${ctx.from.first_name || 'User'}\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `User ID: ${userId}\n` + - `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + - `Tier / Plan: ${planBadge}\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' } - ] - ]) - }); -}); - bot.catch((err, ctx) => { const errMsg = (err.message || "").toLowerCase() + (err.stack || "").toLowerCase(); [diff_block_end] Please note that the above snippet only shows the MODIFIED lines from the last change. It shows up to 3 lines of unchanged lines before and after the modified lines. The actual file contents may have many more lines not shown.