Refactor exit-offline code

This commit is contained in:
miruka
2020-07-16 23:34:35 -04:00
parent f316a24550
commit 4784c80ed9
3 changed files with 22 additions and 17 deletions

View File

@@ -305,6 +305,17 @@ class MatrixClient(nio.AsyncClient):
await self.close()
async def terminate(self) -> None:
"""Stop tasks, Set our presence offline and close HTTP connections."""
await self._stop()
if self._presence != "offline":
await self.set_presence("offline", save=False)
await self.close()
log.info("%s termined", self.user_id)
@property
def syncing(self) -> bool:
"""Return whether this client is currently syncing with the server."""