Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/mcplayer/__init__.py
2022-06-28 14:11:03 +08:00

36 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from core.component import on_command
from core.builtins.message import MessageSession
from core.elements import Plain, Image, Url
from .mojang_api import *
mcplayer = on_command(
bind_prefix='mcplayer',
desc='从 Mojang API 获取 Minecraft Java 版玩家信息',
developers=['Dianliang233'],
)
@mcplayer.handle('<username_or_uuid> {通过玩家名或玩家 UUID 获取玩家信息。}')
async def main(msg: MessageSession):
try:
arg = msg.parsed_msg['<username_or_uuid>']
if len(arg) == 32:
name = await uuid_to_name(arg)
uuid = arg
elif len(arg) == 36 and arg.count('-') == 4:
uuid = arg.replace('-', '')
name = await uuid_to_name(arg)
else:
name = arg
uuid = await name_to_uuid(arg)
sac = await uuid_to_skin_and_cape(uuid)
skin = sac['skin']
cape = sac['cape']
namemc = 'https://namemc.com/profile/' + name
chain = [Plain(f'{name}{uuid}\nNameMC{Url(namemc)}'), Image(skin)]
if cape:
chain.append(Image(cape))
except ValueError:
chain = [Plain(f'未找到 {arg} 的信息。')]
await msg.finish(chain)