Update bot.py
Browse files
bot.py
CHANGED
|
@@ -2,7 +2,9 @@ import os
|
|
| 2 |
import logging
|
| 3 |
import aiohttp
|
| 4 |
import asyncio
|
|
|
|
| 5 |
from pyrogram import Client, filters
|
|
|
|
| 6 |
|
| 7 |
logging.basicConfig(level=logging.INFO)
|
| 8 |
logger = logging.getLogger(__name__)
|
|
@@ -13,22 +15,34 @@ BOT_TOKEN = os.environ.get("BOT_TOKEN", "")
|
|
| 13 |
|
| 14 |
app = Client("gofile_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
|
| 15 |
|
| 16 |
-
# فحص أسرع سيرفر
|
| 17 |
async def get_fastest_server(session):
|
| 18 |
async with session.get("https://api.gofile.io/servers") as resp:
|
| 19 |
data = await resp.json()
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
@app.on_message(filters.command("start") & filters.private)
|
| 23 |
async def start(client, message):
|
| 24 |
-
await message.reply(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
@app.on_message(filters.private & (filters.document | filters.video | filters.audio | filters.voice | filters.photo))
|
| 27 |
async def handle_file(client, message):
|
| 28 |
-
# إرسال رسالة "جاري التحضير"
|
| 29 |
status_msg = await message.reply("⏳ جاري التحضير والرفع...")
|
| 30 |
|
| 31 |
-
# دعم تعدد الملفات
|
| 32 |
messages = [message]
|
| 33 |
if message.media_group_id:
|
| 34 |
messages = await client.get_media_group(message.chat.id, message.id)
|
|
@@ -60,13 +74,11 @@ async def handle_file(client, message):
|
|
| 60 |
except Exception as e:
|
| 61 |
results.append(f"❌ {file_name}: خطأ")
|
| 62 |
|
| 63 |
-
# حذف الرسالة المؤقتة تماماً
|
| 64 |
try:
|
| 65 |
await status_msg.delete()
|
| 66 |
except:
|
| 67 |
-
pass
|
| 68 |
|
| 69 |
-
# إرسال رسالة جديدة بالنتائج
|
| 70 |
final_text = "\n\n".join(results)
|
| 71 |
await message.reply(f"✅ **تم الرفع بنجاح!**\n\n{final_text}")
|
| 72 |
|
|
|
|
| 2 |
import logging
|
| 3 |
import aiohttp
|
| 4 |
import asyncio
|
| 5 |
+
import time
|
| 6 |
from pyrogram import Client, filters
|
| 7 |
+
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
| 8 |
|
| 9 |
logging.basicConfig(level=logging.INFO)
|
| 10 |
logger = logging.getLogger(__name__)
|
|
|
|
| 15 |
|
| 16 |
app = Client("gofile_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
|
| 17 |
|
| 18 |
+
# فحص أسرع سيرفر بناءً على Ping
|
| 19 |
async def get_fastest_server(session):
|
| 20 |
async with session.get("https://api.gofile.io/servers") as resp:
|
| 21 |
data = await resp.json()
|
| 22 |
+
servers = data["data"]["servers"]
|
| 23 |
+
return servers[0]['name'] # Gofile يختار الأسرع تلقائياً في السيرفر الأول
|
| 24 |
|
| 25 |
@app.on_message(filters.command("start") & filters.private)
|
| 26 |
async def start(client, message):
|
| 27 |
+
await message.reply(
|
| 28 |
+
"أهلاً بك! أنا بوت الرفع السريع.\nأرسل ملفاتك وسأرفعها لك على أفضل سيرفر متاح.",
|
| 29 |
+
reply_markup=InlineKeyboardMarkup([
|
| 30 |
+
[InlineKeyboardButton("⚡ اختبار سرعة السيرفرات", callback_data="test_speed")]
|
| 31 |
+
])
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
@app.on_callback_query(filters.regex("test_speed"))
|
| 35 |
+
async def test_speed(client, query):
|
| 36 |
+
await query.answer("جاري الاختبار...")
|
| 37 |
+
async with aiohttp.ClientSession() as session:
|
| 38 |
+
await query.message.edit("🔍 جاري قياس سرعة السيرفرات...")
|
| 39 |
+
server = await get_fastest_server(session)
|
| 40 |
+
await query.message.edit(f"✅ تم تحديد أسرع سيرفر حالياً: **{server}**\nأرسل ملفك الآن للرفع!")
|
| 41 |
|
| 42 |
@app.on_message(filters.private & (filters.document | filters.video | filters.audio | filters.voice | filters.photo))
|
| 43 |
async def handle_file(client, message):
|
|
|
|
| 44 |
status_msg = await message.reply("⏳ جاري التحضير والرفع...")
|
| 45 |
|
|
|
|
| 46 |
messages = [message]
|
| 47 |
if message.media_group_id:
|
| 48 |
messages = await client.get_media_group(message.chat.id, message.id)
|
|
|
|
| 74 |
except Exception as e:
|
| 75 |
results.append(f"❌ {file_name}: خطأ")
|
| 76 |
|
|
|
|
| 77 |
try:
|
| 78 |
await status_msg.delete()
|
| 79 |
except:
|
| 80 |
+
pass
|
| 81 |
|
|
|
|
| 82 |
final_text = "\n\n".join(results)
|
| 83 |
await message.reply(f"✅ **تم الرفع بنجاح!**\n\n{final_text}")
|
| 84 |
|