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

57 lines
1.9 KiB
Python
Raw Normal View History

import ujson as json
2023-06-17 04:39:47 +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):
2023-06-18 04:11:30 +00:00
url = "https://download.fanyu.site/maimai/alias.json"
2023-06-16 15:15:47 +00:00
data = await get_url(url, 200, fmt='json')
result = []
if get_music:
if input in data:
result = data[input]
else:
2023-06-19 16:37:14 +00:00
for alias, ids in data.items():
if input in ids:
result.append(alias)
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-19 16:37:14 +00:00
async def get_record(msg, payload):
url = f"https://www.diving-fish.com/api/maimaidxprober/query/player"
try:
2023-06-19 16:37:14 +00:00
data = await post_url(url,
data=json.dumps(payload),
status_code=200,
headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json')
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-19 16:37:14 +00:00
return data
2023-06-16 15:15:47 +00:00
2023-06-19 16:37:14 +00:00
async def get_plate(msg, payload):
url = f"https://www.diving-fish.com/api/maimaidxprober/query/plate"
try:
data = await post_url(url,
data=json.dumps(payload),
status_code=200,
headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json')
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.finish(ErrorMessage(str(e)))
2023-06-16 15:15:47 +00:00
2023-06-19 16:37:14 +00:00
return data