Add config
This commit is contained in:
parent
2f5694cffb
commit
dfa4c10138
|
@ -5,22 +5,32 @@ import sys
|
||||||
import aiogram as telegram
|
import aiogram as telegram
|
||||||
import nio as matrix
|
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():
|
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:
|
class Application:
|
||||||
def __init__(self):
|
def __init__(self, config):
|
||||||
|
self.config = config
|
||||||
self.matrix_loop = MatrixLoop(
|
self.matrix_loop = MatrixLoop(
|
||||||
MATRIX_HOMESERVER_URL,
|
config.matrix_homeserver_url,
|
||||||
MATRIX_FULL_USER_ID,
|
config.matrix_full_user_id,
|
||||||
MATRIX_PASSWORD,
|
config.matrix_password,
|
||||||
)
|
)
|
||||||
self.telegram_loop = TelegramLoop(TELEGRAM_BOT_TOKEN)
|
self.telegram_loop = TelegramLoop(config.telegram_bot_token)
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
try:
|
try:
|
||||||
|
|
Reference in a new issue