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/getb30.py

106 lines
5.3 KiB
Python
Raw Normal View History

2021-12-25 09:32:41 +00:00
import asyncio
import os
import uuid
import aiohttp
2021-09-10 18:05:27 +00:00
import ujson as json
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
from .drawb30img import drawb30
from .drawsongimg import dsimg
from .errcode import errcode
from .utils import autofix_b30_song_background
2021-05-30 06:06:41 +00:00
assets_path = os.path.abspath('./assets/arcaea')
async def getb30(usercode, official=False):
headers = {"User-Agent": Config('botarcapi_agent')}
d = 0
last5rank = 0
async with aiohttp.ClientSession() as session:
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]'}
a = await resp.text()
loadjson = json.loads(a)
if loadjson["status"] == 0:
b30 = round(loadjson["content"]["best30_avg"], 4)
r10 = round(loadjson["content"]["recent10_avg"], 4)
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 = []
songsinfo = {}
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]
d = d + 1
2021-12-25 09:32:41 +00:00
async def draw_jacket(x, d):
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']
tracknames[x['song_id'] + difficulty] = trackname + f' ({difficulty})'
imgpath = f'{assets_path}/b30background_img{"_official" if official else ""}/{x["song_id"]}_{str(x["difficulty"])}.jpg '
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']
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'
asyncio.create_task(autofix_b30_song_background(x['song_id'],
byd=False if x['difficulty'] != 3 else True))
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)
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)
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}
else:
if loadjson['status'] in errcode:
return {'text': f'查询失败:{errcode[loadjson["status"]]}'}
return {'text': '查询失败。' + a}