Use config instead of forwarding all the variables
This commit is contained in:
parent
ca1af360a4
commit
1d77e32174
|
@ -31,17 +31,8 @@ class Application:
|
|||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.sqlite_adapter = SqliteAdapter(self, config.db_path)
|
||||
self.matrix_loop = MatrixLoop(
|
||||
self,
|
||||
config.matrix_bot_id,
|
||||
config.matrix_homeserver_url,
|
||||
config.matrix_owner_id,
|
||||
config.matrix_password,
|
||||
)
|
||||
self.telegram_loop = TelegramLoop(
|
||||
self,
|
||||
config.telegram_bot_token,
|
||||
)
|
||||
self.matrix_loop = MatrixLoop(self)
|
||||
self.telegram_loop = TelegramLoop(self)
|
||||
|
||||
async def run(self):
|
||||
try:
|
||||
|
@ -55,18 +46,16 @@ class Application:
|
|||
await self.matrix_loop.finish()
|
||||
|
||||
class MatrixLoop:
|
||||
def __init__(self, app, bot_id, homeserver_url, owner_id, password):
|
||||
def __init__(self, app):
|
||||
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 = matrix.AsyncClient(
|
||||
app.config.matrix_homeserver_url,
|
||||
app.config.matrix_bot_id,
|
||||
)
|
||||
self.client.add_event_callback(self.on_message, matrix.RoomMessage)
|
||||
|
||||
async def prepare(self):
|
||||
await self.client.login(self.password)
|
||||
await self.client.login(self.app.config.matrix_password)
|
||||
|
||||
async def finish(self):
|
||||
await self.client.close()
|
||||
|
@ -78,9 +67,9 @@ class MatrixLoop:
|
|||
print(room, event, file=sys.stderr)
|
||||
|
||||
class TelegramLoop:
|
||||
def __init__(self, app, bot_token):
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.bot = telegram.Bot(token=bot_token)
|
||||
self.bot = telegram.Bot(token=app.config.telegram_bot_token)
|
||||
self.dispatcher = telegram.Dispatcher(bot=self.bot)
|
||||
self.dispatcher.register_message_handler(self.on_message)
|
||||
|
||||
|
|
Reference in a new issue