indrajitghosh20006/Igstore_01botPublic Β· Bot Template
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 8h agoCreated Oct 30, 2026
commands/_addkey.js
javascript Β· 237 lines
1/**#command2name: /addkey3answer: 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/**#command52name: /addkey53answer:54keyboard:55parse_mode: markdown56aliases:57allow_only_group: false58need_reply: true59case_insensitive: false60is_web: 061#command**/62 63// π ADMIN β Add one or many manual keys to a product plan.64// Format:65// /addkey PRODUCT NAME | 1h | KEY166// KEY267// KEY368// Also supports 30m, 7d, 1 Day, 1 Hour, 30 Minutes, etc.69 70try {71 var adminId = Bot.getProperty("owner_id") || "7839151435";72 var isCoAdmin = Bot.getProperty("co_admin_" + String(chat.chatid));73 if (String(chat.chatid) !== String(adminId) && !isCoAdmin) {74 Bot.sendMessage("β You are not the admin!");75 return;76 }77 78 if (!params) {79 var pendingAddKey = User.getProperty("addkey_pending_text");80 if (pendingAddKey) {81 User.setProperty("addkey_pending_text", null, "string");82 User.setProperty("addkey_step", null, "string");83 params = pendingAddKey;84 } else {85 User.setProperty("addkey_step", "input", "string");86 Bot.sendMessage(87 "π <b>ADD KEY</b>\n\n" +88 "Send in this format:\n<code>PRODUCT NAME | DURATION | KEY1</code>\n<code>KEY2</code>\n<code>KEY3</code>\n\n" +89 "<b>Examples:</b> <code>1d</code>, <code>7d</code>, <code>1h</code>, <code>30m</code>, <code>1 Hour</code>, <code>30 Minutes</code>\n\n" +90 "<i>Har line me ek key add kar sakte hain.</i>",91 { parse_mode: "HTML" }92 );93 return;94 }95 }96 97 User.setProperty("addkey_step", null, "string");98 var lines = String(params).split("\n");99 var first = lines[0].split("|");100 if (first.length < 3) {101 Bot.sendMessage(102 "β <b>Format Error!</b>\nUse:\n<code>/addkey PRODUCT NAME | DURATION | KEY</code>",103 { parse_mode: "HTML" }104 );105 return;106 }107 108 var pNameInput = first[0].trim();109 var durationText = first[1].trim();110 var firstKey = first.slice(2).join("|").trim();111 112 if (!pNameInput || !durationText || !firstKey) {113 Bot.sendMessage("β Product, duration aur key teeno required hain.", { parse_mode: "HTML" });114 return;115 }116 117 // Parse duration into value + unit while preserving the exact display label.118 var m = durationText.match(/^([0-9]+(?:\.[0-9]+)?)\s*(d|day|days|h|hr|hrs|hour|hours|m|min|mins|minute|minutes)$/i);119 var value = "";120 var unit = "day";121 if (m) {122 value = m[1];123 var u = m[2].toLowerCase();124 if (/^h/.test(u)) unit = "hour";125 else if (/^m/.test(u)) unit = "minute";126 } else {127 // Backward-compatible labels such as "1_Day".128 var legacy = durationText.match(/^([0-9]+(?:\.[0-9]+)?)_?day$/i);129 if (legacy) {130 value = legacy[1];131 unit = "day";132 } else {133 Bot.sendMessage("β Duration samajh nahi aaya. Example: <code>1d</code>, <code>1h</code>, <code>30m</code>.", { parse_mode: "HTML" });134 return;135 }136 }137 138 var productList = Bot.getProperty("stored_products") || [];139 var product = null;140 var prodIdx = -1;141 142 for (var i = 0; i < productList.length; i++) {143 if (productList[i] && productList[i].name &&144 productList[i].name.trim().toLowerCase() === pNameInput.toLowerCase()) {145 product = productList[i];146 prodIdx = i;147 break;148 }149 }150 151 if (!product) {152 Bot.sendMessage("β Product <b>" + pNameInput + "</b> nahi mila. Pehle Add Product/Add Plan se product aur duration banao.", { parse_mode: "HTML" });153 return;154 }155 156 // Make sure the requested duration actually exists as a plan.157 var plan = null;158 var planIdx = -1;159 var plans = product.plans || [];160 for (var j = 0; j < plans.length; j++) {161 var pu = plans[j].unit || "day";162 var pv = String(plans[j].days || "").replace(/[^0-9.]/g, "");163 if (pv === String(value) && pu === unit) {164 plan = plans[j];165 planIdx = j;166 break;167 }168 // Legacy plans without unit are Days.169 if (unit === "day" && pu === "day" && pv === String(value)) {170 plan = plans[j];171 planIdx = j;172 break;173 }174 }175 176 if (!plan) {177 Bot.sendMessage(178 "β <b>Plan nahi mila!</b>\nProduct: <code>" + product.name + "</code>\nDuration: <code>" + durationText + "</code>\n\n" +179 "Pehle isi duration ka <b>Add Plan</b> banayein.",180 { parse_mode: "HTML" }181 );182 return;183 }184 185 var keysToAdd = [firstKey];186 for (var k = 1; k < lines.length; k++) {187 var keyLine = lines[k].trim();188 if (keyLine) keysToAdd.push(keyLine);189 }190 191 var cleanName = product.name.trim().toUpperCase();192 // IMPORTANT: purchase flow uses the same normalized product slug.193 // Spaces/symbols must not create a different stock bucket.194 var productStockSlug = cleanName.replace(/[^A-Z0-9_-]/g, "_");195 var stockKey = "manual_keys_" + productStockSlug + "_" + value + "_" + unit;196 var stock = Bot.getProperty(stockKey) || [];197 if (typeof stock === "string") {198 try { stock = JSON.parse(stock); } catch (e) {199 stock = stock.split("\n").map(function(x){ return x.trim(); }).filter(Boolean);200 }201 }202 if (!Array.isArray(stock)) stock = [];203 204 // Avoid accidentally adding the same key twice.205 var added = 0;206 for (var q = 0; q < keysToAdd.length; q++) {207 if (stock.indexOf(keysToAdd[q]) === -1) {208 stock.push(keysToAdd[q]);209 added++;210 }211 }212 Bot.setProperty(stockKey, stock, "json");213 214 // Keep legacy Day stock synchronized for old purchase flows.215 if (unit === "day") {216 var legacyKey = "manual_keys_" + productStockSlug + "_" + value;217 Bot.setProperty(legacyKey, stock, "json");218 219 var oldStockKey = "stock_" + product.name.trim() + "_" + value + "_Day";220 Bot.setProperty(oldStockKey, stock, "json");221 222 Bot.setProperty("stock_" + prodIdx + "_" + planIdx, stock, "json");223 }224 225 Bot.sendMessage(226 "<blockquote><b>β
KEYS ADDED SUCCESSFULLY</b>\n\n" +227 "π¦ <b>Product:</b> <code>" + product.name + "</code>\n" +228 "β³ <b>Duration:</b> <code>" + durationText + "</code>\n" +229 "π <b>New Keys Added:</b> <code>" + added + "</code>\n" +230 "π¦ <b>Total Stock:</b> <code>" + stock.length + "</code>\n\n" +231 "<i>Ab customer isi plan ko buy karega to available manual key pehle deliver hogi aur balance/payment accounting existing purchase system ke through chalegi.</i></blockquote>",232 { parse_mode: "HTML" }233 );234 235} catch (err) {236 Bot.sendMessage("β οΈ System Error: " + err.message);237}