understanding commited on
Commit
ed36936
·
verified ·
1 Parent(s): 2e1e1ba

Create __main__.py

Browse files
Files changed (1) hide show
  1. bot/__main__.py +50 -0
bot/__main__.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PATH: bot/__main__.py
2
+ import asyncio
3
+ from logging import getLogger
4
+ from logging.config import dictConfig
5
+
6
+ from uvicorn import Config as UvicornConfig, Server as UvicornServer
7
+
8
+ from bot.config import Server, LOGGER_CONFIG_JSON
9
+ from bot.client import create_client
10
+ from bot.handlers import setup_handlers
11
+ from bot.startup_log import log_startup
12
+ from bot.server import create_app
13
+
14
+ logger = getLogger("bot")
15
+
16
+ async def main():
17
+ dictConfig(LOGGER_CONFIG_JSON)
18
+
19
+ # Create web app + uvicorn server
20
+ quart_app = create_app()
21
+ uv_cfg = UvicornConfig(
22
+ app=quart_app,
23
+ host=Server.BIND_ADDRESS,
24
+ port=Server.PORT,
25
+ log_config=LOGGER_CONFIG_JSON,
26
+ )
27
+ uv_server = UvicornServer(uv_cfg)
28
+
29
+ # Create Telegram client
30
+ app = create_client()
31
+ setup_handlers(app)
32
+
33
+ # Start telegram first (so you see quickly if TG blocked)
34
+ await app.start()
35
+ asyncio.create_task(log_startup(app))
36
+
37
+ # Start web server
38
+ asyncio.create_task(uv_server.serve())
39
+
40
+ logger.info("All services started ✅")
41
+
42
+ # Idle forever
43
+ try:
44
+ while True:
45
+ await asyncio.sleep(3600)
46
+ finally:
47
+ await app.stop()
48
+
49
+ if __name__ == "__main__":
50
+ asyncio.run(main())