2022-11-19 09:25:58 +00:00
|
|
|
"""
|
|
|
|
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
|
2023-02-05 14:33:33 +00:00
|
|
|
from core.builtins import Plain
|
2022-01-20 03:39:07 +00:00
|
|
|
from core.logger import Logger
|
2023-02-05 14:33:33 +00:00
|
|
|
from core.utils.http 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
|
|
|
|
|
|
|
|
|
2023-03-17 14:16:12 +00:00
|
|
|
async def get_info_official(msg, usercode):
|
2022-01-20 03:39:07 +00:00
|
|
|
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}')
|
2023-03-17 13:17:43 +00:00
|
|
|
return {'success': False, 'msg': msg.finish(msg.locale.t('arcaea.message.failed'))}
|
2022-01-20 03:39:07 +00:00
|
|
|
except Exception:
|
|
|
|
traceback.print_exc()
|
2023-03-17 13:17:43 +00:00
|
|
|
return {'success': False, 'msg': msg.finish(msg.locale.t('arcaea.message.failed'))}
|
2022-01-20 03:39:07 +00:00
|
|
|
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:
|
2023-05-19 04:46:29 +00:00
|
|
|
return [Plain(msg.finish(msg.locale.t('arcaea.message.info.result.none')))]
|
2022-01-20 03:39:07 +00:00
|
|
|
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)
|
2023-04-30 03:30:59 +00:00
|
|
|
result = {
|
|
|
|
'success': True,
|
|
|
|
'msg': msg.locale.t(
|
2023-05-19 04:46:29 +00:00
|
|
|
'arcaea.message.info.result',
|
2023-04-30 03:30:59 +00:00
|
|
|
username=username,
|
|
|
|
potential=potential,
|
|
|
|
trackname=trackname,
|
|
|
|
difficulty=difficulty,
|
|
|
|
score=score,
|
|
|
|
pure=pure,
|
|
|
|
shiny_pure=shiny_pure,
|
|
|
|
far=far,
|
|
|
|
lost=lost,
|
|
|
|
realptt=realptt,
|
|
|
|
ptt=ptt,
|
|
|
|
time_played=time_played.strftime("%Y-%m-%d %H:%M:%S"))}
|
2022-01-20 03:39:07 +00:00
|
|
|
return result
|