The following changes were made by the replace_file_content tool to: /root/aadharbot/admin/freemode.js. If relevant, proactively run terminal commands to execute this code for the USER. Don't ask for permission. [diff_block_start] @@ -214,13 +214,15 @@ } function registerFreeModeCommands(bot, deps) { - const { pool, isUserAdmin, redisClient, getTodayISTDateStr } = deps; + const { pool, isUserOwner, redisClient, getTodayISTDateStr } = deps; + const { logAdminAction } = require('./actions'); // Toggle Free Mode Handler bot.action('ADMIN_TOGGLE_FREEMODE', async (ctx) => { - const isOwner = await isUserAdmin(ctx.from.id, pool); - if (!isOwner) return ctx.answerCbQuery("Access denied!", { show_alert: true }).catch(() => {}); - + const isOwner = await isUserOwner(ctx.from.id, pool); + if (!isOwner) return ctx.answerCbQuery("❌ Access denied! Only Owner can toggle Free Mode.", { show_alert: true }).catch(() => {}); + + let newStatus = ''; if (freeModeState.active) { freeModeState.active = false; freeModeState.expiresAt = null; @@ -227,3 +227,4 @@ + newStatus = 'Disabled'; await ctx.answerCbQuery("Free Mode Disabled!", { show_alert: true }).catch(() => {}); } else { freeModeState.active = true; @@ -230,7 +230,16 @@ saveFreeModeState(); + newStatus = 'Enabled (Indefinite)'; await ctx.answerCbQuery("Free Mode Enabled (Indefinite)!", { show_alert: true }).catch(() => {}); triggerFreeModeBroadcast(bot, pool); } + + await logAdminAction(pool, { + performerId: ctx.from.id, + performerName: ctx.from.first_name || 'Owner', + performerRole: 'owner', + actionType: 'FREEMODE_TOGGLE', + details: `Toggled Free Mode: ${newStatus}` + }); const freeModeStatus = isFreeModeActive() ? '🟢 ACTIVE (Unlimited Mode)' @@ -242,7 +242,10 @@ `┃ ⚡ ADMIN COMMANDS GUIDE:\n` + `┃ ┣ /addcredit [id] [amount]\n` + `┃ ┣ /addplan [id] [duration]\n` + + `┃ ┣ /setrole [id] [role]\n` + `┃ ┣ /userstatus [id]\n` + + `┃ ┣ /recentaction (Last 10 Logs)\n` + + `┃ ┣ /allaction (Audit Logs Pages)\n` + `┃ ┣ /dbexport (Users & Searches CSV)\n` + `┃ ┣ /dbbackup (Full DB Dump .gz)\n` + `┃ ┗ /broadcast [flags]\n` + @@ -269,8 +269,10 @@ }); bot.command('freeon', async (ctx) => { - const isOwner = await isUserAdmin(ctx.from.id, pool); - if (!isOwner) return; + const isOwner = await isUserOwner(ctx.from.id, pool); + if (!isOwner) { + return ctx.reply("❌ Access Denied: This command is strictly reserved for the Owner.", { parse_mode: 'HTML' }); + } const args = ctx.message.text.split(' ').slice(1); const durationArg = args[0]; @@ -282,6 +282,15 @@ freeModeState.active = true; freeModeState.expiresAt = Date.now() + ms; saveFreeModeState(); + + await logAdminAction(pool, { + performerId: ctx.from.id, + performerName: ctx.from.first_name || 'Owner', + performerRole: 'owner', + actionType: 'FREEMODE_ON', + details: `Enabled Free Mode for duration: ${durationArg}` + }); + ctx.reply(`✅ Free Mode Enabled for ${durationArg}!`); triggerFreeModeBroadcast(bot, pool, durationArg); } else { @@ -288,5 +288,14 @@ freeModeState.expiresAt = null; saveFreeModeState(); + + await logAdminAction(pool, { + performerId: ctx.from.id, + performerName: ctx.from.first_name || 'Owner', + performerRole: 'owner', + actionType: 'FREEMODE_ON', + details: `Enabled Free Mode indefinitely` + }); + ctx.reply(`✅ Free Mode Enabled (Indefinitely)!`); triggerFreeModeBroadcast(bot, pool); } @@ -293,7 +293,9 @@ bot.command('freeoff', async (ctx) => { - const isOwner = await isUserAdmin(ctx.from.id, pool); - if (!isOwner) return; + const isOwner = await isUserOwner(ctx.from.id, pool); + if (!isOwner) { + return ctx.reply("❌ Access Denied: This command is strictly reserved for the Owner.", { parse_mode: 'HTML' }); + } freeModeState.active = false; freeModeState.expiresAt = null; @@ -300,3 +300,12 @@ + + await logAdminAction(pool, { + performerId: ctx.from.id, + performerName: ctx.from.first_name || 'Owner', + performerRole: 'owner', + actionType: 'FREEMODE_OFF', + details: `Disabled Free Mode manually` + }); + ctx.reply("❌ Free Mode Disabled!"); }); @@ -303,7 +303,7 @@ const userId = ctx.from.id; - const isOwner = await isUserAdmin(userId, pool); - if (!isOwner) { - return; + const isOwner = await isUserOwner(userId, pool); + if (!isOwner) { + return ctx.reply("❌ Access Denied: This command is strictly reserved for the Owner.", { parse_mode: 'HTML' }); } try { @@ -320,6 +320,14 @@ console.error("Error resetting daily free search status:", e.message); } + await logAdminAction(pool, { + performerId: userId, + performerName: ctx.from.first_name || 'Owner', + performerRole: 'owner', + actionType: 'DAILY_FREE_BROADCAST', + details: `Triggered reset and broadcast of Daily 1 Free Search to all users` + }); + await ctx.reply("🚀 Daily 1 Free Search reset & broadcast started! All users are being notified. You will receive a summary report once completed.", { parse_mode: 'HTML' }); startDailyResetBroadcast(bot, pool, true, redisClient); }); @@ -326,9 +326,17 @@ bot.action('ADMIN_BROADCAST_FREE', async (ctx) => { const userId = ctx.from.id; - const isOwner = await isUserAdmin(userId, pool); - if (!isOwner) return ctx.answerCbQuery("❌ Only Admin can do this.", { show_alert: true }).catch(() => { }); + const isOwner = await isUserOwner(userId, pool); + if (!isOwner) return ctx.answerCbQuery("❌ Only Owner can do this.", { show_alert: true }).catch(() => { }); ctx.answerCbQuery("Starting broadcast...").catch(() => { }); + await logAdminAction(pool, { + performerId: userId, + performerName: ctx.from.first_name || 'Owner', + performerRole: 'owner', + actionType: 'DAILY_FREE_BROADCAST', + details: `Triggered reset and broadcast of Daily 1 Free Search via panel button` + }); + await ctx.reply("🚀 Daily 1 Free Search reset & broadcast started! All users are being notified.", { parse_mode: 'HTML' }); startDailyResetBroadcast(bot, pool, true, redisClient); }); [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.