2021-12-25 09:32:41 +00:00
|
|
|
|
import asyncio
|
2021-04-28 11:01:25 +00:00
|
|
|
|
import os
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
import aiohttp
|
2021-09-10 18:05:27 +00:00
|
|
|
|
import ujson as json
|
2021-04-28 11:01:25 +00:00
|
|
|
|
|
2021-08-07 07:56:48 +00:00
|
|
|
|
from config import Config
|
2022-08-04 07:52:42 +00:00
|
|
|
|
from core.logger import Logger
|
2021-04-28 11:01:25 +00:00
|
|
|
|
from .drawb30img import drawb30
|
|
|
|
|
from .drawsongimg import dsimg
|
2022-12-25 06:25:23 +00:00
|
|
|
|
from .utils import autofix_b30_song_background, errcode
|
2021-04-28 11:01:25 +00:00
|
|
|
|
|
2021-05-30 06:06:41 +00:00
|
|
|
|
assets_path = os.path.abspath('./assets/arcaea')
|
|
|
|
|
|
|
|
|
|
|
2022-01-19 17:02:23 +00:00
|
|
|
|
async def getb30(usercode, official=False):
|
|
|
|
|
headers = {"User-Agent": Config('botarcapi_agent')}
|
2021-04-28 11:01:25 +00:00
|
|
|
|
d = 0
|
|
|
|
|
last5rank = 0
|
|
|
|
|
async with aiohttp.ClientSession() as session:
|
2022-01-19 17:02:23 +00:00
|
|
|
|
url = Config("botarcapi_url")
|
|
|
|
|
async with session.get(url + f"user/best30?usercode={usercode}&withsonginfo=True", headers=headers) as resp:
|
2022-01-07 15:16:28 +00:00
|
|
|
|
if resp.status != 200:
|
2022-01-07 15:17:22 +00:00
|
|
|
|
return {'text': f'获取失败:{str(resp.status)}[Ke:Image,path=https://http.cat/{str(resp.status)}.jpg]'}
|
2021-04-28 11:01:25 +00:00
|
|
|
|
a = await resp.text()
|
|
|
|
|
loadjson = json.loads(a)
|
|
|
|
|
if loadjson["status"] == 0:
|
2022-01-19 17:02:23 +00:00
|
|
|
|
b30 = round(loadjson["content"]["best30_avg"], 4)
|
|
|
|
|
r10 = round(loadjson["content"]["recent10_avg"], 4)
|
2021-04-28 11:01:25 +00:00
|
|
|
|
newdir = f'./cache/{str(uuid.uuid4())}'
|
|
|
|
|
newdir = os.path.abspath(newdir)
|
|
|
|
|
os.makedirs(newdir)
|
|
|
|
|
tracknames = {}
|
|
|
|
|
realptts = {}
|
|
|
|
|
ptts = {}
|
|
|
|
|
scores = {}
|
|
|
|
|
last5list = ''
|
2021-12-25 09:32:41 +00:00
|
|
|
|
run_lst = []
|
2022-01-19 17:02:23 +00:00
|
|
|
|
songsinfo = {}
|
2021-04-28 11:01:25 +00:00
|
|
|
|
for x in loadjson["content"]["best30_list"]:
|
2022-05-13 11:10:27 +00:00
|
|
|
|
songsinfo[x['song_id'] + str(x['difficulty'])] = loadjson["content"]["best30_songinfo"][d]
|
2021-04-28 11:01:25 +00:00
|
|
|
|
d = d + 1
|
2021-12-25 09:32:41 +00:00
|
|
|
|
|
|
|
|
|
async def draw_jacket(x, d):
|
2022-01-19 17:02:23 +00:00
|
|
|
|
difficulty = '???'
|
|
|
|
|
if x['difficulty'] == 0:
|
|
|
|
|
difficulty = 'PST'
|
|
|
|
|
elif x['difficulty'] == 1:
|
|
|
|
|
difficulty = 'PRS'
|
|
|
|
|
elif x['difficulty'] == 2:
|
|
|
|
|
difficulty = 'FTR'
|
|
|
|
|
elif x['difficulty'] == 3:
|
|
|
|
|
difficulty = 'BYD'
|
2022-05-13 11:10:27 +00:00
|
|
|
|
trackname = songsinfo[x['song_id'] + str(x['difficulty'])]['name_en']
|
2022-01-19 17:02:23 +00:00
|
|
|
|
tracknames[x['song_id'] + difficulty] = trackname + f' ({difficulty})'
|
2022-11-19 09:25:58 +00:00
|
|
|
|
imgpath = f'{assets_path}/b30background_img{"_official" if official else ""}/{x["song_id"]}_{str(x["difficulty"])}.jpg '
|
2022-01-19 17:02:23 +00:00
|
|
|
|
if not os.path.exists(imgpath):
|
|
|
|
|
imgpath = f'{assets_path}/b30background_img{"_official" if official else ""}/{x["song_id"]}.jpg'
|
2022-05-13 11:10:27 +00:00
|
|
|
|
realptt = songsinfo[x['song_id'] + str(x['difficulty'])]['rating']
|
2022-01-19 17:02:23 +00:00
|
|
|
|
realptts[x['song_id'] + difficulty] = realptt
|
|
|
|
|
ptt = x['rating']
|
|
|
|
|
ptts[x['song_id'] + difficulty] = ptt
|
|
|
|
|
score = x['score']
|
|
|
|
|
scores[x['song_id'] + difficulty] = score
|
|
|
|
|
if not os.path.exists(imgpath):
|
|
|
|
|
imgpath = f'{assets_path}/b30background_img{"_official" if official else ""}/random.jpg'
|
2022-11-19 09:25:58 +00:00
|
|
|
|
asyncio.create_task(autofix_b30_song_background(x['song_id'],
|
2023-01-28 05:53:11 +00:00
|
|
|
|
byd=False if x[
|
|
|
|
|
'difficulty'] != 3 else True))
|
2022-01-19 17:02:23 +00:00
|
|
|
|
dsimg(os.path.abspath(imgpath), d, trackname, x['difficulty'], score, ptt, realptt,
|
|
|
|
|
x['perfect_count'], x['near_count'], x['miss_count'], x['time_played'], newdir)
|
2022-01-20 12:13:03 +00:00
|
|
|
|
|
2021-12-25 09:32:41 +00:00
|
|
|
|
run_lst.append(draw_jacket(x, d))
|
|
|
|
|
await asyncio.gather(*run_lst)
|
2022-08-04 07:52:42 +00:00
|
|
|
|
Logger.debug(tracknames)
|
2021-04-28 11:01:25 +00:00
|
|
|
|
for last5 in loadjson["content"]["best30_list"][-5:]:
|
|
|
|
|
last5rank += 1
|
|
|
|
|
if last5['difficulty'] == 0:
|
|
|
|
|
difficulty = 'PST'
|
|
|
|
|
if last5['difficulty'] == 1:
|
|
|
|
|
difficulty = 'PRS'
|
|
|
|
|
if last5['difficulty'] == 2:
|
|
|
|
|
difficulty = 'FTR'
|
|
|
|
|
if last5['difficulty'] == 3:
|
|
|
|
|
difficulty = 'BYD'
|
|
|
|
|
trackname = tracknames[last5['song_id'] + difficulty]
|
|
|
|
|
realptt = realptts[last5['song_id'] + difficulty]
|
|
|
|
|
ptt = ptts[last5['song_id'] + difficulty]
|
|
|
|
|
score = scores[last5['song_id'] + difficulty]
|
2022-01-20 04:42:37 +00:00
|
|
|
|
last5list += f'[{last5rank}] {trackname}\n[{last5rank}] {score} / {realptt / 10} -> {round(ptt, 4)}\n'
|
2022-08-04 07:52:42 +00:00
|
|
|
|
Logger.debug(last5list)
|
2022-01-19 17:02:23 +00:00
|
|
|
|
username = loadjson["content"]['account_info']['name']
|
|
|
|
|
ptt = int(loadjson["content"]['account_info']['rating']) / 100
|
|
|
|
|
character = loadjson["content"]['account_info']['character']
|
|
|
|
|
filename = drawb30(username, b30, r10, ptt, character, newdir, official=official)
|
|
|
|
|
filelist = os.listdir(newdir)
|
|
|
|
|
for x in filelist:
|
|
|
|
|
os.remove(f'{newdir}/{x}')
|
|
|
|
|
os.removedirs(newdir)
|
|
|
|
|
return {'text': f'获取结果\nB30: {b30} | R10: {r10}\nB30倒5列表:\n{last5list}', 'file': filename}
|
2021-04-28 11:01:25 +00:00
|
|
|
|
else:
|
2022-01-19 17:02:23 +00:00
|
|
|
|
if loadjson['status'] in errcode:
|
|
|
|
|
return {'text': f'查询失败:{errcode[loadjson["status"]]}'}
|
2021-04-28 11:01:25 +00:00
|
|
|
|
return {'text': '查询失败。' + a}
|