ashoksarande3/ASHOK_HACK_STORE_BOTPublic ยท Bot Template
AIThis bot operates as a commercial storefront for selling Free Fire game hacks and cheats via UPI QR code payments. It features a dynamic pricing system with separate normal and reseller prices, product plans with flexible durations (days, hours, minutes), and a reseller program requiring a one-time upgrade fee. The bot handles payment verification through QR code generation and expiry tracking, user verification via Telegram contact sharing, and admin tools for stock management, plan creation, and ownership transfer. It includes a balance system, maintenance mode, and Telegram Stars payment fallback. The codebase uses TeleBotHost's TBL JavaScript APIs (Bot, Api, HTTP, db properties, Libs) for all logic.
commands/_start.js
javascript ยท 616 lines
1/**#command2name: /start3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12try { 13 var adminId = String(Bot.getProperty("owner_id") || "8660373585");14 var userId = String(user.telegramid);15 16 // โญ TELEGRAM STARS โ fallback event detection (payment events may route here17 // generically depending on the platform, so we check and delegate explicitly)18 if (request && request.pre_checkout_query) {19 Bot.run({ command: "/onPreCheckoutQuery" });20 return;21 }22 if (request && request.message && request.message.successful_payment) {23 Bot.run({ command: "/onSuccessfulPayment" });24 return;25 }26 27 // Safe variable fallbacks for BJS environment28 var msgText = (typeof message !== 'undefined' && message) ? message.trim() : "";29 // โ
FIXED: pehle "data" naam ka ek undefined global variable padha ja raha tha, jo hamesha30 // empty rehta tha โ isliye koi bhi callback button jo "/start" call karta tha (jaise "Back to31 // Menu"), silently fail ho jaata tha aur user ko koi response hi nahi milta tha.32 var callbackData = (request && request.callback_query && request.callback_query.data) ? request.callback_query.data : "";33 34 // =====================================================35 // ๐ MAINTENANCE MODE GATE (โ
NEW)36 // Owner/Co-Admins hamesha through jaate hain; baaki sabko premium screen dikhta hai.37 // =====================================================38 var isMaintenanceOn = Bot.getProperty("maintenance_mode") || false;39 var isOwnerOrCoAdmin = (userId === adminId) || !!Bot.getProperty("co_admin_" + userId);40 41 if (isMaintenanceOn && !isOwnerOrCoAdmin) {42 Bot.sendMessage(43 "<blockquote><tg-emoji emoji-id='6100657257605763582'>๐ </tg-emoji> <b>BOT UNDER MAINTENANCE</b></blockquote>\n\n" +44 "<i>Hum kuch premium improvements kar rahe hain! Kripya thodi der baad wapas try karein.</i>\n\n" +45 "<tg-emoji emoji-id='6100170496077204999'>๐</tg-emoji> <i>Dhanyawad for your patience!</i>",46 { parse_mode: "HTML" }47 );48 return;49 }50 51 // โ
NEW: Maintenance abhi-abhi hata hai โ is user ko ek baar premium "We're Back!" welcome do52 var maintenanceRemovedAt = Bot.getProperty("maintenance_removed_at");53 var userSeenMaintenanceRemoved = User.getProperty("seen_maintenance_removed_at");54 if (!isMaintenanceOn && maintenanceRemovedAt && userSeenMaintenanceRemoved !== maintenanceRemovedAt) {55 User.setProperty("seen_maintenance_removed_at", maintenanceRemovedAt, "number");56 Api.sendMessage({57 chat_id: chat.chatid,58 text: "<blockquote><tg-emoji emoji-id='6102856637343600044'>โ
</tg-emoji> <b>MAINTENANCE REMOVED โ WE'RE BACK!</b></blockquote>\n\n" +59 "<tg-emoji emoji-id='6091571559233755994'>๐</tg-emoji> <i>Bot fully automated system ke saath phir se live hai!</i>\n" +60 "<i>Tap /start to continue, or Buy Now to grab your keys instantly.</i>",61 parse_mode: "HTML",62 reply_markup: JSON.stringify({63 inline_keyboard: [[64 { text: "Buy Now", callback_data: "/buy_hack", style: "success", icon_custom_emoji_id: "6312263493051489212" }65 ]]66 })67 });68 }69 70 var currentStep = User.getProperty("add_product_step");71 var isAwaitingBroadcast = User.getProperty("awaiting_broadcast_data");72 73 // ๐จ PREMIUM CUSTOM EMOJIS DEFINITION (Fixed with escaped double quotes)74 var EMJ_VERIFIED_CHECK = "<tg-emoji emoji-id=\"5875465628285931233\">โ๏ธ</tg-emoji>";75 var EMJ_CROWN = "<tg-emoji emoji-id=\"6311975081702597046\">๐</tg-emoji>";76 var EMJ_DROP = "<tg-emoji emoji-id=\"6080228009439141516\">๐ง</tg-emoji>";77 var EMJ_CHECK = "<tg-emoji emoji-id=\"6080214566191505147\">โ
</tg-emoji>";78 var EMJ_ROCKET = "<tg-emoji emoji-id=\"6091571559233755994\">๐</tg-emoji>";79 var EMJ_RADAR = "<tg-emoji emoji-id=\"6093591495237967001\">๐ก</tg-emoji>";80 var EMJ_STAR = "<tg-emoji emoji-id=\"6093677128295914531\">โจ</tg-emoji>";81 var EMJ_RED_DOT = "<tg-emoji emoji-id=\"6093854128193152827\">๐ด</tg-emoji>";82 83 // Access Granted ke liye aapka requested special premium custom emoji84 var EMJ_NEW_ACCESS = "<tg-emoji emoji-id=\"5875465628285931233\">โ๏ธ</tg-emoji>";85 86 // ==========================================87 // ๐ HELPER: DIRECTLY SEND MAIN SHOP MENU88 // (Bot.runCommand("/menu") is unreliable in BJS -> inline it instead)89 // ==========================================90 function sendMainMenu() {91 try {92 // โ
FIXED: ab same wallet store se read hoga jo purchase flows use karte hain93 // (Libs.ResourcesLib "balance" resource + admin bonus balance), taaki balance sab jagah same dikhe.94 var userBal = (function() {95 var resBal = 0;96 try { resBal = Number(Libs.ResourcesLib.userRes("balance").value()) || 0; } catch (e) {}97 var bonusBal = Number(Bot.getProperty("balance" + userId) || 0);98 return (resBal + bonusBal).toFixed(2);99 })();100 101 var EMJ_HEADER_ROCKET = "<tg-emoji emoji-id='5217822164362739968'>๐</tg-emoji>";102 var EMJ_HEADER_NEW = "<tg-emoji emoji-id='6082603117763894396'>โจ</tg-emoji>";103 var EMJ_HEADER_SHIELD = "<tg-emoji emoji-id='6113743082358841933'>๐ฐ</tg-emoji>";104 105 var MSG_EMJ_STORE = "<tg-emoji emoji-id='5866053971960929280'>๐</tg-emoji>";106 var MSG_EMJ_FFID = "<tg-emoji emoji-id='5334890573281114250'>๐ฎ</tg-emoji>";107 var MSG_EMJ_PROFILE = "<tg-emoji emoji-id='5260399854500191689'>๐ฐ</tg-emoji>";108 var MSG_EMJ_ADDBAL = "<tg-emoji emoji-id='6147815702163102310'>โจ</tg-emoji>";109 var MSG_EMJ_HISTORY = "<tg-emoji emoji-id='6113743082358841933'>๐ฐ</tg-emoji>";110 var MSG_EMJ_LUDO = "<tg-emoji emoji-id='5371043439020353782'>๐ฒ</tg-emoji>";111 var MSG_EMJ_TUTORIAL = "<tg-emoji emoji-id='5258077307985207053'>๐น</tg-emoji>";112 var MSG_EMJ_PROOF = "<tg-emoji emoji-id='5330237710655306682'>โ
</tg-emoji>";113 var MSG_EMJ_SUPPORT = "<tg-emoji emoji-id='5436113877181941026'>๐ฐ</tg-emoji>";114 115 var EMJ_PREMIUM_MENU = "<tg-emoji emoji-id='5406745015365943482'>โจ</tg-emoji>";116 var EMJ_YOUR_BALANCE = "<tg-emoji emoji-id='5231200819986047254'>๐ฐ</tg-emoji>";117 var EMJ_GET_STARTED = "<tg-emoji emoji-id='6057415823222379852'>๐</tg-emoji>";118 119 var welcomeMessage =120 "<tg-emoji emoji-id=\"6266967801580231067\">๐</tg-emoji> <tg-emoji emoji-id=\"5866053971960929280\">๐ช</tg-emoji> <b>โ ASHOK PAINL STORE โ</b> <tg-emoji emoji-id=\"5866053971960929280\">๐ช</tg-emoji> <tg-emoji emoji-id=\"6266967801580231067\">๐</tg-emoji>\n\n" +121 "<tg-emoji emoji-id=\"6102856637343600044\">๐</tg-emoji> <b>Hello, " + ((user && user.first_name) ? user.first_name.toUpperCase() : "RESELLER") + "!</b>\n\n" +122 "<tg-emoji emoji-id=\"6080228009439141516\">๐ง</tg-emoji> <b>Genuine, limited-stock books. Instant delivery.</b>\n\n" +123 "<tg-emoji emoji-id=\"6147767796097884213\">๐ฆ</tg-emoji> Wide product catalog\n" +124 "<tg-emoji emoji-id=\"6215386799133433653\">๐</tg-emoji> Instant delivery on payment\n" +125 "<tg-emoji emoji-id=\"6267068789146260253\">๐ฐ</tg-emoji> Multiple payment gateways\n" +126 "<tg-emoji emoji-id=\"6100170496077204999\">๐</tg-emoji> 24/7 admin support\n\n" +127 "<i>" + EMJ_YOUR_BALANCE + " Balance: โน" + userBal + "</i>\n\n" +128 "<i>Tap any button below to begin:</i> " + EMJ_GET_STARTED;129 130 var multiColorKeyboard = [131 [{ text: "Shop Now", callback_data: "/buy_hack", style: "primary", icon_custom_emoji_id: "5866053971960929280" }],132 [133 { text: "Profile", callback_data: "/profile", style: "primary", icon_custom_emoji_id: "6145572393499762737" },134 { text: "Add Balance", callback_data: "/addfund", style: "success", icon_custom_emoji_id: "5409048419211682843" }135 ],136 [137 { text: "My Keys", callback_data: "/mykey", style: "primary", icon_custom_emoji_id: "6215386799133433653" },138 { text: "How to use", callback_data: "/how", style: "danger", icon_custom_emoji_id: "6192842983948162969" }139 ],140 [{ text: "Payment Proofs", url: "https://t.me/+_WjC5Zw9cH40Mjdl", style: "success", icon_custom_emoji_id: "5330237710655306682" }],141 [{ text: "Support", callback_data: "/support", style: "danger", icon_custom_emoji_id: "6267129592998270736" }]142 ];143 144 if (Bot.getProperty("reseller_system_enabled") && !Bot.getProperty("is_reseller_" + userId)) {145 multiColorKeyboard.push([146 { text: "Reseller Upgrade", callback_data: "/reseller_upgrade", style: "success", icon_custom_emoji_id: "6102856637343600044" }147 ]);148 }149 150 Api.sendMessage({151 chat_id: chat.chatid,152 text: welcomeMessage,153 parse_mode: "HTML",154 reply_markup: JSON.stringify({ inline_keyboard: multiColorKeyboard })155 });156 } catch (menuErr) {157 Bot.sendMessage("๐ <b>Menu Send Error:</b> <code>" + menuErr.message + "</code>", { parse_mode: "HTML" });158 }159 }160 161 // [Auto-Track User] List me user track karne ke liye162 var trackedUsers = Bot.getProperty("all_users_list") || [];163 if (!trackedUsers.includes(userId)) {164 trackedUsers.push(userId);165 Bot.setProperty("all_users_list", trackedUsers, "json");166 }167 168 // ๐ก๏ธ [ANTI-DUPLICATE CHECK] Agar user already verified hai toh seedhe menu par bhejein169 // โ
FIXED: pehle sirf exact "msgText === '/start'" ya "callbackData === '/trigger_contact_popup'"170 // match hone par hi menu bhejta tha. Kisi bhi button jo callback_data "/start" call karta tha171 // (jaise cancel-order ke baad "Back to Menu"), us case me match fail ho jaata tha aur user ko172 // koi response nahi milta tha. Ab ye check robust hai โ jab tak ye genuinely ek contact-share173 // event nahi hai ya admin ek mid-flow step me nahi hai, verified user ko hamesha menu milega.174 var couponGenStep = User.getProperty("coupon_gen_step");175 var awaitingCouponFor = User.getProperty("awaiting_coupon_for");176 var isAlreadyVerified = Bot.getProperty("verified_" + userId);177 var isContactShareEvent = !!(request && request.contact && request.contact.user_id);178 var isAdminMidFlow = (isOwnerOrCoAdmin && (currentStep || isAwaitingBroadcast || couponGenStep ||179 User.getProperty("addbal_step") || User.getProperty("rembal_step") || User.getProperty("checkbal_step")));180 var isUserMidFlow = !!awaitingCouponFor;181 182 // โ
NEW: User ne jo bhi "/start"/"/START"/"/Start" type kiya, menu aane ke183 // baad us typed command-message ko vanish (delete) kar do โ chat clean rahe.184 if (msgText.toLowerCase() === "/start" && request && request.message_id) {185 try { Api.deleteMessage({ chat_id: chat.chatid, message_id: request.message_id }); } catch (delStartErr) {}186 }187 188 if (isAlreadyVerified && !isContactShareEvent && !isAdminMidFlow && !isUserMidFlow) {189 sendMainMenu();190 return;191 }192 193 // ==========================================194 // โก MODULE: LIVE CONTACT RECEIVER & VERIFIER195 // ==========================================196 if (request && request.contact && request.contact.user_id) {197 if (String(request.contact.user_id) === userId) {198 199 var phoneNumber = request.contact.phone_number;200 var fullName = ((user.first_name || "") + " " + (user.last_name || "")).trim() || "No Name";201 var username = user.username ? "@" + user.username : "No Username";202 203 // Permanently mark user as verified globally204 Bot.setProperty("verified_" + userId, true, "boolean");205 Bot.setProperty("phone_" + userId, phoneNumber, "string");206 // โ
NEW: Joined date save karo (Profile section me dikhane ke liye)207 if (!Bot.getProperty("joined_date_" + userId)) {208 Bot.setProperty("joined_date_" + userId, new Date().toLocaleDateString("en-IN", { day: "2-digit", month: "short", year: "numeric" }), "string");209 }210 211 // 1. USER DETAILS TO ADMIN212 var adminNotification = 213 "<blockquote><b>" + EMJ_CROWN + " NEW USER VERIFIED " + EMJ_VERIFIED_CHECK + "</b></blockquote>\n" +214 "<b>โโโโโโโโโโโโโโโโโโโโโโโโโโ</b>\n" +215 "<b>๐ค Name:</b> " + fullName + "\n" +216 "<b>๐ User ID:</b> <code>" + userId + "</code>\n" +217 "<b>๐ Username:</b> " + username + "\n" +218 "<b>๐ Number:</b> <code>" + phoneNumber + "</code>\n" +219 "<b>โโโโโโโโโโโโโโโโโโโโโโโโโโ</b>";220 221 Api.sendMessage({222 chat_id: adminId,223 text: adminNotification,224 parse_mode: "HTML"225 });226 227 // 2. USER SUCCESS MESSAGE (With your exact requested custom emojis)228 var successMessage = 229 "<blockquote><b>" + EMJ_NEW_ACCESS + " ACCESS GRANTED " + EMJ_NEW_ACCESS + "</b></blockquote>\n" +230 "<b>" + EMJ_VERIFIED_CHECK + " Verification Successful!</b>\n" +231 "<b>โโโโโโโโโโโโโโโโโโโโโโโโโโ</b>\n" +232 "<b>Welcome to ASHOK PAINL STORE PANEL </b>\n" +233 "<b>Your profile is now securely fully verified.</b>\n\n" +234 "<b>" + EMJ_ROCKET + " Store Loaded Successfully Use Now! " + EMJ_CROWN + "</b>";235 236 Api.sendMessage({237 chat_id: chat.chatid,238 text: successMessage,239 parse_mode: "HTML",240 reply_markup: JSON.stringify({ remove_keyboard: true }) 241 });242 243 // โ
FIX: Direct inline menu instead of unreliable Bot.runCommand("/menu")244 sendMainMenu();245 return; 246 } else {247 Bot.sendMessage("โ <b>Verification Failed!</b> Please share your own contact number only.", { parse_mode: "HTML" });248 return;249 }250 }251 252 // ==========================================253 // ๐ฑ MODULE 0: VERIFICATION CALLBACK HANDLER254 // ==========================================255 if (msgText.toLowerCase() === "/start" || callbackData === "/trigger_contact_popup") {256 257 var verifyMessage = 258 "<blockquote><b>" + EMJ_ROCKET + " ASHOK PAINL STORE " + EMJ_RADAR + "</b></blockquote>\n" +259 "<b>" + EMJ_STAR + " Welcome, " + (user.first_name || "User") + " " + EMJ_DROP + "</b>\n" +260 "<b>โโโโโโโโโโโโโโโโโโโโโโโโโโ</b>\n" +261 "<b>" + EMJ_RED_DOT + " VERIFICATION REQUIRED " + EMJ_CHECK + "</b>\n" +262 "<b>โโโโโโโโโโโโโโโโโโโโโโโโโโ</b>\n" +263 "<b>" + EMJ_RADAR + " To start shopping, please verify your phone number.</b>\n\n" +264 "<b>" + EMJ_ROCKET + " Why we need this:</b>\n" +265 "<b> โข Secure your purchases " + EMJ_CHECK + "</b>\n" +266 "<b> โข Deliver your books to you " + EMJ_DROP + "</b>\n" +267 "<b> โข Protect your account " + EMJ_STAR + "</b>\n\n" +268 "<b>" + EMJ_RED_DOT + " Tap the blue button below to verify your account:</b>";269 270 // Standard native reply keyboard because contact sharing works securely here271 var nativeKeyboard = {272 keyboard: [273 [{ text: "โ
Verify Account", request_contact: true }]274 ],275 resize_keyboard: true,276 one_time_keyboard: true277 };278 279 Api.sendMessage({280 chat_id: chat.chatid,281 text: verifyMessage,282 parse_mode: "HTML",283 reply_markup: JSON.stringify(nativeKeyboard)284 });285 return; 286 }287 288 // ==========================================289 // ๐ฆ MODULE 1: STEP-BY-STEP PRODUCT CREATION (UPDATED FOR WEBSITE API ID)290 // ==========================================291 if (isOwnerOrCoAdmin && currentStep) {292 if (currentStep === "waiting_for_name") {293 if (!msgText) {294 Bot.sendMessage("โ ๏ธ Invalid name. Please type a valid Product Name:");295 return;296 }297 User.setProperty("temp_product_name", msgText, "string");298 User.setProperty("add_product_step", "waiting_for_emoji", "string");299 Bot.sendMessage("๐ Great! Now send the <b>Premium Emoji ID</b> for this product:", { parse_mode: "HTML" });300 return; 301 }302 303 if (currentStep === "waiting_for_emoji") {304 // Emoji ID optional: empty input gets the same default emoji used by the shop.305 var emojiValue = msgText ? msgText : "5226656353744862682";306 User.setProperty("temp_product_emoji", emojiValue, "string");307 User.setProperty("add_product_step", "waiting_for_pid", "string");308 Bot.sendMessage("๐ Nice! Now please enter the <b>Website API Product ID (PID)</b> for this item:", { parse_mode: "HTML" });309 return;310 }311 312 if (currentStep === "waiting_for_pid") {313 if (!msgText) {314 Bot.sendMessage("โ ๏ธ Invalid Product ID. Please type a valid Website PID:");315 return;316 }317 318 var savedName = User.getProperty("temp_product_name");319 var savedEmoji = User.getProperty("temp_product_emoji") || "5226656353744862682";320 var savedPid = msgText; // User ne jo PID abhi bheja321 322 if (!savedName || !savedPid) {323 Bot.sendMessage("โ ๏ธ Product details incomplete hain. /addproduct se dobara try karein.");324 User.setProperty("add_product_step", null, "string");325 return;326 }327 328 var rawProductList = Bot.getProperty("stored_products");329 var productList = [];330 if (Array.isArray(rawProductList)) {331 productList = rawProductList;332 } else if (typeof rawProductList === "string") {333 try {334 var parsedProducts = JSON.parse(rawProductList);335 if (Array.isArray(parsedProducts)) productList = parsedProducts;336 } catch (e) {}337 }338 339 // Same-name product ko duplicate banane ke bajay update karo; existing plans preserve rahenge.340 var normalizedName = String(savedName).trim().toLowerCase();341 var foundIndex = -1;342 for (var pi = 0; pi < productList.length; pi++) {343 if (productList[pi] && productList[pi].name && String(productList[pi].name).trim().toLowerCase() === normalizedName) {344 foundIndex = pi;345 break;346 }347 }348 349 if (foundIndex >= 0) {350 productList[foundIndex].name = String(savedName).trim();351 productList[foundIndex].emoji = String(savedEmoji).trim();352 productList[foundIndex].id = String(savedPid).trim();353 if (!Array.isArray(productList[foundIndex].plans)) productList[foundIndex].plans = [];354 } else {355 productList.push({356 name: String(savedName).trim(),357 emoji: String(savedEmoji).trim(),358 id: String(savedPid).trim(),359 plans: []360 });361 }362 363 Bot.setProperty("stored_products", productList, "json");364 365 // Cleanup temporary states366 User.setProperty("add_product_step", null, "string");367 User.setProperty("temp_product_name", null, "string");368 User.setProperty("temp_product_emoji", null, "string");369 370 var successMsg = "โ
<b>Product Added Successfully!</b>\n\n" +371 "๐ฆ <b>Name:</b> " + savedName + "\n" +372 "๐ <b>Emoji ID:</b> <code>" + savedEmoji + "</code>\n" +373 "๐ <b>API Product ID (PID):</b> <code>" + savedPid + "</code>\n\n" +374 "<i>Aap is product ke andar plans baad me configure kar sakte hain. Automatically website se integration ho gaya hai!</i>";375 376 Bot.sendMessage(successMsg, {377 parse_mode: "HTML",378 reply_markup: JSON.stringify({ inline_keyboard: [[{ text: "๐ Open Shop", callback_data: "/buy_hack", style: "success", icon_custom_emoji_id: "5866053971960929280" }]] })379 });380 return; 381 }382 }383 384 // ==========================================385 // ๐ต MODULE 5: ADMIN BALANCE TOOLS (Add Bal / Remove Bal / Check Bal386 // button-click continuation โ fixes buttons that previously just387 // showed a "Wrong Format" error with no way to actually complete it)388 // ==========================================389 if (userId === adminId) {390 var addbalStep = User.getProperty("addbal_step");391 var rembalStep = User.getProperty("rembal_step");392 var checkbalStep = User.getProperty("checkbal_step");393 394 if (addbalStep === "waiting_input" && msgText) {395 User.setProperty("addbal_step", null, "string");396 Bot.run({ command: "/addbal", options: { message: "/addbal " + msgText.trim() } });397 return;398 }399 if (rembalStep === "waiting_input" && msgText) {400 User.setProperty("rembal_step", null, "string");401 Bot.run({ command: "/rembal", options: { message: "/rembal " + msgText.trim() } });402 return;403 }404 if (checkbalStep === "waiting_input" && msgText) {405 User.setProperty("checkbal_step", null, "string");406 Bot.run({ command: "/checkbal", options: { params: msgText.trim() } });407 return;408 }409 }410 411 // ==========================================412 // ๐ MODULE 3: ADMIN COUPON GENERATOR (step-by-step wizard)413 // ==========================================414 if (userId === adminId && couponGenStep) {415 416 if (couponGenStep === "code") {417 if (!msgText) { Bot.sendMessage("โ ๏ธ Kripya ek valid coupon code bhejein."); return; }418 var couponCodeUpper = msgText.trim().toUpperCase();419 if (Bot.getProperty("coupon_" + couponCodeUpper)) {420 Bot.sendMessage("โ Ye coupon code pehle se exist karta hai! Doosra naam try karein.");421 return;422 }423 User.setProperty("coupon_gen_code", couponCodeUpper, "string");424 User.setProperty("coupon_gen_step", "maxclaims", "string");425 Bot.sendMessage("<tg-emoji emoji-id='6091571559233755994'>๐ฅ</tg-emoji> <b>Kitne users ye coupon use (claim) kar sakte hain?</b>\n<i>Sirf number bhejein, jaise: 50</i>", { parse_mode: "HTML" });426 return;427 }428 429 if (couponGenStep === "maxclaims") {430 var maxClaimsVal = parseInt(msgText.trim());431 if (isNaN(maxClaimsVal) || maxClaimsVal <= 0) { Bot.sendMessage("โ Kripya ek valid number bhejein (jaise 50)."); return; }432 User.setProperty("coupon_gen_maxclaims", maxClaimsVal, "number");433 User.setProperty("coupon_gen_step", "discount", "string");434 Bot.sendMessage("<tg-emoji emoji-id='6093591495237967001'>๐ธ</tg-emoji> <b>Kitne % discount dena hai?</b>\n<i>Sirf number bhejein (1-100), jaise: 10</i>", { parse_mode: "HTML" });435 return;436 }437 438 if (couponGenStep === "discount") {439 var discountVal = parseFloat(msgText.trim());440 if (isNaN(discountVal) || discountVal <= 0 || discountVal > 100) { Bot.sendMessage("โ Discount 1 se 100 ke beech honi chahiye."); return; }441 User.setProperty("coupon_gen_discount", discountVal, "number");442 User.setProperty("coupon_gen_step", "scope", "string");443 Bot.sendMessage(444 "<tg-emoji emoji-id='6093677128295914531'>๐ฏ</tg-emoji> <b>Scope batayein:</b>\n\n" +445 "โข Sabhi products/plans ke liye: <code>global</code> likh kar bhejein\n" +446 "โข Sirf ek specific product+plan ke liye: <code>Product Name | Duration</code>\n" +447 " <i>Example:</i> <code>Atomic Habits (Book) | 1d</code>",448 { parse_mode: "HTML" }449 );450 return;451 }452 453 if (couponGenStep === "scope") {454 var scopeInput = msgText.trim();455 var couponData = {456 code: User.getProperty("coupon_gen_code"),457 maxClaims: User.getProperty("coupon_gen_maxclaims"),458 discountPercent: User.getProperty("coupon_gen_discount"),459 claimedBy: [],460 isPaused: false,461 createdAt: new Date().toLocaleDateString()462 };463 464 if (scopeInput.toLowerCase() === "global") {465 couponData.scope = "global";466 } else if (scopeInput.indexOf("|") > -1) {467 var scopeParts = scopeInput.split("|");468 couponData.scope = "specific";469 couponData.productName = scopeParts[0].trim();470 couponData.duration = scopeParts[1].trim();471 } else {472 Bot.sendMessage("โ Galat format! 'global' likhein ya 'Product Name | Duration' format me bhejein.");473 return;474 }475 476 Bot.setProperty("coupon_" + couponData.code, couponData, "json");477 478 // โ
NEW: master list me bhi add karo, taaki /coupons admin command sabko list kar sake479 var couponList = Bot.getProperty("coupon_list") || [];480 if (couponList.indexOf(couponData.code) === -1) {481 couponList.push(couponData.code);482 Bot.setProperty("coupon_list", couponList, "json");483 }484 485 // Cleanup wizard state486 User.setProperty("coupon_gen_step", null, "string");487 User.setProperty("coupon_gen_code", null, "string");488 User.setProperty("coupon_gen_maxclaims", null, "number");489 User.setProperty("coupon_gen_discount", null, "number");490 491 Bot.sendMessage(492 "<blockquote>๐ <b>COUPON CREATED SUCCESSFULLY!</b></blockquote>\n\n" +493 "๐ท <b>Code:</b> <code>" + couponData.code + "</code>\n" +494 "๐ฅ <b>Max Claims:</b> " + couponData.maxClaims + "\n" +495 "๐ธ <b>Discount:</b> " + couponData.discountPercent + "%\n" +496 "๐ฏ <b>Scope:</b> " + (couponData.scope === "global" ? "๐ Global (All Plans)" : "๐ฆ " + couponData.productName + " (" + couponData.duration + ")"),497 { parse_mode: "HTML" }498 );499 return;500 }501 }502 503 // ==========================================504 // ๐ MODULE 4: USER โ APPLY COUPON CODE TEXT ENTRY505 // ==========================================506 if (awaitingCouponFor) {507 var enteredCode = msgText.trim().toUpperCase();508 var couponRec = Bot.getProperty("coupon_" + enteredCode);509 510 User.setProperty("awaiting_coupon_for", null, "string");511 512 if (!couponRec) {513 Bot.sendMessage("โ <b>Invalid Coupon Code!</b>", { parse_mode: "HTML" });514 return;515 }516 if (couponRec.isPaused) {517 Bot.sendMessage("โธ Ye coupon abhi paused hai, thodi der baad try karein.", { parse_mode: "HTML" });518 return;519 }520 if (!Array.isArray(couponRec.claimedBy)) { couponRec.claimedBy = []; }521 if (couponRec.claimedBy.indexOf(userId) > -1) {522 Bot.sendMessage("โ ๏ธ Aapne ye coupon already use kar liya hai!", { parse_mode: "HTML" });523 return;524 }525 if (couponRec.claimedBy.length >= couponRec.maxClaims) {526 Bot.sendMessage("โ Is coupon ki claim limit khatam ho gayi hai!", { parse_mode: "HTML" });527 return;528 }529 530 var couponTargetParts = awaitingCouponFor.split(" ");531 var cTargetProdIdx = couponTargetParts[0];532 var cTargetPlanIdx = couponTargetParts[1];533 534 if (couponRec.scope === "specific") {535 var cProductList = Bot.getProperty("stored_products") || [];536 var cProduct = cProductList[Number(cTargetProdIdx)];537 var cPlan = cProduct ? cProduct.plans[Number(cTargetPlanIdx)] : null;538 var cDurationDisplay = cPlan ? (cPlan.durationDisplay || (cPlan.days + " Days")) : "";539 var matchesProduct = cProduct && cProduct.name.trim().toLowerCase() === couponRec.productName.trim().toLowerCase();540 var matchesDuration = cDurationDisplay.toLowerCase().indexOf(String(couponRec.duration).toLowerCase().replace(/[^a-z0-9]/g, "")) > -1 ||541 String(couponRec.duration).replace(/[^0-9]/g, "") === String(cPlan ? cPlan.days : "");542 if (!matchesProduct) {543 Bot.sendMessage("โ Ye coupon is product ke liye valid nahi hai!", { parse_mode: "HTML" });544 return;545 }546 }547 548 // โ
Valid โ apply and mark claimed549 couponRec.claimedBy.push(userId);550 Bot.setProperty("coupon_" + enteredCode, couponRec, "json");551 User.setProperty("applied_coupon_" + cTargetProdIdx + "_" + cTargetPlanIdx, enteredCode, "string");552 553 Bot.sendMessage("๐ <b>Coupon Applied!</b> -" + couponRec.discountPercent + "% discount added.", { parse_mode: "HTML" });554 555 Bot.run({556 command: "buyitem",557 options: { params: cTargetProdIdx + " " + cTargetPlanIdx }558 });559 return;560 }561 562 // ==========================================563 // ๐ข MODULE 2: PREMIUM BROADCAST SYSTEM564 // ==========================================565 if (userId === adminId && isAwaitingBroadcast) {566 User.setProperty("awaiting_broadcast_data", false, "boolean");567 var userList = Bot.getProperty("all_users_list") || [];568 569 if (userList.length === 0) {570 Bot.sendMessage("โ Bot mein abhi tak koi bhi user registered nahi hai.");571 return;572 }573 574 var targetMessageId = null;575 if (request) {576 if (request.message_id) { targetMessageId = request.message_id; }577 else if (request.message && request.message.message_id) { targetMessageId = request.message.message_id; }578 }579 580 if (!targetMessageId) {581 Bot.sendMessage("โ Unable to fetch message ID for broadcast.");582 return;583 }584 585 Bot.sendMessage("โณ Sending premium broadcast to " + userList.length + " users... Please wait.");586 587 // โ
FIXED: pehle ek bhi blocked/invalid user Api.copyMessage() ko throw karwa deta588 // tha, jo bahar wale catch() tak chala jaata tha โ isse loop beech me hi ruk jaata589 // tha (baaki users ko broadcast nahi jaata tha) aur admin ko scary "Error in handling"590 // dikhta tha, jabki zyada tar users ko message mil chuka hota tha. Ab har send apne591 // try/catch me hai, aur end me accurate success/fail count milega.592 var sentCount = 0;593 var failedCount = 0;594 for (var i = 0; i < userList.length; i++) {595 try {596 Api.copyMessage({597 chat_id: String(userList[i]),598 from_chat_id: adminId,599 message_id: Number(targetMessageId)600 });601 sentCount++;602 } catch (perUserErr) {603 failedCount++;604 }605 }606 Bot.sendMessage(607 "โ
<b>Broadcast Complete!</b>\n" +608 "๐ค <b>Sent:</b> " + sentCount + " users\n" +609 (failedCount > 0 ? "โ ๏ธ <b>Failed/Blocked:</b> " + failedCount + " users" : "๐ <b>No failures!</b>"),610 { parse_mode: "HTML" }611 );612 }613 614} catch (err) {615 Bot.sendMessage("Error in handling: " + err.message);616}