From 2143282195e2eef81568eda5c29862d72798c5d9 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Thu, 28 Apr 2022 01:42:50 -0400 Subject: [PATCH] Actually check connection during ping command --- matrix_appservice_kakaotalk/commands/conn.py | 4 +++- matrix_appservice_kakaotalk/kt/client/client.py | 3 +++ node/src/client.js | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/matrix_appservice_kakaotalk/commands/conn.py b/matrix_appservice_kakaotalk/commands/conn.py index 2799c19..42eb58b 100644 --- a/matrix_appservice_kakaotalk/commands/conn.py +++ b/matrix_appservice_kakaotalk/commands/conn.py @@ -79,8 +79,10 @@ async def whoami(evt: CommandEvent) -> None: help_text="Check if you're connected to KakaoTalk chats", ) async def ping(evt: CommandEvent) -> None: + assert evt.sender.client + is_connected = evt.sender.is_connected and await evt.sender.client.is_connected() await evt.reply( - f"You are {'connected to' if evt.sender.is_connected else '**disconnected** from'} KakaoTalk chats." + f"You are {'connected to' if is_connected else '**disconnected** from'} KakaoTalk chats." ) diff --git a/matrix_appservice_kakaotalk/kt/client/client.py b/matrix_appservice_kakaotalk/kt/client/client.py index 78faa79..e0b4ff1 100644 --- a/matrix_appservice_kakaotalk/kt/client/client.py +++ b/matrix_appservice_kakaotalk/kt/client/client.py @@ -261,6 +261,9 @@ class Client: await self._rpc_client.request("disconnect", mxid=self.user.mxid) await self._on_disconnect(None) + def is_connected(self) -> Awaitable[bool]: + return self._rpc_client.request("is_connected", mxid=self.user.mxid) + def get_settings(self) -> Awaitable[SettingsStruct]: return self._api_user_request_result(SettingsStruct, "get_settings") diff --git a/node/src/client.js b/node/src/client.js index 75ca181..7e1b6e0 100644 --- a/node/src/client.js +++ b/node/src/client.js @@ -389,6 +389,10 @@ class UserClient { } } + isConnected() { + return this.#talkClient?.logon || false + } + /** * Send a user-specific command with (optional) data to the socket. * @@ -644,6 +648,14 @@ export default class PeerClient { this.#tryGetUser(req.mxid)?.disconnect() } + /** + * @param {Object} req + * @param {string} req.mxid + */ + isConnected = (req) => { + return this.#tryGetUser(req.mxid)?.isConnected() + } + /** * @param {Object} req * @param {string} req.mxid @@ -1054,6 +1066,7 @@ export default class PeerClient { stop: this.userStop, connect: this.handleConnect, disconnect: this.handleDisconnect, + is_connected: this.isConnected, get_settings: this.getSettings, get_own_profile: this.getOwnProfile, get_profile: this.getProfile,