tarunpoonia905/OfcDevShopBotPublic · Bot Template

ProfileTelegram

AIDEV SHOP appears to be a Telegram automation bot. Commands include /confirm_delete_stock, /addstock_id, /extkey_menu, /partner_api, /apidelete, /buy_hack_cat, /admin_manage_products, /check_buy. Observed in code: messaging, keyboards, payments, libs, web, http, games.

Utilityutility
228 commands0 envUpdated 12d agoCreated Oct 18, 2026
Back to folder

commands/_onQR.js

javascript · 322 lines

Raw
1/**#command2name: /onQR3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12/*#SIZE_V1*/try{(function(){var z=Bot.getProperty("ui_btn_size");var mx=z==="large"?1:(z==="medium"?2:0);if(!mx||Api.__sz)return;var NAV=/^[◀▶⬅➡«»‹›⏪⏩]|\d+\s*\/\s*\d+|prev|next|page/i;var T=function(m){try{var o=typeof m==="string"?JSON.parse(m):m;if(!o||!o.inline_keyboard)return m;var out=[],cnt=0;o.inline_keyboard.forEach(function(row){var nav=row.some(function(b){return NAV.test(String(b.text||"").trim());});if(row.length<=mx||nav){out.push(row);cnt+=row.length;return;}for(var i=0;i<row.length;i+=mx){var c=row.slice(i,i+mx);out.push(c);cnt+=c.length;}});if(cnt>100||out.length>100)return m;o.inline_keyboard=out;return typeof m==="string"?JSON.stringify(o):o;}catch(e){return m;}};["sendMessage","editMessageText","editMessageCaption","editMessageReplyMarkup","sendPhoto","sendVideo","sendAnimation","sendDocument"].forEach(function(n){var f=Api[n];if(typeof f!=="function")return;Api[n]=function(p){try{if(p&&p.reply_markup)p.reply_markup=T(p.reply_markup);}catch(e){}return f.apply(Api,arguments);};});Api.__sz=true;})();}catch(__szE){}13/*#ANIM_V1*/try{(function(){var M={party:"5046509860389126442",fire:"5104841245755180586",heart:"5159385139981059251",like:"5107584321108051014"};var a=Bot.getProperty("ui_anim");if(!a||!M[a]||Api.__an)return;var E=M[a];var OK=/PURCHASE SUCCESSFUL|PAYMENT SUCCESSFUL|Payment verified|CONGRATULATIONS/i;var priv=function(p){return p&&p.chat_id&&String(p.chat_id).charAt(0)!=="-";};["sendMessage","sendPhoto","sendVideo","sendAnimation"].forEach(function(n){var f=Api[n];if(typeof f!=="function")return;Api[n]=function(p){try{if(priv(p)&&!p.message_effect_id&&OK.test(String(p.text||p.caption||"")))p.message_effect_id=E;}catch(e){}return f.apply(Api,arguments);};});var fe=Api.editMessageText;if(typeof fe==="function"){Api.editMessageText=function(p){var r=fe.apply(Api,arguments);try{if(priv(p)&&OK.test(String(p.text||"")))Api.sendMessage({chat_id:p.chat_id,text:"🎉",message_effect_id:E});}catch(e){}return r;};}Api.__an=true;})();}catch(__anE){}14/*#PREMIUM_UI_V1*/try{(function(){if(Bot.getProperty("ui_premium")!==true||Api.__pm)return;var R=function(t,c){var s=(String(t||"")+" "+String(c||"")).toLowerCase();if(/back|cancel|close|delete|remove|clear|reject|stop|ban|exit/.test(s))return"danger";if(/pay|buy|confirm|verify|paid|add|deposit|shop|claim|yes|receive|wallet|download|update/.test(s))return"success";return"primary";};var T=function(m){try{var o=typeof m==="string"?JSON.parse(m):m;if(!o||!o.inline_keyboard)return m;o.inline_keyboard.forEach(function(row){row.forEach(function(b){if(b.copy_text||b.url||b.callback_data||b.web_app){b.style=R(b.text,b.callback_data||b.url);if(!b.icon_custom_emoji_id&&b.text&&!/^[\u2600-\u27BF\uD83C-\uD83E]/.test(String(b.text).trim())&&!/^[✦✨💎]/.test(b.text))b.text="✦ "+b.text;}});});return typeof m==="string"?JSON.stringify(o):o;}catch(e){return m;}};["sendMessage","editMessageText","editMessageCaption","editMessageReplyMarkup","sendPhoto","sendVideo","sendAnimation","sendDocument"].forEach(function(n){var f=Api[n];if(typeof f!=="function")return;Api[n]=function(p){try{if(p&&p.reply_markup)p.reply_markup=T(p.reply_markup);}catch(e){}return f.apply(Api,arguments);};});Api.__pm=true;})();}catch(__pmE){}15 16 17try {18  // ===== PAYTM QR DISPLAY FIX =====19  // Api.sendPhoto gateway URL reject hone par exception nahi deta (sirf ok:false) -> QR chupchap gayab ho jata tha.20  // Ab result check hota hai aur kai tareeke try hote hain: (1) gateway image URL, (2) image-proxy se clean PNG,21  // (3) UPI intent se khud ka QR (qrserver), (4) text + UPI ID + link. Order/verify state pehle hi save hai.22  function __qrAbs(u) {23    u = String(u || "").trim();24    if (!u) return "";25    if (/^data:|^upi:/i.test(u)) return u;26    if (u.indexOf("//") === 0) return "https:" + u;27    if (/^https?:\/\//i.test(u)) return u;28    if (/^[A-Za-z0-9+\/=\r\n]{200,}$/.test(u)) return u;29    return "https://paytm.anujbots.xyz/" + u.replace(/^\/+/, "");30  }31  function __qrSent(r) {32    if (!r) return null;33    if (r.ok === false || r.error || r.error_code) return null;34    return r;35  }36  function __sendQrPhoto(chatIdX, rawQr, rawRes, orderIdX, amountX, caption, kbJson) {37    var qrA = __qrAbs(rawQr);38    var intent = "";39    try {40      var rr = rawRes || {}, dd = (rr.data && typeof rr.data === "object") ? rr.data : {};41      var cands = [dd.upi_url, dd.upi_link, dd.upi_intent, dd.intent, dd.intent_url, dd.qr_string, dd.qr_data, dd.upi,42                   rr.upi_url, rr.upi_link, rr.upi_intent, rr.intent, rr.intent_url, rr.qr_string, rr.qr_data, rr.upi, qrA];43      for (var ci = 0; ci < cands.length; ci++) {44        if (cands[ci] && /^upi:\/\//i.test(String(cands[ci]).trim())) { intent = String(cands[ci]).trim(); break; }45      }46    } catch (e0) {}47    var upiX = Bot.getProperty("paytm_upi") || Bot.getProperty("payment_upi_id") || "paytm.s1tk6od@pty";48    if (!intent) {49      intent = "upi://pay?pa=" + encodeURIComponent(upiX) + "&pn=" + encodeURIComponent(String(Bot.getProperty("store_name") || "DEV SHOP BOT")) +50               "&am=" + encodeURIComponent(Number(amountX || 0).toFixed(2)) + "&cu=INR&tn=" + encodeURIComponent(String(orderIdX || ""));51    }52    var urls = [];53    if (/^https?:\/\//i.test(qrA)) {54      urls.push(qrA);55      urls.push("https://images.weserv.nl/?output=png&url=" + encodeURIComponent(qrA));56    }57    urls.push("https://api.qrserver.com/v1/create-qr-code/?size=600x600&margin=12&data=" + encodeURIComponent(intent));58    var lastErr = "";59    for (var i = 0; i < urls.length; i++) {60      try {61        var r = Api.sendPhoto({ chat_id: chatIdX, photo: urls[i], caption: caption, parse_mode: "HTML", reply_markup: kbJson });62        var ok = __qrSent(r);63        if (ok) { return { msg: ok, via: i }; }64        lastErr = (r && (r.description || r.error)) ? String(r.description || r.error) : "empty response";65      } catch (e1) { lastErr = String(e1 && e1.message || e1); }66    }67    return { msg: null, err: lastErr, upi: upiX, qr: qrA };68  }69  function __qrFallbackText(chatIdX, caption, kbObj, info, orderIdX, amountX, uidX) {70    var linkRow = [];71    if (info.qr && /^https?:\/\//i.test(info.qr)) linkRow.push([{ text: "🖼️ Open QR", url: info.qr, style: "primary" }]);72    Api.sendMessage({73      chat_id: chatIdX, parse_mode: "HTML",74      text: caption + "\n\n⚠️ QR image load nahi hui. Is UPI ID par <b>exact ₹" + Number(amountX || 0).toFixed(2) + "</b> bhejo:\n<code>" + info.upi + "</code>",75      reply_markup: JSON.stringify({ inline_keyboard: kbObj.concat(linkRow) })76    });77    try {78      var shortQr = String(info.qr || "").slice(0, 120).replace(/&/g, "&amp;").replace(/</g, "&lt;");79      Api.sendMessage({ chat_id: String(Bot.getProperty("owner_id") || "7127818616"), parse_mode: "HTML",80        text: "⚠️ <b>Paytm QR photo failed</b> (user <code>" + uidX + "</code>, order <code>" + orderIdX + "</code>)\nQR: <code>" + shortQr + "</code>\nError: <code>" +81              String(info.err || "").slice(0, 200).replace(/&/g, "&amp;").replace(/</g, "&lt;") + "</code>" });82    } catch (e2) {}83  }84  if (!content) { 85    Bot.sendMessage("❌ Error: No response received from server.");86    return; 87  }88 89  var res = (typeof content === "object") ? content : JSON.parse(content);90  var __rawRes = JSON.parse(JSON.stringify(res || {}));91 92  // Paytm qr.php response -> existing internal QR shape.93  // Normalize common Paytm QR response shapes. Some versions return data.qr_url,94  // others return qrurl/image_url/qr_image or put order_id at the top level.95  if (res && (res.success === true || String(res.status || "").toLowerCase() === "success") && !res.data) {96    res = { status: "success", data: {97      order_id: res.order_id || res.orderid || res.data_order_id,98      qr_url: res.qr_url || res.qrurl || res.image_url || res.qr_image || res.qr_image_url || res.payment_qr,99      amount: res.amount || User.getProperty("pending_pay_amount_" + user.telegramid) || User.getProperty("deposit_amount"),100      payable_amount: res.payable_amount || res.payable || res.amount,101      expires_at_ist: res.expiry ? (isNaN(Number(res.expiry)) ? String(res.expiry) : new Date(Number(res.expiry) * 1000).toLocaleTimeString("en-IN", { hour: "2-digit", minute: "2-digit" })) : "5 Minutes"102    }};103  } else if (res && res.data) {104    res.status = res.status || (res.success === true ? "success" : res.status);105    res.data.qr_url = res.data.qr_url || res.data.qrurl || res.data.image_url || res.data.qr_image || res.data.qr_image_url || res.data.payment_qr;106    res.data.order_id = res.data.order_id || res.data.orderid || res.order_id || res.orderid;107    res.data.amount = res.data.amount || res.amount;108  }109 110  if (!res || res.status != "success" || !res.data) {111    // ✅ FIX: "Generating QR..." message atka rehta tha — ab hata ke retry buttons dete hain,112    // aur admin ko gateway ka asli reason bhejte hain.113    var failUid = user.telegramid;114    var failGen = null;115    try { failGen = Bot.getProperty("gen_msg_id_" + failUid) || User.getProperty("gen_msg_id_" + failUid); } catch (e) {}116    if (failGen) {117      try { Api.deleteMessage({ chat_id: chat.chatid, message_id: failGen }); } catch (e) {}118      Bot.setProperty("gen_msg_id_" + failUid, null, "string");119      User.setProperty("gen_msg_id_" + failUid, null, "string");120    }121    Api.sendMessage({122      chat_id: chat.chatid,123      text: "<tg-emoji emoji-id='6219547832169273793'>❌</tg-emoji> <b>QR Generation Failed</b>\n<i>Thodi der baad dobara try karo ya dusra payment method chuno.</i>",124      parse_mode: "HTML",125      reply_markup: JSON.stringify({ inline_keyboard: [[{ text: "🔄 Try Again", callback_data: "/addfund", style: "success" }], [{ text: "⬅️ Back to Menu", callback_data: "/back", style: "danger" }]] })126    });127    var failOwner = String(Bot.getProperty("owner_id") || "7127818616");128    if (String(failUid) !== failOwner) {129      var failRaw = (typeof content === "string") ? content : JSON.stringify(content || "");130      Api.sendMessage({ chat_id: failOwner, parse_mode: "HTML",131        text: "⚠️ <b>Gateway QR failed</b> (user <code>" + failUid + "</code>)\n<code>" + String(failRaw).replace(/&/g, "&amp;").replace(/</g, "&lt;").slice(0, 500) + "</code>" });132    }133    return;134  }135 136  try { Bot.setProperty("qr_gen_ts_" + user.telegramid, null, "string"); } catch (e) {}137  var order_id = res.data.order_id;138  try {139    var __pendingGw = Bot.getProperty("pending_gateway_" + user.telegramid) || User.getProperty("pending_gateway_" + user.telegramid);140    if (__pendingGw) {141      Bot.setProperty("pay_gw_" + order_id, String(__pendingGw).toLowerCase(), "string");142      Bot.setProperty("pending_gateway_" + user.telegramid, null, "string");143      User.setProperty("pending_gateway_" + user.telegramid, null, "string");144    }145  } catch(__gwTagErr) {}146  var qr = res.data.qr_url;147  var expire = res.data.expires_at_ist ? res.data.expires_at_ist : "5 Minutes";148  149  var userId = user.telegramid;150  151  var deposit_amount = res.data.amount ||152                       Bot.getProperty("pending_pay_amount_" + userId) || 153                       User.getProperty("pending_pay_amount_" + userId) || 154                       Bot.getProperty("deposit_amount_" + userId) || 155                       User.getProperty("deposit_amount") || 156                       "0";157 158  // FamGateway v2 orders (fg_...) verify via /api/verify-order.php — yaad rakho159  try {160    if (order_id && (/^fg_/.test(String(order_id)) || String(qr || "").indexOf("/api/qr-image.php") !== -1)) {161      Bot.setProperty("pay_gw_" + order_id, "famgateway", "string");162    }163  } catch (gwErr) {}164 165  if (!qr) {166    Bot.sendMessage("❌ Error: QR Code link missing from API response.");167    return;168  }169 170  var apiAmount = res.data.amount;171  if (apiAmount !== undefined && apiAmount !== null && apiAmount !== "") {172    deposit_amount = apiAmount;173    User.setProperty("deposit_amount", String(apiAmount), "string");174    User.setProperty("pending_pay_amount_" + userId, String(apiAmount), "string");175  }176 177  var finalAmount = parseFloat(deposit_amount);178  if (isNaN(finalAmount) || finalAmount <= 0) {179    finalAmount = 0.00; 180  }181 182  // FamGateway: QR me "payable_amount" (reconciled, paise ke saath alag ho sakta hai) encode hota hai,183  // "amount" base amount hai. User ko wahi dikhao jo QR me hai; wallet me base amount credit hoga.184  var payableAmount = parseFloat(res.data.payable_amount || res.data.payable || res.data.final_amount);185  if (isNaN(payableAmount) || payableAmount <= 0) payableAmount = 0;186  var shownAmount = payableAmount > 0 ? payableAmount : finalAmount;187 188  // Caption: dusre bot jaisa chhota + clean. Verify button nahi - payment auto-detect hoti hai.189  var gatewayMsg =190    "╔══════════════════════╗\n" +191    "   💰 UPI QR PAYMENT\n" +192    "╚══════════════════════╝\n\n" +193    "┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈\n\n" +194    "💸 <b>Amount To Pay:</b> ₹<code>" + shownAmount.toFixed(2) + "</code>\n\n" +195    "┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈\n\n" +196    " 🪙<b>Order ID:</b> <code>" + order_id + "</code>\n\n" +197    "┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈\n\n" +198    "💸 Scan the QR below &amp; pay exact amount";199 200  // Webhook se auto-credit hota hai; "Verify Payment" safety-net hai (admin chaahe to /famverifybtn off se hide kar sakta hai).201  var inlineButtons = [];202  if (Bot.getProperty("hide_verify_btn") !== true) {203    inlineButtons.push([{ text: "Verify Payment", callback_data: "/check " + order_id, style: "success", icon_custom_emoji_id: "6102856637343600044" }]);204  }205  inlineButtons.push(206    [207      {208        text: "Cancel",209        callback_data: "/cancel_topup " + order_id,210        style: "danger",211        icon_custom_emoji_id: "6219547832169273793"212      }213    ]214  );215 216  // ⚡ SPEED FIX: QR photo pehle bhejo taaki user ko turant dikhe, "Generating..."217  // wala purana message uske baad (background me) delete karo — pehle ye ulta218  // tha (pehle delete, fir photo), jisse QR dikhne me extra gap lagta tha.219  var genMsgId = null;220  try {221    genMsgId = Bot.getProperty("gen_msg_id_" + userId) || User.getProperty("gen_msg_id_" + userId);222  } catch (genErr) {}223 224  // ✅ FIX: order state sendPhoto se PEHLE save — pehle ye baad me tha, isliye agar beech me225  // koi error aata to poll "order active nahi" samajh ke chupchap ruk jata tha.226  if (order_id) {227    Bot.setProperty("qr_order_id_" + userId, order_id, "string");228    User.setProperty("qr_order_id_" + userId, order_id, "string");229    Bot.setProperty("qr_watch_order_" + userId, order_id, "string");230    User.setProperty("qr_watch_order_" + userId, order_id, "string");231    // webhook ke liye: order -> user mapping (kaun sa order kis user ka hai)232    Bot.setProperty("fg_order_owner_" + order_id, String(userId), "string");233    var earlyLock = parseFloat(finalAmount);234    if (!isNaN(earlyLock) && earlyLock > 0) {235      Bot.setProperty("pay_order_amount_" + order_id, earlyLock, "number");236      User.setProperty("pay_order_amount_" + order_id, earlyLock, "number");237    }238  }239 240  var sentQrMsg = null;241  var __qrRes = __sendQrPhoto(chat.chatid, qr, __rawRes, order_id, shownAmount, gatewayMsg, JSON.stringify({ inline_keyboard: inlineButtons }));242  if (__qrRes.msg) {243    sentQrMsg = __qrRes.msg;244  } else {245    __qrFallbackText(chat.chatid, gatewayMsg, inlineButtons, __qrRes, order_id, shownAmount, userId);246  }247 248  if (genMsgId) {249    try { Api.deleteMessage({ chat_id: chat.chatid, message_id: genMsgId }); } catch (delGenErr) {}250    Bot.setProperty("gen_msg_id_" + userId, null, "string");251    User.setProperty("gen_msg_id_" + userId, null, "string");252  }253 254  var qrMsgId = null;255  try {256    if (sentQrMsg) {257      if (sentQrMsg.result && sentQrMsg.result.message_id) {258        qrMsgId = sentQrMsg.result.message_id;259      } else if (sentQrMsg.message_id) {260        qrMsgId = sentQrMsg.message_id;261      }262    }263 264    if (qrMsgId) {265      Bot.setProperty("qr_msg_id_" + userId, qrMsgId, "string");266      User.setProperty("qr_msg_id_" + userId, qrMsgId, "string");267    }268 269    if (order_id) {270      // Bind the payable amount to this specific gateway order.271      // This is the amount verification must later enforce.272      var lockedOrderAmount = parseFloat(finalAmount);273      if (!isNaN(lockedOrderAmount) && lockedOrderAmount > 0) {274        User.setProperty("pay_order_amount_" + order_id, lockedOrderAmount, "number");275        Bot.setProperty("pay_order_amount_" + order_id, lockedOrderAmount, "number");276      }277      if (payableAmount > 0) {278        Bot.setProperty("pay_order_payable_" + order_id, payableAmount, "number");279      }280 281      Bot.setProperty("qr_order_id_" + userId, order_id, "string");282      User.setProperty("qr_order_id_" + userId, order_id, "string");283      User.setProperty("pending_order_id", order_id, "string");284 285      // ✅ Ye "watch id" hai — expiry callback isse compare karega ki order abhi bhi wahi hai ya resolve ho chuka286      Bot.setProperty("qr_watch_order_" + userId, order_id, "string");287      User.setProperty("qr_watch_order_" + userId, order_id, "string");288    }289 290    Bot.setProperty("qr_caption_" + userId, gatewayMsg, "string");291    User.setProperty("qr_caption_" + userId, gatewayMsg, "string");292    Bot.setProperty("qr_buttons_" + userId, JSON.stringify(inlineButtons), "string");293    User.setProperty("qr_buttons_" + userId, JSON.stringify(inlineButtons), "string");294 295    var nowTs = String(new Date().getTime());296    Bot.setProperty("qr_created_ts_" + userId, nowTs, "string");297    User.setProperty("qr_created_ts_" + userId, nowTs, "string");298 299    Bot.setProperty("verifying_lock_" + userId, false, "boolean");300    User.setProperty("verifying_lock_" + userId, false, "boolean");301 302  } catch (saveErr) {303    // pehle ye silent tha — ab admin ko dikhega304    try {305      Api.sendMessage({ chat_id: String(Bot.getProperty("owner_id") || "7127818616"),306        text: "⚠️ QR post-send state save error: " + saveErr.message });307    } catch (e) {}308  }309 310  // ✅ AUTO-VERIFY (v8): ab polling nahi — FamGateway ka WEBHOOK (see /fam_webhook) payment hote hi bot ko call karta hai.311  // Pehle yahan 80 polls `run_after` ke saath schedule hote the, par TeleBotHost Bot.run me run_after hai hi nahi,312  // isliye wo sab 80 verify-order calls TURANT ek saath chal jaate the (rate-limit + QR dikhne se pehle poll khatam).313  // Safety net: "Verify Payment" button (manual /check) QR ke saath hi dikhta hai.314 315  // ✅ CHANGED (per request): koi auto-expiry timer nahi hai ab. QR tab tak316  // valid rehta hai jab tak user khud "Cancel" na dabaye ya payment verify317  // na ho jaaye. Order kabhi background me apne aap "expire" nahi hoga —318  // sirf manual Cancel button se hi QR vanish hoga (see /cancel_topup).319 320} catch (err) {321  Bot.sendMessage("⚠️ System Error: " + err.message);322}
commands/_onQR.js · tarunpoonia905/OfcDevShopBot · TeleDevs