Move "whoami" command to Account Management section

This commit is contained in:
Andrew Ferrazzutti 2022-05-06 02:46:52 -04:00
parent dfdd98da96
commit faf174c226
2 changed files with 38 additions and 37 deletions

View File

@ -14,12 +14,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
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,42 +54,18 @@ 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
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."
)

View File

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