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_official.py

88 lines
3.2 KiB
Python
Raw Normal View History

"""
This service utilizes API functionality provided by and with permission from lowiro. It is not affiliated with or endorsed by lowiro.
"""
2022-01-20 03:39:07 +00:00
import os
import traceback
2022-06-12 07:07:53 +00:00
from datetime import datetime
2022-01-20 03:39:07 +00:00
from config import Config
from core.elements import Plain
from core.logger import Logger
2022-06-12 07:07:53 +00:00
from core.utils import get_url
2022-01-20 03:39:07 +00:00
assets_path = os.path.abspath('./assets/arcaea')
apiurl = Config('arcapi_official_url')
headers = {'Authorization': Config('arcapi_official_token')}
headers_botarcapi = {"User-Agent": Config('botarcapi_agent')}
botarcapi_url = Config('botarcapi_url')
async def get_songinfo(songid):
try:
get_songinfo_from_botarcapi = await get_url(f'{botarcapi_url}song/info?songid={songid}',
headers=headers_botarcapi, status_code=200, fmt='json')
return get_songinfo_from_botarcapi['content']
except Exception:
traceback.print_exc()
return False
async def get_info_official(usercode):
try:
getuserinfo_json = await get_url(f'{apiurl}user/{usercode}', headers=headers, status_code=200, fmt='json')
except ValueError as e:
Logger.info(f'[{usercode}] {e}')
return {'success': False, 'msg': '查询失败。'}
except Exception:
traceback.print_exc()
return {'success': False, 'msg': '查询失败。'}
getuserinfo = getuserinfo_json['data']
username = getuserinfo['display_name']
2022-07-20 11:51:15 +00:00
potential = getuserinfo['potential']
if potential is not None:
potential = int(potential) / 100
else:
potential = '--'
2022-01-20 03:39:07 +00:00
recent = getuserinfo["last_played_song"]
if recent is None:
return [Plain('此用户无游玩记录。')]
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'
score = recent['score']
ptt = realptt = '???'
trackname = recent['song_id']
songinfo = await get_songinfo(recent['song_id'])
if songinfo:
2022-05-13 11:10:27 +00:00
s = songinfo['difficulties'][recent['difficulty']]
trackname = s['name_en']
realptt = s['rating'] / 10
2022-01-20 03:39:07 +00:00
ptt = realptt
if score >= 10000000:
ptt += 2
elif score >= 9800000:
ptt += 1 + (score - 9800000) / 200000
2023-01-26 15:40:57 +00:00
else:
2022-01-20 03:39:07 +00:00
ptt += (score - 9500000) / 300000
shiny_pure = recent['shiny_pure_count']
pure = recent['pure_count']
far = recent['far_count']
lost = recent['lost_count']
2022-03-12 10:10:49 +00:00
time_played = datetime.fromtimestamp(recent['time_played'] / 1000)
2022-01-20 03:39:07 +00:00
result = {'success': True, 'msg': f'{username} (Ptt: {potential})的最近游玩记录:\n'
f'{trackname} ({difficulty})\n'
f'Score: {score}\n'
f'Pure: {pure} ({shiny_pure})\n'
f'Far: {far}\n'
f'Lost: {lost}\n'
2022-03-12 10:10:49 +00:00
f'Potential: {realptt} -> {ptt}\n'
f'Time: {time_played.strftime("%Y-%m-%d %H:%M:%S")}(UTC+8)'}
2022-01-20 03:39:07 +00:00
return result