133 lines
5.4 KiB
Python
Raw Normal View History

2022-03-13 21:25:42 +08:00
from hoshino import aiorequests
from .util import get_headers, cache, get_use_cookie, get_own_cookie, check_retcode
from .db_util import update_cookie_cache
2022-03-13 21:25:42 +08:00
import datetime
2022-03-15 10:34:19 +08:00
import re
import random
2022-03-13 21:25:42 +08:00
# TODO注意每处参数顺序的更改
@cache(ttl=datetime.timedelta(hours=1))
async def get_abyss_data(user_id, uid, schedule_type = "1", use_cache=True):
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
2022-03-13 21:25:42 +08:00
url ="https://api-takumi.mihoyo.com/game_record/app/genshin/api/spiralAbyss"
params ={
"schedule_type": schedule_type,
"role_id": uid,
"server": server_id}
while True:
cookie = await get_use_cookie(user_id, uid=uid, action='查询深渊')
if not cookie:
return '现在派蒙没有可以用的cookie哦,请让主人 添加公共ck 吧!'
headers = get_headers(q=f'role_id={uid}&schedule_type={schedule_type}&server={server_id}', cookie=cookie['cookie'])
res = await aiorequests.get(url=url, headers=headers, params=params)
data = await res.json()
if await check_retcode(data, cookie, uid):
return data
2022-03-13 21:25:42 +08:00
async def get_daily_note_data(uid):
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
2022-03-13 21:25:42 +08:00
url ="https://api-takumi.mihoyo.com/game_record/app/genshin/api/dailyNote"
cookie = await get_own_cookie(uid, action='查询实时便签')
if not cookie:
return f'你的uid{uid}没有绑定对应的cookie哦,先用ysb给派蒙绑定吧!'
await update_cookie_cache(cookie['cookie'], uid, 'uid')
headers = get_headers(q=f'role_id={uid}&server={server_id}', cookie=cookie['cookie'])
2022-03-13 21:25:42 +08:00
params = {
"server": server_id,
"role_id": uid
}
res = await aiorequests.get(url=url, headers=headers, params=params)
return await res.json()
@cache(ttl=datetime.timedelta(hours=1))
async def get_player_card_data(user_id, uid, use_cache=True):
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
2022-03-13 21:25:42 +08:00
url ="https://api-takumi.mihoyo.com/game_record/app/genshin/api/index"
params = {
"server": server_id,
"role_id": uid
}
while True:
cookie = await get_use_cookie(user_id, uid=uid, action='查询原神卡片')
if not cookie:
return '现在派蒙没有可以用的cookie哦,请让主人 添加公共ck 吧!'
headers = get_headers(q=f'role_id={uid}&server={server_id}', cookie=cookie['cookie'])
res = await aiorequests.get(url=url, headers=headers, params=params)
data = await res.json()
if await check_retcode(data, cookie, uid):
return data
2022-03-13 21:25:42 +08:00
@cache(ttl=datetime.timedelta(hours=1))
async def get_chara_detail_data(user_id, uid, use_cache=True):
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
2022-03-13 21:25:42 +08:00
json_data = {
"server": server_id,
"role_id": uid,
"character_ids": []
}
url = 'https://api-takumi.mihoyo.com/game_record/app/genshin/api/character'
while True:
cookie = await get_use_cookie(user_id, uid=uid, action='查询角色详情')
if not cookie:
return '现在派蒙没有可以用的cookie哦,请让主人 添加公共ck 吧!'
headers = get_headers(b=json_data, cookie=cookie['cookie'])
res = await aiorequests.post(url=url, headers=headers, json=json_data)
data = await res.json()
if await check_retcode(data, cookie, uid):
return data
2022-03-13 21:25:42 +08:00
@cache(ttl=datetime.timedelta(hours=1))
async def get_chara_skill_data(uid, chara_id, use_cache=True):
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
2022-03-13 21:25:42 +08:00
url = 'https://api-takumi.mihoyo.com/event/e20200928calculate/v1/sync/avatar/detail'
cookie = await get_own_cookie(uid, action='查询角色天赋')
if not cookie:
return None
await update_cookie_cache(cookie['cookie'], uid, 'uid')
headers = get_headers(q=f'uid={uid}&region={server_id}&avatar_id={chara_id}', cookie=cookie['cookie'])
2022-03-13 21:25:42 +08:00
params = {
"region": server_id,
"uid": uid,
"avatar_id": chara_id
}
res = await aiorequests.get(url=url, headers=headers, params=params)
data = await res.json()
# TODO:待定未知cookie对技能的影响
return data
2022-03-13 21:25:42 +08:00
@cache(ttl=datetime.timedelta(hours=1))
async def get_monthinfo_data(uid, month, use_cache=True):
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
2022-03-13 21:25:42 +08:00
url = 'https://hk4e-api.mihoyo.com/event/ys_ledger/monthInfo'
cookie = await get_own_cookie(uid, action='查询每月札记')
if not cookie:
return f'你的uid{uid}没有绑定对应的cookie哦,先用ysb给派蒙绑定吧!'
await update_cookie_cache(cookie['cookie'], uid, 'uid')
headers = get_headers(q=f'month={month}&bind_uid={uid}&bind_region={server_id}', cookie=cookie['cookie'])
2022-03-13 21:25:42 +08:00
params = {
"month": int(month),
"bind_uid": uid,
"bind_region": server_id
}
res = await aiorequests.get(url=url, headers=headers, params=params)
data = await res.json()
if await check_retcode(data, cookie, uid):
return data
2022-03-15 10:34:19 +08:00
async def get_bind_game(cookie):
2022-03-21 08:40:13 +08:00
finduid = re.search(r'account_id=(\d{6,12})', cookie)
2022-03-15 10:34:19 +08:00
if not finduid:
return None
uid = finduid.group(1)
url = 'https://api-takumi.mihoyo.com/game_record/card/wapi/getGameRecordCard'
headers = get_headers(q=f'uid={uid}', cookie = cookie)
2022-03-15 10:34:19 +08:00
params = {
"uid": uid
}
res = await aiorequests.get(url=url, headers=headers, params=params)
return (await res.json()), uid
2022-03-15 10:34:19 +08:00