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