455 commands2 envUpdated 7h agoCreated Aug 26, 2026
commands/shop_ok.js
javascript · 113 lines
1/**#command2name: shop_ok3answer: 4keyboard: 5parse_mode: markdown6aliases: 7allow_only_group: false8need_reply: false9is_web: 010#command**/11 12/**#command13name: shop_ok14answer: 15keyboard: 16parse_mode: markdown17aliases: 18allow_only_group: false19need_reply: false20is_web: 021#command**/22 23try {24try { Api.answerCallbackQuery({ text: "تایید شد" }); } catch (e0) {}25var uid = "";26if (typeof user !== "undefined" && user) {27 if (user.telegramid) uid = String(user.telegramid);28 else if (user.id) uid = String(user.id);29}30var isBoss = (uid === "5861439682");31var isAdmin = isBoss || ((await db.global.get("rank_" + uid)) === "admin");32if (!isAdmin) { Bot.sendMessage("🚫 فقط ادمین"); return; }33 34var msgTxt = "";35try {36 if (typeof update !== "undefined" && update && update.callback_query && update.callback_query.message) {37 var cm = update.callback_query.message;38 if (cm.caption) msgTxt = String(cm.caption);39 else if (cm.text) msgTxt = String(cm.text);40 }41} catch (eT) {}42 43var oid = "";44var hx = msgTxt.indexOf("#");45if (hx >= 0) {46 oid = msgTxt.slice(hx + 1);47 var cut = oid.length;48 var i = 0;49 for (i = 0; i < oid.length; i++) {50 var ch = oid.charAt(i);51 if (ch < "0" || ch > "9") { cut = i; break; }52 }53 oid = oid.slice(0, cut);54}55if (!oid) oid = String((await db.global.get("shop_last_pending")) || "");56if (!oid) { Bot.sendMessage("شماره سفارش پیدا نشد."); return; }57 58var rawO = await db.global.get("shop_order_" + oid);59if (!rawO) { Bot.sendMessage("سفارش #" + oid + " نیست"); return; }60var ord = null;61try { ord = JSON.parse(String(rawO)); } catch (eJ) { ord = null; }62if (!ord) { Bot.sendMessage("سفارش خراب است"); return; }63if (ord.status === "ok") { Bot.sendMessage("قبلا تایید شده"); return; }64if (ord.status === "no") { Bot.sendMessage("قبلا رد شده"); return; }65 66var buyer = String(ord.uid || "");67var kind = String(ord.kind || "");68var extra = String(ord.extra || "");69var days = parseInt(extra) || 30;70if (days < 1) days = 1;71 72if (kind === "normal") {73 await db.global.set("plan_" + buyer, "normal");74 await db.global.set("plan_exp_" + buyer, Date.now() + days * 86400000);75} else if (kind === "super") {76 await db.global.set("plan_" + buyer, "super");77 await db.global.set("plan_exp_" + buyer, Date.now() + days * 86400000);78} else if (kind === "msgs") {79 var b = parseInt(await db.global.get("bonus_msg_" + buyer) || 0) || 0;80 await db.global.set("bonus_msg_" + buyer, b + (parseInt(extra) || 0));81} else if (kind === "coins") {82 var c = parseInt(await db.global.get("m_coins_" + buyer) || 0) || 0;83 await db.global.set("m_coins_" + buyer, c + (parseInt(extra) || 0));84}85 86ord.status = "ok";87await db.global.set("shop_order_" + oid, JSON.stringify(ord));88await db.global.set("shop_last_pending", "");89 90try {91 Api.sendMessage({ chat_id: buyer, text: "✅ سفارش #" + oid + " تایید شد.\n📦 " + String(ord.title || "") });92} catch (eS) {}93 94var bodyTxt = extra;95if (kind === "normal" || kind === "super" || kind === "msgs" || kind === "coins") bodyTxt = "";96if (bodyTxt && (!ord.file_id || bodyTxt.length > 900)) {97 try { Api.sendMessage({ chat_id: buyer, text: bodyTxt }); } catch (eX) {}98}99if (ord.file_id) {100 var cap = bodyTxt && bodyTxt.length <= 900 ? bodyTxt : String(ord.title || "محصول");101 try {102 if (String(ord.file_type) === "photo") {103 Api.sendPhoto({ chat_id: buyer, photo: String(ord.file_id), caption: cap });104 } else {105 Api.sendDocument({ chat_id: buyer, document: String(ord.file_id), caption: cap });106 }107 } catch (eF) {}108}109 110Bot.sendMessage("✅ سفارش #" + oid + "\n📦 " + String(ord.title || "") + "\nبرای کاربر ارسال شد.");111} catch (e) {112 Bot.sendMessage("⚠️ shop_ok: " + String(e && e.message ? e.message : e));113}