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

javascript · 148 lines

Raw
1/**#command2name: /addplan3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// Apni Admin Telegram ID yahan dalein13var adminId = Bot.getProperty("owner_id") || "7839151435";14var isCoAdmin0 = Bot.getProperty("co_admin_" + String(chat.chatid));15 16if (chat.chatid != adminId && !isCoAdmin0) {17  Bot.sendMessage("❌ You are not the admin!");18  return;19}20 21// ✅ FIXED: Ab sirf "Days" nahi — Hour / Minute bhi support karta hai!22// Format: /addplan PRODUCT NAME | DURATION | NORMAL PRICE | RESELLER PRICE23// DURATION examples: "7" ya "7d" ya "7days" = 7 Days | "1h" ya "1hour" = 1 Hour | "30m" ya "30min" = 30 Minutes24if (!params) {25  Bot.sendMessage(26    "⚠️ Format: `/addplan PRODUCT NAME | DURATION | NORMAL PRICE | RESELLER PRICE`\n\n" +27    "*Examples:*\n" +28    "`/addplan FreeFire Hack | 7d | 91 | 64`  (7 Days)\n`/addplan FreeFire Hack | 1 Hours | 91 | 64`  (Exact API duration: 1 Hours)\n" +29    "`/addplan FreeFire Hack | 1h | 10 | 8`  (1 Hour)\n" +30    "`/addplan FreeFire Hack | 30m | 5 | 4`  (30 Minutes)",31    { parse_mode: "Markdown" }32  );33  return;34}35 36var data = params.split("|");37if (data.length < 4) {38  Bot.sendMessage("⚠️ Galat Format! Charo cheezein '|' se alag honi chahiye.");39  return;40}41 42var pName = data[0].trim();43var rawDuration = data[1].trim();44var pNormal = parseFloat(data[2].trim());45var pReseller = parseFloat(data[3].trim());46 47if (isNaN(pNormal) || isNaN(pReseller)) {48  Bot.sendMessage("❌ Price numeric (number) honi chahiye!");49  return;50}51 52// 🕒 DURATION PARSER — exact API/website labels are preserved verbatim.53// Supports labels such as:54// 1 DaYS NONROOT, House, 1 DaYs, 15 DaYs All Colours Mix,55// 30 DaYs PRO, 1 DaYs Basic, 1 Year Ios Esign Gbox Certificate,56// 1 DaYs Root + Nonroot, 7 DaYS PC AIMKILL, 30 Day Pc Modmenu x86,57// 3 DaYs SAFE, 3 DaYs BRUTAL, etc.58var durationText = rawDuration.replace(/\s+/g, " ").trim();59var durMatch = durationText.toLowerCase().match(/^([0-9]+(?:\.[0-9]+)?)\s*(d|day|days|h|hr|hrs|hour|hours|m|min|mins|minute|minutes)(?:\s+(.+))?$/);60var numericOnly = durationText.match(/^([0-9]+(?:\.[0-9]+)?)/);61var pValue = durMatch ? durMatch[1] : (numericOnly ? numericOnly[1] : "0");62var unitRaw = durMatch ? durMatch[2] : "d";63var customSuffix = durMatch && durMatch[3] ? durMatch[3].trim() : "";64var pUnit = "day";65if (/^h/.test(unitRaw)) { pUnit = "hour"; }66else if (/^m/.test(unitRaw)) { pUnit = "minute"; }67 68// A non-numeric label (for example "House") is valid as an exact API duration name.69if (!durationText) {70  Bot.sendMessage("❌ Duration/API name empty hai!");71  return;72}73 74var pDays = String(pValue); // legacy field; exact API label is stored separately below.75 76// 🟢 Dynamic Global Price Keys — unit-aware (Day plans purane format me hi rehte hain,77// taaki pehle se set kiye hue Day-prices na tootein; Hour/Minute plans naye suffix format me)78var cleanProdName = pName.toUpperCase();79var priceKeySuffix = (pUnit === "day") ? pDays : (pDays + "_" + pUnit);80var normalKey = "price_normal_" + cleanProdName + "_" + priceKeySuffix;81var resellerKey = "price_reseller_" + cleanProdName + "_" + priceKeySuffix;82 83Bot.setProperty(normalKey, pNormal, "number");84Bot.setProperty(resellerKey, pReseller, "number");85 86// Database se existing products list nikalna87var productList = Bot.getProperty("stored_products") || [];88 89// Check karna ki kya yeh product pehle se list me hai?90var productIndex = -1;91for (var i = 0; i < productList.length; i++) {92  if (productList[i].name.toLowerCase() === pName.toLowerCase()) {93    productIndex = i;94    break;95  }96}97 98// 🕒 Human-readable duration label99var unitLabelWord = (pUnit === "hour") ? (Number(pDays) === 1 ? "Hour" : "Hours") :100                     (pUnit === "minute") ? (Number(pDays) === 1 ? "Minute" : "Minutes") :101                     (Number(pDays) === 1 ? "Day" : "Days");102var durationDisplay = durationText;103 104// 🪄 EXACT WEBSITE/API DURATION LABEL105// Never rewrite casing, pluralisation, suffixes, or custom names.106// This fixes labels such as "1 DaYs NONROOT" and "1 Year Ios Esign Gbox Certificate".107var autoWebsiteName = durationText;108 109// Setup complete plan object with dynamic fallback name + unit info110var newPlan = {111  days: pDays,                 // ab ye numeric "value" hai (backward-compat naam)112  unit: pUnit,                 // "day" | "hour" | "minute"  ✅ NEW113  durationDisplay: durationDisplay, // ✅ NEW — human readable, jaise "1 Hour", "30 Minutes", "7 Days"114  normal_price: pNormal,115  reseller_price: pReseller,116  name_on_website: autoWebsiteName,117  api_duration: autoWebsiteName118};119 120if (productIndex !== -1) {121  if (!productList[productIndex].plans) { productList[productIndex].plans = []; }122  123  var planUpdated = false;124  for (var p = 0; p < productList[productIndex].plans.length; p++) {125    var existingUnit = productList[productIndex].plans[p].unit || "day";126    if (String(productList[productIndex].plans[p].days) === pDays && existingUnit === pUnit) {127      productList[productIndex].plans[p] = newPlan;128      planUpdated = true;129      break;130    }131  }132  133  if (!planUpdated) {134    productList[productIndex].plans.push(newPlan);135  }136  Bot.sendMessage("✅ Product <b>" + pName + "</b> me <code>" + durationDisplay + "</code> ka plan ₹" + pNormal + " (Reseller: ₹" + pReseller + ") par set ho gaya!\nℹ️ <i>API Target Format: " + autoWebsiteName + "</i>", { parse_mode: "HTML" });137} else {138  var defaultEmoji = "5226656353744862682"; 139  productList.push({140    name: pName,141    emoji: defaultEmoji,142    plans: [newPlan]143  });144  Bot.sendMessage("✅ Naya Product <b>" + pName + "</b> successfully register ho gaya!\nℹ️ <i>API Target Format: " + autoWebsiteName + "</i>", { parse_mode: "HTML" });145}146 147// Database array update execution148Bot.setProperty("stored_products", productList, "json");