From 2117685df797d4fae97fb0f5eacdbaeab261564f Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Wed, 5 May 2021 02:42:41 -0400 Subject: [PATCH] Post startup messages in notice room --- matrix_puppeteer_line/commands/auth.py | 3 +-- matrix_puppeteer_line/commands/conn.py | 1 - matrix_puppeteer_line/user.py | 11 +++++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/matrix_puppeteer_line/commands/auth.py b/matrix_puppeteer_line/commands/auth.py index 58cb6db..6cf44a9 100644 --- a/matrix_puppeteer_line/commands/auth.py +++ b/matrix_puppeteer_line/commands/auth.py @@ -91,9 +91,8 @@ async def login_do(evt: CommandEvent, gen: AsyncGenerator[Tuple[str, str], None] # else: pass if not failure and evt.sender.command_status: - await evt.reply("Successfully logged in, now syncing") + await evt.reply("Successfully logged in") await evt.sender.sync() - await evt.reply("Syncing complete") # else command was cancelled or failed. Don't post message about it, "cancel" command or failure did already evt.sender.command_status = None diff --git a/matrix_puppeteer_line/commands/conn.py b/matrix_puppeteer_line/commands/conn.py index b4cd980..21cf4c1 100644 --- a/matrix_puppeteer_line/commands/conn.py +++ b/matrix_puppeteer_line/commands/conn.py @@ -44,4 +44,3 @@ async def ping(evt: CommandEvent) -> None: help_text="Synchronize portals") async def sync(evt: CommandEvent) -> None: await evt.sender.sync() - await evt.reply("Synchronization complete") diff --git a/matrix_puppeteer_line/user.py b/matrix_puppeteer_line/user.py index 7c2ced1..b2c9923 100644 --- a/matrix_puppeteer_line/user.py +++ b/matrix_puppeteer_line/user.py @@ -64,6 +64,10 @@ class User(DBUser, BaseUser): cls.loop = bridge.loop Client.config = bridge.config + async def send_notice(self, text) -> None: + if self.notice_room: + await self.az.intent.send_notice(self.notice_room, text) + async def is_logged_in(self) -> bool: try: return self.client and (await self.client.start()).is_logged_in @@ -92,13 +96,17 @@ class User(DBUser, BaseUser): self.loop.create_task(self.connect_double_puppet()) self.client = Client(self.mxid) self.log.debug("Starting client") + await self.send_notice("Starting up...") state = await self.client.start() await self.client.on_message(self.handle_message) await self.client.on_receipt(self.handle_receipt) if state.is_connected: self._track_metric(METRIC_CONNECTED, True) if state.is_logged_in: + await self.send_notice("Already logged in to LINE") self.loop.create_task(self._try_sync()) + else: + await self.send_notice("Ready to log in to LINE") async def _try_sync(self) -> None: try: @@ -117,6 +125,7 @@ class User(DBUser, BaseUser): self._connection_check_task = self.loop.create_task(self._check_connection_loop()) await self.client.set_last_message_ids(await DBMessage.get_max_mids()) self.log.info("Syncing chats") + await self.send_notice("Synchronizing chats...") await self.client.pause() chats = await self.client.get_chats() limit = self.config["bridge.initial_conversation_sync"] @@ -129,8 +138,10 @@ class User(DBUser, BaseUser): else: await portal.create_matrix_room(self, chat) await self.client.resume() + await self.send_notice("Synchronization complete") async def stop(self) -> None: + # TODO Notices for shutdown messages if self._connection_check_task: self._connection_check_task.cancel() self._connection_check_task = None