kkapil9112/Hguuuuuv45botPublic · Bot Template

AITelegram commerce bot for an admin-managed digital store: admins create categories, products, time-based plans, stock entries and license keys, and can grant reseller roles or adjust user balances. End users can view their balance, start a deposit flow with an inline amount keypad, apply coupon codes, and navigate back to the store menu. It uses Bot properties for product/stock/coupon data and Libs.ResourcesLib for per-user balances.

Commercecommerceshopreselleradmin-panelbalanceproduct-management
ProfileTelegram
102 commands0 envUpdated 29d agoCreated Aug 7, 2026
Back to folder

commands/_addkey.js

javascript · 102 lines

Raw
1/**#command2name: /addkey3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12try {13  var adminId = "8812621370";14  if (String(chat.chatid) !== adminId) {15    Bot.sendMessage("❌ You are not the admin!");16    return;17  }18 19  if (!params) {20    Bot.sendMessage("⚠️ *Format:* `/addkey PRODUCT NAME | DAYS | KEY1`\n`KEY2`\n`KEY3` (Line-by-line)", { parse_mode: "Markdown" });21    return;22  }23 24  var lines = params.split("\n");25  var firstLineParts = lines[0].split("|");26 27  if (firstLineParts.length < 3) {28    Bot.sendMessage("⚠️ *Galat Format!*\nPehli line me `Product Name | Days | Key` hona chahiye.", { parse_mode: "Markdown" });29    return;30  }31 32  // 1. Inputs ko clean aur trim karna33  var pName = firstLineParts[0].trim().toLowerCase();34  var pDays = firstLineParts[1].trim(); 35  36  var pDaysClean = pDays.includes("_Day") ? pDays : pDays + "_Day";37  var pDaysNumOnly = pDays.replace("_Day", "").trim(); 38 39  var keysToAdd = [];40  keysToAdd.push(firstLineParts[2].trim());41 42  for (var l = 1; l < lines.length; l++) {43    var currentLineKey = lines[l].trim();44    if (currentLineKey !== "") {45      keysToAdd.push(currentLineKey);46    }47  }48 49  // 2. Products fetching50  var productList = Bot.getProperty("stored_products") || [];51  var prodIdx = -1;52  var planIdx = -1;53  var exactProdName = firstLineParts[0].trim(); // Fallback name54 55  // Soft loop matching (Case insensitive)56  for (var i = 0; i < productList.length; i++) {57    if (productList[i].name.trim().toLowerCase() === pName) {58      prodIdx = i;59      exactProdName = productList[i].name.trim();60      break;61    }62  }63 64  // FORCE CORRECTION: Agar index loop se na mile to handle anyway65  if (prodIdx === -1) {66    Bot.sendMessage("⚠️ Product *" + exactProdName + "* lists me nahi mila, par system dynamic key store bypass generate kar raha hai...", { parse_mode: "Markdown" });67  } else {68    var plans = productList[prodIdx].plans || [];69    for (var j = 0; j < plans.length; j++) {70      if (String(plans[j].days).trim() === pDaysNumOnly) {71        planIdx = j;72        break;73      }74    }75  }76 77  // 3. Dual-pipeline saving mechanics78  var stockKeyText = "stock_" + exactProdName + "_" + pDaysClean;79  var currentStock = Bot.getProperty(stockKeyText) || [];80  81  // Array merging82  var updatedStock = currentStock.concat(keysToAdd);83  Bot.setProperty(stockKeyText, updatedStock, "json");84 85  // Agar structured index match hua hai to us pipeline ko bhi update karein86  if (prodIdx !== -1 && planIdx !== -1) {87    var stockKeyIndex = "stock_" + prodIdx + "_" + planIdx;88    Bot.setProperty(stockKeyIndex, updatedStock, "json");89  }90 91  // 4. GUARANTEED SUCCESS CONFIRMATION MESSAGE92  var successMsg = "<blockquote><b>📦 STOCK UPDATED SUCCESSFULLY</b>\n\n" +93                   "• <b>Product:</b> <code>" + exactProdName + "</code>\n" +94                   "• <b>Plan:</b> <code>" + pDaysClean + "</code>\n" +95                   "• <b>Added Keys:</b> <code>" + keysToAdd.length + " Keys</code>\n" +96                   "• <b>Total Stock Now:</b> <code>" + updatedStock.length + " Keys available</code></blockquote>";97 98  Bot.sendMessage(successMsg, { parse_mode: "HTML" });99 100} catch (err) {101  Bot.sendMessage("⚠️ System Error: " + err.message);102}