From d9c3b0f01b7dd48c40fd78a94dc77bded4b5e7aa Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Tue, 29 Mar 2022 02:50:51 -0400 Subject: [PATCH] Auto-login after auto-logout Instead of only on bridge startup --- matrix_puppeteer_line/user.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/matrix_puppeteer_line/user.py b/matrix_puppeteer_line/user.py index e7efa15..bf610dd 100644 --- a/matrix_puppeteer_line/user.py +++ b/matrix_puppeteer_line/user.py @@ -230,13 +230,21 @@ class User(DBUser, BaseUser): await portal.handle_remote_receipt(receipt) async def handle_logged_out(self, message: str) -> None: - newline = "\n" - await self.send_bridge_notice( - f"Logged out of LINE{'.' if not message else ' with message: ' + message.replace(newline, ' ') + newline} " - "Please run either \"login-qr\" or \"login-email\" to log back in.") if self._connection_check_task: self._connection_check_task.cancel() self._connection_check_task = None + newline = "\n" + # TODO Use an asyncio.Task for auto-login + # TODO Don't auto-login if logout was intentional! + if await auto_login(self): + await self.send_bridge_notice( + f"Auto-logged back in to LINE{'' if not message else ' (logout reason: ' + message.replace(newline, ' ') + ')'}" + ) + else: + await self.send_bridge_notice( + f"Logged out of LINE{'.' if not message else ' with message: ' + message.replace(newline, ' ') + newline} " + "Please run either \"login-qr\" or \"login-email\" to log back in." + ) def _add_to_cache(self) -> None: self.by_mxid[self.mxid] = self