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.