# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence. """Console entrypoint, so `python -m signal_bot` actually starts the bot. The old readme told people to run `python main.py`, which had no __main__ block and no uvicorn.run() call, so it silently did nothing at all. The bind address comes from Config rather than os.getenv() here: this module runs *before* uvicorn imports the app, and therefore before anything has called load_dotenv(), so reading the environment directly would ignore BIND_HOST/BIND_PORT whenever they live in .env -- which is where they live. """ from __future__ import annotations import uvicorn from signal_bot.config_env import load_config from signal_bot.logging_setup import configure as configure_logging from signal_bot.portcheck import PortInUseError, assert_port_free def main() -> None: """Run the ASGI app under uvicorn, refusing to start on a taken port.""" config = load_config() # Before anything else: uvicorn only configures its own loggers, so # without this the bot's own log lines go to logging.lastResort and # anything below WARNING is thrown away. configure_logging(config.log_level) try: assert_port_free(config.bind_host, config.bind_port) except PortInUseError as exc: raise SystemExit(str(exc)) from exc uvicorn.run("signal_bot.app:app", host=config.bind_host, port=config.bind_port) if __name__ == "__main__": main()