["nom" => "šŸ“¢ Majburiy obuna (Kanal)", "narx" => 50000, "ikon" => "āž•"], "2" => ["nom" => "šŸš€ Oddiy post (Hammaga)", "narx" => 30000, "ikon" => "šŸ“©"], "3" => ["nom" => "šŸ‘‘ Profil Banner (Max 3)", "narx" => 100000, "ikon" => "šŸ’Ž"] ]; $services = [ "ā˜€ļø Ob-havo" => "obhavo", "šŸ’ø Valyuta" => "kurs", "šŸŒ™ Ramazon" => "ramazon", "šŸ•Œ Namoz" => "namoz", "⚽ La Liga" => "futjadval" ]; /* ================= UPDATE ================= */ $update = json_decode(file_get_contents("php://input"), true); $chat_id = $update['message']['chat']['id'] ?? null; $text = $update['message']['text'] ?? ""; $photo = $update['message']['photo'] ?? null; $callback = $update['callback_query']['data'] ?? null; $callback_id = $update['callback_query']['id'] ?? null; $callback_chat = $update['callback_query']['message']['chat']['id'] ?? null; $callback_msg_id = $update['callback_query']['message']['message_id'] ?? null; /* ================= DATA STORAGE ================= */ if(!file_exists("data")) mkdir("data", 0755, true); $users_file = "data/users.json"; $ads_file = "data/ads.json"; $users = file_exists($users_file) ? json_decode(file_get_contents($users_file), true) : []; $global_ads = file_exists($ads_file) ? json_decode(file_get_contents($ads_file), true) : ['profil' => [], 'majburiy' => []]; function saveAll(){ global $users, $users_file, $global_ads, $ads_file; file_put_contents($users_file, json_encode($users, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); file_put_contents($ads_file, json_encode($global_ads, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); } function bot($method, $data = []){ $url = "https://api.telegram.org/bot".TOKEN."/".$method; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $res = curl_exec($ch); curl_close($ch); return json_decode($res, true); } /* ================= MAJBURIY OBUNA TEKSHIRISH ================= */ function checkJoin($id){ global $global_ads; $now = time(); $btn = []; $must_join = false; foreach($global_ads['majburiy'] as $index => $ad){ if($now < $ad['expire']){ $res = bot('getChatMember', ['chat_id' => $ad['link'], 'user_id' => $id]); $st = $res['result']['status'] ?? ''; if($st != 'creator' && $st != 'administrator' && $st != 'member'){ $must_join = true; $btn[] = [["text" => "āž• " . $ad['descr'], "url" => "https://t.me/" . str_replace('@', '', $ad['link'])]]; } } } if($must_join){ $btn[] = [["text" => "āœ… Tekshirish", "callback_data" => "check_subs"]]; bot('sendMessage', [ 'chat_id' => $id, 'text' => "āš ļø *Botdan foydalanish uchun quyidagi kanallarga a'zo bo'ling:*", 'parse_mode' => 'Markdown', 'reply_markup' => json_encode(['inline_keyboard' => $btn]) ]); return false; } return true; } /* ================= CALLBACK HANDLING ================= */ if(isset($callback)){ if($callback == "check_subs"){ if(checkJoin($callback_chat)){ bot('deleteMessage', ['chat_id' => $callback_chat, 'message_id' => $callback_msg_id]); bot('sendMessage', ['chat_id' => $callback_chat, 'text' => "āœ… Rahmat! Bosh menyuga o'tishingiz mumkin. /start bosing."]); } else { bot('answerCallbackQuery', ['callback_query_id' => $callback_id, 'text' => "āŒ Hamma kanallarga a'zo bo'lmadingiz!", 'show_alert' => true]); } exit; } if(strpos($callback, "buy_") === 0){ $type = str_replace("buy_", "", $callback); if($type == "3" && count($global_ads['profil']) >= 3){ bot('answerCallbackQuery', ['callback_query_id' => $callback_id, 'text' => "āš ļø Profil banner joyi band!", 'show_alert' => true]); exit; } $users[$callback_chat]['step'] = 'wait_chek'; $users[$callback_chat]['tmp_type'] = $type; saveAll(); bot('editMessageText', [ 'chat_id' => $callback_chat, 'message_id' => $callback_msg_id, 'text' => "šŸ’  Turi: " . $reklama_turlari[$type]['nom'] . "\nšŸ’° Narxi: " . number_format($reklama_turlari[$type]['narx']) . " so'm\nšŸ’³ Karta: `$karta_raqam`\n\n1ļøāƒ£ To'lov chekini (rasm) yuboring.", 'parse_mode' => 'Markdown' ]); } if(strpos($callback, "accept_") === 0){ list($act, $u_id, $type) = explode("_", $callback); $ad = $users[$u_id]['tmp_ads']; $expire = time() + (24 * 3600); if($type == "1") $global_ads['majburiy'][] = ['link' => $ad['link'], 'descr' => $ad['descr'], 'expire' => $expire]; if($type == "3") $global_ads['profil'][] = ['link' => $ad['link'], 'descr' => $ad['descr'], 'expire' => $expire]; if($type == "2"){ foreach(array_keys($users) as $id) bot('sendMessage', ['chat_id' => $id, 'text' => "šŸ“¢ *REKLAMA:*\n\n" . $ad['descr'] . "\n\nšŸ”— [Batafsil](" . $ad['link'] . ")", 'parse_mode' => 'Markdown']); } saveAll(); bot('sendMessage', ['chat_id' => $u_id, 'text' => "āœ… Reklamangiz aktivlashdi!"]); bot('editMessageCaption', ['chat_id' => ADMIN_ID, 'message_id' => $callback_msg_id, 'caption' => "āœ… Tasdiqlandi"]); } } /* ================= STEPS ================= */ if(!checkJoin($chat_id) && $chat_id) exit; if($photo && isset($users[$chat_id]['step']) && $users[$chat_id]['step'] == 'wait_chek'){ $users[$chat_id]['tmp_ads']['chek'] = end($photo)['file_id']; $users[$chat_id]['step'] = 'wait_link'; saveAll(); bot('sendMessage', ['chat_id'=>$chat_id, 'text'=>"šŸ”— Reklama ssilkasi yoki kanal @username yuboring:"]); exit; } if($text && isset($users[$chat_id]['step']) && $users[$chat_id]['step'] == 'wait_link'){ $users[$chat_id]['tmp_ads']['link'] = $text; $users[$chat_id]['step'] = 'wait_descr'; saveAll(); bot('sendMessage', ['chat_id'=>$chat_id, 'text'=>"šŸ“ Reklama tavsifini yuboring:"]); exit; } if($text && isset($users[$chat_id]['step']) && $users[$chat_id]['step'] == 'wait_descr'){ $users[$chat_id]['tmp_ads']['descr'] = $text; $type = $users[$chat_id]['tmp_type']; bot('sendPhoto', [ 'chat_id' => ADMIN_ID, 'photo' => $users[$chat_id]['tmp_ads']['chek'], 'caption' => "šŸ’Ž Yangi Reklama:\nšŸ‘¤ Kimdan: $chat_id\nšŸ“¦ Turi: " . $reklama_turlari[$type]['nom'] . "\nšŸ”— Link: " . $users[$chat_id]['tmp_ads']['link'] . "\nšŸ“ Izoh: $text", 'reply_markup' => json_encode(['inline_keyboard' => [[["text"=>"āœ… Tasdiqlash", "callback_data"=>"accept_{$chat_id}_{$type}"], ["text"=>"āŒ Rad etish", "callback_data"=>"reject_$chat_id"]]]]) ]); bot('sendMessage', ['chat_id'=>$chat_id, 'text'=>"āŒ› Rahmat! Kuting..."]); $users[$chat_id]['step'] = ""; saveAll(); exit; } /* ================= MENU ================= */ if($text == "/start" || $text == "Orqaga" || $text == "šŸ‘¤ Profil"){ $now = time(); $global_ads['profil'] = array_values(array_filter($global_ads['profil'], function($a) use ($now) { return $now < $a['expire']; })); $global_ads['majburiy'] = array_values(array_filter($global_ads['majburiy'], function($a) use ($now) { return $now < $a['expire']; })); saveAll(); $header = ""; foreach($global_ads['profil'] as $ad) $header .= "šŸ”„ *HAMKOR:* [" . $ad['descr'] . "](" . $ad['link'] . ")\n"; if(!empty($header)) $header .= "————————————————\n\n"; $msg = $header . "šŸ‘¤ *Profilingiz*\n✨ Bot xizmatlaridan foydalanishingiz mumkin."; $kb = [[["text"=>"šŸ‘¤ Profil"], ["text"=>"šŸ›  Xizmatlar"]], [["text"=>"šŸ“¢ Reklama"], ["text"=>"šŸ“ž Aloqa"]]]; bot('sendMessage', ['chat_id'=>$chat_id, 'text'=>$msg, 'parse_mode'=>'Markdown', 'reply_markup'=>json_encode(['keyboard'=>$kb,'resize_keyboard'=>true]), 'disable_web_page_preview'=>true]); exit; } if($text == "šŸ›  Xizmatlar"){ $kb = []; foreach($services as $nom => $key) $kb[] = [["text" => $nom]]; $kb[] = [["text" => "Orqaga"]]; bot('sendMessage', ['chat_id'=>$chat_id, 'text'=>"āš™ļø *Xizmatni tanlang:*", 'reply_markup'=>json_encode(['keyboard'=>$kb,'resize_keyboard'=>true]), 'parse_mode'=>'Markdown']); } if($text == "šŸ“¢ Reklama"){ $inline = []; foreach($reklama_turlari as $k => $v) $inline[] = [["text"=>$v['ikon']." ".$v['nom'], "callback_data"=>"buy_$k"]]; bot('sendMessage', ['chat_id'=>$chat_id, 'text'=>"šŸ“¢ *Reklama turi:*", 'reply_markup'=>json_encode(['inline_keyboard'=>$inline]), 'parse_mode'=>'Markdown']); } if($text == "šŸ“ž Aloqa") bot('sendMessage', ['chat_id'=>$chat_id, 'text'=>"šŸ‘Øā€šŸ’» Admin: @AdminUsername", 'parse_mode'=>'Markdown']); ?>