Post startup messages in notice room

This commit is contained in:
Andrew Ferrazzutti 2021-05-05 02:42:41 -04:00
parent 27c66887c3
commit 2117685df7
3 changed files with 12 additions and 3 deletions

View File

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

View File

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

View File

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