refactoring-by-def #1

Merged
def merged 10 commits from refactoring-by-def into master 2023-01-10 13:21:03 +00:00
5 changed files with 15 additions and 8 deletions
Showing only changes of commit 9c97b12c19 - Show all commits

View file

@ -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:...

View file

@ -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 }}"

View file

@ -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:

View file

@ -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)

View file

@ -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()