use config as arg for function instead of values

master
histausse 3 years ago
parent c7de4cfbc0
commit c2e149aa1d
Signed by: histausse
GPG Key ID: 67486F107F62E9E9

@ -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
)

@ -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
)
)

@ -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()

Loading…
Cancel
Save