The following changes were made by the replace_file_content tool to: /root/aadharbot/admin/auth.js. If relevant, proactively run terminal commands to execute this code for the USER. Don't ask for permission. [diff_block_start] @@ -167,6 +167,98 @@ const roleEmoji = role === ROLES.OWNER ? '👑 OWNER' : (role === ROLES.ADMIN ? 'đŸ›Ąī¸ ADMIN' : '👤 USER'); ctx.reply(`👤 Your Account Role: ${roleEmoji}`, { parse_mode: 'HTML' }); }); + + // Command to appoint an Admin: /addadmin + bot.command('addadmin', async (ctx) => { + const senderId = ctx.from.id; + const senderIsOwner = await isUserOwner(senderId, pool); + if (!senderIsOwner) { + return ctx.reply("❌ Access Denied: Only the Owner can appoint an Admin.", { parse_mode: 'HTML' }); + } + + const args = ctx.message.text.split(' ').slice(1).filter(Boolean); + if (args.length < 1) { + return ctx.reply("💡 Usage: /addadmin <telegram_id>", { parse_mode: 'HTML' }); + } + + const targetUserId = parseInt(args[0], 10); + if (isNaN(targetUserId)) { + return ctx.reply("❌ Invalid Telegram User ID.", { parse_mode: 'HTML' }); + } + + try { + await setUserRole(targetUserId, ROLES.ADMIN, pool, invalidateUserCache); + + const { logAdminAction } = require('./actions'); + await logAdminAction(pool, { + performerId: senderId, + performerName: ctx.from.first_name || 'Owner', + performerRole: 'owner', + actionType: 'ADD_ADMIN', + targetId: targetUserId, + details: `Appointed User ${targetUserId} as Admin` + }); + + ctx.reply(`✅ Successfully appointed User ${targetUserId} as đŸ›Ąī¸ ADMIN.`, { parse_mode: 'HTML' }); + + bot.telegram.sendMessage( + targetUserId, + `🎉 Congratulations!\n\nYou have been appointed as an Admin đŸ›Ąī¸ by the Owner.\nYou can now use /admin to manage credits and plans.`, + { parse_mode: 'HTML' } + ).catch(() => {}); + } catch (err) { + console.error("addadmin error:", err); + ctx.reply(`❌ Failed to appoint admin: ${err.message}`); + } + }); + + // Command to demote an Admin back to User: /rmadmin + bot.command('rmadmin', async (ctx) => { + const senderId = ctx.from.id; + const senderIsOwner = await isUserOwner(senderId, pool); + if (!senderIsOwner) { + return ctx.reply("❌ Access Denied: Only the Owner can remove an Admin.", { parse_mode: 'HTML' }); + } + + const args = ctx.message.text.split(' ').slice(1).filter(Boolean); + if (args.length < 1) { + return ctx.reply("💡 Usage: /rmadmin <telegram_id>", { parse_mode: 'HTML' }); + } + + const targetUserId = parseInt(args[0], 10); + if (isNaN(targetUserId)) { + return ctx.reply("❌ Invalid Telegram User ID.", { parse_mode: 'HTML' }); + } + + if (String(targetUserId) === String(senderId) || (await isUserOwner(targetUserId, pool))) { + return ctx.reply("❌ Cannot remove the Owner account.", { parse_mode: 'HTML' }); + } + + try { + await setUserRole(targetUserId, ROLES.USER, pool, invalidateUserCache); + + const { logAdminAction } = require('./actions'); + await logAdminAction(pool, { + performerId: senderId, + performerName: ctx.from.first_name || 'Owner', + performerRole: 'owner', + actionType: 'REMOVE_ADMIN', + targetId: targetUserId, + details: `Revoked Admin access for User ${targetUserId}` + }); + + ctx.reply(`✅ Successfully revoked Admin access for User ${targetUserId}. Account role is now 👤 USER.`, { parse_mode: 'HTML' }); + + bot.telegram.sendMessage( + targetUserId, + `â„šī¸ Role Update Notification\n\nYour Admin privileges have been revoked by the Owner. Your account is now a regular User.`, + { parse_mode: 'HTML' } + ).catch(() => {}); + } catch (err) { + console.error("rmadmin error:", err); + ctx.reply(`❌ Failed to remove admin: ${err.message}`); + } + }); } module.exports = { [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.