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] @@ -1682,19 +1682,55 @@ ctx.reply(msg, { parse_mode: 'HTML' }); }); -bot.command('cancel', (ctx) => { - const userId = ctx.chat.id; +bot.command('cancel', async (ctx) => { + const userId = ctx.from?.id || ctx.chat?.id; + let cleared = false; + + // 1. Clear active search/payment session if (sessions[userId]) { delete sessions[userId]; - const msg = `❌ Process Cancelled / प्रक्रिया निरस्त\n\n` + - `
🚫 This process is cancelled. Your credit has not been deducted.\n\n` + - `⚠️ Aapka process cancel kar diya gaya hai. Koi credit nahi kata hai.
`; - ctx.reply(msg, { parse_mode: 'HTML' }); - - - } else { - ctx.reply("💡 No active process is currently running.", { parse_mode: 'HTML' }); - } + cleared = true; + } + + // 2. Clear pending referral state if any + if (pendingReferrals && pendingReferrals[userId]) { + delete pendingReferrals[userId]; + cleared = true; + } + + // 3. Clear pending UTR / payment queue for this user if exists + try { + const PAYMENTS_FILE = 'payments.json'; + if (fs.existsSync(PAYMENTS_FILE)) { + const payments = JSON.parse(fs.readFileSync(PAYMENTS_FILE, 'utf8') || '[]'); + const initialLen = payments.length; + const filtered = payments.filter(p => p.userId !== userId); + if (filtered.length !== initialLen) { + fs.writeFileSync(PAYMENTS_FILE, JSON.stringify(filtered, null, 2)); + cleared = true; + } + } + } catch (e) { + console.error("Cancel payment cleanup error:", e.message); + } + + // 4. Invalidate cache to ensure fresh state + if (typeof invalidateUserCache === 'function') { + invalidateUserCache(userId); + } + + const cancelMsg = `❌ ALL REQUESTS CLEARED / सभी अनुरोध निरस्त ❌\n` + + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + + `
🚫 Your active operation, payment session, and input requests have been completely cancelled.\n\n` + + `⚠️ Aapka active search, payment request aur sabhi inputs successfully clear kar diye gaye hain. Koi credit deduct nahi hua hai.
\n` + + `━━━━━━━━━━━━━━━━━━━━━━━━━━\n` + + `👇 Main menu me jane ke liye /start dabayein.`; + + const keyboard = Markup.inlineKeyboard([ + [{ text: '🏠 Main Menu', callback_data: 'MAIN_MENU_REFRESH', style: 'primary' }] + ]); + + await ctx.reply(cancelMsg, { parse_mode: 'HTML', ...keyboard }); }); bot.command('api', (ctx) => { [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.