The command exited with code 0.
Output:
bot.action(/^BUY_PLAN_(\w+)_(\d+)$/, async (ctx) => {
ctx.answerCbQuery().catch(() => { });
const planType = ctx.match[1];
const amount = parseInt(ctx.match[2]);
const userId = ctx.from.id;
let plans = [];
try {
const fs = require('fs');
plans = JSON.parse(fs.readFileSync(__dirname + '/plans.json', 'utf8'));
} catch(e) {
plans = [];
}
let planLabel = planType.charAt(0).toUpperCase() + planType.slice(1);
const matchedPlan = plans.find(p => p.type === planType);
if (matchedPlan) planLabel = matchedPlan.label.replace(' š', '');
console.log(`[PAYMENT] User ${userId} selected ${planLabel} Plan (ā¹${amount})`);
if (amount > 20000) {
return ctx.reply(`š ${planLabel} Plan\n\nFor amounts above ā¹20,000, please directly DM our admin @EverythingBypass to arrange the payment and activation.\n\nš Click here to contact @EverythingBypass`, {
parse_mode: 'HTML',
disable_web_page_preview: true
});
}
try {
if (process.env.DATABASE_URL) {
const userRes = await pool.query('SELECT credits FROM users WHERE telegram_id = $1', [userId]);
if (userRes.rows.length > 0) {
const currentCredits = Number(userRes.rows[0].credits || 0);
if (currentCredits >= amount) {
const planDurations = {
'daily': 24 * 60 * 60 * 1000,
'weekly': 7 * 24 * 60 * 60 * 1000,
'monthly': 30 * 24 * 60 * 60 * 1000,
'2months': 60 * 24 * 60 * 60 * 1000,
'yearly': 365 * 24 * 60 * 60 * 1000,
'lifetime': 10 * 365 * 24 * 60 * 60 * 1000
};
const duration = planDurations[planType] || (30 * 24 * 60 * 60 * 1000);
const planExpiresAt = new Date(Date.now() + duration);
const planExpiryStr = planExpiresAt.toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' });
await pool.query(
`UPDATE users SET credits = credits - $1, plan_type = 'unlimited', plan_expires_at = $2, plan_started_at = NOW(), updated_at = NOW() WHERE telegram_id = $3`,
[amount, planExpiresAt, userId]
);
return ctx.reply(`ā
Payment Successful! (Paid from Wallet)\n\n` +
`š You have successfully purchased the ${planLabel} Plan for ā¹${amount}.\n` +
`ā³ Plan Expires: ${planExpiryStr}\n\n` +
`Enjoy your unlimited searches!`, { parse_mode: 'HTML' });
}
}
}
} catch (e) {
console.error("Wallet deduction error:", e);
}
const loadMsg = await ctx.reply(`ā³ Generating secure payment QR for ${planLabel} Plan (ā¹${amount})... Please wait.`, { parse_mode: 'HTML' });
try {
await generatePaymentRequest(ctx, userId, amount, planType, loadMsg);
} catch (err) {
console.error("Plan purchase generation error:", err.message);
ctx.reply(`ā Failed to generate payment: ${err.message}`, { parse_mode: 'HTML' });
}
});