indrajitghosh20006/Testseller_01botPublic · Bot Template

ProfileTelegram

AIThis bot provides an admin‑controlled system for managing user balances, products, and reseller roles. It includes commands to add balances (via manual input, Binance Pay, or UPI), approve and credit payments, and set up product listings with categories and pricing. Admins can also add resellers, view reseller info, and manage stock entries. The bot uses built‑in TeleBotHost APIs such as Bot, Api, HTTP, and Libs for database operations and message handling.

Commerceadminbalanceproductresellerpaymentsbinance
138 commands0 envUpdated 17h agoCreated Sep 27, 2026
Back to folder

commands/_addkey.js

javascript · 105 lines

Raw
1/**#command2name: /addkey3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12try {13  var adminId = "7839151435";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 rawDuration = firstLineParts[1].trim();35  var durMatch = rawDuration.toLowerCase().match(/^([0-9]+(?:\.[0-9]+)?)\s*(d|day|days|h|hr|hrs|hour|hours|m|min|mins|minute|minutes)$/);36  var pDaysNumOnly = durMatch ? durMatch[1] : rawDuration.replace(/[^0-9.]/g, "");37  var unitRaw = durMatch ? durMatch[2] : "d";38  var pUnit = /^h/.test(unitRaw) ? "hour" : (/^m/.test(unitRaw) ? "minute" : "day");39  var pDaysClean = (pUnit === "day") ? pDaysNumOnly + "_Day" : pDaysNumOnly + "_" + pUnit;40 41  var keysToAdd = [];42  keysToAdd.push(firstLineParts[2].trim());43 44  for (var l = 1; l < lines.length; l++) {45    var currentLineKey = lines[l].trim();46    if (currentLineKey !== "") {47      keysToAdd.push(currentLineKey);48    }49  }50 51  // 2. Products fetching52  var productList = Bot.getProperty("stored_products") || [];53  var prodIdx = -1;54  var planIdx = -1;55  var exactProdName = firstLineParts[0].trim(); // Fallback name56 57  // Soft loop matching (Case insensitive)58  for (var i = 0; i < productList.length; i++) {59    if (productList[i].name.trim().toLowerCase() === pName) {60      prodIdx = i;61      exactProdName = productList[i].name.trim();62      break;63    }64  }65 66  // FORCE CORRECTION: Agar index loop se na mile to handle anyway67  if (prodIdx === -1) {68    Bot.sendMessage("⚠️ Product *" + exactProdName + "* lists me nahi mila, par system dynamic key store bypass generate kar raha hai...", { parse_mode: "Markdown" });69  } else {70    var plans = productList[prodIdx].plans || [];71    for (var j = 0; j < plans.length; j++) {72      var pu = plans[j].unit || "day";73      if (String(plans[j].days).trim() === pDaysNumOnly && pu === pUnit) {74        planIdx = j;75        break;76      }77    }78  }79 80  // 3. Dual-pipeline saving mechanics81  var stockKeyText = "stock_" + exactProdName + "_" + pDaysClean;82  var currentStock = Bot.getProperty(stockKeyText) || [];83  84  // Array merging85  var updatedStock = currentStock.concat(keysToAdd);86  Bot.setProperty(stockKeyText, updatedStock, "json");87 88  // Agar structured index match hua hai to us pipeline ko bhi update karein89  if (prodIdx !== -1 && planIdx !== -1) {90    var stockKeyIndex = "stock_" + prodIdx + "_" + planIdx;91    Bot.setProperty(stockKeyIndex, updatedStock, "json");92  }93 94  // 4. GUARANTEED SUCCESS CONFIRMATION MESSAGE95  var successMsg = "<blockquote><b>📦 STOCK UPDATED SUCCESSFULLY</b>\n\n" +96                   "• <b>Product:</b> <code>" + exactProdName + "</code>\n" +97                   "• <b>Plan:</b> <code>" + pDaysClean + "</code>\n" +98                   "• <b>Added Keys:</b> <code>" + keysToAdd.length + " Keys</code>\n" +99                   "• <b>Total Stock Now:</b> <code>" + updatedStock.length + " Keys available</code></blockquote>";100 101  Bot.sendMessage(successMsg, { parse_mode: "HTML" });102 103} catch (err) {104  Bot.sendMessage("⚠️ System Error: " + err.message);105}