""" 2026-matrix-downloader entry point """ import asyncio import traceback import signal import html from pathlib import Path import config import util from new_bot import MatrixBot from bot_types import MatrixBotConfig import nio.events from nio import MatrixRoom, RoomMessageText from datatypes import AppConfig bot: MatrixBot = None async def callback_test_text(room: MatrixRoom, event: RoomMessageText) -> None: if event.sender == bot.get_client().user_id: return await bot.send_text_to_room(room.room_id, f"{html.escape(event.body)}") async def main() -> None: """Entry point""" global bot # setup signal handler util.setup_app_stop_event() loop = asyncio.get_running_loop() for sig in (signal.SIGINT, signal.SIGTERM): loop.add_signal_handler(sig, lambda: util.request_app_stop("Signal caught")) # setup util.setup_logging() util.log_info("2026-matrix-csonac") # load the config cfg: AppConfig = await config.load_config("config.json") # type: ignore if cfg is None: util.log_error("Could't load config") return # setup the bot matrix_bot_config = MatrixBotConfig( matrix_homeserver_url=cfg.matrix_homeserver, matrix_username_localpart=cfg.matrix_user, storage_directory=Path(cfg.store_dir) ) bot = MatrixBot(matrix_bot_config) bot.add_event_callback(callback_test_text, RoomMessageText) bot.add_event_callback(None, nio.events.Event) # start the app bot.start() # wait for Ctrl+C await util.get_app_stop_event().wait() # stop the app await bot.stop() if __name__ == "__main__": try: asyncio.run(main()) except SystemExit: raise except: traceback.print_exc()