From dfa4c10138c7475eef7f8dbae052ec33c5cf142d Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 8 Jan 2023 23:31:11 +0400 Subject: [PATCH] Add config --- mirrortea/__main__.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/mirrortea/__main__.py b/mirrortea/__main__.py index 926643d..0ab3598 100644 --- a/mirrortea/__main__.py +++ b/mirrortea/__main__.py @@ -5,22 +5,32 @@ import sys import aiogram as telegram import nio as matrix -MATRIX_HOMESERVER_URL = os.environ['MATRIX_HOMESERVER_URL'] -MATRIX_FULL_USER_ID = os.environ['MATRIX_FULL_USER_ID'] -MATRIX_PASSWORD = os.environ['MATRIX_PASSWORD'] -TELEGRAM_BOT_TOKEN = os.environ['TELEGRAM_BOT_TOKEN'] - def main(): - asyncio.run(Application().run()) + config = Config( + matrix_homeserver_url=os.environ['MATRIX_HOMESERVER_URL'], + matrix_full_user_id=os.environ['MATRIX_FULL_USER_ID'], + matrix_password=os.environ['MATRIX_PASSWORD'], + telegram_bot_token=os.environ['TELEGRAM_BOT_TOKEN'], + ) + + asyncio.run(Application(config).run()) + +class Config: + def __init__(self, **kwargs): + self.matrix_homeserver_url = kwargs['matrix_homeserver_url'] + self.matrix_full_user_id = kwargs['matrix_full_user_id'] + self.matrix_password = kwargs['matrix_password'] + self.telegram_bot_token = kwargs['telegram_bot_token'] class Application: - def __init__(self): + def __init__(self, config): + self.config = config self.matrix_loop = MatrixLoop( - MATRIX_HOMESERVER_URL, - MATRIX_FULL_USER_ID, - MATRIX_PASSWORD, + config.matrix_homeserver_url, + config.matrix_full_user_id, + config.matrix_password, ) - self.telegram_loop = TelegramLoop(TELEGRAM_BOT_TOKEN) + self.telegram_loop = TelegramLoop(config.telegram_bot_token) async def run(self): try: