Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,18 @@
|
|
| 1 |
import telebot
|
|
|
|
| 2 |
import time
|
| 3 |
import random
|
| 4 |
import threading
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
-
# ا
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
TOKEN = "8238023143:AAHLMQFTBSjdusQvvsat9FNdCx968neiaj0"
|
| 9 |
bot = telebot.TeleBot(TOKEN)
|
| 10 |
|
| 11 |
-
# قائمة صيغ الصلاة على النبي (يمكنك إضافة المزيد)
|
| 12 |
azkar = [
|
| 13 |
"اللهم صل وسلم على نبينا محمد 🤍",
|
| 14 |
"اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم ✨",
|
|
@@ -17,19 +21,16 @@ azkar = [
|
|
| 17 |
"عليه أفضل الصلاة والسلام 🌿"
|
| 18 |
]
|
| 19 |
|
| 20 |
-
# لتخزين الـ IDs الخاصة بالمستخدمين لتجنب تكرار اللوب إذا ضغط ستارت أكثر من مرة
|
| 21 |
active_users = set()
|
| 22 |
|
| 23 |
def send_azkar(chat_id):
|
| 24 |
-
"""دالة إرسال الرسائل كل 3 ثواني في Thread منفصل"""
|
| 25 |
while chat_id in active_users:
|
| 26 |
try:
|
| 27 |
msg = random.choice(azkar)
|
| 28 |
bot.send_message(chat_id, msg)
|
| 29 |
-
time.sleep(3)
|
| 30 |
except Exception as e:
|
| 31 |
print(f"Error sending to {chat_id}: {e}")
|
| 32 |
-
# الانتظار في حالة حظر البوت مؤقتاً من تيليجرام (Flood Wait)
|
| 33 |
time.sleep(5)
|
| 34 |
|
| 35 |
@bot.message_handler(commands=['start'])
|
|
@@ -39,7 +40,6 @@ def start_message(message):
|
|
| 39 |
active_users.add(chat_id)
|
| 40 |
bot.reply_to(message, "تم تفعيل التذكير بالصلاة على النبي كل 3 ثواني 🤍\nلإيقاف التذكير ارسل /stop")
|
| 41 |
|
| 42 |
-
# تشغيل التذكير في Thread منفصل لكل مستخدم عشان البوت ميهنجش
|
| 43 |
threading.Thread(target=send_azkar, args=(chat_id,), daemon=True).start()
|
| 44 |
else:
|
| 45 |
bot.reply_to(message, "التذكير شغال بالفعل! 🤍")
|
|
@@ -53,17 +53,15 @@ def stop_message(message):
|
|
| 53 |
else:
|
| 54 |
bot.reply_to(message, "التذكير متوقف أصلاً.")
|
| 55 |
|
| 56 |
-
# تشغيل استماع البوت في Thread منفصل تماماً عن واجهة Gradio
|
| 57 |
def run_bot():
|
| 58 |
print("Bot is running...")
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
threading.Thread(target=run_bot, daemon=True).start()
|
| 62 |
|
| 63 |
-
# بناء واجهة Gradio بسيطة لإبقاء الـ Space قيد التشغيل (Running)
|
| 64 |
with gr.Blocks() as demo:
|
| 65 |
gr.Markdown("<center><h1>🐳 البوت يعمل بنجاح في الخلفية</h1></center>")
|
| 66 |
-
gr.Markdown("<center>
|
| 67 |
|
| 68 |
-
# تشغيل السيرفر
|
| 69 |
demo.launch()
|
|
|
|
| 1 |
import telebot
|
| 2 |
+
from telebot import apihelper
|
| 3 |
import time
|
| 4 |
import random
|
| 5 |
import threading
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
+
# إعدادات الشبكة لحل مشكلة الـ Timeouts على سيرفرات Hugging Face
|
| 9 |
+
apihelper.RETRY_ON_ERROR = True
|
| 10 |
+
apihelper.CONNECT_TIMEOUT = 60
|
| 11 |
+
apihelper.READ_TIMEOUT = 60
|
| 12 |
+
|
| 13 |
TOKEN = "8238023143:AAHLMQFTBSjdusQvvsat9FNdCx968neiaj0"
|
| 14 |
bot = telebot.TeleBot(TOKEN)
|
| 15 |
|
|
|
|
| 16 |
azkar = [
|
| 17 |
"اللهم صل وسلم على نبينا محمد 🤍",
|
| 18 |
"اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم ✨",
|
|
|
|
| 21 |
"عليه أفضل الصلاة والسلام 🌿"
|
| 22 |
]
|
| 23 |
|
|
|
|
| 24 |
active_users = set()
|
| 25 |
|
| 26 |
def send_azkar(chat_id):
|
|
|
|
| 27 |
while chat_id in active_users:
|
| 28 |
try:
|
| 29 |
msg = random.choice(azkar)
|
| 30 |
bot.send_message(chat_id, msg)
|
| 31 |
+
time.sleep(3)
|
| 32 |
except Exception as e:
|
| 33 |
print(f"Error sending to {chat_id}: {e}")
|
|
|
|
| 34 |
time.sleep(5)
|
| 35 |
|
| 36 |
@bot.message_handler(commands=['start'])
|
|
|
|
| 40 |
active_users.add(chat_id)
|
| 41 |
bot.reply_to(message, "تم تفعيل التذكير بالصلاة على النبي كل 3 ثواني 🤍\nلإيقاف التذكير ارسل /stop")
|
| 42 |
|
|
|
|
| 43 |
threading.Thread(target=send_azkar, args=(chat_id,), daemon=True).start()
|
| 44 |
else:
|
| 45 |
bot.reply_to(message, "التذكير شغال بالفعل! 🤍")
|
|
|
|
| 53 |
else:
|
| 54 |
bot.reply_to(message, "التذكير متوقف أصلاً.")
|
| 55 |
|
|
|
|
| 56 |
def run_bot():
|
| 57 |
print("Bot is running...")
|
| 58 |
+
# زيادة وقت الـ Long Polling لتقليل الضغط وعمليات الـ Handshake
|
| 59 |
+
bot.infinity_polling(timeout=60, long_polling_timeout=30)
|
| 60 |
|
| 61 |
threading.Thread(target=run_bot, daemon=True).start()
|
| 62 |
|
|
|
|
| 63 |
with gr.Blocks() as demo:
|
| 64 |
gr.Markdown("<center><h1>🐳 البوت يعمل بنجاح في الخلفية</h1></center>")
|
| 65 |
+
gr.Markdown("<center>تم تحسين الاتصال لتجنب مشكلة الـ Timeout</center>")
|
| 66 |
|
|
|
|
| 67 |
demo.launch()
|