2023-06-17 03:38:06 +00:00
|
|
|
from core.builtins import ErrorMessage
|
|
|
|
from core.utils.http import get_url, post_url
|
2023-06-16 15:15:47 +00:00
|
|
|
|
|
|
|
async def get_alias(input, get_music = False):
|
|
|
|
url = f"https://download.fanyu.site/maimai/alias.json"
|
|
|
|
data = await get_url(url, 200, fmt='json')
|
|
|
|
|
|
|
|
result = []
|
|
|
|
|
|
|
|
if get_music:
|
|
|
|
if input in data:
|
|
|
|
result = data[input]
|
|
|
|
else:
|
|
|
|
result = list(data.keys())
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2023-06-17 03:38:06 +00:00
|
|
|
async def get_rank(msg, payload):
|
|
|
|
try:
|
2023-06-17 04:14:40 +00:00
|
|
|
userdata = await post_url('https://www.diving-fish.com/api/maimaidxprober/query/player', payload, 200,
|
2023-06-17 04:15:55 +00:00
|
|
|
headers={'Content-Type': 'application/json'}, fmt='json')
|
2023-06-17 03:38:06 +00:00
|
|
|
username = userdata['username']
|
|
|
|
rating = userdata['rating']
|
|
|
|
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:
|
|
|
|
await msg.sendMessage(ErrorMessage(str(e)))
|
|
|
|
|
|
|
|
data = await get_url('https://www.diving-fish.com/api/maimaidxprober/rating_ranking', 200, fmt='json')
|
|
|
|
sorted_data = sorted(data, key=lambda x: x['ra'], reverse=True)
|
2023-06-16 15:15:47 +00:00
|
|
|
|
|
|
|
rank = None
|
2023-06-17 03:38:06 +00:00
|
|
|
total_rating = 0
|
2023-06-16 16:25:18 +00:00
|
|
|
|
|
|
|
for i, scoreboard in enumerate(sorted_data):
|
2023-06-17 03:38:06 +00:00
|
|
|
if scoreboard['username'] == username:
|
2023-06-16 15:15:47 +00:00
|
|
|
rank = i + 1
|
2023-06-17 03:38:06 +00:00
|
|
|
total_rating += scoreboard['ra']
|
2023-06-16 15:15:47 +00:00
|
|
|
|
2023-06-17 03:38:06 +00:00
|
|
|
average_rating = total_rating / len(sorted_data)
|
2023-06-16 15:15:47 +00:00
|
|
|
|
2023-06-16 15:34:58 +00:00
|
|
|
if rank is None:
|
|
|
|
rank = 0
|
|
|
|
|
2023-06-16 16:25:18 +00:00
|
|
|
surpassing_rate = (len(sorted_data) - rank) / len(sorted_data) * 100
|
2023-06-16 15:15:47 +00:00
|
|
|
|
2023-06-17 04:14:40 +00:00
|
|
|
return username, rating, rank, average_rating, surpassing_rate
|