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] @@ -2238,9 +2238,28 @@ -// Admin command to manage user plans: /addplan +// Admin command to manage user plans: /addplan +function parsePlanDurationDays(planDuration) { + if (!planDuration) return null; + const str = String(planDuration).toLowerCase().trim(); + if (str === 'daily') return 1; + if (str === 'weekly') return 7; + if (str === 'monthly') return 30; + if (str === 'yearly') return 365; + + const match = str.match(/^(\d+)(?:day|days|d)?$/); + if (match) { + const num = parseInt(match[1]); + if (num > 0 && num <= 3650) { + return num; + } + } + return null; +} + async function assignPlanToUser(targetUserId, planDuration) { - const days = planDuration === 'daily' ? 1 : planDuration === 'weekly' ? 7 : planDuration === 'monthly' ? 30 : 365; + const days = parsePlanDurationDays(planDuration); + if (!days) throw new Error("Invalid plan duration. Supported: daily, weekly, monthly, yearly, or {day}day (e.g. 15day)"); const planExpiry = new Date(Date.now() + days * 24 * 60 * 60 * 1000); if (!process.env.DATABASE_URL) { @@ -2265,7 +2265,7 @@ ); } invalidateUserCache(targetUserId); - return planExpiry; + return { planExpiry, days }; } @@ -2285,20 +2285,27 @@ return ctx.reply("āŒ You are not authorized to run this command."); } - const args = ctx.message.text.split(' ').slice(1); - if (args.length < 2) { - return ctx.reply("šŸ’” **Usage:** `/addplan `", { parse_mode: 'Markdown' }); - } - const targetUserId = parseInt(args[0]); - const planDuration = args[1].toLowerCase(); - - if (isNaN(targetUserId) || !['daily', 'weekly', 'monthly', 'yearly'].includes(planDuration)) { - return ctx.reply("āŒ Invalid user ID or plan duration."); - } - - try { - const planExpiry = await assignPlanToUser(targetUserId, planDuration); - ctx.reply(`āœ… Activated **${planDuration.toUpperCase()}** unlimited plan for User \`${targetUserId}\` until **${planExpiry.toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' })}**`, { parse_mode: 'Markdown' }); + const args = ctx.message.text.split(' ').slice(1).filter(Boolean); + if (args.length < 2) { + return ctx.reply("šŸ’” **Usage:** `/addplan `", { parse_mode: 'Markdown' }); + } + const targetUserId = parseInt(args[0]); + const planDuration = args[1].toLowerCase().trim(); + const days = parsePlanDurationDays(planDuration); + + if (isNaN(targetUserId) || !days) { + return ctx.reply("āŒ Invalid user ID or plan duration. Usage: `/addplan `", { parse_mode: 'Markdown' }); + } + + try { + const { planExpiry } = await assignPlanToUser(targetUserId, planDuration); + const displayDuration = ['daily', 'weekly', 'monthly', 'yearly'].includes(planDuration) + ? planDuration.toUpperCase() + : `${days} DAYS (${planDuration.toUpperCase()})`; + + ctx.reply(`āœ… Activated **${displayDuration}** unlimited plan for User \`${targetUserId}\` until **${planExpiry.toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' })}**`, { parse_mode: 'Markdown' }); + + bot.telegram.sendMessage(targetUserId, `šŸŽ‰ Congratulations!\n\nYour ${displayDuration} Unlimited Plan has been activated by Admin.\n\nā³ Expires on: ${planExpiry.toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' })}\n\nEnjoy unlimited searches!`, { parse_mode: 'HTML' }).catch(() => {}); } catch (err) { ctx.reply("āŒ Error activating plan: " + err.message); } [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.