indrajitghosh20006/Igstore_01botPublic Β· Bot Template

ProfileTelegram

AIThe bot provides an admin interface for a digital store, allowing the owner or co‑admins to add balances, products, plans, and categories. It supports payment workflows via UPI and Binance Pay, automatically generating QR codes and handling manual approval of deposits. The code patches inline keyboards to use premium emoji icons and includes helper functions for user and bot properties. Overall, it serves as a commerce management tool for a Telegram-based storefront.

Commercestoreadminbalanceproductplancategory
170 commands0 envUpdated 7h agoCreated Oct 30, 2026
Back to folder

commands/_set_discount.js

javascript Β· 140 lines

Raw
1/**#command2name: /set_discount3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12// PREMIUM BUTTON ICONS13(function(){14  try {15    if (!JSON.__premiumPatched) {16      var __origStringify = JSON.stringify;17      JSON.stringify = function(value, replacer, space) {18        try {19          if (value && value.inline_keyboard && Array.isArray(value.inline_keyboard)) {20            var premiumIds = [21              "6143444134125379822",22              "6091379307907652768",23              "6147534454819661264",24              "6147817325660741985",25              "6235683689292897318",26              "6102856637343600044"27            ];28            var rows = value.inline_keyboard.map(function(row, ri) {29              if (!Array.isArray(row)) return row;30              return row.map(function(btn, bi) {31                if (!btn || typeof btn !== "object") return btn;32                var copy = {};33                for (var k in btn) copy[k] = btn[k];34                if (!copy.icon_custom_emoji_id) copy.icon_custom_emoji_id = premiumIds[(ri + bi) % premiumIds.length];35                return copy;36              });37            });38            var cloned = {};39            for (var key in value) cloned[key] = value[key];40            cloned.inline_keyboard = rows;41            return __origStringify.call(JSON, cloned, replacer, space);42          }43        } catch (e) {}44        return __origStringify.call(JSON, value, replacer, space);45      };46      JSON.__premiumPatched = true;47    }48  } catch (e) {}49})();50 51 52 53// =========================================================54// πŸ’Έ ADMIN/CO-ADMIN β€” Auto-Discount System (no coupon code needed)55// Usage:56//   /set_discount global | 10                        β†’ 10% off EVERYTHING57//   /set_discount PRODUCT NAME | all | 15             β†’ 15% off entire product (all plans)58//   /set_discount PRODUCT NAME | 1d | 20               β†’ 20% off just that one plan59//   /set_discount PRODUCT NAME | 1d | remove           β†’ removes that specific discount60// Most SPECIFIC discount wins (plan > product > global). If the user also61// applies a coupon, the coupon takes priority over an auto-discount.62// =========================================================63 64try {65  var ownerId = Bot.getProperty("owner_id") || "7839151435";66  var isCoAdmin = Bot.getProperty("co_admin_" + String(chat.chatid));67  if (String(chat.chatid) !== ownerId && !isCoAdmin) {68    Bot.sendMessage("❌ Restricted command!");69    return;70  }71 72  if (!params || params.trim() === "") {73    Bot.sendMessage(74      "⚠️ <b>Format:</b>\n" +75      "<code>/set_discount global | 10</code>  (sab par 10%)\n" +76      "<code>/set_discount PRODUCT NAME | all | 15</code>  (pure product par)\n" +77      "<code>/set_discount PRODUCT NAME | 1d | 20</code>  (sirf 1 Day plan par)\n" +78      "<code>/set_discount PRODUCT NAME | 1d | remove</code>  (hata do)",79      { parse_mode: "HTML" }80    );81    return;82  }83 84  var parts = params.split("|").map(function (p) { return p.trim(); });85 86  if (parts[0].toLowerCase() === "global") {87    var pct = parts[1];88    if (!pct || pct.toLowerCase() === "remove") {89      Bot.setProperty("auto_discount_global", null, "number");90      Bot.sendMessage("βœ… Global discount hata diya gaya.", { parse_mode: "HTML" });91      return;92    }93    var pctVal = parseFloat(pct);94    if (isNaN(pctVal) || pctVal <= 0 || pctVal > 100) { Bot.sendMessage("❌ Valid % chahiye (1-100)."); return; }95    Bot.setProperty("auto_discount_global", pctVal, "number");96    Bot.sendMessage("βœ… <b>Global Discount set:</b> -" + pctVal + "% (sabhi products/plans par apply hoga)", { parse_mode: "HTML" });97    return;98  }99 100  if (parts.length < 3) {101    Bot.sendMessage("⚠️ Format: <code>/set_discount PRODUCT NAME | DURATION | PERCENT</code>", { parse_mode: "HTML" });102    return;103  }104 105  var prodNameUpper = parts[0].toUpperCase();106  var scopeKey;107  if (parts[1].toLowerCase() === "all") {108    scopeKey = "ALL";109  } else {110    var durMatch = parts[1].toLowerCase().match(/^([0-9]+(?:\.[0-9]+)?)\s*(h|hr|hrs|hour|hours|m|min|mins|minute|minutes|d|day|days)?$/);111    var dVal = durMatch ? durMatch[1] : parts[1].replace(/[^0-9.]/g, "");112    var uRaw = durMatch ? (durMatch[2] || "d") : "d";113    var uNorm = /^h/.test(uRaw) ? "HOUR" : /^m/.test(uRaw) ? "MINUTE" : "DAY";114    scopeKey = dVal + "_" + uNorm;115  }116  var pctOrRemove = parts[2];117 118  var propKey = "auto_discount_" + prodNameUpper + "_" + scopeKey;119 120  if (pctOrRemove.toLowerCase() === "remove") {121    Bot.setProperty(propKey, null, "number");122    Bot.sendMessage("βœ… Discount hata diya gaya: <code>" + parts[0] + " (" + parts[1] + ")</code>", { parse_mode: "HTML" });123    return;124  }125 126  var pctVal2 = parseFloat(pctOrRemove);127  if (isNaN(pctVal2) || pctVal2 <= 0 || pctVal2 > 100) { Bot.sendMessage("❌ Valid % chahiye (1-100)."); return; }128 129  Bot.setProperty(propKey, pctVal2, "number");130  Bot.sendMessage(131    "<blockquote>βœ… <b>Discount Set!</b></blockquote>\n\n" +132    "πŸ“¦ <b>Product:</b> " + parts[0] + "\n" +133    "⏳ <b>Scope:</b> " + (scopeKey === "ALL" ? "Entire Product (all plans)" : parts[1]) + "\n" +134    "πŸ’Έ <b>Discount:</b> -" + pctVal2 + "%",135    { parse_mode: "HTML" }136  );137 138} catch (err) {139  Bot.sendMessage("⚠️ Error: " + err.message);140}