diff --git a/src/kassandra/__main__.py b/src/kassandra/__main__.py index 90a4d15..0b3f6a0 100644 --- a/src/kassandra/__main__.py +++ b/src/kassandra/__main__.py @@ -17,10 +17,7 @@ async def __main(): bot_corout = send_messages( message_queue, - config.username, - config.homeserver, - config.password, - config.alert_rooms + config ) format_corout = format_alerts( alert_queue, @@ -28,8 +25,7 @@ async def __main(): ) webhook_corout = run_webhook( alert_queue, - config.host, - config.port + config ) diff --git a/src/kassandra/bot.py b/src/kassandra/bot.py index 5f5c723..a58dcf7 100644 --- a/src/kassandra/bot.py +++ b/src/kassandra/bot.py @@ -9,6 +9,7 @@ from typing import ( ) from matrix_bot.client import Client from matrix_bot.invite_policy import WhiteList +from .config import Config from .format import Message async def __send_messsages( @@ -31,27 +32,24 @@ async def __send_messsages( async def send_messages( message_queue: asyncio.Queue[dict[str, Any]], # For now, type will change in the futur - username: str, - homeserver: str, - password: str, - alert_rooms: list[str] + config: Config ): """ Initialize the bot and send messages added to the queue to the alert_rooms. """ bot = await Client( - username, - homeserver, - password + config.username, + config.homeserver, + config.password ) - invite_policy = await WhiteList(bot, alert_rooms) + invite_policy = await WhiteList(bot, config.alert_rooms) bot.set_invite_policy(invite_policy) await asyncio.gather( bot.run(), __send_messsages( message_queue, bot, - alert_rooms + config.alert_rooms ) ) diff --git a/src/kassandra/webhook.py b/src/kassandra/webhook.py index 709959c..7a91237 100644 --- a/src/kassandra/webhook.py +++ b/src/kassandra/webhook.py @@ -10,13 +10,13 @@ from typing import ( Any, NoReturn ) +from .config import Config ENDPOINT = "/webhook" async def run_webhook( alert_queue: asyncio.Queue[dict[str, Any]], - host: str, - port: int + config: Config )->NoReturn: """ Run the webhook endpoint and put the alerts in the queue. @@ -31,5 +31,5 @@ async def run_webhook( app.add_routes([aiohttp.web.post(ENDPOINT, handler)]) runner = aiohttp.web.AppRunner(app) await runner.setup() - site = aiohttp.web.TCPSite(runner, host, port) + site = aiohttp.web.TCPSite(runner, config.host, config.port) await site.start()