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

78 lines
2.5 KiB
Python
Raw Normal View History

import ujson as json
2021-02-11 12:41:07 +00:00
2023-02-05 14:33:33 +00:00
from core.builtins import Bot
from core.builtins import Plain, Image
from core.utils.http import get_url
from .dbutils import CytoidBindInfoManager
2021-02-11 12:41:07 +00:00
2023-02-05 14:33:33 +00:00
async def cytoid_profile(msg: Bot.MessageSession):
2023-05-21 09:44:07 +00:00
pat = msg.parsed_msg.get('<UserID>', False)
if pat:
2023-05-21 09:44:07 +00:00
query_id = pat.lower()
else:
query_id = CytoidBindInfoManager(msg).get_bind_username()
if query_id is None:
2023-08-19 19:11:08 +00:00
await msg.finish(msg.locale.t('cytoid.message.user_unbound', prefix=msg.prefixes[0]))
profile_url = 'http://services.cytoid.io/profile/' + query_id
2022-08-18 18:10:42 +00:00
try:
profile = json.loads(await get_url(profile_url, status_code=200))
except ValueError as e:
if str(e).startswith('404'):
2023-08-19 19:11:08 +00:00
await msg.finish(msg.locale.t('cytoid.message.user_not_found'))
2022-08-18 18:10:42 +00:00
raise e
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']
2023-09-03 11:49:14 +00:00
basic_exp = profile['exp']['basicExp']
level_exp = profile['exp']['levelExp']
total_exp = profile['exp']['totalExp']
current_level = profile['exp']['currentLevel']
next_level_exp = 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']
2022-10-28 04:09:10 +00:00
grade_t = []
2022-10-27 22:00:47 +00:00
max = grade.get('MAX')
if max is not None:
2022-10-28 04:09:10 +00:00
grade_t.append(f'MAX: {max}')
2022-10-27 22:00:47 +00:00
sss = grade.get('SSS')
if sss is not None:
2022-10-28 04:09:10 +00:00
grade_t.append(f'SSS: {sss}')
2022-10-27 22:00:47 +00:00
ss = grade.get('SS')
if ss is not None:
2022-10-28 04:09:10 +00:00
grade_t.append(f'SS: {ss}')
2022-10-27 22:00:47 +00:00
s = grade.get('S')
if s is not None:
2022-10-28 04:09:10 +00:00
grade_t.append(f'S: {s}')
aa = grade.get('AA')
if aa is not None:
grade_t.append(f'AA: {aa}')
2022-01-19 04:13:39 +00:00
a = grade.get('A')
if a is not None:
2022-10-28 04:09:10 +00:00
grade_t.append(f'A: {a}')
2022-01-19 04:13:39 +00:00
b = grade.get('B')
if b is not None:
2022-10-28 04:09:10 +00:00
grade_t.append(f'B: {b}')
2022-01-19 04:13:39 +00:00
c = grade.get('C')
if c is not None:
2022-10-28 04:09:10 +00:00
grade_t.append(f'C: {c}')
2022-01-19 04:13:39 +00:00
d = grade.get('D')
if d is not None:
2022-10-28 04:09:10 +00:00
grade_t.append(f'D: {d}')
2022-10-27 22:00:47 +00:00
f = grade.get('F')
if f is not None:
2022-10-28 04:09:10 +00:00
grade_t.append(f'F: {f}')
2021-02-19 12:18:47 +00:00
text = f'UID: {uid}\n' + \
(f'Nickname: {nick}\n' if nick else '') + \
2023-09-03 11:49:14 +00:00
f'BasicExp: {basic_exp}\n' + \
f'LevelExp: {level_exp}\n' + \
f'TotalExp: {total_exp}\n' + \
f'CurrentLevel: {current_level}\n' + \
f'NextLevelExp: {next_level_exp}\n' + \
2021-02-19 12:18:47 +00:00
f'Rating: {rating}\n' + \
2022-10-28 04:09:10 +00:00
f'Grade: {", ".join(grade_t)}'
2023-09-01 14:38:32 +00:00
message_chain = [Image(path=avatar), Plain(text)]
await msg.finish(message_chain)