From e6f40ac0a6b0cc503b7672a081724a252e6949e3 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 8 Jan 2023 23:33:30 +0400 Subject: [PATCH] Forward the application object --- mirrortea/__main__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mirrortea/__main__.py b/mirrortea/__main__.py index 0ab3598..81a1885 100644 --- a/mirrortea/__main__.py +++ b/mirrortea/__main__.py @@ -26,11 +26,15 @@ class Application: def __init__(self, config): self.config = config self.matrix_loop = MatrixLoop( + self, config.matrix_homeserver_url, config.matrix_full_user_id, config.matrix_password, ) - self.telegram_loop = TelegramLoop(config.telegram_bot_token) + self.telegram_loop = TelegramLoop( + self, + config.telegram_bot_token, + ) async def run(self): try: @@ -44,7 +48,8 @@ class Application: await self.matrix_loop.finish() class MatrixLoop: - def __init__(self, homeserver_url, full_user_id, password): + def __init__(self, app, homeserver_url, full_user_id, password): + self.app = app self.password = password self.client = matrix.AsyncClient(homeserver_url, full_user_id) self.client.add_event_callback(self.on_message, matrix.RoomMessage) @@ -62,7 +67,8 @@ class MatrixLoop: print(room, event, file=sys.stderr) class TelegramLoop: - def __init__(self, bot_token): + def __init__(self, app, bot_token): + self.app = app self.bot = telegram.Bot(token=bot_token) self.dispatcher = telegram.Dispatcher(bot=self.bot) self.dispatcher.register_message_handler(self.on_message)