indrajitghosh20006/Igstore_01botPublic Β· Bot Template

ProfileTelegram

AIThe bot provides an admin interface for a digital store, allowing the owner or co‑admins to add balances, products, plans, and categories. It supports payment workflows via UPI and Binance Pay, automatically generating QR codes and handling manual approval of deposits. The code patches inline keyboards to use premium emoji icons and includes helper functions for user and bot properties. Overall, it serves as a commerce management tool for a Telegram-based storefront.

Commercestoreadminbalanceproductplancategory
170 commands0 envUpdated 7h agoCreated Oct 30, 2026
Back to folder

commands/_rembal.js

javascript Β· 150 lines

Raw
1/**#command2name: /rembal3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// PREMIUM BUTTON ICONS13(function(){14  try {15    if (!JSON.__premiumPatched) {16      var __origStringify = JSON.stringify;17      JSON.stringify = function(value, replacer, space) {18        try {19          if (value && value.inline_keyboard && Array.isArray(value.inline_keyboard)) {20            var premiumIds = [21              "6143444134125379822",22              "6091379307907652768",23              "6147534454819661264",24              "6147817325660741985",25              "6235683689292897318",26              "6102856637343600044"27            ];28            var rows = value.inline_keyboard.map(function(row, ri) {29              if (!Array.isArray(row)) return row;30              return row.map(function(btn, bi) {31                if (!btn || typeof btn !== "object") return btn;32                var copy = {};33                for (var k in btn) copy[k] = btn[k];34                if (!copy.icon_custom_emoji_id) copy.icon_custom_emoji_id = premiumIds[(ri + bi) % premiumIds.length];35                return copy;36              });37            });38            var cloned = {};39            for (var key in value) cloned[key] = value[key];40            cloned.inline_keyboard = rows;41            return __origStringify.call(JSON, cloned, replacer, space);42          }43        } catch (e) {}44        return __origStringify.call(JSON, value, replacer, space);45      };46      JSON.__premiumPatched = true;47    }48  } catch (e) {}49})();50 51 52 53try {54  var adminId = Bot.getProperty("owner_id") || "7839151435";55  var requesterId = String(user.telegramid);56  var isCoAdmin = Bot.getProperty("co_admin_" + requesterId);57 58  if (requesterId !== String(adminId) && !isCoAdmin) {59    Bot.sendMessage("❌ You are not authorized to use this command.");60    return;61  }62 63  if (request && request.id) {64    try {65      HTTP.post({66        url: "https://api.telegram.org/bot" + bot.token + "/answerCallbackQuery",67        body: { callback_query_id: request.id }68      });69    } catch (e) {}70  }71 72  var raw = "";73  if (typeof params !== "undefined" && params) raw = String(params).trim();74  if (!raw && typeof message !== "undefined" && message) {75    var parts = String(message).trim().split(/\s+/);76    if (parts.length > 1) raw = parts.slice(1).join(" ").trim();77  }78 79  if (!raw || raw.indexOf("|") === -1) {80    User.setProperty("rembal_step", "waiting_input", "string");81    Bot.sendMessage(82      "πŸ’΅ <b>Remove Balance</b>\n\n" +83      "User ID aur amount is format me bhejein:\n" +84      "<code>user_id|amount</code>\n\n" +85      "Example: <code>123456789|50</code>",86      { parse_mode: "HTML" }87    );88    return;89  }90 91  var splitData = raw.split("|");92  var targetUserId = String(splitData[0] || "").trim();93  var amountToRemove = Number(String(splitData[1] || "").trim());94 95  if (!/^\d+$/.test(targetUserId) || !isFinite(amountToRemove) || amountToRemove <= 0) {96    Bot.sendMessage("❌ Invalid format. Use <code>user_id|amount</code>.", { parse_mode: "HTML" });97    return;98  }99 100  var wallet = Libs.ResourcesLib.anotherUserRes("balance", targetUserId);101  var currentBalance = Number(wallet.value()) || 0;102  var legacyBalance = Number(Bot.getProperty("balance" + targetUserId) || 0);103  var totalBalance = currentBalance + legacyBalance;104 105  if (amountToRemove > totalBalance) {106    Bot.sendMessage(107      "❌ <b>Insufficient Balance</b>\n\n" +108      "Member balance: <code>β‚Ή" + totalBalance.toFixed(2) + "</code>\n" +109      "Remove requested: <code>β‚Ή" + amountToRemove.toFixed(2) + "</code>",110      { parse_mode: "HTML" }111    );112    return;113  }114 115  // Remove from the main ResourcesLib wallet first.116  var fromResource = Math.min(currentBalance, amountToRemove);117  if (fromResource > 0) wallet.remove(fromResource);118 119  // If old balance storage is still used, remove the remainder from it.120  var remainder = amountToRemove - fromResource;121  if (remainder > 0) {122    var newLegacy = Math.max(0, legacyBalance - remainder);123    Bot.setProperty("balance" + targetUserId, newLegacy, "float");124  }125 126  var afterBalance = (totalBalance - amountToRemove).toFixed(2);127 128  Bot.sendMessage(129    "βœ… <b>Balance Removed</b>\n\n" +130    "Member: <code>" + targetUserId + "</code>\n" +131    "Removed: <code>β‚Ή" + amountToRemove.toFixed(2) + "</code>\n" +132    "Remaining: <code>β‚Ή" + afterBalance + "</code>",133    { parse_mode: "HTML" }134  );135 136  try {137    Api.sendMessage({138      chat_id: targetUserId,139      text:140        "<blockquote><b>πŸ’³ BALANCE UPDATED</b>\n\n" +141        "β€’ Removed by Admin: <code>β‚Ή" + amountToRemove.toFixed(2) + "</code>\n" +142        "β€’ Remaining Balance: <code>β‚Ή" + afterBalance + "</code>\n\n" +143        "Use /balance to check your wallet.</blockquote>",144      parse_mode: "HTML"145    });146  } catch (notifyErr) {}147 148} catch (err) {149  Bot.sendMessage("⚠️ <b>Remove Balance Error:</b> <code>" + err.message + "</code>", { parse_mode: "HTML" });150}