[] ])); } $data = json_decode(file_get_contents($data_file), true); // ====== UPDATE ====== $update = json_decode(file_get_contents("php://input"), true); $message = $update["message"] ?? null; if (!$message) exit; $chat_id = $message["chat"]["id"]; $text = trim($message["text"] ?? ""); // ====== FUNKSIYALAR ====== function sendMessage($chat_id, $text) { global $api; file_get_contents($api."/sendMessage?chat_id=$chat_id&text=".urlencode($text)); } function isJoined($user_id, $channel) { global $api; $res = json_decode(file_get_contents( $api."/getChatMember?chat_id=@$channel&user_id=$user_id" ), true); return isset($res["result"]["status"]) && in_array($res["result"]["status"], ["member","administrator","creator"]); } // ====== ADMIN BUYRUQLAR ====== if ($chat_id == $admin_id) { if (strpos($text, "/add ") === 0) { $ch = str_replace("/add ", "", $text); $data["channels"][] = $ch; file_put_contents($data_file, json_encode($data)); sendMessage($chat_id, "✅ Kanal qo‘shildi: @$ch"); exit; } if (strpos($text, "/del ") === 0) { $ch = str_replace("/del ", "", $text); $data["channels"] = array_values(array_diff($data["channels"], [$ch])); file_put_contents($data_file, json_encode($data)); sendMessage($chat_id, "❌ Kanal o‘chirildi: @$ch"); exit; } if ($text == "/channels") { $list = empty($data["channels"]) ? "Yo‘q" : implode("\n@", $data["channels"]); sendMessage($chat_id, "📢 Kanallar:\n@".$list); exit; } } // ====== START ====== if ($text == "/start") { sendMessage($chat_id, "👋 Salom!\n\n📌 Kodni kiriting:"); exit; } // ====== KOD KIRITILGANDA ====== $not_joined = []; foreach ($data["channels"] as $ch) { if (!isJoined($chat_id, $ch)) { $not_joined[] = "@$ch"; } } if (!empty($not_joined)) { sendMessage( $chat_id, "❗ Avval quyidagi kanallarga obuna bo‘ling:\n\n". implode("\n", $not_joined) ); } else { sendMessage($chat_id, "✅ Rahmat! Ruxsat berildi."); }