2021-12-06 15:32:27 +00:00
|
|
|
import os
|
2022-01-08 13:41:20 +00:00
|
|
|
import traceback
|
2021-12-06 15:32:27 +00:00
|
|
|
|
|
|
|
from config import Config
|
|
|
|
from core.elements import Plain, Image
|
|
|
|
|
|
|
|
from core.utils.bot import get_url
|
2022-01-19 17:02:23 +00:00
|
|
|
from modules.arcaea.errcode import errcode
|
2021-12-06 15:32:27 +00:00
|
|
|
|
|
|
|
assets_path = os.path.abspath('./assets/arcaea')
|
2022-01-19 17:02:23 +00:00
|
|
|
api_url = Config("botarcapi_url")
|
2021-12-06 15:32:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def get_info(usercode):
|
2022-01-19 17:02:23 +00:00
|
|
|
headers = {"User-Agent": Config('botarcapi_agent')}
|
2021-12-07 11:28:59 +00:00
|
|
|
try:
|
2022-01-19 17:02:23 +00:00
|
|
|
get_ = await get_url(api_url + f"user/info?usercode={usercode}&recent=1&withsonginfo=True", headers=headers, fmt='json')
|
2022-01-07 15:16:28 +00:00
|
|
|
except ValueError as e:
|
|
|
|
return [Plain('查询失败:' + str(e))]
|
2021-12-07 11:28:59 +00:00
|
|
|
except Exception:
|
2022-01-08 13:41:20 +00:00
|
|
|
traceback.print_exc()
|
2021-12-07 11:28:59 +00:00
|
|
|
return [Plain('查询失败。')]
|
2021-12-06 15:32:27 +00:00
|
|
|
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'
|
2022-01-19 17:02:23 +00:00
|
|
|
elif recent['difficulty'] == 1:
|
2021-12-06 15:32:27 +00:00
|
|
|
difficulty = 'PRS'
|
2022-01-19 17:02:23 +00:00
|
|
|
elif recent['difficulty'] == 2:
|
2021-12-06 15:32:27 +00:00
|
|
|
difficulty = 'FTR'
|
2022-01-19 17:02:23 +00:00
|
|
|
elif recent['difficulty'] == 3:
|
2021-12-06 15:32:27 +00:00
|
|
|
difficulty = 'BYD'
|
2022-01-19 17:02:23 +00:00
|
|
|
songsinfo = {}
|
|
|
|
for si in get_["content"]["songinfo"]:
|
|
|
|
songsinfo[si["id"]] = si
|
|
|
|
trackname = songsinfo[recent["song_id"]]['title_localized']['en']
|
2021-12-25 09:42:42 +00:00
|
|
|
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'
|
2022-01-19 17:02:23 +00:00
|
|
|
realptt = songsinfo[recent["song_id"]]['difficulties'][recent['difficulty']]['realrating']
|
2021-12-06 15:32:27 +00:00
|
|
|
ptt = recent['rating']
|
|
|
|
score = recent['score']
|
|
|
|
shiny_pure = recent['shiny_perfect_count']
|
|
|
|
pure = recent['perfect_count']
|
|
|
|
far = recent['near_count']
|
|
|
|
lost = recent['miss_count']
|
2022-01-19 17:02:23 +00:00
|
|
|
username = get_['content']['account_info']['name']
|
|
|
|
usrptt = int(get_['content']['account_info']['rating']) / 100
|
2021-12-25 10:05:05 +00:00
|
|
|
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}')]
|
2021-12-25 09:42:42 +00:00
|
|
|
if os.path.exists(imgpath):
|
|
|
|
result.append(Image(imgpath))
|
|
|
|
return result
|
2021-12-06 15:32:27 +00:00
|
|
|
else:
|
2022-01-19 17:02:23 +00:00
|
|
|
if get_['status'] in errcode:
|
2022-01-20 03:39:07 +00:00
|
|
|
return Plain(f'查询失败:{errcode[get_["status"]]}')
|
2022-01-19 17:02:23 +00:00
|
|
|
else:
|
2022-01-20 03:39:07 +00:00
|
|
|
return Plain('查询失败。' + get_)
|