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]
@@ -704,7 +704,144 @@
});
});
-bot.command(['profile', 'Profile', 'mysubscription', 'subscription', 'plan', 'myplan'], async (ctx) => {
+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);
@@ -744,7 +744,7 @@
`━━━━━━━━━━━━━━━━━━━━━━━━━━\n`;
}
- const subMsg = `USER PROFILE\n` +
+ const profMsg = `USER PROFILE\n` +
`━━━━━━━━━━━━━━━━━━━━━━━━━━\n` +
`Name: ${ctx.from.first_name || 'User'}\n` +
`━━━━━━━━━━━━━━━━━━━━━━━━━━\n` +
@@ -756,10 +756,13 @@
`${datesText}` +
`Search Cost: 1 Search = 1 Credit ${CREDIT_EMOJI}`;
- return ctx.reply(subMsg, {
- parse_mode: 'HTML',
- ...Markup.inlineKeyboard([
- [{ text: '🛒 Buy Now', callback_data: 'BUY_CREDITS_MENU', style: 'primary' }]
+ 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' }
+ ]
])
});
});
[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.