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

90 lines
3.4 KiB
Python
Raw Normal View History

import asyncio
2021-12-06 15:32:27 +00:00
import os
2022-01-08 13:41:20 +00:00
import traceback
2022-06-12 07:07:53 +00:00
from datetime import datetime
2022-03-12 10:10:49 +00:00
2021-12-06 15:32:27 +00:00
from config import Config
2023-02-05 14:33:33 +00:00
from core.builtins import Plain, Image
2022-08-04 07:52:42 +00:00
from core.logger import Logger
2023-02-05 14:33:33 +00:00
from core.utils.http import get_url
2023-05-15 10:36:23 +00:00
from modules.arcaea.utils import autofix_b30_song_background
2021-12-06 15:32:27 +00:00
assets_path = os.path.abspath('./assets/arcaea')
api_url = Config("botarcapi_url")
2023-05-15 10:36:23 +00:00
headers = {"Authorization": f'Bearer {Config("botarcapi_token")}'}
2021-12-06 15:32:27 +00:00
2023-03-17 14:16:12 +00:00
async def get_info(msg, usercode):
2021-12-07 11:28:59 +00:00
try:
2023-05-15 10:36:23 +00:00
get_ = await get_url(api_url + f"user/info?user_code={usercode}&recent=1&with_song_info=True",
2022-08-01 15:33:35 +00:00
status_code=200,
headers=headers,
2022-01-20 12:13:03 +00:00
fmt='json')
2022-01-07 15:16:28 +00:00
except ValueError as e:
2023-03-17 13:13:28 +00:00
return [Plain(msg.locale.t('arcaea.message.failed.errcode') + str(e))]
2021-12-07 11:28:59 +00:00
except Exception:
2022-01-08 13:41:20 +00:00
traceback.print_exc()
2023-03-17 13:13:28 +00:00
return [Plain(msg.locale.t('arcaea.message.failed'))]
2022-08-04 07:52:42 +00:00
Logger.debug(get_)
2021-12-06 15:32:27 +00:00
if get_["status"] == 0:
recent = get_['content']["recent_score"]
if len(recent) < 0:
2023-05-19 04:46:29 +00:00
return [Plain(msg.locale.t('arcaea.message.info.result.none'))]
2021-12-06 15:32:27 +00:00
recent = recent[0]
difficulty = '???'
if recent['difficulty'] == 0:
difficulty = 'PST'
elif recent['difficulty'] == 1:
2021-12-06 15:32:27 +00:00
difficulty = 'PRS'
elif recent['difficulty'] == 2:
2021-12-06 15:32:27 +00:00
difficulty = 'FTR'
elif recent['difficulty'] == 3:
2021-12-06 15:32:27 +00:00
difficulty = 'BYD'
2023-05-15 10:36:23 +00:00
songinfo = get_['content']['song_info'][0]
2022-05-13 11:10:27 +00:00
trackname = songinfo['name_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-07-20 11:51:15 +00:00
realptt = songinfo['rating'] / 10
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']
username = get_['content']['account_info']['name']
2022-07-20 11:51:15 +00:00
usrptt = int(get_['content']['account_info']['rating'])
if usrptt == -1:
usrptt = '--'
else:
usrptt = usrptt / 100
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 = [
Plain(
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=usrptt,
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")))]
2021-12-25 09:42:42 +00:00
if os.path.exists(imgpath):
result.append(Image(imgpath))
else:
asyncio.create_task(autofix_b30_song_background(recent["song_id"],
byd=False if recent["difficulty"] != 3 else True))
2021-12-25 09:42:42 +00:00
return result
2023-04-30 03:30:59 +00:00
2021-12-06 15:32:27 +00:00
else:
2023-03-18 11:31:45 +00:00
errcode_string = f"arcaea.errcode.{get_['status']}"
if locale := msg.locale.t(errcode_string) != errcode_string:
return Plain(f'{msg.locale.t("arcaea.message.failed.errcode")}{locale}')
2023-03-17 13:13:28 +00:00
return Plain(msg.locale.t('arcaea.message.failed') + get_)