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/_addstock.js

javascript Β· 188 lines

Raw
1/**#command2name: _addstock3answer: 4keyboard: 5parse_mode: 6aliases: 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/**#command52name: /addstock53answer:54keyboard:55parse_mode: markdown56aliases:57allow_only_group: false58need_reply: false59case_insensitive: false60is_web: 061#end**/62 63/*64 /addstock PRODUCT NAME | DURATION | KEY1 KEY2 ...65 1 key = 1 stock.66 Stock is isolated by Product + Duration + Unit.67 Duplicate and previously-sold keys are rejected.68*/69try {70  var adminId = Bot.getProperty("owner_id") || "7839151435";71  var isCoAdmin = Bot.getProperty("co_admin_" + String(chat.chatid));72  if (String(chat.chatid) !== String(adminId) && !isCoAdmin) {73    Bot.sendMessage("❌ You are not the admin!");74    return;75  }76 77  var input = String(params || "").trim();78  var parts = input.split("|");79  if (parts.length < 3) {80    Bot.sendMessage("❌ <b>Format:</b> <code>/addstock PRODUCT NAME | DURATION | KEY1 KEY2 ...</code>", {parse_mode:"HTML"});81    return;82  }83 84  var productName = parts[0].trim();85  var durationText = parts[1].trim();86  var keyText = parts.slice(2).join("|").trim();87 88  var products = Bot.getProperty("stored_products") || [];89  var product = null;90  for (var i = 0; i < products.length; i++) {91    if (String(products[i].name || "").trim().toLowerCase() === productName.toLowerCase()) {92      product = products[i];93      productName = String(products[i].name).trim();94      break;95    }96  }97  if (!product) {98    Bot.sendMessage("❌ Product nahi mila: <code>" + productName.replace(/</g,"&lt;").replace(/>/g,"&gt;") + "</code>", {parse_mode:"HTML"});99    return;100  }101 102  var rawDur = durationText.replace(/\s+/g, " ").trim();103  var dm = rawDur.toLowerCase().match(/^([0-9]+(?:\.[0-9]+)?)\s*(h|hr|hrs|hour|hours|d|day|days|m|min|mins|minute|minutes)$/);104  var value = null, unit = null;105 106  if (dm) {107    value = dm[1];108    if (/^h/.test(dm[2])) unit = "hour";109    else if (/^m/.test(dm[2])) unit = "minute";110    else unit = "day";111  } else {112    for (var p = 0; p < (product.plans || []).length; p++) {113      var pp = product.plans[p];114      var labels = [pp.durationDisplay, pp.api_duration, pp.name_on_website];115      for (var l = 0; l < labels.length; l++) {116        if (labels[l] && String(labels[l]).trim().toLowerCase() === rawDur.toLowerCase()) {117          value = String(pp.days);118          unit = pp.unit || "day";119          break;120        }121      }122      if (value !== null) break;123    }124  }125 126  if (value === null) {127    Bot.sendMessage("❌ Duration match nahi hua. Example: <code>1d</code>, <code>2 days</code>, <code>1h</code>, <code>16 hours</code>.", {parse_mode:"HTML"});128    return;129  }130 131  var productSlug = productName.toUpperCase().replace(/[^A-Z0-9_-]/g, "_");132  var stockKey = "manual_keys_" + productSlug + "_" + value + "_" + unit;133  var stock = Bot.getProperty(stockKey) || [];134  if (!Array.isArray(stock)) stock = [];135 136  var soldIndex = Bot.getProperty("manual_sold_key_index") || {};137  if (!soldIndex || typeof soldIndex !== "object") soldIndex = {};138 139  // Prevent a key from being added twice anywhere in manual stock.140  var existingIndex = {};141  for (var si = 0; si < products.length; si++) {142    var sp = products[si];143    var spSlug = String(sp.name || "").toUpperCase().replace(/[^A-Z0-9_-]/g, "_");144    var splans = sp.plans || [];145    for (var sj = 0; sj < splans.length; sj++) {146      var sv = String(splans[sj].days);147      var su = splans[sj].unit || "day";148      var sk = "manual_keys_" + spSlug + "_" + sv + "_" + su;149      var ss = Bot.getProperty(sk) || [];150      if (!Array.isArray(ss)) continue;151      for (var sx = 0; sx < ss.length; sx++) existingIndex[String(ss[sx]).trim()] = true;152    }153  }154 155  var rawKeys = keyText.split(/[\s,\n]+/).map(function(k){return String(k).trim();}).filter(Boolean);156  var accepted = [];157  var duplicateCount = 0;158  var soldAgainCount = 0;159 160  for (var k = 0; k < rawKeys.length; k++) {161    var key = rawKeys[k];162    if (soldIndex[key]) {163      soldAgainCount++;164      continue;165    }166    if (existingIndex[key] || accepted.indexOf(key) !== -1) {167      duplicateCount++;168      continue;169    }170    accepted.push(key);171  }172 173  for (var a = 0; a < accepted.length; a++) stock.push(accepted[a]);174  Bot.setProperty(stockKey, stock, "json");175 176  Bot.sendMessage(177    "πŸ“¦ <b>STOCK UPDATED</b>\n\n" +178    "πŸ“Œ <b>Panel:</b> <code>" + productName + "</code>\n" +179    "⏱️ <b>Duration:</b> <code>" + rawDur + "</code>\n" +180    "βž• <b>Added:</b> <code>" + accepted.length + "</code>\n" +181    "πŸ“Š <b>Current Stock:</b> <code>" + stock.length + "</code>\n" +182    "♻️ <b>Duplicates skipped:</b> <code>" + duplicateCount + "</code>\n" +183    "🚫 <b>Already sold keys skipped:</b> <code>" + soldAgainCount + "</code>",184    {parse_mode:"HTML"}185  );186} catch (e) {187  Bot.sendMessage("❌ /addstock error: <code>" + String(e.message || e).replace(/</g,"&lt;").replace(/>/g,"&gt;") + "</code>", {parse_mode:"HTML"});188}