From ca1af360a4b89a47b6c63402b96c4f4309bbf2ce Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Mon, 9 Jan 2023 01:08:52 +0400 Subject: [PATCH] Improve env vars --- .env.example | 3 ++- mirrortea/__main__.py | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index 45df895..d311fec 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ DB_PATH=data/database.sqlite3 +MATRIX_BOT_ID=@fckidiots:matrix.org MATRIX_HOMESERVER_URL=https://matrix.org -MATRIX_FULL_USER_ID=@fckidiots:matrix.org +MATRIX_OWNER_ID=@kotovalexarian:matrix.org MATRIX_PASSWORD=... TELEGRAM_BOT_TOKEN=5890667880:... diff --git a/mirrortea/__main__.py b/mirrortea/__main__.py index 5c6741b..8f6bf6e 100644 --- a/mirrortea/__main__.py +++ b/mirrortea/__main__.py @@ -9,8 +9,9 @@ import nio as matrix def main(): config = Config( db_path=os.environ['DB_PATH'], + matrix_bot_id=os.environ['MATRIX_BOT_ID'], matrix_homeserver_url=os.environ['MATRIX_HOMESERVER_URL'], - matrix_full_user_id=os.environ['MATRIX_FULL_USER_ID'], + matrix_owner_id=os.environ['MATRIX_OWNER_ID'], matrix_password=os.environ['MATRIX_PASSWORD'], telegram_bot_token=os.environ['TELEGRAM_BOT_TOKEN'], ) @@ -20,8 +21,9 @@ def main(): class Config: def __init__(self, **kwargs): self.db_path = kwargs['db_path'] + self.matrix_bot_id = kwargs['matrix_bot_id'] self.matrix_homeserver_url = kwargs['matrix_homeserver_url'] - self.matrix_full_user_id = kwargs['matrix_full_user_id'] + self.matrix_owner_id = kwargs['matrix_owner_id'] self.matrix_password = kwargs['matrix_password'] self.telegram_bot_token = kwargs['telegram_bot_token'] @@ -31,8 +33,9 @@ class Application: self.sqlite_adapter = SqliteAdapter(self, config.db_path) self.matrix_loop = MatrixLoop( self, + config.matrix_bot_id, config.matrix_homeserver_url, - config.matrix_full_user_id, + config.matrix_owner_id, config.matrix_password, ) self.telegram_loop = TelegramLoop( @@ -52,10 +55,14 @@ class Application: await self.matrix_loop.finish() class MatrixLoop: - 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) + def __init__(self, app, bot_id, homeserver_url, owner_id, password): + self.app = app + self.bot_id = bot_id + self.homeserver_url = homeserver_url + self.owner_id = owner_id + self.password = password + + self.client = matrix.AsyncClient(homeserver_url, bot_id) self.client.add_event_callback(self.on_message, matrix.RoomMessage) async def prepare(self):