2021-08-29 16:53:43 +00:00
|
|
|
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
|
2022-01-19 17:02:23 +00:00
|
|
|
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)
|
2022-01-19 17:02:23 +00:00
|
|
|
if pat:
|
2023-05-21 09:44:07 +00:00
|
|
|
query_id = pat.lower()
|
2022-01-19 17:02:23 +00:00
|
|
|
else:
|
|
|
|
query_id = CytoidBindInfoManager(msg).get_bind_username()
|
|
|
|
if query_id is None:
|
2023-07-26 08:20:12 +00:00
|
|
|
await msg.finish(msg.locale.t('cytoid.message.user.unbound', prefix=msg.prefixes[0]))
|
2022-01-19 17:02:23 +00:00
|
|
|
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-07-26 08:18:01 +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']
|
|
|
|
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']
|
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}')
|
2023-01-26 01:15:09 +00:00
|
|
|
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 '') + \
|
|
|
|
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-10-28 04:09:10 +00:00
|
|
|
f'Grade: {", ".join(grade_t)}'
|
2021-08-29 16:53:43 +00:00
|
|
|
msgchain = [Image(path=avatar), Plain(text)]
|
2022-05-21 16:04:29 +00:00
|
|
|
await msg.finish(msgchain)
|