mansuriamaan803/SANJEEVFFSTORE_botPublic · Bot Template

AIThis bot is a commerce platform for selling digital products, primarily focused on FreeFire accounts and related services. It provides admin tools for managing products, categories, stock, reseller roles, and a balance system for user payments. Users can browse products, apply coupons, and check their balance through an interactive interface with premium emojis and inline keyboards.

Commercecommercestoreproductsresellerbalancecoupon
ProfileTelegram
102 commands0 envUpdated 12d agoCreated Aug 26, 2026
Back to folder

commands/_addplan.js

javascript · 152 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") || "8963001413";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" +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 — value + unit (day / hour / minute) nikalta hai53var durMatch = rawDuration.toLowerCase().match(/^([0-9]+(?:\.[0-9]+)?)\s*(h|hr|hrs|hour|hours|m|min|mins|minute|minutes|d|day|days)?$/);54var pValue = durMatch ? durMatch[1] : rawDuration.replace(/[^0-9.]/g, "");55var unitRaw = durMatch ? (durMatch[2] || "d") : "d";56var pUnit = "day";57if (/^h/.test(unitRaw)) { pUnit = "hour"; }58else if (/^m/.test(unitRaw)) { pUnit = "minute"; }59else { pUnit = "day"; }60 61if (!pValue || isNaN(Number(pValue))) {62  Bot.sendMessage("❌ Duration samajh nahi aayi! Example: 7d, 1h, 30m");63  return;64}65 66var pDays = String(pValue); // (naam legacy rakha hai backward-compat ke liye, ab ye "value" hai)67 68// 🟢 Dynamic Global Price Keys — unit-aware (Day plans purane format me hi rehte hain,69// taaki pehle se set kiye hue Day-prices na tootein; Hour/Minute plans naye suffix format me)70var cleanProdName = pName.toUpperCase();71var priceKeySuffix = (pUnit === "day") ? pDays : (pDays + "_" + pUnit);72var normalKey = "price_normal_" + cleanProdName + "_" + priceKeySuffix;73var resellerKey = "price_reseller_" + cleanProdName + "_" + priceKeySuffix;74 75Bot.setProperty(normalKey, pNormal, "number");76Bot.setProperty(resellerKey, pReseller, "number");77 78// Database se existing products list nikalna79var productList = Bot.getProperty("stored_products") || [];80 81// Check karna ki kya yeh product pehle se list me hai?82var productIndex = -1;83for (var i = 0; i < productList.length; i++) {84  if (productList[i].name.toLowerCase() === pName.toLowerCase()) {85    productIndex = i;86    break;87  }88}89 90// 🕒 Human-readable duration label91var unitLabelWord = (pUnit === "hour") ? (Number(pDays) === 1 ? "Hour" : "Hours") :92                     (pUnit === "minute") ? (Number(pDays) === 1 ? "Minute" : "Minutes") :93                     (Number(pDays) === 1 ? "Day" : "Days");94var durationDisplay = pDays + " " + unitLabelWord;95 96// 🪄 AUTOMATIC WEBSITE PLAN NAME PREDICTOR ENGINE (sirf Day-unit plans ke liye — 97// external API generally sirf Day-based duration hi samajhta hai)98var lowerName = pName.toLowerCase();99var autoWebsiteName = durationDisplay; // Default fallback — Hour/Minute plans literal label use karte hain100 101if (pUnit === "day") {102  autoWebsiteName = pDays + " Days"; // Default Fallback103  if (lowerName.indexOf("pato") > -1) {104    autoWebsiteName = pDays + " DaYs All Colours Mix";105  } else if (lowerName.indexOf("prime") > -1 || lowerName.indexOf("hook") > -1) {106    autoWebsiteName = (pDays === "7") ? "7 Days NonRoot" : pDays + " Days Nonroot";107  } else if (lowerName.indexOf("nonroot") > -1 || lowerName.indexOf("non root") > -1) {108    autoWebsiteName = pDays + " DaYs NONROOT";109  } else if (lowerName.indexOf("all android") > -1 || lowerName.indexOf("mix") > -1) {110    autoWebsiteName = pDays + " DaYs All Colours Mix";111  }112}113 114// Setup complete plan object with dynamic fallback name + unit info115var newPlan = {116  days: pDays,                 // ab ye numeric "value" hai (backward-compat naam)117  unit: pUnit,                 // "day" | "hour" | "minute"  ✅ NEW118  durationDisplay: durationDisplay, // ✅ NEW — human readable, jaise "1 Hour", "30 Minutes", "7 Days"119  normal_price: pNormal,120  reseller_price: pReseller,121  name_on_website: autoWebsiteName122};123 124if (productIndex !== -1) {125  if (!productList[productIndex].plans) { productList[productIndex].plans = []; }126  127  var planUpdated = false;128  for (var p = 0; p < productList[productIndex].plans.length; p++) {129    var existingUnit = productList[productIndex].plans[p].unit || "day";130    if (String(productList[productIndex].plans[p].days) === pDays && existingUnit === pUnit) {131      productList[productIndex].plans[p] = newPlan;132      planUpdated = true;133      break;134    }135  }136  137  if (!planUpdated) {138    productList[productIndex].plans.push(newPlan);139  }140  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" });141} else {142  var defaultEmoji = "5226656353744862682"; 143  productList.push({144    name: pName,145    emoji: defaultEmoji,146    plans: [newPlan]147  });148  Bot.sendMessage("✅ Naya Product <b>" + pName + "</b> successfully register ho gaya!\nℹ️ <i>API Target Format: " + autoWebsiteName + "</i>", { parse_mode: "HTML" });149}150 151// Database array update execution152Bot.setProperty("stored_products", productList, "json");