Actually check connection during ping command

This commit is contained in:
Andrew Ferrazzutti 2022-04-28 01:42:50 -04:00
parent ee8b0a2fca
commit 2143282195
3 changed files with 19 additions and 1 deletions

View File

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

View File

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

View File

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