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/cytoid/profile.py

68 lines
2.2 KiB
Python
Raw Normal View History

import ujson as json
2021-02-11 12:41:07 +00:00
2022-06-28 06:11:03 +00:00
from core.elements import Plain, Image
from core.builtins.message import MessageSession
2021-08-07 07:56:48 +00:00
from core.utils import get_url
from .dbutils import CytoidBindInfoManager
2021-02-11 12:41:07 +00:00
2021-07-27 17:42:47 +00:00
async def cytoid_profile(msg: MessageSession):
pat = msg.parsed_msg['<UserID>']
if pat:
query_id = pat
else:
query_id = CytoidBindInfoManager(msg).get_bind_username()
if query_id is None:
return await msg.sendMessage('未绑定用户,请使用~cytoid bind <friendcode>绑定一个用户。')
profile_url = 'http://services.cytoid.io/profile/' + query_id
2021-02-11 12:41:07 +00:00
profile = json.loads(await get_url(profile_url))
2021-02-12 16:44:53 +00:00
if 'statusCode' in profile:
if profile['statusCode'] == 404:
2021-07-27 17:42:47 +00:00
await msg.sendMessage('发生错误:此用户不存在。')
2021-02-12 16:44:53 +00:00
return
2021-02-11 12:41:07 +00:00
uid = profile['user']['uid']
nick = profile['user']['name']
if nick is None:
nick = False
avatar = profile['user']['avatar']['large']
basicExp = profile['exp']['basicExp']
levelExp = profile['exp']['levelExp']
totalExp = profile['exp']['totalExp']
currentLevel = profile['exp']['currentLevel']
nextLevelExp = profile['exp']['nextLevelExp']
2021-02-11 12:42:19 +00:00
rating = profile['rating']
2022-01-19 04:13:39 +00:00
grade: dict = profile['grade']
gradet = ''
a = grade.get('A')
if a is not None:
gradet += f'A: {a},'
b = grade.get('B')
if b is not None:
gradet += f' B: {b},'
c = grade.get('C')
if c is not None:
gradet += f' C: {c},'
d = grade.get('D')
if d is not None:
gradet += f' D: {d},'
e = grade.get('E')
if e is not None:
gradet += f' E: {e},'
s = grade.get('S')
if s is not None:
gradet += f' S: {s},'
ss = grade.get('SS')
if ss is not None:
gradet += f' SS: {ss}'
2021-02-19 12:18:47 +00:00
text = f'UID: {uid}\n' + \
(f'Nickname: {nick}\n' if nick else '') + \
f'BasicExp: {basicExp}\n' + \
f'LevelExp: {levelExp}\n' + \
f'TotalExp: {totalExp}\n' + \
f'CurrentLevel: {currentLevel}\n' + \
f'NextLevelExp: {nextLevelExp}\n' + \
f'Rating: {rating}\n' + \
2022-01-19 04:13:39 +00:00
f'Grade: {gradet}'
msgchain = [Image(path=avatar), Plain(text)]
2022-05-21 16:04:29 +00:00
await msg.finish(msgchain)