"obhavo", "💸 Valyuta kurs yuborish" => "kurs", "🌙 Ramazon taqvimi yuborish" => "ramazon", "🕌 Namoz vaqtlar yuborish" => "namoz", "⛔ Reklama tarqatishni taqiqlash" => "reklamaoff", "🤬 Sokinishlarni taqiqlash" => "sokinish", " 📞 Telefon raqam tarqatish" => "telefon", "⚽ Futbol live Bundesliga" => "futlive", "⚽ Futbol live Primerliga" => "futlivepremer", "⚽ La Liga jadvali (foto)" => "futjadval" ]; /* ================= FUNCTIONS ================= */ 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); } function saveUsers(){ global $users, $users_file; file_put_contents($users_file, json_encode($users, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); } function sendKB($id, $txt, $kb){ $rm = json_encode(['keyboard' => $kb, 'resize_keyboard' => true]); return bot('sendMessage', ['chat_id' => $id, 'text' => $txt, 'reply_markup' => $rm, 'parse_mode' => 'Markdown']); } /* ================= CALLBACK HANDLING ================= */ if(isset($callback) && strpos($callback, "del_") === 0){ $service_key = urldecode(str_replace("del_", "", $callback)); if(isset($users[$callback_chat]['active_services'][$service_key])){ unset($users[$callback_chat]['active_services'][$service_key]); saveUsers(); } if(isset($services[$service_key])){ $json_file = __DIR__ . "/" . $services[$service_key] . "/baza.json"; if(file_exists($json_file)){ $data = json_decode(file_get_contents($json_file), true); if(isset($data[$callback_chat])){ unset($data[$callback_chat]); file_put_contents($json_file, json_encode($data, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); } } } bot('answerCallbackQuery', ['callback_query_id' => $callback_id, 'text' => "✅ O'chirildi"]); bot('deleteMessage', ['chat_id' => $callback_chat, 'message_id' => $callback_msg_id]); $text = "Profil"; $chat_id = $callback_chat; } /* ================= MAIN COMMANDS ================= */ if($text == "/start" || $text == "Orqaga"){ if($chat_id && !isset($users[$chat_id])) $users[$chat_id] = ["active_services"=>[]]; saveUsers(); sendKB($chat_id, "🏠 *Bosh menyu*", [ [["text"=>"Profil"], ["text"=>"Xizmatlar"]], [["text"=>"Savollar"]], [["text"=>"Reklama"], ["text"=>"Aloqa"]] ]); exit; } /* ================= PROFIL SECTION ================= */ if($text == "Profil"){ $act = $users[$chat_id]['active_services'] ?? []; $msg = "👤 *Profilingiz*\n\nAktiv xizmatlar:\n"; $inline = []; if(!empty($act)){ foreach($act as $service => $channels){ $list = []; foreach($channels as $cid){ $info = bot('getChat', ['chat_id' => $cid]); if($info['ok'] && isset($info['result']['username'])){ $u = "@" . $info['result']['username']; $list[] = str_replace('_', '\_', $u); } else { $list[] = $cid; } } $safe_s = str_replace('_', '\_', $service); $msg .= "✅ $safe_s " . implode(", ", $list) . "\n"; $inline[] = [["text" => "❌ $service o'chirish", "callback_data" => "del_".urlencode($service)]]; } } else { $msg .= "Hech qanday xizmat yoqilmagan"; } bot('sendMessage', [ 'chat_id' => $chat_id, 'text' => $msg, 'reply_markup' => json_encode(['inline_keyboard' => $inline]), 'parse_mode' => 'Markdown' ]); exit; } if($text == "Xizmatlar"){ $kb = []; foreach($services as $s => $f) $kb[] = [["text" => $s]]; $kb[] = [["text" => "Orqaga"]]; sendKB($chat_id, "*Xizmatlar ro'yxati*", $kb); exit; } /* ================= SERVICE REGISTRATION ================= */ if(array_key_exists($text, $services)){ bot('sendMessage', [ 'chat_id' => $chat_id, 'text' => "Kanal username yoki linkini yuboring:\n\nNamuna: @kanal yoki https://t.me/kanal", 'reply_markup' => json_encode(['remove_keyboard' => true]) ]); $users[$chat_id]['pending_service'] = $text; saveUsers(); exit; } if(isset($users[$chat_id]['pending_service']) && !empty($text)){ $service = $users[$chat_id]['pending_service']; // Linkni username ko'rinishiga keltirish $clean_chat = str_replace(['https://t.me/', 'http://t.me/', 't.me/'], '@', $text); if(strpos($clean_chat, '@') !== 0) $clean_chat = '@' . $clean_chat; // 1. Kanal ma'lumotlarini olish $info = bot('getChat', ['chat_id' => $clean_chat]); if(!$info['ok']){ bot('sendMessage', ['chat_id' => $chat_id, 'text' => "❌ Xato! Bot kanalda yo'q yoki admin emas. Qayta urinib ko'ring:"]); exit; } $cid = $info['result']['id']; // 2. FOYDALANUVCHI ADMINLIGINI TEKSHIRISH $member = bot('getChatMember', ['chat_id' => $cid, 'user_id' => $chat_id]); $status = $member['result']['status'] ?? ''; if($status != 'administrator' && $status != 'creator'){ sendKB($chat_id, "❌ Siz bu kanalning egasi yoki admini emassiz! Faqat o'zingiz boshqaradigan kanallarni qo'shishingiz mumkin.", [ [["text"=>"Profil"], ["text"=>"Xizmatlar"]], [["text"=>"Savollar"]], [["text"=>"Reklama"], ["text"=>"Aloqa"]] ]); unset($users[$chat_id]['pending_service']); saveUsers(); exit; } // 3. DUPLIKAT TEKSHIRUVI if(isset($users[$chat_id]['active_services'][$service]) && in_array($cid, $users[$chat_id]['active_services'][$service])){ sendKB($chat_id, "⚠️ Bu kanal *$service* xizmatiga allaqachon qo'shilgan!", [ [["text"=>"Profil"], ["text"=>"Xizmatlar"]], [["text"=>"Savollar"]], [["text"=>"Reklama"], ["text"=>"Aloqa"]] ]); unset($users[$chat_id]['pending_service']); saveUsers(); exit; } // 4. BAZA.JSON GA YOZISH $path = __DIR__ . "/" . $services[$service]; if (!file_exists($path)) mkdir($path, 0777, true); $json_file = $path . "/baza.json"; $data = file_exists($json_file) ? json_decode(file_get_contents($json_file), true) : []; if(!is_array($data)) $data = []; if(!isset($data[$chat_id])) $data[$chat_id] = []; if(!in_array($cid, $data[$chat_id])) $data[$chat_id][] = $cid; file_put_contents($json_file, json_encode($data, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); // 5. USERS.JSON GA YOZISH $users[$chat_id]['active_services'][$service][] = $cid; unset($users[$chat_id]['pending_service']); saveUsers(); sendKB($chat_id, "✅ Tayyor! Kanal tasdiqlandi va muvaffaqiyatli saqlandi.", [ [["text"=>"Profil"], ["text"=>"Xizmatlar"]], [["text"=>"Savollar"]], [["text"=>"Reklama"], ["text"=>"Aloqa"]] ]); exit; } /* ================= OTHER SECTIONS ================= */ if($text == "Savollar") sendKB($chat_id, "❓ *Ko'p beriladigan savollar*\n\nAdmin: @AdminUsername", [[["text"=>"Orqaga"]]]); if($text == "Reklama") sendKB($chat_id, "📢 *Reklama*\n\nAdmin: @AdminUsername", [[["text"=>"Orqaga"]]]); if($text == "Aloqa") sendKB($chat_id, "📞 *Aloqa*\n\nTexnik yordam: @AdminUsername", [[["text"=>"Orqaga"]]]); ?>