yaainnnxitstore/YASIN_XIT_BOTPublic · Bot Template

ProfileTelegram

AIYASIN XIT FREE KEY appears to be a Telegram automation bot. Commands include /menu, /addfund, /confirm_buyitem, /rembal, /sendorderkey_input, /removeproduct, /add_reseller, /addkey. Observed in code: messaging, keyboards, payments, games, libs, web.

Utilityutility
140 commands0 envUpdated 1mo agoCreated Sep 11, 2026
Back to folder

commands/_confirm_buyitem.js

javascript · 224 lines

Raw
1/**#command2name: /confirm_buyitem3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12function __money(n){var x=Number(n||0).toFixed(2).split(".");x[0]=x[0].replace(/\B(?=(\d{3})+(?!\d))/g,",");return x.join(".");}13function __esc(v){return String(v==null?"":v).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");}14var __swfUpdate = (typeof update !== "undefined" && update) ? update : null;15var __swfCb = (__swfUpdate && __swfUpdate.callback_query) ? __swfUpdate.callback_query : null;16var __swfCbMsg = (__swfCb && __swfCb.message) ? __swfCb.message : null;17var __swfMsgId = __swfCbMsg && __swfCbMsg.message_id ? Number(__swfCbMsg.message_id) : 0;18var __swfCbId = __swfCb && __swfCb.id ? String(__swfCb.id) : "";19try {20  if (typeof request !== "undefined" && request && __swfCb) {21    if (__swfCb.message) request.message = __swfCb.message;22    if (!request.id && __swfCb.id) request.id = __swfCb.id;23  }24} catch(__swf_norm_err) {}25function __swfEditMessage(a) {26  a = a || {};27  var mid = Number(a.message_id || __swfMsgId || 0);28  var cid = a.chat_id || (typeof chat !== "undefined" && chat ? (chat.id || chat.chatid) : null);29  if (!mid || !cid) throw new Error("Callback message ID not found");30  var markup = a.reply_markup;31  if (typeof markup === "string") { try { markup = JSON.parse(markup); } catch(_) {} }32  var base = {chat_id:cid,message_id:mid,parse_mode:a.parse_mode,reply_markup:markup};33  var cm = __swfCbMsg;34  if (cm && (cm.photo || cm.video || cm.document || cm.audio || cm.animation)) {35    return Api.editMessageCaption({chat_id:cid,message_id:mid,caption:String(a.text == null ? "" : a.text),parse_mode:a.parse_mode,reply_markup:markup});36  }37  return Api.editMessageText({chat_id:cid,message_id:mid,text:String(a.text == null ? "" : a.text),parse_mode:a.parse_mode,reply_markup:markup});38}39function __uiSend(text, opts) {40  opts = opts || {};41  var req = (typeof request !== "undefined" && request) ? request : null;42  var chatId = (typeof chat !== "undefined" && chat && chat.chatid) ? chat.chatid : null;43  var isCallback = !!__swfCb;44  var mid = 0;45  if (isCallback && update.callback_query.message && update.callback_query.message.message_id) mid = Number(update.callback_query.message.message_id);46  if (!mid) { try { mid = Number(User.getProperty("pending_menu_message_id") || User.getProperty("main_menu_message_id") || User.getProperty("support_message_id") || 0); } catch(e0) { mid = 0; } }47  var markup = opts.reply_markup;48  if (markup && typeof markup !== "string") { try { markup = JSON.stringify(markup); } catch(e1) {} }49  var textValue = String(text == null ? "" : text);50  if (mid && chatId) {51    try {52      __swfEditMessage({chat_id:chatId,message_id:mid,text:textValue,parse_mode:opts.parse_mode,reply_markup:markup});53      try { User.setProperty("main_menu_message_id",String(mid),"string"); User.setProperty("pending_menu_message_id",String(mid),"string"); } catch(se) {}54      return true;55    } catch(e2) {56      var s=String(e2).toLowerCase();57      if(s.indexOf("message is not modified")>=0 || s.indexOf("not modified")>=0) return true;58      if(isCallback && update.callback_query.message && update.callback_query.message.photo) {59        try { Api.editMessageCaption({chat_id:chatId,message_id:mid,caption:textValue,parse_mode:opts.parse_mode,reply_markup:markup}); return true; } catch(e3) {60          var s3=String(e3).toLowerCase(); if(s3.indexOf("not modified")>=0) return true;61        }62      }63      if(isCallback) { try { Api.answerCallbackQuery({callback_query_id:String(update.callback_query.id),text:"⚠️ Could not update the screen.",show_alert:true}); } catch(e4) {} return false; }64    }65  }66  if (isCallback) { try { Api.answerCallbackQuery({callback_query_id:String(update.callback_query.id),text:"⚠️ Screen message not found.",show_alert:true}); } catch(e5) {} return false; }67  try {68    var sent=Api.sendMessage({chat_id:chatId,text:textValue,parse_mode:opts.parse_mode,reply_markup:markup});69    try { if(sent&&sent.message_id){User.setProperty("pending_menu_message_id",String(sent.message_id),"string");User.setProperty("main_menu_message_id",String(sent.message_id),"string");} } catch(e6) {}70    return true;71  } catch(e7) { return false; }72}73try {74  if (Bot.getProperty("banned_" + String(user.telegramid)) === true && String(user.telegramid) !== String(Bot.getProperty("owner_id")||"8225479428")) {75    __uiSend("🚫 <b>ACCESS DENIED</b>\n\nYour account has been suspended by the administrator.",{parse_mode:"HTML"});76    return;77  }78  var parts=String(params||"").trim().split(/\s+/), prodIdx=Number(parts[0]), planIdx=Number(parts[1]);79  var products=Bot.getProperty("stored_products")||[]; if(Array.isArray(products)) products=products.slice();80  if(!Array.isArray(products))products=[];81  var product=products[prodIdx], plan=product&&Array.isArray(product.plans)?product.plans[planIdx]:null;82  if(product){var pm=Bot.getProperty("product_maintenance")||{};if(pm[String(prodIdx)]||pm[String(product.name)]){try{Api.answerCallbackQuery({callback_query_id:String(__swfCbId || request.id),text:"🔧 This product is currently being updated.",show_alert:true});}catch(e){}return;}}83  var chatId=chat.chatid, userId=String(user.telegramid);84  if(!product||!plan){__uiSend("❌ <b>Product or plan not found.</b>",{parse_mode:"HTML"});return;}85  var stock=Number(plan.stock_count||0);86  if(!isFinite(stock)||stock<=0){__uiSend("❌ <b>This plan is currently out of stock.</b>\nPlease choose another plan.",{parse_mode:"HTML"});return;}87  var isReseller = Bot.getProperty("is_reseller_" + userId) === true;88  var __rsPct = Number(Bot.getProperty("reseller_discount_pct")); if(!isFinite(__rsPct)||__rsPct<0||__rsPct>90) __rsPct=20;89  var __normalPrice = Number(plan.normal_price != null ? plan.normal_price : (plan.price || 0));90  var __resPrice = (plan.reseller_price != null && Number(plan.reseller_price) > 0 && Number(plan.reseller_price) < __normalPrice) ? Number(plan.reseller_price) : Number((__normalPrice*(1-__rsPct/100)).toFixed(2));91  var basePrice = Number(isReseller ? __resPrice : __normalPrice);92  if(!isFinite(basePrice)||basePrice<0){__uiSend("❌ <b>This plan has an invalid price.</b> Please contact the administrator.",{parse_mode:"HTML"});return;}93  var discountPct = Number(Bot.getProperty("auto_discount_global") || 0);94  var productUpper = String(product.name||"").toUpperCase();95  var unitKey = String(plan.unit || "day").toUpperCase() === "HOUR" ? "HOUR" : String(plan.unit || "day").toUpperCase() === "MINUTE" ? "MINUTE" : "DAY";96  var specificKey = "auto_discount_" + productUpper + "_" + String(plan.days) + "_" + unitKey;97  var allKey = "auto_discount_" + productUpper + "_ALL";98  var specificDiscount = Bot.getProperty(specificKey);99  var allDiscount = Bot.getProperty(allKey);100  if(specificDiscount !== null && specificDiscount !== undefined && isFinite(Number(specificDiscount))) discountPct=Number(specificDiscount);101  else if(allDiscount !== null && allDiscount !== undefined && isFinite(Number(allDiscount))) discountPct=Number(allDiscount);102  discountPct=Math.max(0,Math.min(100,discountPct));103  var couponKey="applied_coupon_"+prodIdx+"_"+planIdx;104  var couponCode=String(User.getProperty(couponKey)||"").trim().toUpperCase();105  var couponRec=couponCode ? Bot.getProperty("coupon_"+couponCode) : null; if(couponRec && typeof couponRec === "object") couponRec=Object.assign({}, couponRec);106  if(couponRec && Number(couponRec.expiresAt||0)>0 && Date.now()>Number(couponRec.expiresAt)) { User.setProperty(couponKey,null,"string"); couponRec=null; couponCode=""; }107  if(couponRec && Array.isArray(couponRec.claimedBy) && couponRec.claimedBy.indexOf(userId)>=0) { User.setProperty(couponKey,null,"string"); couponRec=null; couponCode=""; }108  if(couponRec && !couponRec.isPaused && Number(couponRec.maxClaims||0)>0 && Array.isArray(couponRec.claimedBy) && couponRec.claimedBy.length < Number(couponRec.maxClaims)) {109    var couponPct=Number(couponRec.discountPercent||0);110    if(isFinite(couponPct)) discountPct=Math.max(discountPct,Math.min(100,couponPct));111  } else if(couponCode) { User.setProperty(couponKey,null,"string"); couponRec=null; couponCode=""; }112  var price=Number((basePrice*(1-discountPct/100)).toFixed(2));113  var rate=1; // 1 USDT = $1.00 (fixed)114  var usdt=rate>0?price/rate:0;115  var bal=0;try{bal=Number(Libs.ResourcesLib.userRes("balance").value())||0;}catch(e){}116  var legacy=Number(Bot.getProperty("balance"+userId)||0);117  if(isFinite(legacy)&&legacy>0){try{Libs.ResourcesLib.userRes("balance").add(legacy);bal+=legacy;Bot.setProperty("balance"+userId,0,"number");}catch(eLegacy){}}118  var total=Number(bal)||0;119  if(total<price){120    var kb=[[{text:"💳 Add Funds",callback_data:"/addfund"}],[{text:"🔙 Back",callback_data:"/viewprod "+prodIdx}]];121    __uiSend("❌ <b>Insufficient balance.</b>\n\n💰 Available: <b>$"+total.toFixed(2)+"</b>\n💳 Required: <b>$"+price.toFixed(2)+"</b>",{parse_mode:"HTML",reply_markup:JSON.stringify({inline_keyboard:kb})});122    return;123  }124  var lockKey="purchase_lock_"+userId;125  if(Bot.getProperty(lockKey)===true){__uiSend("⏳ <b>Your request is already being processed.</b> Please wait a few seconds.",{parse_mode:"HTML"});return;}126  Bot.setProperty(lockKey,true,"boolean");127  var stockLockKey="purchase_stock_lock_"+prodIdx+"_"+planIdx;128  if(Bot.getProperty(stockLockKey)===true){Bot.setProperty(lockKey,false,"boolean");__uiSend("⏳ <b>This stock is currently locked by another order.</b> Please try again in a few seconds.",{parse_mode:"HTML"});return;}129  Bot.setProperty(stockLockKey,true,"boolean");130  products=Bot.getProperty("stored_products")||[];131  product=products[prodIdx];132  plan=product&&Array.isArray(product.plans)?product.plans[planIdx]:null;133  stock=plan?Number(plan.stock_count||0):0;134  if(!plan||stock<=0){Bot.setProperty(stockLockKey,false,"boolean");Bot.setProperty(lockKey,false,"boolean");__uiSend("❌ <b>This plan just sold out.</b>",{parse_mode:"HTML"});return;}135  plan.stock_count=stock-1;136  products[prodIdx]=product;137  Bot.setProperty("stored_products",products,"json");138  try{ Libs.ResourcesLib.userRes("balance").remove(price); }catch(paymentErr){139    plan.stock_count=stock;products[prodIdx]=product;Bot.setProperty("stored_products",products,"json");Bot.setProperty(stockLockKey,false,"boolean");Bot.setProperty(lockKey,false,"boolean");140    __uiSend("❌ <b>The payment could not be completed.</b> The stock change has been rolled back.",{parse_mode:"HTML"});return;141  }142  var orderId="ORD_"+Date.now()+"_"+Math.floor(Math.random()*10000);143  var duration=String(plan.durationDisplay||plan.days+" "+(plan.unit==="hour"?"Hour":plan.unit==="minute"?"Minute":plan.unit==="month"?"Month":"Days"));144  var rec={id:orderId,user_id:userId,user_name:((user.first_name||"")+(user.last_name?" "+user.last_name:"" )).trim()||"User",username:user.username?String(user.username):"None",product_name:String(product.name),category_name:String(product.category_name||product.category||product.categoryName||"Not specified"),product_index:prodIdx,plan_index:planIdx,duration:duration,amount:price,usdt_amount:Number(usdt.toFixed(6)),status:"paid_waiting_manual_delivery",created_at:new Date().toISOString()};145  Bot.setProperty("order_"+orderId,rec,"json");146  if(couponRec && couponCode){147    if(!Array.isArray(couponRec.claimedBy)) couponRec.claimedBy=[];148    if(couponRec.claimedBy.indexOf(userId)<0){ couponRec.claimedBy.push(userId); Bot.setProperty("coupon_"+couponCode,couponRec,"json"); }149    User.setProperty(couponKey,null,"string");150  }151  Bot.setProperty("total_spent_by_"+userId,Number(Bot.getProperty("total_spent_by_"+userId)||0)+price,"number");152  var referrer=Bot.getProperty("referred_by_"+userId);153  if(referrer && String(referrer)!==userId && !Bot.getProperty("referral_commission_paid_"+orderId)){154    var refPct=Number(Bot.getProperty("referral_percent"));if(!isFinite(refPct)||refPct<0||refPct>100)refPct=20;155    var commission=Number((price*(refPct/100)).toFixed(2));156    if(commission>0){157      Bot.setProperty("referral_earnings_"+String(referrer),Number(Bot.getProperty("referral_earnings_"+String(referrer))||0)+commission,"number");158      Bot.setProperty("referral_available_"+String(referrer),Number(Bot.getProperty("referral_available_"+String(referrer))||0)+commission,"number");159      Bot.setProperty("referral_commission_paid_"+orderId,true,"boolean");160      var activeKey="referral_active_buyer_"+String(referrer)+"_"+userId;161      if(!Bot.getProperty(activeKey)){ Bot.setProperty(activeKey,true,"boolean"); Bot.setProperty("active_referrals_"+String(referrer),Number(Bot.getProperty("active_referrals_"+String(referrer))||0)+1,"number"); }162      try{Api.sendMessage({chat_id:String(referrer),text:"🎁 <b>Referral Earnings</b>\n\n💵 <b>Commission:</b> $"+commission.toFixed(2)+" ("+refPct+"%)\n💸 <b>Withdrawable:</b> $"+Number(Bot.getProperty("referral_available_"+String(referrer))||0).toFixed(2)+"\n\n🙏 Open Referral → Withdraw to cash out.",parse_mode:"HTML"});}catch(refMsgErr){}163    }164  }165  try {166    if (isReseller && __normalPrice > price) {167      Bot.setProperty("reseller_saved_"+userId, Number(Bot.getProperty("reseller_saved_"+userId)||0) + (__normalPrice - price), "number");168    }169  } catch(__svErr) {}170  Bot.setProperty("total_orders_count", Number(Bot.getProperty("total_orders_count")||0)+1, "number");171  var orderDateKey=new Date().toISOString().slice(0,10);172  Bot.setProperty("today_orders_"+orderDateKey, Number(Bot.getProperty("today_orders_"+orderDateKey)||0)+1, "number");173  Bot.setProperty("total_earnings", Number(Bot.getProperty("total_earnings")||0)+price, "number");174  Bot.setProperty("total_profit", Number(Bot.getProperty("total_profit")||0)+price, "number");175  Bot.setProperty("today_earnings_"+orderDateKey, Number(Bot.getProperty("today_earnings_"+orderDateKey)||0)+price, "number");176  var userOrderIds=Bot.getProperty("user_order_ids_"+userId)||[]; if(Array.isArray(userOrderIds)) userOrderIds=userOrderIds.slice();if(!Array.isArray(userOrderIds))userOrderIds=[];userOrderIds.push(orderId);if(userOrderIds.length>100)userOrderIds=userOrderIds.slice(-100);Bot.setProperty("user_order_ids_"+userId,userOrderIds,"json");177  var pending=Bot.getProperty("pending_admin_orders")||[]; if(Array.isArray(pending)) pending=pending.slice();if(!Array.isArray(pending))pending=[];if(pending.indexOf(orderId)<0)pending.push(orderId);Bot.setProperty("pending_admin_orders",pending,"json");178  var remaining=0;try{remaining=Number(Libs.ResourcesLib.userRes("balance").value())||0;}catch(e3){}179  var successText="✅ <b>Order Created!</b>\n\n🎮 <b>Game:</b> "+__esc(product.name)+"\n⏳ <b>Duration:</b> "+duration+"\n📦 <b>Quantity:</b> 1\n💰 <b>Paid:</b> $"+price.toFixed(2)+"\n🧾 <b>Order ID:</b> <code>"+orderId+"</code>\n\n🙏 Thank you! Your key will be delivered shortly.";180  var successMid=request&&((__swfCb&&__swfCb.message&&__swfCb.message.message_id)||(request.message&&request.message.message_id));181  if(!successMid){try{successMid=Number(User.getProperty("main_menu_message_id")||User.getProperty("pending_menu_message_id")||0);}catch(eMid){successMid=0;}}182  if(successMid){try{__swfEditMessage({chat_id:chatId,message_id:Number(successMid),text:successText,parse_mode:"HTML",reply_markup:JSON.stringify({inline_keyboard:[[{text:"🧾 My Orders",callback_data:"/orders"}],[{text:"🏠 Main Menu",callback_data:"/back"}]]})});}catch(eSuccess){__uiSend(successText,{parse_mode:"HTML",reply_markup:JSON.stringify({inline_keyboard:[[{text:"🧾 My Orders",callback_data:"/orders"}],[{text:"🔙 Main Menu",callback_data:"/back"}]]})});}}183  else __uiSend(successText,{parse_mode:"HTML",reply_markup:JSON.stringify({inline_keyboard:[[{text:"🧾 My Orders",callback_data:"/orders"}],[{text:"🔙 Main Menu",callback_data:"/back"}]]})});184  var adminId=Bot.getProperty("owner_id") || "8225479428";185  var buyerName=((user.first_name||"")+(user.last_name?" "+user.last_name:"")).trim()||"User";186  var buyerHandle=user.username ? String(user.username) : "None";187  var saleLogText =188    "✨ <b>[ NEW HACK SOLD ]</b> ✨\n\n"+189    "🛒 <b>Product:</b> "+__esc(product.name)+"\n"+190    "🗓️ <b>Duration:</b> "+__esc(duration)+"\n"+191    "💰 <b>Price:</b> $"+__money(price)+"\n"+192    "👤 <b>Buyer:</b> "+__esc(buyerName)+(buyerHandle&&buyerHandle!=="None"?" [ "+__esc(buyerHandle)+" ]":"")+"\n"+193    "🆔 <b>Buyer Chat ID:</b> "+userId+"\n"+194    "📦 <b>Remaining Stock:</b> "+Number(plan.stock_count||0)+"\n\n"+195    "⏳ <b>Awaiting key delivery — tap below to send it.</b>\n\n"+196    "📢 @"+String(Bot.getProperty("bot_username")||"Yasin_Xit_Shop_bot");197  try {198    if(adminId){199      Api.sendMessage({200        chat_id:adminId,201        text:saleLogText+"\n🧾 Order ID: <code>"+orderId+"</code>",202        parse_mode:"HTML",203        reply_markup:JSON.stringify({inline_keyboard:[[{text:"🔑 Send Key",callback_data:"/manual_orders"}]]})204      });205    }206  } catch(adminLogErr) {}207  try {208    var configuredSaleLog=Bot.getProperty("log_channel_id");209    if(configuredSaleLog){210      var logSaleText = "✨ <b>[ NEW HACK SOLD ]</b> ✨\n\n"+211        "🛒 <b>Product:</b> "+__esc(product.name)+"\n"+212        "🗓️ <b>Duration:</b> "+__esc(duration)+"\n"+213        "💰 <b>Price:</b> $"+__money(price)+"\n"+214        "👤 <b>Buyer:</b> "+__esc(buyerName)+(buyerHandle&&buyerHandle!=="None"?" [ "+__esc(buyerHandle)+" ]":"")+"\n"+215        "🆔 <b>Buyer Chat ID:</b> "+userId+"\n\n"+216        "🔥 <b>Order Received! Thank you for your business!</b>\n\n"+217        "📢 @"+String(Bot.getProperty("bot_username")||"Yasin_Xit_Shop_bot");218      Api.sendMessage({chat_id:configuredSaleLog,text:logSaleText,parse_mode:"HTML"});219    }220  } catch(saleLogErr) { try{Api.sendMessage({chat_id:String(Bot.getProperty("owner_id")||"8225479428"),text:"\u26A0\uFE0F Log channel delivery failed. Check it with /logtest."});}catch(dbgErr){} }221  if(typeof request!=="undefined"&&request&&request.id){try{Api.answerCallbackQuery({callback_query_id:String(request.id),text:"✅ Order created.",show_alert:false});}catch(e4){}}222  Bot.setProperty(stockLockKey,false,"boolean");223  Bot.setProperty(lockKey,false,"boolean");224}catch(e){try{Bot.setProperty("purchase_lock_"+String(user.telegramid),false,"boolean");Bot.setProperty("purchase_stock_lock_"+String((typeof prodIdx!=="undefined"?prodIdx:""))+"_"+String((typeof planIdx!=="undefined"?planIdx:"")),false,"boolean");}catch(lockErr){}__uiSend("❌ <b>An error occurred during the operation.</b> Please try again.",{parse_mode:"HTML"});}