refactoring-by-def #1
|
@ -1,4 +1,4 @@
|
||||||
MATRIX_BOT_ID=@fckidiots:matrix.org
|
|
||||||
MATRIX_HOMESERVER_URL=https://matrix.org
|
MATRIX_HOMESERVER_URL=https://matrix.org
|
||||||
MATRIX_PASSWORD=...
|
MATRIX_FULL_BOT_ID=@fckidiots:matrix.org
|
||||||
|
MATRIX_BOT_PASSWORD=...
|
||||||
TELEGRAM_BOT_TOKEN=5890667880:...
|
TELEGRAM_BOT_TOKEN=5890667880:...
|
||||||
|
|
|
@ -1,2 +1,7 @@
|
||||||
matrix_owner_id: "@dettlaff:inex.rocks"
|
matrix_owner_id: "@dettlaff:inex.rocks"
|
||||||
db_path: "data/database.sqlite3"
|
db_path: "data/database.sqlite3"
|
||||||
|
|
||||||
|
matrix_homeserver_url: "{{ MATRIX_HOMESERVER_URL }}"
|
||||||
|
matrix_full_bot_id: "{{ MATRIX_FULL_BOT_ID }}"
|
||||||
|
matrix_bot_password: "{{ MATRIX_BOT_PASSWORD }}"
|
||||||
|
telegram_bot_token: "{{ TELEGRAM_BOT_TOKEN }}"
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Application:
|
||||||
await self.matrix_loop.prepare()
|
await self.matrix_loop.prepare()
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
self.matrix_loop.run(),
|
self.matrix_loop.run(),
|
||||||
self.telegram_loop.run(),
|
self.telegram.run(),
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
if self.matrix_loop:
|
if self.matrix_loop:
|
||||||
|
|
|
@ -16,12 +16,14 @@ def render_env_template(raw_config: str) -> dict:
|
||||||
class Config:
|
class Config:
|
||||||
db_path: Path
|
db_path: Path
|
||||||
|
|
||||||
matrix_bot_id: str
|
|
||||||
matrix_homeserver_url: str
|
matrix_homeserver_url: str
|
||||||
matrix_password: str
|
matrix_full_bot_id: str
|
||||||
matrix_owner_id: str
|
matrix_bot_password: str
|
||||||
|
|
||||||
telegram_bot_token: str
|
telegram_bot_token: str
|
||||||
|
|
||||||
|
matrix_owner_id: str
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(config_class, dict):
|
def from_dict(config_class, dict):
|
||||||
return config_class(**dict)
|
return config_class(**dict)
|
||||||
|
|
|
@ -7,12 +7,12 @@ class MatrixLoop:
|
||||||
self.app = app
|
self.app = app
|
||||||
self.client = matrix.AsyncClient(
|
self.client = matrix.AsyncClient(
|
||||||
app.config.matrix_homeserver_url,
|
app.config.matrix_homeserver_url,
|
||||||
app.config.matrix_bot_id,
|
app.config.matrix_full_bot_id,
|
||||||
)
|
)
|
||||||
self.client.add_event_callback(self.on_message, matrix.RoomMessage)
|
self.client.add_event_callback(self.on_message, matrix.RoomMessage)
|
||||||
|
|
||||||
async def prepare(self):
|
async def prepare(self):
|
||||||
await self.client.login(self.app.config.matrix_password)
|
await self.client.login(self.app.config.matrix_bot_password)
|
||||||
|
|
||||||
async def finish(self):
|
async def finish(self):
|
||||||
await self.client.close()
|
await self.client.close()
|
||||||
|
|
Reference in a new issue