2023-01-07 20:11:46 +00:00
|
|
|
import asyncio
|
|
|
|
|
2023-01-14 17:27:41 +00:00
|
|
|
from messengers import Matrix as MatrixLoop, Telegram as TelegramLoop
|
2023-01-10 00:48:55 +00:00
|
|
|
|
|
|
|
from config_dataclass import Config
|
2023-01-09 20:57:05 +00:00
|
|
|
|
2023-01-10 00:48:55 +00:00
|
|
|
CONFIG_FILE_NAME = "config.yaml"
|
2023-01-08 22:13:27 +00:00
|
|
|
|
|
|
|
|
2023-01-08 19:28:13 +00:00
|
|
|
def main():
|
2023-01-10 00:48:55 +00:00
|
|
|
config = Config.from_yaml_config(CONFIG_FILE_NAME)
|
2023-01-08 19:31:11 +00:00
|
|
|
|
|
|
|
asyncio.run(Application(config).run())
|
|
|
|
|
2023-01-09 20:57:05 +00:00
|
|
|
|
2023-01-08 19:28:13 +00:00
|
|
|
class Application:
|
2023-01-08 19:31:11 +00:00
|
|
|
def __init__(self, config):
|
|
|
|
self.config = config
|
2023-01-08 21:18:45 +00:00
|
|
|
self.matrix_loop = MatrixLoop(self)
|
2023-01-14 17:27:41 +00:00
|
|
|
self.telegram_loop = TelegramLoop(self)
|
2023-01-08 19:28:13 +00:00
|
|
|
|
|
|
|
async def run(self):
|
|
|
|
try:
|
|
|
|
await self.matrix_loop.prepare()
|
|
|
|
await asyncio.gather(
|
|
|
|
self.matrix_loop.run(),
|
2023-01-14 17:27:41 +00:00
|
|
|
self.telegram_loop.run(),
|
2023-01-08 19:28:13 +00:00
|
|
|
)
|
|
|
|
finally:
|
|
|
|
if self.matrix_loop:
|
|
|
|
await self.matrix_loop.finish()
|
2023-01-08 18:43:37 +00:00
|
|
|
|
2023-01-08 13:54:22 +00:00
|
|
|
|
2023-01-09 20:57:05 +00:00
|
|
|
if __name__ == "__main__":
|
2023-01-08 19:28:13 +00:00
|
|
|
main()
|