tarunpoonia905/OfcDevShopBotPublic · Bot Template
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
commands/_buyitem.js
javascript · 303 lines
1/**#command2name: /buyitem3answer: 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 17// =========================================================18// 🚀 PLAN CLICK HANDLER — Premium "Payment Method" confirmation screen19// (Pay from Wallet / Pay via UPI / Apply Coupon / Back to Shop)20// ✅ Supports Hour / Minute / Day duration units21// ✅ Supports coupon discounts (global or product-specific)22// =========================================================23 24try {25 26 // 🛠 PANEL MAINTENANCE GUARD27 // Re-check at every purchase/payment stage so an admin can switch a panel28 // OFF even if a user already opened the checkout screen.29 function isPanelUnderMaintenance(product) {30 if (!product) return false;31 var mKey = "panel_maintenance_" +32 String(product.id || product.name || "").toUpperCase().replace(/[^A-Z0-9_-]/g, "_");33 return Bot.getProperty(mKey) === true;34 }35 36 var productList = Bot.getProperty("stored_products") || [];37 var callbackId = (request && request.id) ? request.id : ((request && request.callback_query && request.callback_query.id) || null);38 var chatId = chat.chatid;39 var userId = user.telegramid;40 41 // Plan-list screen ab video/GIF message ho sakta hai -> us par text-edit nahi hota (delete + fresh send).42 var biSrc = (request && request.message) ? request.message : null;43 var biSrcIsMedia = !!(biSrc && (biSrc.photo || biSrc.video || biSrc.animation || biSrc.document));44 var biSrcMid = (biSrc && biSrc.message_id) ? Number(biSrc.message_id) : null;45 46 var parts = params ? params.split(" ") : [];47 if (parts.length < 2) {48 var cbData = (request && request.callback_query) ? request.callback_query.data : "";49 parts = cbData.replace("buyitem ", "").split(" ");50 }51 52 var prodIdx = Number(parts[0]);53 var planIdx = Number(parts[1]);54 55 var product = productList[prodIdx];56 // 🛠 PANEL MAINTENANCE CHECK57 var panelMaintenanceKey = "panel_maintenance_" +58 String(product && (product.id || product.name) || prodIdx).toUpperCase().replace(/[^A-Z0-9_-]/g, "_");59 if (product && Bot.getProperty(panelMaintenanceKey) === true) {60 var maintenanceLink = String(product.maintenance_link || "").trim();61 var maintenanceText = "<tg-emoji emoji-id='6194949330399407789'>🛠️</tg-emoji> <b>Ye product abhi maintenance mein hai.</b>\n\n" +62 "<tg-emoji emoji-id='6215414866744712399'>📥</tg-emoji> <b>Update Files neeche open karo.</b>";63 var maintenanceMarkup = { inline_keyboard: [64 maintenanceLink65 ? [{ text: "Update Files", url: maintenanceLink, style: "success", icon_custom_emoji_id: "6143177515440544964" }]66 : [{ text: "⚠️ Update Link Not Set", callback_data: "/viewprod " + String(prodIdx), style: "danger" }],67 [{ text: "⬅️ Back to Shop", callback_data: "/buy_hack", style: "danger", icon_custom_emoji_id: "5893163582194978381" }]68 ] };69 if (request && request.message && request.message.message_id) {70 try {71 Api.editMessageText({72 chat_id: String(chatId),73 message_id: Number(request.message.message_id),74 text: maintenanceText,75 parse_mode: "HTML",76 reply_markup: JSON.stringify(maintenanceMarkup)77 });78 } catch (e) {79 Api.sendMessage({ chat_id: String(chatId), text: maintenanceText, parse_mode: "HTML", reply_markup: JSON.stringify(maintenanceMarkup) });80 }81 } else {82 Api.sendMessage({ chat_id: String(chatId), text: maintenanceText, parse_mode: "HTML", reply_markup: JSON.stringify(maintenanceMarkup) });83 }84 return;85 }86 87 if (!product || !product.plans || !product.plans[planIdx]) {88 Bot.sendMessage("❌ Product or Plan configuration missing!"); (function(){ try { var __pl = (typeof productList !== "undefined" && Array.isArray(productList)) ? productList : []; var __pr = (typeof prodIdx !== "undefined") ? prodIdx : "?"; var __pi = (typeof planIdx !== "undefined") ? planIdx : "?"; var __p = __pl[__pr]; var __own = String(Bot.getProperty("owner_id") || "7127818616"); Api.sendMessage({ chat_id: __own, text: "Config missing debug (" + "_buyitem.js" + ")\nuser: " + String(user.telegramid) + "\nprodIdx=" + __pr + " planIdx=" + __pi + "\nproduct=" + (__p ? String(__p.name) : "NOT FOUND") + " | plans=" + (__p && __p.plans ? __p.plans.length : "none") + " | totalProducts=" + __pl.length }); } catch (__dg) {} })();89 return;90 }91 92 var plan = product.plans[planIdx];93 var planUnit = plan.unit || "day";94 var cleanPlanDays = String(plan.days).replace(/[^0-9.]/g, "").trim();95 var unitLabelWord = (planUnit === "hour") ? (Number(cleanPlanDays) === 1 ? "Hour" : "Hours") :96 (planUnit === "minute") ? (Number(cleanPlanDays) === 1 ? "Minute" : "Minutes") :97 (Number(cleanPlanDays) === 1 ? "Day" : "Days");98 var durationDisplay = plan.durationDisplay || (cleanPlanDays + " " + unitLabelWord);99 100 var unifiedBal = (function () {101 var resBal = 0;102 try { resBal = Number(Libs.ResourcesLib.userRes("balance").value()) || 0; } catch (e) {}103 var bonusBal = Number(Bot.getProperty("balance" + userId) || 0);104 return resBal + bonusBal;105 })();106 107 var isReseller = Bot.getProperty("is_reseller_" + userId) === true;108 var cleanProdName = product.name.trim().toUpperCase();109 110 // ✅ Unit-aware price key (Day plans keep the old key format for backward-compat)111 var priceKeySuffix = (planUnit === "day") ? cleanPlanDays : (cleanPlanDays + "_" + planUnit);112 var normalKey = "price_normal_" + cleanProdName + "_" + priceKeySuffix;113 var resellerKey = "price_reseller_" + cleanProdName + "_" + priceKeySuffix;114 115 var adminNormalPrice = Bot.getProperty(normalKey);116 var adminResellerPrice = Bot.getProperty(resellerKey);117 118 var currentNormal = (adminNormalPrice !== undefined && adminNormalPrice !== null) ? adminNormalPrice : plan.normal_price;119 var currentReseller = (adminResellerPrice !== undefined && adminResellerPrice !== null) ? adminResellerPrice : plan.reseller_price;120 121 var basePrice = isReseller ? Number(currentReseller) : Number(currentNormal);122 var memberPriceKey = "member_custom_price_" + userId + "_" + cleanProdName.replace(/[^A-Z0-9_-]/g, "_") + "_" + ((planUnit === "day") ? cleanPlanDays : (cleanPlanDays + "_hour"));123 var memberCustomPrice = Bot.getProperty(memberPriceKey);124 var hasMemberCustomPrice = memberCustomPrice !== undefined && memberCustomPrice !== null && isFinite(Number(memberCustomPrice));125 var originalPrice = hasMemberCustomPrice ? Number(memberCustomPrice) : basePrice;126 var price = originalPrice;127 128 // 💸 Auto-discount (admin-set, no coupon code needed) — plan-specific > product-wide > global129 var planSpecificDiscKey = "auto_discount_" + cleanProdName + "_" + cleanPlanDays + "_" + planUnit.toUpperCase();130 var productWideDiscKey = "auto_discount_" + cleanProdName + "_ALL";131 var autoDiscountPercent = Bot.getProperty(planSpecificDiscKey) || Bot.getProperty(productWideDiscKey) || Bot.getProperty("auto_discount_global") || 0;132 133 // 🎟 Coupon check (if user applied one for this exact prod/plan) — coupon overrides auto-discount134 var appliedCouponCode = User.getProperty("applied_coupon_" + prodIdx + "_" + planIdx);135 // 🎟 Profile coupon (account-level): Profile > Apply Coupon me save hota hai, purchase par khud lagta hai.136 var __profileCouponUsed = false;137 if (!appliedCouponCode) {138 try {139 var __pc = User.getProperty("profile_coupon");140 var __pcRec = __pc ? Bot.getProperty("coupon_" + __pc) : null;141 if (__pcRec && !__pcRec.isPaused && __pcRec.discountPercent) {142 var __pcClaimed = Array.isArray(__pcRec.claimedBy) ? __pcRec.claimedBy : [];143 var __pcOk = __pcClaimed.indexOf(String(userId)) === -1 && __pcClaimed.length < Number(__pcRec.maxClaims || 0);144 if (__pcOk && __pcRec.scope === "specific") {145 __pcOk = String(__pcRec.productName || "").trim().toLowerCase() === String(product.name).trim().toLowerCase();146 }147 if (__pcOk) { appliedCouponCode = __pc; __profileCouponUsed = true; }148 }149 } catch (__pcErr) {}150 }151 var couponDiscountPercent = 0;152 if (appliedCouponCode) {153 var couponRec = Bot.getProperty("coupon_" + appliedCouponCode);154 if (couponRec && couponRec.discountPercent) {155 couponDiscountPercent = couponRec.discountPercent;156 price = Number((originalPrice * (1 - couponDiscountPercent / 100)).toFixed(2));157 }158 } else if (autoDiscountPercent > 0) {159 couponDiscountPercent = autoDiscountPercent; // reuse the same display variable160 price = Number((originalPrice * (1 - autoDiscountPercent / 100)).toFixed(2));161 }162 163 // =====================================================164 // ⚡ DIRECT QR (no "Pay / Coupon" screen)165 // Wallet balance kam hai -> seedha pehla enabled gateway ka QR banao.166 // Priority: UPI -> FamPay -> Zapupi. Wallet me poore paise hain to167 // neeche wali chhoti confirm screen aati hai (bina coupon button ke).168 // =====================================================169 if (unifiedBal < price) {170 // ✋ Manual Payment (owner's own QR) — ON + configured ho to sabse upar.171 if (Bot.getProperty("gateway_manual_enabled") === true && Bot.getProperty("manual_qr_file_id") && Bot.getProperty("manual_upi_id")) {172 User.setProperty("buy_prod_name", String(product.name).trim(), "string");173 Bot.run({ command: "/manualpay", options: { params: "show " + Number(price - unifiedBal).toFixed(2) + " " + prodIdx + " " + planIdx } });174 return;175 }176 // Gateway selection is strict: ON + fully configured only.177 // This prevents a default/empty Paytm toggle from hijacking checkout when178 // the admin has actually enabled FamPay or Zapupi.179 var dPaytmReady = (Bot.getProperty("gateway_upi_enabled") !== false) &&180 !!(Bot.getProperty("paytm_upi") || Bot.getProperty("payment_upi_id") || "paytm.s1tk6od@pty") &&181 !!(Bot.getProperty("paytm_merchant_id") || "SDfRhW21109811758334") && !!(Bot.getProperty("paytm_merchant_key") || "SDfRhW21109811758334");182 var dFamReady = (Bot.getProperty("gateway_fampay_enabled") === true) &&183 !!(Bot.getProperty("fampay_merchant_key") || Bot.getProperty("fampay_api_key"));184 var dZapReady = (Bot.getProperty("gateway_zapupi_enabled") === true) &&185 !!Bot.getProperty("zapupi_key");186 187 var directPayCmd = dPaytmReady ? "/pay_upi" : (dFamReady ? "/pay_fampay" : (dZapReady ? "/pay_zapupi" : null));188 if (directPayCmd) {189 var directGateway = directPayCmd === "/pay_upi" ? "paytm" : (directPayCmd === "/pay_fampay" ? "famgateway" : "zapupi");190 User.setProperty("buy_selected_gateway", directGateway, "string");191 Bot.setProperty("pending_gateway_" + userId, directGateway, "string");192 User.setProperty("pending_gateway_" + userId, directGateway, "string");193 Bot.run({ command: directPayCmd, options: { params: prodIdx + " " + planIdx } });194 return;195 }196 }197 198 // 💎 PREMIUM EMOJI SET (verified valid custom-emoji IDs from your reference bot)199 var e_diamond = "<tg-emoji emoji-id='6266967801580231067'>💎</tg-emoji>";200 var e_pack = "<tg-emoji emoji-id='6147767796097884213'>📦</tg-emoji>";201 var e_hour = "<tg-emoji emoji-id='5787432469598835099'>⏱️</tg-emoji>";202 var e_tag = "<tg-emoji emoji-id='6199422882435571592'>💲</tg-emoji>";203 var e_wallet = "<tg-emoji emoji-id='5348392971207194994'>💳</tg-emoji>";204 var e_check = "<tg-emoji emoji-id='6100657257605763582'>✔️</tg-emoji>";205 var e_offer = "<tg-emoji emoji-id='6102856637343600044'>🎉</tg-emoji>";206 var e_lock = "<tg-emoji emoji-id='6215386799133433653'>🔒</tg-emoji>";207 var e_coupon = "<tg-emoji emoji-id='6093677128295914531'>🎫</tg-emoji>";208 var e_back = "<tg-emoji emoji-id='5893163582194978381'>⬅️</tg-emoji>";209 210 var priceLine;211 if (couponDiscountPercent > 0) {212 priceLine = e_tag + " <b>Price:</b> <s>₹" + originalPrice.toFixed(2) + "</s> ➜ <b>₹" + price.toFixed(2) + "</b> " + e_offer + " <b>-" + couponDiscountPercent + "%</b>";213 } else if (hasMemberCustomPrice && Number(basePrice) !== Number(originalPrice)) {214 priceLine = e_tag + " <b>Member Price:</b> <s>₹" + Number(basePrice).toFixed(2) + "</s> ➜ <b>₹" + price.toFixed(2) + "</b> 👤";215 } else {216 priceLine = e_tag + " <b>Price:</b> ₹<code>" + price.toFixed(2) + "</code>";217 }218 219 // =====================================================220 // 💎 PREMIUM CHECKOUT SCREEN — always shown on plan click221 // =====================================================222 var confirmText =223 "<blockquote>" + e_diamond + " <b>CONFIRM YOUR ORDER</b> " + e_diamond + "</blockquote>\n" +224 "━━━━━━━━━━━━━━━━━━━━━\n\n" +225 e_pack + " <b>Product:</b> " + product.name + "\n" +226 e_hour + " <b>Duration:</b> " + durationDisplay + "\n" +227 priceLine + "\n" +228 e_wallet + " <b>Wallet Balance:</b> ₹<code>" + unifiedBal.toFixed(2) + "</code>\n\n" +229 "━━━━━━━━━━━━━━━━━━━━━\n" +230 e_lock + " <i>Secure checkout — tap below to confirm</i> " + e_check;231 232 var confirmButtons = [];233 234 if (unifiedBal >= price) {235 confirmButtons.push([236 { text: "Pay ₹" + price.toFixed(2) + " from Wallet", callback_data: "/confirm_buyitem " + prodIdx + " " + planIdx, style: "success", icon_custom_emoji_id: "6100657257605763582" }237 ]);238 } else {239 var needToPayPreview = (price - unifiedBal).toFixed(2);240 // ✅ NEW: checkout ab bhi gateway toggle respect karta hai — jo gateway241 // admin ne OFF kiya hai woh yahan checkout par bhi nahi dikhega.242 var upiEnabledCheckout = (Bot.getProperty("gateway_upi_enabled") !== false) &&243 !!(Bot.getProperty("paytm_upi") || Bot.getProperty("payment_upi_id") || "paytm.s1tk6od@pty") &&244 !!(Bot.getProperty("paytm_merchant_id") || "SDfRhW21109811758334") && !!(Bot.getProperty("paytm_merchant_key") || "SDfRhW21109811758334");245 var fampayEnabledCheckout = (Bot.getProperty("gateway_fampay_enabled") === true) &&246 !!(Bot.getProperty("fampay_merchant_key") || Bot.getProperty("fampay_api_key"));247 var zapupiEnabledCheckout = (Bot.getProperty("gateway_zapupi_enabled") === true) &&248 !!Bot.getProperty("zapupi_key");249 250 if (upiEnabledCheckout) {251 confirmButtons.push([252 { text: "Pay ₹" + needToPayPreview, callback_data: "/pay_upi " + prodIdx + " " + planIdx, style: "success", icon_custom_emoji_id: "5348392971207194994" }253 ]);254 }255 if (fampayEnabledCheckout) {256 confirmButtons.push([257 { text: "Pay ₹" + needToPayPreview, callback_data: "/pay_fampay " + prodIdx + " " + planIdx, style: "success", icon_custom_emoji_id: "6312263493051489212" }258 ]);259 }260 if (zapupiEnabledCheckout) {261 confirmButtons.push([262 { text: "Pay ₹" + needToPayPreview, callback_data: "/pay_zapupi " + prodIdx + " " + planIdx, style: "success", icon_custom_emoji_id: "5348392971207194994" }263 ]);264 }265 if (!upiEnabledCheckout && !fampayEnabledCheckout && !zapupiEnabledCheckout) {266 confirmButtons.push([267 { text: "⚠️ No payment method available", callback_data: "/buyitem " + prodIdx + " " + planIdx, style: "danger" }268 ]);269 }270 }271 272 confirmButtons.push([273 { text: "Back to Shop", callback_data: "/buy_hack", style: "danger", icon_custom_emoji_id: "5893163582194978381" }274 ]);275 276 if (request && request.message && !biSrcIsMedia) {277 Api.editMessageText({278 chat_id: String(chatId),279 message_id: Number(request.message.message_id),280 text: confirmText,281 parse_mode: "HTML",282 reply_markup: JSON.stringify({ inline_keyboard: confirmButtons })283 });284 } else {285 if (biSrcIsMedia && biSrcMid) { try { Api.deleteMessage({ chat_id: String(chatId), message_id: biSrcMid }); } catch (e) {} }286 Api.sendMessage({287 chat_id: String(chatId),288 text: confirmText,289 parse_mode: "HTML",290 reply_markup: JSON.stringify({ inline_keyboard: confirmButtons })291 });292 }293 294 if (callbackId) {295 Api.answerCallbackQuery({ callback_query_id: String(callbackId) });296 }297 298} catch (e) {299 var errChatId = (typeof chat !== "undefined" && chat && chat.chatid) ? chat.chatid : null;300 if (errChatId) {301 try { Api.sendMessage({ chat_id: errChatId, text: "❌ <b>Error:</b> <code>" + e.message + "</code>", parse_mode: "HTML" }); } catch (fatal) {}302 }303}