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/arcaea/info.py
2022-01-20 11:39:07 +08:00

68 lines
2.6 KiB
Python

import os
import traceback
from config import Config
from core.elements import Plain, Image
from core.utils.bot import get_url
from modules.arcaea.errcode import errcode
assets_path = os.path.abspath('./assets/arcaea')
api_url = Config("botarcapi_url")
async def get_info(usercode):
headers = {"User-Agent": Config('botarcapi_agent')}
try:
get_ = await get_url(api_url + f"user/info?usercode={usercode}&recent=1&withsonginfo=True", headers=headers, fmt='json')
except ValueError as e:
return [Plain('查询失败:' + str(e))]
except Exception:
traceback.print_exc()
return [Plain('查询失败。')]
print(get_)
if get_["status"] == 0:
recent = get_['content']["recent_score"]
if len(recent) < 0:
return [Plain('此用户无游玩记录。')]
recent = recent[0]
difficulty = '???'
if recent['difficulty'] == 0:
difficulty = 'PST'
elif recent['difficulty'] == 1:
difficulty = 'PRS'
elif recent['difficulty'] == 2:
difficulty = 'FTR'
elif recent['difficulty'] == 3:
difficulty = 'BYD'
songsinfo = {}
for si in get_["content"]["songinfo"]:
songsinfo[si["id"]] = si
trackname = songsinfo[recent["song_id"]]['title_localized']['en']
imgpath = f'{assets_path}/jacket/{recent["song_id"]}_{recent["difficulty"]}.jpg'
if not os.path.exists(imgpath):
imgpath = f'{assets_path}/jacket/{recent["song_id"]}.jpg'
realptt = songsinfo[recent["song_id"]]['difficulties'][recent['difficulty']]['realrating']
ptt = recent['rating']
score = recent['score']
shiny_pure = recent['shiny_perfect_count']
pure = recent['perfect_count']
far = recent['near_count']
lost = recent['miss_count']
username = get_['content']['account_info']['name']
usrptt = int(get_['content']['account_info']['rating']) / 100
result = [Plain(f'{username} (Ptt: {usrptt})的最近游玩记录:\n'
f'{trackname} ({difficulty})\n'
f'Score: {score}\n'
f'Pure: {pure} ({shiny_pure})\n'
f'Far: {far}\n'
f'Lost: {lost}\n'
f'Potential: {realptt} -> {ptt}')]
if os.path.exists(imgpath):
result.append(Image(imgpath))
return result
else:
if get_['status'] in errcode:
return Plain(f'查询失败:{errcode[get_["status"]]}')
else:
return Plain('查询失败。' + get_)