2023-06-17 05:01:34 +00:00
|
|
|
import ujson as json
|
2023-06-17 04:39:47 +00:00
|
|
|
|
2023-06-17 05:01:34 +00:00
|
|
|
from core.builtins import ErrorMessage
|
|
|
|
from core.utils.http import get_url, post_url
|
2023-06-17 17:08:38 +00:00
|
|
|
from datetime import datetime
|
2023-06-16 15:15:47 +00:00
|
|
|
|
2023-06-17 05:01:34 +00:00
|
|
|
|
|
|
|
async def get_alias(input, get_music=False):
|
2023-06-16 15:15:47 +00:00
|
|
|
url = f"https://download.fanyu.site/maimai/alias.json"
|
|
|
|
data = await get_url(url, 200, fmt='json')
|
|
|
|
|
|
|
|
result = []
|
2023-06-17 04:39:47 +00:00
|
|
|
|
2023-06-16 15:15:47 +00:00
|
|
|
if get_music:
|
|
|
|
if input in data:
|
|
|
|
result = data[input]
|
|
|
|
else:
|
|
|
|
result = list(data.keys())
|
2023-06-17 04:39:47 +00:00
|
|
|
|
2023-06-16 15:15:47 +00:00
|
|
|
return result
|
|
|
|
|
2023-06-17 04:39:47 +00:00
|
|
|
|
2023-06-17 03:38:06 +00:00
|
|
|
async def get_rank(msg, payload):
|
2023-06-17 05:01:34 +00:00
|
|
|
try:
|
|
|
|
userdata = await post_url('https://www.diving-fish.com/api/maimaidxprober/query/player',
|
|
|
|
data=json.dumps(payload),
|
|
|
|
status_code=200,
|
|
|
|
headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json')
|
2023-06-17 04:44:54 +00:00
|
|
|
username = userdata['username']
|
|
|
|
rating = userdata['rating']
|
2023-06-17 05:01:34 +00:00
|
|
|
except ValueError as e:
|
|
|
|
if str(e).startswith('400'):
|
|
|
|
await msg.finish(msg.locale.t("maimai.message.user_not_found"))
|
|
|
|
if str(e).startswith('403'):
|
|
|
|
await msg.finish(msg.locale.t("maimai.message.forbidden"))
|
|
|
|
else:
|
2023-06-17 05:48:44 +00:00
|
|
|
await msg.finish(ErrorMessage(str(e)))
|
2023-06-17 03:38:06 +00:00
|
|
|
|
2023-06-17 17:08:38 +00:00
|
|
|
rank_data = await get_url('https://www.diving-fish.com/api/maimaidxprober/rating_ranking', 200, fmt='json')
|
|
|
|
sorted_data = sorted(rank_data, key=lambda x: x['ra'], reverse=True)
|
2023-06-16 15:15:47 +00:00
|
|
|
|
2023-06-17 05:01:34 +00:00
|
|
|
rank = None
|
|
|
|
total_rating = 0
|
2023-06-16 16:25:18 +00:00
|
|
|
|
2023-06-17 05:01:34 +00:00
|
|
|
for i, scoreboard in enumerate(sorted_data):
|
|
|
|
if scoreboard['username'] == username:
|
|
|
|
rank = i + 1
|
|
|
|
total_rating += scoreboard['ra']
|
2023-06-16 15:15:47 +00:00
|
|
|
|
2023-06-17 05:01:34 +00:00
|
|
|
if rank is None:
|
2023-06-17 05:48:44 +00:00
|
|
|
rank = len(sorted_data)
|
2023-06-16 15:34:58 +00:00
|
|
|
|
2023-06-17 17:08:38 +00:00
|
|
|
average_rating = total_rating / len(sorted_data)
|
2023-06-17 05:01:34 +00:00
|
|
|
surpassing_rate = (len(sorted_data) - rank) / len(sorted_data) * 100
|
2023-06-17 17:08:38 +00:00
|
|
|
time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
2023-06-16 15:15:47 +00:00
|
|
|
|
2023-06-17 17:08:38 +00:00
|
|
|
return username, rating, rank, average_rating, surpassing_rate, time
|