pnxh2371/Ankit_mods_store_botPublic ยท Bot Template
AI๐ษดแดษชแด ๐แดแด ๊ฑ ๐แดแดสแด ๐ appears to be a Telegram automation bot. Commands include /*, /addbal, /addbal_all, /addbal_binance, /addbal_binance_approve, /addbal_binance_paid, /addbal_upi, /addcat_id. Observed in code: messaging, http, libs, keyboards, payments.
Utilityutility
133 commands0 envUpdated 8h agoCreated Sep 10, 2026
commands/_onBuyCheck.js
javascript ยท 468 lines
1/**#command2name: /onBuyCheck3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12function resolveApiDuration(plan, cleanPlanDays, planUnit, productNameOverride) {13 // IMPORTANT: Keep the admin/API duration name exactly as entered.14 // The product-specific day ranges below are used only when the stored plan15 // contains a plain numeric Day duration; this lets 1-30 Day plans target16 // the exact website/API names requested by the admin without changing any17 // other product data or purchase logic.18 var raw = String((plan && (plan.api_duration || plan.name_on_website || plan.durationDisplay || plan.name || plan.title)) || "").replace(/\s+/g, " ").trim();19 20 // Already-custom API labels (including casing/suffixes) must pass through unchanged.21 if (raw && !/^[0-9]+(?:\.[0-9]+)?\s*(day|days)$/i.test(raw)) {22 return raw;23 }24 25 var dayMatch = raw.match(/^([0-9]+(?:\.[0-9]+)?)\s*(day|days)$/i);26 var n = dayMatch ? dayMatch[1] : String(cleanPlanDays || "1");27 var productName = String(productNameOverride || (plan && (plan.product_name || plan.productName || plan.product || plan.category)) || "").trim().toLowerCase();28 29 // If product name is not stored on the plan, the caller's raw API label is30 // still preserved above. Generic numeric Day plans remain "N Days".31 if (/pc\s*aim\s*silent/.test(productName)) return n + " Day Pc Aim Silent";32 if (/pc\s*modmenu\s*x86/.test(productName)) return n + " Day Pc Modmenu x86";33 if (/pc\s*bypass\s*\+\s*silent/.test(productName) || /bypass\s*\+\s*silent/.test(productName)) return n + " Days Pc Bypass + Silent";34 if (/nonroot/.test(productName) && !/root\s*\+\s*nonroot/.test(productName)) return n + " DaYS NONROOT";35 if (/pc\s*aimkill/.test(productName) || /aimkill/.test(productName)) return n + " DaYS PC AIMKILL";36 if (/root\s*\+\s*nonroot/.test(productName)) return n + " DaYs Root + Nonroot";37 if (/fluo?rite\s*ff/.test(productName)) return n + " DAYs FluoRite FF";38 if (/\broot\b/.test(productName)) return n + " DaYs ROOT";39 if (/all\s*colou?rs\s*mix/.test(productName)) return n + " DaYs All Colours Mix";40 if (/\bbasic\b/.test(productName)) return n + " DaYs Basic";41 if (/\bpro\b/.test(productName)) return n + " DaYs PRO";42 if (/\bsafe\b/.test(productName)) return n + " DaYs SAFE";43 if (/\bbrutal\b/.test(productName)) return n + " DaYs BRUTAL";44 45 // Hours/minutes are preserved exactly; no existing API duration is removed.46 var gh = raw.match(/^([0-9]+(?:\.[0-9]+)?)\s*(hour|hours)$/i);47 if (gh) return gh[1] + " Hours";48 var gm = raw.match(/^([0-9]+(?:\.[0-9]+)?)\s*(minute|minutes)$/i);49 if (gm) return gm[1] + (Number(gm[1]) === 1 ? " Minute" : " Minutes");50 51 return raw || n + " Days";52}53 54 55try {56 var userId = user.telegramid;57 58 // โ
CRITICAL FIX: Proper atomic duplicate-payment prevention59 var utrFromContent = null;60 61 // Parse content to get UTR early62 if (content) {63 var res = (typeof content === "object") ? content : JSON.parse(content);64 if (res && res.data && buyData.utr) {65 utrFromContent = buyData.utr;66 }67 }68 69 // ๐ STEP 1: Check if payment already processed using UTR (most reliable identifier)70 if (utrFromContent && Bot.getProperty("paid_" + utrFromContent)) {71 // โ
FIX: Vanish the QR completely instead of leaving a stale "already used" caption behind72 try {73 Api.deleteMessage({ chat_id: chat.chatid, message_id: request.message.message_id });74 } catch (e) {}75 76 try {77 Bot.setProperty("buy_qr_msg_id_" + userId, null, "string");78 User.setProperty("buy_qr_msg_id_" + userId, null, "string");79 } catch (e) {}80 81 if (request && request.id) {82 try {83 Api.answerCallbackQuery({84 callback_query_id: String(request.id),85 text: "โ
ALREADY CLAIMED โ
\nYe order pehle hi deliver ho chuka hai.",86 show_alert: true87 });88 } catch (e) {}89 }90 91 Api.sendMessage({92 chat_id: chat.chatid,93 text: "<blockquote><tg-emoji emoji-id='5330237710655306682'>โ
</tg-emoji> <b>ORDER ALREADY CLAIMED</b>\n<i>Ye payment pehle hi verify ho kar item deliver ho chuka hai. Apni keys 'All History' me check karein.</i></blockquote>",94 parse_mode: "HTML",95 reply_markup: JSON.stringify({96 inline_keyboard: [[97 { text: "๐ My Keys", callback_data: "/mykey", style: "primary" },98 { text: "๐ Shop Menu", callback_data: "/buy_hack", style: "success" }99 ]]100 })101 });102 return;103 }104 105 // ๐ STEP 2: Duplicate-click lock check106 var isChecking = User.getProperty("buy_verifying_lock_" + userId);107 if (isChecking) {108 if (request && request.id) {109 Api.answerCallbackQuery({110 callback_query_id: String(request.id),111 text: "โณ ALREADY CHECKING โ PLEASE WAIT...",112 show_alert: true113 });114 }115 return;116 }117 118 // ๐ STEP 3: SET LOCK IMMEDIATELY before any async operations119 User.setProperty("buy_verifying_lock_" + userId, true, "boolean");120 121 if (!content) {122 Api.editMessageCaption({123 chat_id: chat.chatid, message_id: request.message.message_id,124 caption: "<blockquote>โ ๏ธ <b>Server didn't respond.</b>\nClick 'I have paid' again.</blockquote>", parse_mode: "HTML"125 });126 User.setProperty("buy_verifying_lock_" + userId, false, "boolean");127 return;128 }129 130 var res = (typeof content === "object") ? content : JSON.parse(content);131 132 // Normalize FamPay response variants. Older code accepted only the exact133 // {status:"success",data:{...}} shape, which caused false "not received"134 // messages when the gateway returned SUCCESS/PAID or success:true.135 var buyData = (res && res.data && typeof res.data === "object") ? res.data :136 (res && res.result && typeof res.result === "object") ? res.result :137 (res && res.payment && typeof res.payment === "object") ? res.payment :138 res;139 var buyStatus = String(140 (res && (res.status || res.payment_status || res.state)) ||141 (buyData && (buyData.status || buyData.payment_status || buyData.state)) || ""142 ).trim().toLowerCase().replace(/[\s-]+/g, "_");143 var buySuccess = ["success","successful","paid","completed","complete","verified",144 "payment_success","payment_successful","payment_paid"].indexOf(buyStatus) !== -1;145 if (!buySuccess && res) {146 buySuccess = res.success === true || String(res.success).toLowerCase() === "true" ||147 res.success === 1 || String(res.success) === "1";148 }149 if (!buySuccess && buyData) {150 buySuccess = buyData.paid === true || String(buyData.paid).toLowerCase() === "true";151 }152 153 if (buySuccess && buyData) {154 var utr = buyData.utr || buyData.transaction_id || buyData.txn_id ||155 buyData.reference_id || buyData.ref_id || ("ORDER-" + String(User.getProperty("buy_pending_order_id") || "UNKNOWN"));156 var isPaid = Bot.getProperty("paid_" + utr);157 158 if (isPaid) {159 // โ
FIX: Vanish the QR completely instead of leaving a stale "already used" caption behind160 try {161 Api.deleteMessage({ chat_id: chat.chatid, message_id: request.message.message_id });162 } catch (e) {}163 164 try {165 Bot.setProperty("buy_qr_msg_id_" + userId, null, "string");166 User.setProperty("buy_qr_msg_id_" + userId, null, "string");167 } catch (e) {}168 169 if (request && request.id) {170 try {171 Api.answerCallbackQuery({172 callback_query_id: String(request.id),173 text: "โ
ALREADY CLAIMED โ
\nYe order pehle hi deliver ho chuka hai.",174 show_alert: true175 });176 } catch (e) {}177 }178 179 Api.sendMessage({180 chat_id: chat.chatid,181 text: "<blockquote><tg-emoji emoji-id='5330237710655306682'>โ
</tg-emoji> <b>ORDER ALREADY CLAIMED</b>\n<i>Ye payment pehle hi verify ho kar item deliver ho chuka hai. Apni keys 'All History' me check karein.</i></blockquote>",182 parse_mode: "HTML",183 reply_markup: JSON.stringify({184 inline_keyboard: [[185 { text: "๐ My Keys", callback_data: "/mykey", style: "primary" },186 { text: "๐ Shop Menu", callback_data: "/buy_hack", style: "success" }187 ]]188 })189 });190 User.setProperty("buy_verifying_lock_" + userId, false, "boolean");191 return;192 }193 194 // โ
IMMEDIATELY mark as paid BEFORE any async API calls to prevent race condition195 Bot.setProperty("paid_" + utr, true, "boolean");196 197 Api.editMessageCaption({198 chat_id: chat.chatid, message_id: request.message.message_id,199 caption: "<tg-emoji emoji-id='6192822213486321961'>๐</tg-emoji> <b>Payment verified! Delivering your key...</b>",200 parse_mode: "HTML"201 });202 203 // โ
FIX: Detect which purchase pipeline this QR payment belongs to.204 // "ffid" = local stock-based FF ID item (set by /execute_id_buy on low balance)205 // default/"plan" = original plan-based product via external xyzcheats API206 var flowType = User.getProperty("buy_flow_type") || "plan";207 208 if (flowType === "ffid") {209 // =========================================================210 // ๐ฎ FF ID STOCK DELIVERY (after successful QR payment)211 // =========================================================212 try {213 var rawType = User.getProperty("buy_ffid_rawtype") || "";214 var isResellerFlow = User.getProperty("buy_ffid_is_reseller") === true;215 var finalCost = Number(User.getProperty("buy_price") || 0);216 var displayTypeName = User.getProperty("buy_prod_name") || rawType;217 218 var stockData = [];219 var isDynamicCategory = false;220 var isGeneralCategory = false;221 var selectedCat = null;222 223 var fbCategories = Bot.getProperty("fb_categories") || [];224 if (!Array.isArray(fbCategories)) { fbCategories = []; }225 226 if (rawType.indexOf("fb_") === 0) {227 isDynamicCategory = true;228 var targetCatId = rawType.replace("fb_", "").trim();229 for (var i = 0; i < fbCategories.length; i++) {230 if (fbCategories[i].id === targetCatId) { selectedCat = fbCategories[i]; break; }231 }232 if (selectedCat) { stockData = selectedCat.stock_list || []; }233 } else if (rawType === "fb" || rawType === "google") {234 stockData = Bot.getProperty("ff_stock_" + rawType) || [];235 } else {236 isGeneralCategory = true;237 var categoriesFF = Bot.getProperty("ff_categories") || {};238 selectedCat = categoriesFF[rawType];239 if (selectedCat) {240 var fallbackStock = Bot.getProperty("ff_stock_" + rawType) || [];241 stockData = (selectedCat.stock_list && selectedCat.stock_list.length > 0) ? selectedCat.stock_list : fallbackStock;242 }243 }244 245 if (!stockData || stockData.length === 0) {246 Api.editMessageCaption({247 chat_id: chat.chatid, message_id: request.message.message_id,248 caption: "โ ๏ธ Payment received but item went out of stock. Contact admin with UTR: " + utr,249 parse_mode: "HTML"250 });251 User.setProperty("buy_verifying_lock_" + userId, false, "boolean");252 return;253 }254 255 var accountExtracted = stockData.shift();256 257 if (isDynamicCategory && selectedCat) {258 selectedCat.stock_list = stockData;259 Bot.setProperty("fb_categories", fbCategories, "json");260 } else if (isGeneralCategory && selectedCat) {261 selectedCat.stock_list = stockData;262 var categoriesFF2 = Bot.getProperty("ff_categories") || {};263 categoriesFF2[rawType] = selectedCat;264 Bot.setProperty("ff_categories", categoriesFF2, "json");265 Bot.setProperty("ff_stock_" + rawType, stockData, "json");266 } else {267 Bot.setProperty("ff_stock_" + rawType, stockData, "json");268 }269 270 var fullRawString = String(accountExtracted || "").trim();271 var emailData = fullRawString;272 var passwordData = "No Password Found";273 274 if (fullRawString.indexOf("|") !== -1) {275 var lastPipeIndex = fullRawString.lastIndexOf("|");276 var firstPart = fullRawString.substring(0, lastPipeIndex).trim();277 var secondPart = fullRawString.substring(lastPipeIndex + 1).trim();278 279 if (firstPart.indexOf(" ") !== -1) {280 var spaceParts = firstPart.split(" ");281 emailData = spaceParts[spaceParts.length - 1].trim();282 } else {283 emailData = firstPart;284 }285 passwordData = secondPart;286 }287 288 var purchasedKeys = User.getProperty("my_purchased_keys") || [];289 if (!Array.isArray(purchasedKeys)) { purchasedKeys = []; }290 var currentDate = new Date().toLocaleDateString('en-IN', { timeZone: "Asia/Kolkata" });291 purchasedKeys.push({292 productName: displayTypeName,293 cost: finalCost.toString(),294 key: emailData + (passwordData !== "No Password Found" ? " | " + passwordData : ""),295 days: "Permanent",296 date: currentDate297 });298 User.setProperty("my_purchased_keys", purchasedKeys, "json");299 300 var deliveryText =301 "โโโโโโโโโโโโโโโโโโโโโโโโโโ\n" +302 "โ โค๏ธโ๐ฅ <b>PURCHASE SUCCESSFUL!</b> โค๏ธโ๐ฅ โ\n" +303 "โโโโโโโโโโโโโโโโโโโโโโโโโโ\n\n" +304 "๐ฆ <b>Item:</b> <code>" + displayTypeName + "</code>\n" +305 "๐ฐ <b>Paid:</b> <code>โน" + finalCost + "</code> " + (isResellerFlow ? "<b>(Reseller)</b>" : "") + "\n" +306 "โโโโโโโโโโโโโโโโโโโโโโโโโโ\n" +307 "๐ค <b>ACCOUNT DETAILS:</b>\n\n" +308 "๐ <b>Email:</b> <code>" + emailData + "</code>\n" +309 "๐ <b>Password:</b> <code>" + passwordData + "</code>\n" +310 "โโโโโโโโโโโโโโโโโโโโโโโโโโ\n" +311 "โ ๏ธ <i>Copy details instantly.</i>";312 313 Api.sendMessage({314 chat_id: chat.chatid,315 text: deliveryText,316 parse_mode: "HTML"317 });318 319 var adminLogChannel = "6182067327";320 var adminNotificationMsg =321 "<blockquote>โ ๏ธ <b>NEW ORDER ALERT (QR)</b>" + (isResellerFlow ? " [RESELLER]" : "") + "</blockquote>\n" +322 "๐ค <b>User:</b> <a href='tg://user?id=" + userId + "'>" + user.first_name + "</a> (<code>" + userId + "</code>)\n" +323 "๐ฆ <b>Item:</b> <code>" + displayTypeName + "</code>\n" +324 "๐ฐ <b>Revenue:</b> <code>โน" + finalCost + "</code>\n" +325 "โก <b>Stock Left:</b> <code>" + stockData.length + " units</code>\n\n" +326 "๐ฅ <b>ACCOUNT DETAILS:</b>\n" +327 "โ <b>Email:</b> <code>" + emailData + "</code>\n" +328 "โ <b>Password:</b> <code>" + passwordData + "</code>";329 330 Api.sendMessage({331 chat_id: adminLogChannel,332 text: adminNotificationMsg,333 parse_mode: "HTML"334 });335 336 // Cleanup all buy_ state for this order337 User.setProperty("buy_flow_type", null, "string");338 User.setProperty("buy_ffid_rawtype", null, "string");339 User.setProperty("buy_ffid_is_reseller", null, "boolean");340 User.setProperty("buy_price", null, "number");341 User.setProperty("buy_needpay", null, "number");342 User.setProperty("buy_prod_name", null, "string");343 User.setProperty("buy_plan_unit", null, "string");344 User.setProperty("buy_plan_name_on_website", null, "string");345 User.setProperty("buy_pending_order_id", null);346 Bot.setProperty("buy_qr_msg_id_" + userId, null, "string");347 User.setProperty("buy_qr_msg_id_" + userId, null, "string");348 Bot.setProperty("buy_qr_caption_" + userId, null, "string");349 User.setProperty("buy_qr_caption_" + userId, null, "string");350 Bot.setProperty("buy_qr_buttons_" + userId, null, "string");351 User.setProperty("buy_qr_buttons_" + userId, null, "string");352 353 } catch (ffErr) {354 Api.editMessageCaption({355 chat_id: chat.chatid, message_id: request.message.message_id,356 caption: "โ ๏ธ Delivery error. Contact admin with UTR: " + utr + " | Error: " + ffErr.message,357 parse_mode: "HTML"358 });359 }360 User.setProperty("buy_verifying_lock_" + userId, false, "boolean");361 return;362 }363 364 // =========================================================365 // ๐ฆ ORIGINAL PLAN-BASED DELIVERY (external xyzcheats API)366 // =========================================================367 var prodIdx = User.getProperty("buy_prod_idx");368 var planIdx = User.getProperty("buy_plan_idx");369 var productList = Bot.getProperty("stored_products") || [];370 var product = productList[prodIdx];371 var plan = product && product.plans ? product.plans[planIdx] : null;372 373 if (!product || !plan) {374 Api.editMessageCaption({375 chat_id: chat.chatid, message_id: request.message.message_id,376 caption: "โ ๏ธ Payment received but product data missing. Contact admin with UTR: " + utr,377 parse_mode: "HTML"378 });379 User.setProperty("buy_verifying_lock_" + userId, false, "boolean");380 return;381 }382 383 var webProductId = String(product.id || "PID_ID").trim();384 var cleanPlanDays = User.getProperty("buy_plan_days") || String(plan.days);385 var planUnit = User.getProperty("buy_plan_unit") || plan.unit || "day";386 var prodNameLower = String(product.name).toLowerCase();387 var durationParam = resolveApiDuration(plan, cleanPlanDays, planUnit, product && product.name);388 389 // ๐ Use configured multi-API system instead of a hardcoded API.390 var apiRegistry = Bot.getProperty("api_registry") || {};391 var activeApiId = Bot.getProperty("active_reseller_api") || "";392 var selectedApi = activeApiId ? apiRegistry[activeApiId] : null;393 if (!selectedApi) {394 selectedApi = { id:"default", url:"https://bantibhaiya.com/api/reseller_v1.php", api_key:"5d655f6da12d22c618747031c78421ac", master_key:"a7f3e8b2c9d1f4a6b8c2d5e9f1a3b6c8", android_required:false, enabled:true };395 }396 if (selectedApi.enabled === false) {397 Bot.sendMessage("โ Selected API is disabled. Admin ko /apiset se active API select karna hoga.");398 return;399 }400 var postFields = { api_key:selectedApi.api_key || "", action:"buy", product_id:webProductId, duration:durationParam };401 var savedAndroidId = User.getProperty("android_id") || User.getProperty("android_id_" + userId) || Bot.getProperty("android_id_" + userId) || "";402 if (selectedApi.android_required && !savedAndroidId) {403 Bot.sendMessage("โ ๏ธ Android ID required for this API/product.");404 return;405 }406 if (savedAndroidId) postFields.android_id = String(savedAndroidId);407 var postFieldsString = Object.keys(postFields).map(function(k){ return encodeURIComponent(k) + "=" + encodeURIComponent(postFields[k]); }).join("&");408 User.setProperty("last_pending_api_id", String(selectedApi.id || activeApiId || ""), "string");409 410 User.setProperty("last_pending_price", User.getProperty("buy_price"), "number");411 User.setProperty("last_pending_prod_id", webProductId, "string");412 User.setProperty("last_pending_prod_name", String(product.name).trim(), "string");413 User.setProperty("last_pending_plan_days", cleanPlanDays, "string");414 User.setProperty("last_pending_plan_unit", planUnit, "string");415 416 HTTP.post({417 url: selectedApi.url,418 body: postFieldsString,419 headers: (function(){ var h={"Content-Type":"application/x-www-form-urlencoded"}; if(selectedApi.master_key) h["x-master-key"]=selectedApi.master_key; return h; })(),420 success: "/onWebKeyReceive",421 error: "/onWebKeyError"422 });423 424 User.setProperty("buy_pending_order_id", null);425 User.setProperty("buy_prod_idx", null);426 User.setProperty("buy_plan_idx", null);427 Bot.setProperty("buy_qr_msg_id_" + userId, null, "string");428 User.setProperty("buy_qr_msg_id_" + userId, null, "string");429 Bot.setProperty("buy_qr_caption_" + userId, null, "string");430 User.setProperty("buy_qr_caption_" + userId, null, "string");431 Bot.setProperty("buy_qr_buttons_" + userId, null, "string");432 User.setProperty("buy_qr_buttons_" + userId, null, "string");433 434 User.setProperty("buy_verifying_lock_" + userId, false, "boolean");435 436 } else {437 // โ Payment not found โ restore original QR caption/buttons, then show dismissible notice438 try {439 var origCaption = Bot.getProperty("buy_qr_caption_" + userId) || User.getProperty("buy_qr_caption_" + userId);440 var origButtons = Bot.getProperty("buy_qr_buttons_" + userId) || User.getProperty("buy_qr_buttons_" + userId);441 442 if (origCaption) {443 Api.editMessageCaption({444 chat_id: chat.chatid,445 message_id: request.message.message_id,446 caption: origCaption,447 parse_mode: "HTML",448 reply_markup: origButtons ? origButtons : undefined449 });450 }451 } catch (e) {}452 453 if (request && request.id) {454 Api.answerCallbackQuery({455 callback_query_id: String(request.id),456 text: "โ PAYMENT NOT FOUND โ\nPlease complete the payment first, then tap again.",457 show_alert: true458 });459 }460 User.setProperty("buy_verifying_lock_" + userId, false, "boolean");461 }462 463} catch (err) {464 try {465 User.setProperty("buy_verifying_lock_" + user.telegramid, false, "boolean");466 } catch (e) {}467 Bot.sendMessage("โ ๏ธ <b>Verification Exception:</b> " + err.message, { parse_mode: "HTML" });468}