Forward the application object

This commit is contained in:
Alex Kotov 2023-01-08 23:33:30 +04:00
parent dfa4c10138
commit e6f40ac0a6
No known key found for this signature in database
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 9 additions and 3 deletions

View File

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