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/maimai/libraries/maimaidx_project.py

216 lines
8 KiB
Python
Raw Normal View History

2023-06-19 16:37:14 +00:00
from datetime import datetime
from core.utils.http import get_url
from .maimaidx_api_data import get_record, get_plate
2023-06-21 13:48:55 +00:00
from .maimaidx_music import *
2023-06-19 16:37:14 +00:00
2023-06-20 11:20:34 +00:00
total_list = TotalList()
2023-06-19 16:37:14 +00:00
2023-06-21 13:40:37 +00:00
achievementList = [50.0, 60.0, 70.0, 75.0, 80.0, 90.0, 94.0, 97.0, 98.0, 99.0, 99.5, 100.0, 100.5]
2023-06-19 16:37:14 +00:00
plate_to_version = {
'': 'maimai',
'': 'maimai PLUS',
'': 'maimai GreeN',
'': 'maimai GreeN PLUS',
'': 'maimai ORANGE',
'': 'maimai ORANGE PLUS',
'': 'maimai ORANGE PLUS',
'': 'maimai PiNK',
'': 'maimai PiNK PLUS',
'': 'maimai PiNK PLUS',
'': 'maimai MURASAKi',
'': 'maimai MURASAKi PLUS',
'': 'maimai MURASAKi PLUS',
'': 'maimai MiLK',
'': 'MiLK PLUS',
'': 'maimai FiNALE',
'': 'maimai FiNALE',
'': 'maimai でらっくす',
'': 'maimai でらっくす PLUS',
'': 'maimai でらっくす PLUS',
'': 'maimai でらっくす Splash',
'': 'maimai でらっくす Splash PLUS',
'': 'maimai でらっくす UNiVERSE',
'': 'maimai でらっくす UNiVERSE PLUS',
'': 'maimai でらっくす FESTiVAL',
'fesp': 'maimai でらっくす FESTiVAL PLUS'
}
2023-06-20 11:20:34 +00:00
score_to_rank = {
(0.0, 50.0): "D",
(50.0, 60.0): "C",
(60.0, 70.0): "B",
(70.0, 75.0): "BB",
(75.0, 80.0): "BBB",
(80.0, 90.0): "A",
(90.0, 94.0): "AA",
(94.0, 97.0): "AAA",
(97.0, 98.0): "S",
(98.0, 99.0): "S+",
(99.0, 99.5): "SS",
(99.5, 100.0): "SS+",
(100.0, 100.5): "SSS",
(100.5, float('inf')): "SSS+",
}
combo_conversion = {
"fc": "FC",
"fcp": "FC+",
"ap": "AP",
"app": "AP+",
}
sync_conversion = {
"fs": "FS",
"fsp": "FS+",
"fsd": "FDX",
"fsdp": "FDX+",
}
2023-06-21 13:40:37 +00:00
diffs = {
2023-06-20 11:20:34 +00:00
0: "Basic",
1: "Advanced",
2: "Expert",
3: "Master",
4: "Re:MASTER",
}
2023-06-21 13:40:37 +00:00
scoreRank = ['d', 'c', 'b', 'bb', 'bbb', 'a', 'aa', 'aaa', 's', 's+', 'ss', 'ss+', 'sss', 'sss+']
levelList = ['1', '2', '3', '4', '5', '6', '7', '7+', '8', '8+', '9', '9+', '10', '10+', '11', '11+', '12', '12+', '13', '13+', '14', '14+', '15']
2023-06-19 16:37:14 +00:00
async def get_rank(msg, payload):
player_data = await get_record(msg, payload)
username = player_data['username']
rating = player_data['rating']
url = f"https://www.diving-fish.com/api/maimaidxprober/rating_ranking"
rank_data = await get_url(url, 200, fmt='json')
sorted_data = sorted(rank_data, key=lambda x: x['ra'], reverse=True)
rank = None
total_rating = 0
total_rank = len(sorted_data)
for i, scoreboard in enumerate(sorted_data):
if scoreboard['username'] == username:
rank = i + 1
total_rating += scoreboard['ra']
if rank is None:
rank = total_rank
average_rating = total_rating / total_rank
surpassing_rate = (total_rank - rank) / total_rank * 100
time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
2023-06-20 11:20:34 +00:00
return time, total_rank, average_rating, username, rating, rank, surpassing_rate
async def get_player_score(msg, payload, input_id):
payload['version'] = list(set(version for version in plate_to_version.values()))
2023-06-20 12:06:48 +00:00
res = await get_plate(msg, payload)
verlist = res["verlist"]
music = (await total_list.get()).by_id(input_id)
level_scores = {level: [] for level in range(len(music['level']))}
2023-06-20 11:20:34 +00:00
for entry in verlist:
sid = entry["id"]
achievements = entry["achievements"]
fc = entry["fc"]
fs = entry["fs"]
level_index = entry["level_index"]
2023-06-20 16:15:37 +00:00
if str(sid) == input_id:
2023-06-20 11:20:34 +00:00
score_rank = next(
rank for interval, rank in score_to_rank.items() if interval[0] <= achievements < interval[1]
)
combo_rank = combo_conversion.get(fc, "")
sync_rank = sync_conversion.get(fs, "")
2023-06-21 13:40:37 +00:00
level_scores[level_index].append((diffs[level_index], achievements, score_rank, combo_rank, sync_rank))
2023-06-20 11:20:34 +00:00
output_lines = []
for level, scores in level_scores.items():
if scores:
2023-06-21 13:40:37 +00:00
output_lines.append(f"{diffs[level]} {music['level'][level]}")
2023-06-20 11:20:34 +00:00
for score in scores:
level, achievements, score_rank, combo_rank, sync_rank = score
entry_output = f"{achievements} {score_rank}"
if combo_rank and sync_rank:
entry_output += f" {combo_rank} {sync_rank}"
elif combo_rank or sync_rank:
entry_output += f" {sync_rank}{sync_rank}"
2023-06-20 11:20:34 +00:00
output_lines.append(entry_output)
else:
2023-06-21 13:40:37 +00:00
output_lines.append(f"{diffs[level]} {music['level'][level]}\n{msg.locale.t('maimai.message.info.no_record')}")
2023-06-20 11:20:34 +00:00
return '\n'.join(output_lines)
2023-06-21 13:40:37 +00:00
2023-06-21 13:42:25 +00:00
async def get_level_process(msg, payload, process, goal):
2023-06-21 13:40:37 +00:00
song_played = []
song_remain = []
2023-06-21 13:48:55 +00:00
2023-06-21 13:44:24 +00:00
payload['version'] = list(set(version for version in plate_to_version.values()))
2023-06-21 13:40:37 +00:00
res = await get_plate(msg, payload)
verlist = res["verlist"]
if goal.lower() in score_to_rank.values():
achievement = achievementList[list(score_to_rank.values()).index(goal.lower()) - 1]
for song in verlist:
if song['level'] == process and song['achievements'] < achievement:
song_remain.append([song['id'], song['level_index']])
song_played.append([song['id'], song['level_index']])
elif goal.lower() in combo_conversion.values():
combo_index = list(combo_conversion.values()).index(goal.lower())
for song in verlist:
if song['level'] == process and ((song['fc'] and list(combo_conversion.keys()).index(song['fc']) < combo_index) or not song['fc']):
song_remain.append([song['id'], song['level_index']])
song_played.append([song['id'], song['level_index']])
elif goal.lower() in sync_conversion.values():
sync_index = list(sync_conversion.values()).index(goal.lower())
for song in verlist:
if song['level'] == process and ((song['fs'] and list(sync_conversion.keys()).index(song['fs']) < sync_index) or not song['fs']):
song_remain.append([song['id'], song['level_index']])
song_played.append([song['id'], song['level_index']])
for music in (await total_list):
for i, lv in enumerate(music.level[2:]):
if lv == process and [int(music.id), i + 2] not in song_played:
song_remain.append([int(music.id), i + 2])
song_remain = sorted(song_remain, key=lambda i: int(i[1]))
song_remain = sorted(song_remain, key=lambda i: int(i[0]))
songs = []
for song in song_remain:
music = (await total_list.get()).by_id(str(song[0]))
songs.append([music.id, music.title, diffs[song[1]], music.ds[song[1]], song[1]])
msg = ''
if len(song_remain) > 0:
if len(song_remain) < 50:
song_record = [[s['id'], s['level_index']] for s in verlist]
msg += f'{process}全谱面{goal.upper()}剩余曲目如下:\n'
for i, s in enumerate(sorted(songs, key=lambda i: i[3])):
self_record = ''
if [int(s[0]), s[-1]] in song_record:
record_index = song_record.index([int(s[0]), s[-1]])
if goal.lower() in score_to_rank.values():
self_record = str(verlist[record_index]['achievements']) + '%'
elif goal.lower() in combo_conversion.values():
if verlist[record_index]['fc']:
self_record = list(combo_conversion.values())[list(combo_conversion.keys()).index(verlist[record_index]['fc'])].upper()
elif goal.lower() in sync_conversion.values():
if verlist[record_index]['fs']:
self_record = list(sync_conversion.values())[list(sync_conversion.keys()).index(verlist[record_index]['fs'])].upper()
msg += f'No.{i + 1} {s[0]}. {s[1]} {s[2]} {s[3]} {self_record}'.strip() + '\n'
else:
msg = f'还有{len(song_remain)}{process}曲目没有达成{goal.upper()},加油推分捏!'
else:
msg = f'恭喜达成{process}全谱面{goal.upper()}'
return msg