Move "whoami" command to Account Management section
This commit is contained in:
parent
dfdd98da96
commit
faf174c226
@ -14,12 +14,9 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
from mautrix.bridge.commands import HelpSection, command_handler
|
from mautrix.bridge.commands import HelpSection, command_handler
|
||||||
from mautrix.types import SerializerError
|
|
||||||
|
|
||||||
from .typehint import CommandEvent
|
from .typehint import CommandEvent
|
||||||
|
|
||||||
from ..kt.client.errors import CommandException
|
|
||||||
|
|
||||||
SECTION_CONNECTION = HelpSection("Connection management", 15, "")
|
SECTION_CONNECTION = HelpSection("Connection management", 15, "")
|
||||||
|
|
||||||
|
|
||||||
@ -57,44 +54,20 @@ async def disconnect(evt: CommandEvent) -> None:
|
|||||||
|
|
||||||
|
|
||||||
@command_handler(
|
@command_handler(
|
||||||
needs_auth=True,
|
needs_auth=False,
|
||||||
management_only=True,
|
management_only=True,
|
||||||
help_section=SECTION_CONNECTION,
|
help_section=SECTION_CONNECTION,
|
||||||
help_text="Check if you're logged into KakaoTalk and retrieve your account information",
|
help_text="Check if you're logged in to KakaoTalk and connected to chats",
|
||||||
)
|
|
||||||
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",
|
|
||||||
)
|
)
|
||||||
async def ping(evt: CommandEvent) -> None:
|
async def ping(evt: CommandEvent) -> None:
|
||||||
assert evt.sender.client
|
if not await evt.sender.is_logged_in():
|
||||||
is_connected = evt.sender.is_connected and await evt.sender.client.is_connected()
|
await evt.reply("You are **logged out** of KakaoTalk.")
|
||||||
await evt.reply(
|
else:
|
||||||
f"You are {'connected to' if is_connected else '**disconnected** from'} KakaoTalk chats."
|
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(
|
@command_handler(
|
||||||
|
@ -19,6 +19,7 @@ from typing import TYPE_CHECKING, Awaitable
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from mautrix.bridge.commands import HelpSection, command_handler
|
from mautrix.bridge.commands import HelpSection, command_handler
|
||||||
|
from mautrix.types import SerializerError
|
||||||
from mautrix.util import utf16_surrogate
|
from mautrix.util import utf16_surrogate
|
||||||
from mautrix.util.formatter import (
|
from mautrix.util.formatter import (
|
||||||
EntityString,
|
EntityString,
|
||||||
@ -47,6 +48,33 @@ if TYPE_CHECKING:
|
|||||||
from ..kt.types.bson import Long
|
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"
|
_CMD_CONFIRM_CHANGE_ID = "confirm-change-id"
|
||||||
|
|
||||||
@command_handler(
|
@command_handler(
|
||||||
|
Loading…
Reference in New Issue
Block a user