2022-04-30 14:13:39 +08:00
|
|
|
|
import datetime
|
|
|
|
|
import re
|
|
|
|
|
|
2022-07-03 21:26:33 +08:00
|
|
|
|
from littlepaimon_utils import aiorequests
|
2022-08-12 11:55:49 +08:00
|
|
|
|
from nonebot import logger
|
2022-07-03 21:26:33 +08:00
|
|
|
|
|
|
|
|
|
from ..utils.auth_util import get_headers, get_sign_headers, get_use_cookie, get_own_cookie, check_retcode
|
2022-07-19 00:23:49 +08:00
|
|
|
|
from ..utils.db_util import get_private_cookie, update_cookie_cache, update_private_cookie
|
2022-07-03 21:26:33 +08:00
|
|
|
|
from ..utils.decorator import cache
|
|
|
|
|
|
2022-07-19 18:10:38 +08:00
|
|
|
|
|
2022-04-30 14:13:39 +08:00
|
|
|
|
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-05-18 16:01:49 +08:00
|
|
|
|
url = "https://api-takumi-record.mihoyo.com/game_record/app/genshin/api/spiralAbyss"
|
2022-04-30 14:13:39 +08:00
|
|
|
|
params = {
|
|
|
|
|
"schedule_type": schedule_type,
|
2022-05-19 18:15:56 +08:00
|
|
|
|
"role_id": uid,
|
|
|
|
|
"server": server_id}
|
2022-04-30 14:13:39 +08:00
|
|
|
|
while True:
|
|
|
|
|
cookie = await get_use_cookie(user_id, uid=uid, action='查询深渊')
|
|
|
|
|
if not cookie:
|
|
|
|
|
return '现在派蒙没有可以用的cookie哦,可能是:\n1.公共cookie全都达到了每日30次上限\n2.公共池全都失效了或没有cookie\n让管理员使用 添加公共ck 吧!'
|
|
|
|
|
headers = get_headers(q=f'role_id={uid}&schedule_type={schedule_type}&server={server_id}',
|
|
|
|
|
cookie=cookie['cookie'])
|
2022-05-19 18:15:56 +08:00
|
|
|
|
|
|
|
|
|
resp = await aiorequests.get(url=url, headers=headers, params=params)
|
|
|
|
|
data = resp.json()
|
|
|
|
|
check = await check_retcode(data, cookie, uid)
|
|
|
|
|
if check == '私人cookie达到了每日30次查询上限':
|
|
|
|
|
return check
|
|
|
|
|
elif check:
|
|
|
|
|
return data
|
2022-04-30 14:13:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_daily_note_data(uid):
|
|
|
|
|
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
|
2022-05-18 16:01:49 +08:00
|
|
|
|
url = "https://api-takumi-record.mihoyo.com/game_record/app/genshin/api/dailyNote"
|
2022-04-30 14:13:39 +08:00
|
|
|
|
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'])
|
|
|
|
|
params = {
|
2022-05-19 18:15:56 +08:00
|
|
|
|
"server": server_id,
|
2022-04-30 14:13:39 +08:00
|
|
|
|
"role_id": uid
|
|
|
|
|
}
|
2022-05-19 18:15:56 +08:00
|
|
|
|
resp = await aiorequests.get(url=url, headers=headers, params=params)
|
|
|
|
|
data = resp.json()
|
|
|
|
|
if await check_retcode(data, cookie, uid):
|
|
|
|
|
return data
|
|
|
|
|
else:
|
|
|
|
|
return f'你的uid{uid}的cookie已过期,需要重新绑定哦!'
|
2022-04-30 14:13:39 +08:00
|
|
|
|
|
|
|
|
|
|
2022-05-21 18:51:47 +08:00
|
|
|
|
@cache(ttl=datetime.timedelta(hours=1))
|
2022-04-30 14:13:39 +08:00
|
|
|
|
async def get_player_card_data(user_id, uid, use_cache=True):
|
|
|
|
|
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
|
2022-05-18 16:01:49 +08:00
|
|
|
|
url = "https://api-takumi-record.mihoyo.com/game_record/app/genshin/api/index"
|
2022-04-30 14:13:39 +08:00
|
|
|
|
params = {
|
2022-05-19 18:15:56 +08:00
|
|
|
|
"server": server_id,
|
2022-04-30 14:13:39 +08:00
|
|
|
|
"role_id": uid
|
|
|
|
|
}
|
|
|
|
|
while True:
|
|
|
|
|
cookie = await get_use_cookie(user_id, uid=uid, action='查询原神卡片')
|
|
|
|
|
if not cookie:
|
|
|
|
|
return '现在派蒙没有可以用的cookie哦,可能是:\n1.公共cookie全都达到了每日30次上限\n2.公共池全都失效了或没有cookie\n让管理员使用 添加公共ck 吧!'
|
|
|
|
|
headers = get_headers(q=f'role_id={uid}&server={server_id}', cookie=cookie['cookie'])
|
2022-05-19 18:15:56 +08:00
|
|
|
|
resp = await aiorequests.get(url=url, headers=headers, params=params)
|
|
|
|
|
data = resp.json()
|
|
|
|
|
check = await check_retcode(data, cookie, uid)
|
|
|
|
|
if check == '私人cookie达到了每日30次查询上限':
|
|
|
|
|
return check
|
|
|
|
|
elif check:
|
|
|
|
|
return data
|
2022-04-30 14:13:39 +08:00
|
|
|
|
|
|
|
|
|
|
2022-05-21 18:51:47 +08:00
|
|
|
|
@cache(ttl=datetime.timedelta(hours=1))
|
2022-04-30 14:13:39 +08:00
|
|
|
|
async def get_chara_detail_data(user_id, uid, use_cache=True):
|
|
|
|
|
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
|
|
|
|
|
json_data = {
|
2022-05-19 18:15:56 +08:00
|
|
|
|
"server": server_id,
|
|
|
|
|
"role_id": uid,
|
2022-04-30 14:13:39 +08:00
|
|
|
|
"character_ids": []
|
|
|
|
|
}
|
2022-05-18 16:01:49 +08:00
|
|
|
|
url = 'https://api-takumi-record.mihoyo.com/game_record/app/genshin/api/character'
|
2022-04-30 14:13:39 +08:00
|
|
|
|
while True:
|
|
|
|
|
cookie = await get_use_cookie(user_id, uid=uid, action='查询角色详情')
|
|
|
|
|
if not cookie:
|
|
|
|
|
return '现在派蒙没有可以用的cookie哦,可能是:\n1.公共cookie全都达到了每日30次上限\n2.公共池全都失效了或没有cookie\n让管理员使用 添加公共ck 吧!'
|
|
|
|
|
headers = get_headers(b=json_data, cookie=cookie['cookie'])
|
2022-05-19 18:15:56 +08:00
|
|
|
|
resp = await aiorequests.post(url=url, headers=headers, json=json_data)
|
|
|
|
|
data = resp.json()
|
|
|
|
|
check = await check_retcode(data, cookie, uid)
|
|
|
|
|
if check == '私人cookie达到了每日30次查询上限':
|
|
|
|
|
return check
|
|
|
|
|
elif check:
|
|
|
|
|
return data
|
2022-04-30 14:13:39 +08:00
|
|
|
|
|
|
|
|
|
|
2022-05-21 18:51:47 +08:00
|
|
|
|
@cache(ttl=datetime.timedelta(hours=1))
|
2022-04-30 14:13:39 +08:00
|
|
|
|
async def get_chara_skill_data(uid, chara_id, use_cache=True):
|
|
|
|
|
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
|
2022-05-18 16:42:56 +08:00
|
|
|
|
url = 'https://api-takumi.mihoyo.com/event/e20200928calculate/v1/sync/avatar/detail'
|
2022-04-30 14:13:39 +08:00
|
|
|
|
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}®ion={server_id}&avatar_id={chara_id}', cookie=cookie['cookie'])
|
|
|
|
|
params = {
|
2022-05-19 18:15:56 +08:00
|
|
|
|
"region": server_id,
|
|
|
|
|
"uid": uid,
|
2022-04-30 14:13:39 +08:00
|
|
|
|
"avatar_id": chara_id
|
|
|
|
|
}
|
2022-05-19 18:15:56 +08:00
|
|
|
|
resp = await aiorequests.get(url=url, headers=headers, params=params)
|
|
|
|
|
data = resp.json()
|
|
|
|
|
return data
|
2022-04-30 14:13:39 +08:00
|
|
|
|
|
|
|
|
|
|
2022-05-21 18:51:47 +08:00
|
|
|
|
@cache(ttl=datetime.timedelta(hours=1))
|
2022-04-30 14:13:39 +08:00
|
|
|
|
async def get_monthinfo_data(uid, month, use_cache=True):
|
|
|
|
|
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
|
2022-05-18 16:42:56 +08:00
|
|
|
|
url = 'https://hk4e-api.mihoyo.com/event/ys_ledger/monthInfo'
|
2022-04-30 14:13:39 +08:00
|
|
|
|
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'])
|
|
|
|
|
params = {
|
2022-05-19 18:15:56 +08:00
|
|
|
|
"month": int(month),
|
|
|
|
|
"bind_uid": uid,
|
2022-04-30 14:13:39 +08:00
|
|
|
|
"bind_region": server_id
|
|
|
|
|
}
|
2022-05-19 18:15:56 +08:00
|
|
|
|
resp = await aiorequests.get(url=url, headers=headers, params=params)
|
|
|
|
|
data = resp.json()
|
|
|
|
|
if await check_retcode(data, cookie, uid):
|
|
|
|
|
return data
|
|
|
|
|
else:
|
|
|
|
|
return f'你的uid{uid}的cookie已过期,需要重新绑定哦!'
|
2022-04-30 14:13:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_bind_game(cookie):
|
|
|
|
|
finduid = re.search(r'account_id=(\d{6,12})', cookie)
|
|
|
|
|
if not finduid:
|
|
|
|
|
finduid = re.search(r'ltuid=(\d{6,12})', cookie)
|
|
|
|
|
if not finduid:
|
|
|
|
|
return None, None
|
|
|
|
|
uid = finduid.group(1)
|
2022-05-18 16:01:49 +08:00
|
|
|
|
url = 'https://api-takumi-record.mihoyo.com/game_record/card/wapi/getGameRecordCard'
|
2022-04-30 14:13:39 +08:00
|
|
|
|
headers = get_headers(q=f'uid={uid}', cookie=cookie)
|
|
|
|
|
params = {
|
|
|
|
|
"uid": uid
|
|
|
|
|
}
|
2022-05-19 18:15:56 +08:00
|
|
|
|
resp = await aiorequests.get(url=url, headers=headers, params=params)
|
|
|
|
|
data = resp.json()
|
|
|
|
|
return data, uid
|
2022-04-30 14:13:39 +08:00
|
|
|
|
|
2022-07-19 18:10:38 +08:00
|
|
|
|
|
|
|
|
|
# 添加stoken
|
|
|
|
|
async def addStoken(stoken, uid):
|
|
|
|
|
login_ticket = re.search(r'login_ticket=([0-9a-zA-Z]+)', stoken)
|
|
|
|
|
if login_ticket:
|
|
|
|
|
login_ticket = login_ticket.group(0).split('=')[1]
|
|
|
|
|
else:
|
|
|
|
|
return None, None, None, '你的cookie中没有login_ticket字段哦,请重新获取'
|
|
|
|
|
ck = await get_private_cookie(uid, key='uid')
|
2022-07-19 00:23:49 +08:00
|
|
|
|
if not ck:
|
2022-07-19 18:10:38 +08:00
|
|
|
|
return None, None, None, '你还没绑定私人cookie哦,请先用ysb绑定吧'
|
2022-07-19 00:23:49 +08:00
|
|
|
|
ck = ck[0][1]
|
2022-07-19 18:30:00 +08:00
|
|
|
|
mys_id = re.search(r'account_id=(\d*)', ck)
|
|
|
|
|
if mys_id:
|
|
|
|
|
mys_id = mys_id.group(0).split('=')[1]
|
|
|
|
|
else:
|
|
|
|
|
return None, None, None, '你的cookie中没有account_id字段哦,请重新获取'
|
2022-07-19 00:23:49 +08:00
|
|
|
|
raw_data = await get_stoken_by_login_ticket(login_ticket, mys_id)
|
2022-07-19 18:10:38 +08:00
|
|
|
|
try:
|
|
|
|
|
stoken = raw_data['data']['list'][0]['token']
|
|
|
|
|
except TypeError:
|
|
|
|
|
return None, None, None, '该stoken无效获取过期了,请重新获取'
|
2022-07-19 00:23:49 +08:00
|
|
|
|
s_cookies = 'stuid={};stoken={}'.format(mys_id, stoken)
|
2022-07-19 18:10:38 +08:00
|
|
|
|
return s_cookies, mys_id, raw_data, 'OK'
|
|
|
|
|
|
2022-04-30 14:13:39 +08:00
|
|
|
|
|
|
|
|
|
# 获取今日签到信息
|
|
|
|
|
async def get_sign_info(uid):
|
|
|
|
|
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
|
|
|
|
|
url = 'https://api-takumi.mihoyo.com/event/bbs_sign_reward/info'
|
|
|
|
|
cookie = await get_own_cookie(uid, action='查询米游社签到')
|
|
|
|
|
if not cookie:
|
|
|
|
|
return f'你的uid{uid}没有绑定对应的cookie,使用ysb绑定才能用米游社签到哦!'
|
|
|
|
|
headers = {
|
|
|
|
|
'x-rpc-app_version': '2.11.1',
|
|
|
|
|
'x-rpc-client_type': '5',
|
2022-05-19 18:15:56 +08:00
|
|
|
|
'Origin': 'https://webstatic.mihoyo.com',
|
|
|
|
|
'Referer': 'https://webstatic.mihoyo.com/',
|
|
|
|
|
'Cookie': cookie['cookie'],
|
|
|
|
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS '
|
|
|
|
|
'X) AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBS/2.11.1',
|
2022-04-30 14:13:39 +08:00
|
|
|
|
}
|
|
|
|
|
params = {
|
|
|
|
|
'act_id': 'e202009291139501',
|
|
|
|
|
'region': server_id,
|
2022-05-19 18:15:56 +08:00
|
|
|
|
'uid': uid
|
2022-04-30 14:13:39 +08:00
|
|
|
|
}
|
2022-05-19 18:15:56 +08:00
|
|
|
|
resp = await aiorequests.get(url=url, headers=headers, params=params)
|
|
|
|
|
data = resp.json()
|
|
|
|
|
if await check_retcode(data, cookie, uid):
|
|
|
|
|
return data
|
|
|
|
|
else:
|
|
|
|
|
return f'你的uid{uid}的cookie已过期,需要重新绑定哦!'
|
2022-04-30 14:13:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 执行签到操作
|
|
|
|
|
async def sign(uid):
|
|
|
|
|
server_id = "cn_qd01" if uid[0] == '5' else "cn_gf01"
|
|
|
|
|
url = 'https://api-takumi.mihoyo.com/event/bbs_sign_reward/sign'
|
|
|
|
|
cookie = await get_own_cookie(uid, action='米游社签到')
|
|
|
|
|
if not cookie:
|
|
|
|
|
return f'你的uid{uid}没有绑定对应的cookie,使用ysb绑定才能用米游社签到哦!'
|
|
|
|
|
headers = get_sign_headers(cookie['cookie'])
|
|
|
|
|
json_data = {
|
|
|
|
|
'act_id': 'e202009291139501',
|
2022-05-19 18:15:56 +08:00
|
|
|
|
'uid': uid,
|
2022-04-30 14:13:39 +08:00
|
|
|
|
'region': server_id
|
|
|
|
|
}
|
2022-05-19 18:15:56 +08:00
|
|
|
|
resp = await aiorequests.post(url=url, headers=headers, json=json_data)
|
2022-08-12 11:55:49 +08:00
|
|
|
|
data = resp.json()
|
|
|
|
|
logger.info(f'---UID{uid}的签到状态码为{data["retcode"]},结果为{data["message"]}---')
|
2022-05-19 18:15:56 +08:00
|
|
|
|
if await check_retcode(data, cookie, uid):
|
|
|
|
|
return data
|
|
|
|
|
else:
|
|
|
|
|
return f'你的uid{uid}的cookie已过期,需要重新绑定哦!'
|
2022-04-30 14:13:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取签到奖励列表
|
|
|
|
|
async def get_sign_list():
|
|
|
|
|
url = 'https://api-takumi.mihoyo.com/event/bbs_sign_reward/home'
|
|
|
|
|
headers = {
|
|
|
|
|
'x-rpc-app_version': '2.11.1',
|
2022-05-19 18:15:56 +08:00
|
|
|
|
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 ('
|
|
|
|
|
'KHTML, like Gecko) miHoYoBBS/2.11.1',
|
2022-04-30 14:13:39 +08:00
|
|
|
|
'x-rpc-client_type': '5',
|
2022-05-19 18:15:56 +08:00
|
|
|
|
'Referer': 'https://webstatic.mihoyo.com/'
|
2022-04-30 14:13:39 +08:00
|
|
|
|
}
|
|
|
|
|
params = {
|
|
|
|
|
'act_id': 'e202009291139501'
|
|
|
|
|
}
|
2022-05-19 18:15:56 +08:00
|
|
|
|
resp = await aiorequests.get(url=url, headers=headers, params=params)
|
|
|
|
|
data = resp.json()
|
|
|
|
|
return data
|
2022-06-03 14:33:31 +08:00
|
|
|
|
|
|
|
|
|
|
2022-06-03 20:33:10 +08:00
|
|
|
|
async def get_enka_data(uid):
|
2022-08-02 12:33:25 +08:00
|
|
|
|
try:
|
|
|
|
|
url = f'https://enka.network/u/{uid}/__data.json'
|
|
|
|
|
resp = await aiorequests.get(url=url, headers={'User-Agent': 'LittlePaimon/2.0'}, follow_redirects=True)
|
|
|
|
|
data = resp.json()
|
|
|
|
|
return data
|
|
|
|
|
except Exception:
|
|
|
|
|
url = f'https://enka.microgg.cn/u/{uid}/__data.json'
|
|
|
|
|
resp = await aiorequests.get(url=url, headers={'User-Agent': 'LittlePaimon/2.0'}, follow_redirects=True)
|
|
|
|
|
data = resp.json()
|
|
|
|
|
return data
|
2022-06-05 01:03:43 +08:00
|
|
|
|
|
2022-07-19 18:10:38 +08:00
|
|
|
|
|
2022-07-19 00:23:49 +08:00
|
|
|
|
async def get_stoken_by_login_ticket(loginticket, mys_id):
|
2022-07-23 16:04:50 +08:00
|
|
|
|
req = await aiorequests.get(url='https://api-takumi.mihoyo.com/auth/api/getMultiTokenByLoginTicket',
|
|
|
|
|
params={
|
|
|
|
|
'login_ticket': loginticket,
|
|
|
|
|
'token_types': '3',
|
|
|
|
|
'uid': mys_id
|
|
|
|
|
})
|
2022-07-19 00:23:49 +08:00
|
|
|
|
return req.json()
|