From faf174c226619af5a407fdcc6bf3877d0e14e39c Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Fri, 6 May 2022 02:46:52 -0400 Subject: [PATCH] Move "whoami" command to Account Management section --- matrix_appservice_kakaotalk/commands/conn.py | 47 ++++--------------- .../commands/kakaotalk.py | 28 +++++++++++ 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/matrix_appservice_kakaotalk/commands/conn.py b/matrix_appservice_kakaotalk/commands/conn.py index 257d807..47996c9 100644 --- a/matrix_appservice_kakaotalk/commands/conn.py +++ b/matrix_appservice_kakaotalk/commands/conn.py @@ -14,12 +14,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from mautrix.bridge.commands import HelpSection, command_handler -from mautrix.types import SerializerError from .typehint import CommandEvent -from ..kt.client.errors import CommandException - SECTION_CONNECTION = HelpSection("Connection management", 15, "") @@ -57,44 +54,20 @@ async def disconnect(evt: CommandEvent) -> None: @command_handler( - needs_auth=True, + needs_auth=False, management_only=True, help_section=SECTION_CONNECTION, - help_text="Check if you're logged into KakaoTalk and retrieve your account information", -) -async def whoami(evt: CommandEvent) -> None: - await evt.mark_read() - try: - own_info = await evt.sender.get_own_info() - except SerializerError: - evt.sender.log.exception("Failed to deserialize settings struct") - own_info = None - except CommandException as e: - await evt.reply(f"Error from KakaoTalk: {e}") - return - if own_info: - uuid = f"`{own_info.more.uuid}` ({'' if own_info.more.uuidSearchable else 'not '}searchable)" if own_info.more.uuid else "_none_" - await evt.reply( - f"You're logged in as **{own_info.more.nickName}** (KakaoTalk ID: {uuid}, internal ID: `{evt.sender.ktid}`)" - ) - else: - await evt.reply( - f"You're logged in, but the bridge is unable to retrieve your profile information (internal ID: {evt.sender.ktid})" - ) - - -@command_handler( - needs_auth=True, - management_only=True, - help_section=SECTION_CONNECTION, - help_text="Check if you're connected to KakaoTalk chats", + help_text="Check if you're logged in to KakaoTalk and connected to 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 is_connected else '**disconnected** from'} KakaoTalk chats." - ) + if not await evt.sender.is_logged_in(): + await evt.reply("You are **logged out** of KakaoTalk.") + else: + is_connected = evt.sender.is_connected and await evt.sender.client.is_connected() + await evt.reply( + "You are logged into KakaoTalk.\n\n" + f"You are {'connected to' if is_connected else '**disconnected** from'} KakaoTalk chats." + ) @command_handler( diff --git a/matrix_appservice_kakaotalk/commands/kakaotalk.py b/matrix_appservice_kakaotalk/commands/kakaotalk.py index 093f787..85c1443 100644 --- a/matrix_appservice_kakaotalk/commands/kakaotalk.py +++ b/matrix_appservice_kakaotalk/commands/kakaotalk.py @@ -19,6 +19,7 @@ from typing import TYPE_CHECKING, Awaitable import asyncio from mautrix.bridge.commands import HelpSection, command_handler +from mautrix.types import SerializerError from mautrix.util import utf16_surrogate from mautrix.util.formatter import ( EntityString, @@ -47,6 +48,33 @@ if TYPE_CHECKING: from ..kt.types.bson import Long +@command_handler( + needs_auth=True, + management_only=True, + help_section=SECTION_ACCOUNT, + help_text="Retrieve your KakaoTalk account information", +) +async def whoami(evt: CommandEvent) -> None: + await evt.mark_read() + try: + own_info = await evt.sender.get_own_info(force=True) + except SerializerError: + evt.sender.log.exception("Failed to deserialize settings struct") + own_info = None + except CommandException as e: + await evt.reply(f"Error from KakaoTalk: {e}") + return + if own_info: + uuid = f"`{own_info.more.uuid}` ({'searchable' if own_info.more.uuidSearchable else 'hidden'})" if own_info.more.uuid else "_none_" + await evt.reply( + f"You're logged in as **{own_info.more.nickName}** (KakaoTalk ID: {uuid}, internal ID: `{evt.sender.ktid}`)" + ) + else: + await evt.reply( + f"You're logged in, but the bridge is unable to retrieve your profile information (internal ID: {evt.sender.ktid})" + ) + + _CMD_CONFIRM_CHANGE_ID = "confirm-change-id" @command_handler(