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
2023-03-18 01:42:23 +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.builtins import Bot
from core.builtins import Plain, Image, Url
from core.component import module
from .mojang_api import *
mcplayer = module(
bind_prefix='mcplayer',
desc='{mcplayer.help}',
developers=['Dianliang233'],
)
@mcplayer.handle('<username_or_uuid> {{mcplayer.help.player}}')
async def main(msg: Bot.MessageSession):
arg = msg.parsed_msg['<username_or_uuid>']
try:
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)
render = sac['render']
skin = sac['skin']
cape = sac['cape']
namemc = 'https://namemc.com/profile/' + name
chain = [Plain(f'{name}{uuid}\nNameMC{Url(namemc)}'), Image(render), Image(skin)]
if cape:
chain.append(Image(cape))
except ValueError:
chain = [Plain(msg.locale.t('mcplayer.message.not_found', player=arg))]
await msg.finish(chain)