Improve env vars
This commit is contained in:
parent
9c1a12fb89
commit
ca1af360a4
|
@ -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:...
|
||||
|
|
|
@ -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):
|
||||
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, full_user_id)
|
||||
|
||||
self.client = matrix.AsyncClient(homeserver_url, bot_id)
|
||||
self.client.add_event_callback(self.on_message, matrix.RoomMessage)
|
||||
|
||||
async def prepare(self):
|
||||
|
|
Reference in a new issue