Muttered3 commited on
Commit
27761fb
·
verified ·
1 Parent(s): 30e9d64

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +19 -19
main.py CHANGED
@@ -1,29 +1,29 @@
1
  import asyncio
2
  import os
3
- import nest_asyncio
4
- from telethon import TelegramClient
5
- from telethon.sessions import MemorySession
6
  from dummy_server import run_server
7
- from bot import setup_handlers
8
  from worker import run_worker
9
-
10
- nest_asyncio.apply()
11
 
12
  async def main():
13
- api_id = int(os.environ["API_ID"])
14
- api_hash = os.environ["API_HASH"]
15
- bot_token = os.environ["BOT_TOKEN"]
16
-
17
- client = TelegramClient(MemorySession(), api_id, api_hash)
18
- await client.start(bot_token=bot_token)
 
 
 
 
 
19
 
20
- setup_handlers(client)
 
21
 
22
- await asyncio.gather(
23
- run_server(),
24
- client.run_until_disconnected(),
25
- run_worker(),
26
- )
27
 
28
  if __name__ == "__main__":
29
- asyncio.run(main())
 
 
1
  import asyncio
2
  import os
 
 
 
3
  from dummy_server import run_server
4
+ from bot import app
5
  from worker import run_worker
6
+ from pyrogram import idle
 
7
 
8
  async def main():
9
+ # 1. Start the dummy web server so Hugging Face keeps the Space awake on port 7860
10
+ print("🌐 Starting Dummy Server...")
11
+ asyncio.create_task(run_server())
12
+
13
+ # 2. Start the Pyrogram Bot
14
+ print("🤖 Starting Pyrogram Bot...")
15
+ await app.start()
16
+
17
+ # 3. Start the Sniper Workers
18
+ print("🚀 Firing up Sniper Workers...")
19
+ asyncio.create_task(run_worker())
20
 
21
+ # 4. Keep the process alive forever
22
+ await idle()
23
 
24
+ # Cleanup on shutdown
25
+ await app.stop()
 
 
 
26
 
27
  if __name__ == "__main__":
28
+ # Pyrogram's app.run() handles the async event loop perfectly
29
+ app.run(main())