indrajitghosh20006/HgfhhuybotPublic · Bot Template
AIThis bot provides a command‑based admin interface for managing user balances, products, and resellers. It supports adding balances via UPI or Binance Pay, approving payments, and configuring product details and categories. The bot also handles user role changes, stock uploads, and offers a simple calculator UI for entering amounts. All interactions are handled through short commands and inline keyboards, with no long‑running listeners or external frameworks.
Utilityadminbalanceproductresellerpaymentupi
138 commands0 envUpdated 15h agoCreated Sep 27, 2026
commands/_set_discount.js
javascript · 99 lines
1/**#command2name: /set_discount3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// =========================================================13// 💸 ADMIN/CO-ADMIN — Auto-Discount System (no coupon code needed)14// Usage:15// /set_discount global | 10 → 10% off EVERYTHING16// /set_discount PRODUCT NAME | all | 15 → 15% off entire product (all plans)17// /set_discount PRODUCT NAME | 1d | 20 → 20% off just that one plan18// /set_discount PRODUCT NAME | 1d | remove → removes that specific discount19// Most SPECIFIC discount wins (plan > product > global). If the user also20// applies a coupon, the coupon takes priority over an auto-discount.21// =========================================================22 23try {24 var ownerId = Bot.getProperty("owner_id") || "7839151435";25 var isCoAdmin = Bot.getProperty("co_admin_" + String(chat.chatid));26 if (String(chat.chatid) !== ownerId && !isCoAdmin) {27 Bot.sendMessage("❌ Restricted command!");28 return;29 }30 31 if (!params || params.trim() === "") {32 Bot.sendMessage(33 "⚠️ <b>Format:</b>\n" +34 "<code>/set_discount global | 10</code> (sab par 10%)\n" +35 "<code>/set_discount PRODUCT NAME | all | 15</code> (pure product par)\n" +36 "<code>/set_discount PRODUCT NAME | 1d | 20</code> (sirf 1 Day plan par)\n" +37 "<code>/set_discount PRODUCT NAME | 1d | remove</code> (hata do)",38 { parse_mode: "HTML" }39 );40 return;41 }42 43 var parts = params.split("|").map(function (p) { return p.trim(); });44 45 if (parts[0].toLowerCase() === "global") {46 var pct = parts[1];47 if (!pct || pct.toLowerCase() === "remove") {48 Bot.setProperty("auto_discount_global", null, "number");49 Bot.sendMessage("✅ Global discount hata diya gaya.", { parse_mode: "HTML" });50 return;51 }52 var pctVal = parseFloat(pct);53 if (isNaN(pctVal) || pctVal <= 0 || pctVal > 100) { Bot.sendMessage("❌ Valid % chahiye (1-100)."); return; }54 Bot.setProperty("auto_discount_global", pctVal, "number");55 Bot.sendMessage("✅ <b>Global Discount set:</b> -" + pctVal + "% (sabhi products/plans par apply hoga)", { parse_mode: "HTML" });56 return;57 }58 59 if (parts.length < 3) {60 Bot.sendMessage("⚠️ Format: <code>/set_discount PRODUCT NAME | DURATION | PERCENT</code>", { parse_mode: "HTML" });61 return;62 }63 64 var prodNameUpper = parts[0].toUpperCase();65 var scopeKey;66 if (parts[1].toLowerCase() === "all") {67 scopeKey = "ALL";68 } else {69 var durMatch = parts[1].toLowerCase().match(/^([0-9]+(?:\.[0-9]+)?)\s*(h|hr|hrs|hour|hours|m|min|mins|minute|minutes|d|day|days)?$/);70 var dVal = durMatch ? durMatch[1] : parts[1].replace(/[^0-9.]/g, "");71 var uRaw = durMatch ? (durMatch[2] || "d") : "d";72 var uNorm = /^h/.test(uRaw) ? "HOUR" : /^m/.test(uRaw) ? "MINUTE" : "DAY";73 scopeKey = dVal + "_" + uNorm;74 }75 var pctOrRemove = parts[2];76 77 var propKey = "auto_discount_" + prodNameUpper + "_" + scopeKey;78 79 if (pctOrRemove.toLowerCase() === "remove") {80 Bot.setProperty(propKey, null, "number");81 Bot.sendMessage("✅ Discount hata diya gaya: <code>" + parts[0] + " (" + parts[1] + ")</code>", { parse_mode: "HTML" });82 return;83 }84 85 var pctVal2 = parseFloat(pctOrRemove);86 if (isNaN(pctVal2) || pctVal2 <= 0 || pctVal2 > 100) { Bot.sendMessage("❌ Valid % chahiye (1-100)."); return; }87 88 Bot.setProperty(propKey, pctVal2, "number");89 Bot.sendMessage(90 "<blockquote>✅ <b>Discount Set!</b></blockquote>\n\n" +91 "📦 <b>Product:</b> " + parts[0] + "\n" +92 "⏳ <b>Scope:</b> " + (scopeKey === "ALL" ? "Entire Product (all plans)" : parts[1]) + "\n" +93 "💸 <b>Discount:</b> -" + pctVal2 + "%",94 { parse_mode: "HTML" }95 );96 97} catch (err) {98 Bot.sendMessage("⚠️ Error: " + err.message);99}