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]
@@ -2376,324 +2376,6 @@
sendNext();
});
-// Retailer panel: /maya command
-bot.command('maya', async (ctx) => {
- const userId = ctx.from.id;
- const isRetailer = await isUserRetailer(userId);
- const isOwner = await isUserAdmin(userId);
-
- if (!isRetailer && !isOwner) {
- return; // Silent skip
- }
-
- const access = await checkUserAccess(userId);
- const retailerMsg = `šŖ ` + (isOwner ? 'MAYA-S ADMIN CONTROL PANEL' : 'MAYA-S RETAILER CONTROL PANEL') + ` šŖ\n` +
- `āāāāāāāāāāāāāāāāāāāāāāāāāā\n` +
- `š¤ ` + (isOwner ? 'Admin Info:' : 'Retailer Info:') + `\n` +
- `⢠Name: ${ctx.from.first_name || (isOwner ? 'Admin' : 'Retailer')}\n` +
- `⢠ID: ${userId}\n` +
- `⢠Your Credit Balance: ${isOwner ? 'Unlimited' : access.credits} Credits šŖ\n\n` +
- `ā” ` + (isOwner ? 'Admin' : 'Retailer') + ` Commands:\n\n` +
- `⢠Give Credits to User:\n` +
- ` /givecredit [telegram_id] [amount]\n` +
- ` (Deducts from your balance and adds to target user)\n\n` +
- `⢠Remove Credits from User:\n` +
- ` /rmcredit [telegram_id] [amount]\n` +
- ` (Removes from target user and refunds to your balance)\n\n` +
- `⢠Give Unlimited Plan to User:\n` +
- ` /giveplan [telegram_id] [daily|weekly|monthly|yearly]\n` +
- ` (Requires Owner approval request)\n` +
- `āāāāāāāāāāāāāāāāāāāāāāāāāā`;
-
- return ctx.reply(retailerMsg, { parse_mode: 'HTML' });
-});
-
-// Retailer command to distribute credits: /givecredit
-bot.command('givecredit', async (ctx) => {
- const userId = ctx.from.id;
- const isRetailer = await isUserRetailer(userId);
- const isOwner = await isUserAdmin(userId);
-
- if (!isRetailer && !isOwner) {
- return; // Silent skip
- }
-
- const args = ctx.message.text.split(' ').slice(1);
- if (args.length < 2) {
- return ctx.reply("š” **Usage:** `/givecredit `", { parse_mode: 'Markdown' });
- }
-
- const targetUserId = parseInt(args[0]);
- const creditsToGive = parseInt(args[1]);
-
- if (isNaN(targetUserId) || isNaN(creditsToGive) || creditsToGive <= 0) {
- return ctx.reply("ā Invalid user ID or credit amount.");
- }
-
- let retailerCredits = 0;
- if (!isOwner) {
- const access = await checkUserAccess(userId);
- retailerCredits = access.credits;
- if (retailerCredits < creditsToGive) {
- return ctx.reply(`ā **Insufficient Balance:** You only have \`${retailerCredits}\` credits, but tried to give \`${creditsToGive}\`.`, { parse_mode: 'Markdown' });
- }
- }
-
- try {
- if (!isOwner) {
- if (!process.env.DATABASE_URL) {
- const fs = require('fs');
- let db = {};
- if (fs.existsSync('db.json')) {
- try { db = JSON.parse(fs.readFileSync('db.json', 'utf8')); } catch (e) {
- console.error("Retailer check err:", e); }
- }
- if (db[userId]) {
- db[userId].credits = Math.max(0, (db[userId].credits || 0) - creditsToGive);
- fs.writeFileSync('db.json', JSON.stringify(db, null, 2));
- }
- } else {
- await pool.query('UPDATE users SET credits = GREATEST(0, credits - $1) WHERE telegram_id = $2', [creditsToGive, userId]);
- }
- }
-
- let newTargetCredits = 0;
- if (!process.env.DATABASE_URL) {
- const fs = require('fs');
- let db = {};
- if (fs.existsSync('db.json')) {
- try { db = JSON.parse(fs.readFileSync('db.json', 'utf8')); } catch (e) {
- console.error("Retailer check err:", e); }
- }
- if (!db[targetUserId]) {
- db[targetUserId] = { name: 'User', credits: 0 };
- }
- db[targetUserId].credits = (db[targetUserId].credits || 0) + creditsToGive;
- fs.writeFileSync('db.json', JSON.stringify(db, null, 2));
- newTargetCredits = db[targetUserId].credits;
- } else {
- const res = await pool.query(
- `INSERT INTO users (telegram_id, name, credits, created_at, updated_at) VALUES ($1, 'User', $2, NOW(), NOW())
- ON CONFLICT (telegram_id)
- DO UPDATE SET credits = users.credits + EXCLUDED.credits
- RETURNING credits`,
- [targetUserId, creditsToGive]
- );
- newTargetCredits = res.rows[0].credits;
- }
-
- ctx.reply(`ā
**Credits Transferred Successfully!**\n\n⢠Target User: \`${targetUserId}\`\n⢠Amount: \`${creditsToGive}\` Credits\n⢠New Target Balance: \`${newTargetCredits}\` Credits`, { parse_mode: 'Markdown' });
-
- ctx.telegram.sendMessage(targetUserId, `š **You received ${creditsToGive} credits!**\n⢠Transferred by: Retailer\n⢠Current Balance: ${newTargetCredits} Credits šŖ`, { parse_mode: 'HTML' }).catch(() => {});
-
- } catch (err) {
- console.error("Error in givecredit:", err.message);
- ctx.reply(`ā Error transferring credits: ${err.message}`);
- }
-});
-
-// Retailer command to remove credits: /rmcredit
-bot.command('rmcredit', async (ctx) => {
- const userId = ctx.from.id;
- const isRetailer = await isUserRetailer(userId);
- const isOwner = await isUserAdmin(userId);
-
- if (!isRetailer && !isOwner) {
- return; // Silent skip
- }
-
- const args = ctx.message.text.split(' ').slice(1);
- if (args.length < 2) {
- return ctx.reply("š” **Usage:** `/rmcredit `", { parse_mode: 'Markdown' });
- }
-
- const targetUserId = parseInt(args[0]);
- const creditsToRemove = parseInt(args[1]);
-
- if (isNaN(targetUserId) || isNaN(creditsToRemove) || creditsToRemove <= 0) {
- return ctx.reply("ā Invalid user ID or credit amount.");
- }
-
- try {
- let currentTargetCredits = 0;
- let newTargetCredits = 0;
-
- // Find target user and remove credits
- if (!process.env.DATABASE_URL) {
- const fs = require('fs');
- let db = {};
- if (fs.existsSync('db.json')) {
- try { db = JSON.parse(fs.readFileSync('db.json', 'utf8')); } catch (e) {
- console.error("Retailer check err:", e); }
- }
- if (!db[targetUserId]) {
- return ctx.reply(`ā Target user \`${targetUserId}\` not found in database.`, { parse_mode: 'Markdown' });
- }
- currentTargetCredits = db[targetUserId].credits || 0;
- if (currentTargetCredits < creditsToRemove) {
- return ctx.reply(`ā **Insufficient Target Balance:** Target user only has \`${currentTargetCredits}\` credits.`, { parse_mode: 'Markdown' });
- }
- db[targetUserId].credits = currentTargetCredits - creditsToRemove;
- fs.writeFileSync('db.json', JSON.stringify(db, null, 2));
- newTargetCredits = db[targetUserId].credits;
- } else {
- // First check if target has enough credits
- const checkRes = await pool.query('SELECT credits FROM users WHERE telegram_id = $1', [targetUserId]);
- if (checkRes.rows.length === 0) {
- return ctx.reply(`ā Target user \`${targetUserId}\` not found in database.`, { parse_mode: 'Markdown' });
- }
- currentTargetCredits = checkRes.rows[0].credits;
- if (currentTargetCredits < creditsToRemove) {
- return ctx.reply(`ā **Insufficient Target Balance:** Target user only has \`${currentTargetCredits}\` credits.`, { parse_mode: 'Markdown' });
- }
-
- const res = await pool.query(
- `UPDATE users SET credits = credits - $1 WHERE telegram_id = $2 RETURNING credits`,
- [creditsToRemove, targetUserId]
- );
- newTargetCredits = res.rows[0].credits;
- }
-
- // Add credits back to retailer if not owner
- if (!isOwner) {
- if (!process.env.DATABASE_URL) {
- const fs = require('fs');
- let db = {};
- if (fs.existsSync('db.json')) {
- try { db = JSON.parse(fs.readFileSync('db.json', 'utf8')); } catch (e) {
- console.error("Retailer check err:", e); }
- }
- if (db[userId]) {
- db[userId].credits = (db[userId].credits || 0) + creditsToRemove;
- fs.writeFileSync('db.json', JSON.stringify(db, null, 2));
- }
- } else {
- await pool.query('UPDATE users SET credits = credits + $1 WHERE telegram_id = $2', [creditsToRemove, userId]);
- }
- }
-
- ctx.reply(`ā
**Credits Removed Successfully!**\n\n⢠Target User: \`${targetUserId}\`\n⢠Amount Removed: \`${creditsToRemove}\` Credits\n⢠New Target Balance: \`${newTargetCredits}\` Credits\n\n_(Credits have been refunded to your account)_`, { parse_mode: 'Markdown' });
-
- ctx.telegram.sendMessage(targetUserId, `š **${creditsToRemove} credits were removed from your account.**\n⢠Removed by: Retailer/Admin\n⢠Current Balance: ${newTargetCredits} Credits šŖ`, { parse_mode: 'HTML' }).catch(() => {});
-
- } catch (err) {
- console.error("Error in rmcredit:", err.message);
- ctx.reply(`ā Error removing credits: ${err.message}`);
- }
-});
-
-// Retailer command to grant unlimited plan (requires Owner approval): /giveplan
-bot.command('giveplan', async (ctx) => {
- const userId = ctx.from.id;
- const isRetailer = await isUserRetailer(userId);
- const isOwner = await isUserAdmin(userId);
-
- if (!isRetailer && !isOwner) {
- return; // Silent skip
- }
-
- const args = ctx.message.text.split(' ').slice(1);
- if (args.length < 2) {
- return ctx.reply("š” **Usage:** `/giveplan `", { parse_mode: 'Markdown' });
- }
-
- const targetUserId = parseInt(args[0]);
- const duration = args[1].toLowerCase();
-
- const allowedDurations = ['daily', 'weekly', 'monthly', 'yearly'];
- if (isNaN(targetUserId) || !allowedDurations.includes(duration)) {
- return ctx.reply("ā Invalid user ID or duration. Choose from: daily, weekly, monthly, yearly.");
- }
-
- if (isOwner) {
- try {
- const planExpiry = await assignPlanToUser(targetUserId, duration);
- ctx.reply(`ā
Plan \`${duration}\` assigned to user \`${targetUserId}\` immediately by Owner.`, { parse_mode: 'Markdown' });
- ctx.telegram.sendMessage(targetUserId, `š **Your Unlimited Plan (${duration}) has been activated by the Owner!**`, { parse_mode: 'HTML' }).catch(() => {});
- } catch (err) {
- ctx.reply(`ā Error: ${err.message}`);
- }
- return;
- }
-
- const retailerName = ctx.from.first_name || 'Retailer';
- const ownerMsg = `š Unlimited Plan Request from Retailer\n` +
- `āāāāāāāāāāāāāāāāāāāāāāāāāā\n` +
- `⢠Retailer: ${retailerName} (ID: ${userId})\n` +
- `⢠Target User: ${targetUserId}\n` +
- `⢠Requested Plan: ${duration.toUpperCase()}\n` +
- `āāāāāāāāāāāāāāāāāāāāāāāāāā\n` +
- `Do you want to accept or deny this request?`;
-
- const keyboard = [
- [
- Markup.button.callback('ā
Accept', `R_ACC_${userId}_${targetUserId}_${duration}`),
- Markup.button.callback('ā Deny', `R_DEN_${userId}_${targetUserId}_${duration}`)
- ]
- ];
-
- try {
- const ownerId = process.env.ADMIN_ID || '8439525687';
- const logGroupId = process.env.LOG_GROUP_ID;
- const targetChat = logGroupId ? logGroupId : ownerId;
-
- await ctx.telegram.sendMessage(targetChat, ownerMsg, {
- parse_mode: 'HTML',
- ...Markup.inlineKeyboard(keyboard)
- });
- ctx.reply(`ā³ **Request Sent to Admin Group:** Your request to assign **${duration.toUpperCase()}** plan to user \`${targetUserId}\` has been forwarded for approval.`, { parse_mode: 'Markdown' });
- } catch (err) {
- console.error("Error sending approval request:", err.message);
- ctx.reply(`ā Failed to send request: ${err.message}`);
- }
-});
-
-// Callback handlers for Retailer Plan Request Approvals
-bot.action(/^R_ACC_(\d+)_(\d+)_(.+)$/, async (ctx) => {
- const senderId = ctx.from.id;
- const isOwner = await isUserAdmin(senderId);
- if (!isOwner) {
- return ctx.answerCbQuery("Access denied!", { show_alert: true }).catch(() => { });
- }
-
- ctx.answerCbQuery("ā
Request Approved!").catch(() => { });
-
- const retailerId = ctx.match[1];
- const targetUserId = ctx.match[2];
- const duration = ctx.match[3];
-
- try {
- const planExpiry = await assignPlanToUser(parseInt(targetUserId), duration);
-
- ctx.editMessageText(`ā
**Request Approved**\n\n⢠**Retailer ID:** \`${retailerId}\`\n⢠**Target User:** \`${targetUserId}\`\n⢠**Plan Duration:** \`${duration.toUpperCase()}\`\n⢠**Status:** Activated until ${planExpiry.toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' })}`, { parse_mode: 'Markdown' });
-
- ctx.telegram.sendMessage(retailerId, `ā
**Plan Request Approved!**\n\nYour request to assign **${duration.toUpperCase()}** plan to user \`${targetUserId}\` has been approved by an Admin.`, { parse_mode: 'Markdown' }).catch(() => {});
-
- ctx.telegram.sendMessage(targetUserId, `š **Your Unlimited Plan (${duration}) has been activated!**`, { parse_mode: 'HTML' }).catch(() => {});
-
- } catch (err) {
- ctx.reply(`ā Error executing plan activation: ${err.message}`);
- }
-});
-
-bot.action(/^R_DEN_(\d+)_(\d+)_(.+)$/, async (ctx) => {
- const senderId = ctx.from.id;
- const isOwner = await isUserAdmin(senderId);
- if (!isOwner) {
- return ctx.answerCbQuery("Access denied!", { show_alert: true }).catch(() => { });
- }
-
- ctx.answerCbQuery("ā Request Denied!").catch(() => { });
-
- const retailerId = ctx.match[1];
- const targetUserId = ctx.match[2];
- const duration = ctx.match[3];
-
- ctx.editMessageText(`ā **Request Denied**\n\n⢠**Retailer ID:** \`${retailerId}\`\n⢠**Target User:** \`${targetUserId}\`\n⢠**Plan Duration:** \`${duration.toUpperCase()}\`\n⢠**Status:** Rejected by Admin`, { parse_mode: 'Markdown' });
-
- ctx.telegram.sendMessage(retailerId, `ā **Plan Request Denied!**\n\nYour request to assign **${duration.toUpperCase()}** plan to user \`${targetUserId}\` was denied by an Admin.`, { parse_mode: 'Markdown' }).catch(() => {});
-});
-
// āā BROADCAST SYSTEM STATE & LOGIC āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
let broadcastState = {
running: false,
[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.