Reooiq commited on
Commit
32a36f2
·
verified ·
1 Parent(s): f4f1c14

Update bot.py

Browse files
Files changed (1) hide show
  1. bot.py +11 -9
bot.py CHANGED
@@ -5,7 +5,7 @@ import shutil
5
  import time
6
  import threading
7
  import gradio as gr
8
- from pyrogram import Client, filters
9
  from pyrogram.errors import FloodWait, RPCError
10
  from pyrogram.types import InputMediaPhoto, InputMediaVideo, InputMediaDocument, InputMediaAudio
11
 
@@ -144,7 +144,7 @@ async def flush_media_group(chat_id, mg_id):
144
  except:
145
  pass
146
 
147
- # ============ المعالج الرئيسي — بدون filters.channel/group ============
148
  @app.on_message(filters.incoming & ~filters.me & filters.media)
149
  async def on_media(client, message):
150
  chat_id = message.chat.id
@@ -225,15 +225,12 @@ async def monitor_all(client, message):
225
  if message.chat.id == TARGET_CHAT:
226
  return
227
  chat_type = message.chat.type
228
- logger.info(f"👁️ رسالة من {message.chat.id} | نوع: {chat_type} | عنوان: {message.chat.title or 'بدون اسم'} | نص: {message.text or '[ملف]'}")
229
  if message.media:
230
  logger.info(f" └─ تحتوي على media: {message.media}")
231
 
232
- # ============ تشغيل البوت ============
233
  def run_bot():
234
- loop = asyncio.new_event_loop()
235
- asyncio.set_event_loop(loop)
236
-
237
  async def bot_main():
238
  await app.start()
239
  me = await app.get_me()
@@ -244,8 +241,13 @@ def run_bot():
244
  logger.info("📡 المصدر: جميع القنوات والمجموعات")
245
  logger.info("=" * 50)
246
 
247
- while True:
248
- await asyncio.sleep(3600)
 
 
 
 
 
249
 
250
  while True:
251
  try:
 
5
  import time
6
  import threading
7
  import gradio as gr
8
+ from pyrogram import Client, filters, idle
9
  from pyrogram.errors import FloodWait, RPCError
10
  from pyrogram.types import InputMediaPhoto, InputMediaVideo, InputMediaDocument, InputMediaAudio
11
 
 
144
  except:
145
  pass
146
 
147
+ # ============ المعالج الرئيسي ============
148
  @app.on_message(filters.incoming & ~filters.me & filters.media)
149
  async def on_media(client, message):
150
  chat_id = message.chat.id
 
225
  if message.chat.id == TARGET_CHAT:
226
  return
227
  chat_type = message.chat.type
228
+ logger.info(f"👁️ رسالة واردة من {message.chat.id} | نوع: {chat_type} | عنوان: {message.chat.title or 'بدون اسم'} | نص: {message.text or '[ملف]'}")
229
  if message.media:
230
  logger.info(f" └─ تحتوي على media: {message.media}")
231
 
232
+ # ============ تشغيل البوت بـ idle() ============
233
  def run_bot():
 
 
 
234
  async def bot_main():
235
  await app.start()
236
  me = await app.get_me()
 
241
  logger.info("📡 المصدر: جميع القنوات والمجموعات")
242
  logger.info("=" * 50)
243
 
244
+ # 🔑 المفتاح: idle() يحافظ على الاتصال ويستقبل التحديثات
245
+ await idle()
246
+
247
+ await app.stop()
248
+
249
+ loop = asyncio.new_event_loop()
250
+ asyncio.set_event_loop(loop)
251
 
252
  while True:
253
  try: