mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-12-16 13:40:53 +08:00
修复添加公共ck,优化ck使用逻辑,优化提示
This commit is contained in:
parent
8175622c37
commit
39f4787e30
@ -22,7 +22,7 @@ def reload_public_cookie(is_drop=True):
|
|||||||
with open(os.path.join(os.path.dirname(__file__), 'user_data', 'user_cookies.json'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(os.path.dirname(__file__), 'user_data', 'user_cookies.json'), 'r', encoding='utf-8') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
for d in data['通用']:
|
for d in data['通用']:
|
||||||
cursor.execute('INSERT IGNORE INTO public_cookies VALUES (?, ?, "OK");', (d['no'], d['cookie']))
|
cursor.execute('INSERT OR IGNORE INTO public_cookies VALUES (?, ?, "OK");', (d['no'], d['cookie']))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
logger.info('---公共cookie池载入成功!---')
|
logger.info('---公共cookie池载入成功!---')
|
||||||
@ -104,7 +104,7 @@ async def insert_public_cookie(cookie):
|
|||||||
cookie TEXT,
|
cookie TEXT,
|
||||||
status TEXT
|
status TEXT
|
||||||
);''')
|
);''')
|
||||||
cursor.execute('INSERT IGNORE INTO public_cookies (cookie, status) VALUES (?,"OK");', (cookie,))
|
cursor.execute('INSERT OR IGNORE INTO public_cookies (cookie, status) VALUES (?,"OK");', (cookie,))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ async def ckjl(bot,ev):
|
|||||||
return
|
return
|
||||||
uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
|
uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
|
||||||
if not uid:
|
if not uid:
|
||||||
await bot.send(ev,'请把uid给派蒙哦,比如获取抽卡记录100000001 链接',at_sender=True)
|
await bot.send(ev,'请把uid给派蒙哦,比如导出抽卡记录100000001 xlsx',at_sender=True)
|
||||||
return
|
return
|
||||||
find_filetype = r'(?P<filetype>xlsx|json)'
|
find_filetype = r'(?P<filetype>xlsx|json)'
|
||||||
match = re.search(find_filetype, msg)
|
match = re.search(find_filetype, msg)
|
||||||
|
@ -17,7 +17,7 @@ async def get_abyss_data(user_id, uid, schedule_type = "1", use_cache=True):
|
|||||||
while True:
|
while True:
|
||||||
cookie = await get_use_cookie(user_id, uid=uid, action='查询深渊')
|
cookie = await get_use_cookie(user_id, uid=uid, action='查询深渊')
|
||||||
if not cookie:
|
if not cookie:
|
||||||
return '现在派蒙没有可以用的cookie哦,请让主人 添加公共ck 吧!'
|
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'])
|
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)
|
res = await aiorequests.get(url=url, headers=headers, params=params)
|
||||||
data = await res.json()
|
data = await res.json()
|
||||||
@ -30,7 +30,7 @@ async def get_daily_note_data(uid):
|
|||||||
url ="https://api-takumi.mihoyo.com/game_record/app/genshin/api/dailyNote"
|
url ="https://api-takumi.mihoyo.com/game_record/app/genshin/api/dailyNote"
|
||||||
cookie = await get_own_cookie(uid, action='查询实时便签')
|
cookie = await get_own_cookie(uid, action='查询实时便签')
|
||||||
if not cookie:
|
if not cookie:
|
||||||
return f'你的uid{uid}没有绑定对应的cookie哦,先用ysb给派蒙绑定吧!'
|
return '现在派蒙没有可以用的cookie哦,可能是:\n1.公共cookie全都达到了每日30次上限\n2.公共池全都失效了或没有cookie\n让管理员使用 添加公共ck 吧!'
|
||||||
await update_cookie_cache(cookie['cookie'], uid, 'uid')
|
await update_cookie_cache(cookie['cookie'], uid, 'uid')
|
||||||
headers = get_headers(q=f'role_id={uid}&server={server_id}', cookie=cookie['cookie'])
|
headers = get_headers(q=f'role_id={uid}&server={server_id}', cookie=cookie['cookie'])
|
||||||
params = {
|
params = {
|
||||||
@ -51,7 +51,7 @@ async def get_player_card_data(user_id, uid, use_cache=True):
|
|||||||
while True:
|
while True:
|
||||||
cookie = await get_use_cookie(user_id, uid=uid, action='查询原神卡片')
|
cookie = await get_use_cookie(user_id, uid=uid, action='查询原神卡片')
|
||||||
if not cookie:
|
if not cookie:
|
||||||
return '现在派蒙没有可以用的cookie哦,请让主人 添加公共ck 吧!'
|
return '现在派蒙没有可以用的cookie哦,可能是:\n1.公共cookie全都达到了每日30次上限\n2.公共池全都失效了或没有cookie\n让管理员使用 添加公共ck 吧!'
|
||||||
headers = get_headers(q=f'role_id={uid}&server={server_id}', cookie=cookie['cookie'])
|
headers = get_headers(q=f'role_id={uid}&server={server_id}', cookie=cookie['cookie'])
|
||||||
res = await aiorequests.get(url=url, headers=headers, params=params)
|
res = await aiorequests.get(url=url, headers=headers, params=params)
|
||||||
data = await res.json()
|
data = await res.json()
|
||||||
@ -70,7 +70,7 @@ async def get_chara_detail_data(user_id, uid, use_cache=True):
|
|||||||
while True:
|
while True:
|
||||||
cookie = await get_use_cookie(user_id, uid=uid, action='查询角色详情')
|
cookie = await get_use_cookie(user_id, uid=uid, action='查询角色详情')
|
||||||
if not cookie:
|
if not cookie:
|
||||||
return '现在派蒙没有可以用的cookie哦,请让主人 添加公共ck 吧!'
|
return '现在派蒙没有可以用的cookie哦,可能是:\n1.公共cookie全都达到了每日30次上限\n2.公共池全都失效了或没有cookie\n让管理员使用 添加公共ck 吧!'
|
||||||
headers = get_headers(b=json_data, cookie=cookie['cookie'])
|
headers = get_headers(b=json_data, cookie=cookie['cookie'])
|
||||||
res = await aiorequests.post(url=url, headers=headers, json=json_data)
|
res = await aiorequests.post(url=url, headers=headers, json=json_data)
|
||||||
data = await res.json()
|
data = await res.json()
|
||||||
|
@ -19,7 +19,7 @@ sv = Service('派蒙原神信息查询', bundle='派蒙', help_=help_msg)
|
|||||||
async def player_card(bot,ev):
|
async def player_card(bot,ev):
|
||||||
uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
|
uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
|
||||||
if not uid:
|
if not uid:
|
||||||
await bot.send(ev,'请把正确的uid给派蒙哦,例如sy100123456!',at_sender=True)
|
await bot.send(ev,'请把正确的uid给派蒙哦,例如ys100123456!',at_sender=True)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
data = await get_player_card_data(user_id, uid, use_cache=use_cache)
|
data = await get_player_card_data(user_id, uid, use_cache=use_cache)
|
||||||
@ -42,7 +42,7 @@ async def player_card(bot,ev):
|
|||||||
async def all_characters(bot,ev):
|
async def all_characters(bot,ev):
|
||||||
uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
|
uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
|
||||||
if not uid:
|
if not uid:
|
||||||
await bot.send(ev,'请把正确的uid给派蒙哦,例如sy100123456!',at_sender=True)
|
await bot.send(ev,'请把正确的uid给派蒙哦,例如ysa100123456!',at_sender=True)
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
chara_data = await get_chara_detail_data(user_id, uid, use_cache=use_cache)
|
chara_data = await get_chara_detail_data(user_id, uid, use_cache=use_cache)
|
||||||
@ -58,7 +58,7 @@ async def all_characters(bot,ev):
|
|||||||
async def my_characters(bot,ev):
|
async def my_characters(bot,ev):
|
||||||
uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
|
uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
|
||||||
if not uid:
|
if not uid:
|
||||||
await bot.send(ev,'请把正确的uid给派蒙哦,例如sy100123456!',at_sender=True)
|
await bot.send(ev,'请把正确的uid给派蒙哦,例如ysc100123456钟离',at_sender=True)
|
||||||
return
|
return
|
||||||
if not msg:
|
if not msg:
|
||||||
await bot.send(ev,f'要把角色名给派蒙呀!例如ysc100123456钟离',at_sender=True)
|
await bot.send(ev,f'要把角色名给派蒙呀!例如ysc100123456钟离',at_sender=True)
|
||||||
|
@ -218,7 +218,8 @@ async def draw_player_card(data, chara_data, uid, nickname="旅行者"):
|
|||||||
# 世界探索
|
# 世界探索
|
||||||
await draw_world_data(bg_draw,data)
|
await draw_world_data(bg_draw,data)
|
||||||
# 角色
|
# 角色
|
||||||
if chara_data:
|
nocha = ''
|
||||||
|
if chara_data['data']:
|
||||||
chara_data = chara_data['data']['avatars']
|
chara_data = chara_data['data']['avatars']
|
||||||
w = 1045
|
w = 1045
|
||||||
i = 0
|
i = 0
|
||||||
@ -231,8 +232,10 @@ async def draw_player_card(data, chara_data, uid, nickname="旅行者"):
|
|||||||
bg_img.alpha_composite(chara_card.resize((180, 249)), (840 + (i - 4) * 205, 974))
|
bg_img.alpha_composite(chara_card.resize((180, 249)), (840 + (i - 4) * 205, 974))
|
||||||
elif i > 8:
|
elif i > 8:
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
nocha = '*这uid关闭了角色详情显示,派蒙看不到哦'
|
||||||
bg_img = pil2b64(bg_img, 80)
|
bg_img = pil2b64(bg_img, 80)
|
||||||
bg_img = MessageSegment.image(bg_img)
|
bg_img = MessageSegment.image(bg_img) + nocha
|
||||||
return bg_img
|
return bg_img
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,16 +15,17 @@ from .db_util import get_private_cookie, get_cookie_cache, get_public_cookie, li
|
|||||||
|
|
||||||
async def get_use_cookie(user_id, uid='', mys_id='', action=''):
|
async def get_use_cookie(user_id, uid='', mys_id='', action=''):
|
||||||
cache_cookie = await get_cookie_cache(uid, 'uid')
|
cache_cookie = await get_cookie_cache(uid, 'uid')
|
||||||
if cache_cookie:
|
|
||||||
if cache_cookie['type'] == 'public':
|
|
||||||
logger.info(f'---派蒙调用{uid}的缓存公共cookie执行{action}操作---')
|
|
||||||
else:
|
|
||||||
logger.info(f'---派蒙调用{uid}的缓存私人cookie执行{action}操作---')
|
|
||||||
return cache_cookie
|
|
||||||
cookies = await get_private_cookie(user_id, 'user_id')
|
cookies = await get_private_cookie(user_id, 'user_id')
|
||||||
if not cookies:
|
if not cookies:
|
||||||
|
if cache_cookie:
|
||||||
|
if cache_cookie['type'] == 'public':
|
||||||
|
logger.info(f'---派蒙调用{uid}的缓存公共cookie执行{action}操作---')
|
||||||
|
else:
|
||||||
|
logger.info(f'---派蒙调用{uid}的缓存私人cookie执行{action}操作---')
|
||||||
|
return cache_cookie
|
||||||
public_cookie = await get_public_cookie()
|
public_cookie = await get_public_cookie()
|
||||||
if not public_cookie:
|
if not public_cookie:
|
||||||
|
logger.info(f'---派蒙当前没有可用的公共cookie,可能是都达到了上限或没有公共cookie---')
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
logger.info(f'---派蒙调用{public_cookie[0]}号公共cookie执行{action}操作---')
|
logger.info(f'---派蒙调用{public_cookie[0]}号公共cookie执行{action}操作---')
|
||||||
@ -34,6 +35,12 @@ async def get_use_cookie(user_id, uid='', mys_id='', action=''):
|
|||||||
if (uid and uid_ == uid) or (mys_id and mys_id_ == mys_id):
|
if (uid and uid_ == uid) or (mys_id and mys_id_ == mys_id):
|
||||||
logger.info(f'---派蒙调用用户{user_id_}的uid{uid_}私人cookie执行{action}操作---')
|
logger.info(f'---派蒙调用用户{user_id_}的uid{uid_}私人cookie执行{action}操作---')
|
||||||
return {'type':'private', 'user_id': user_id_, 'cookie': cookie, 'uid': uid_, 'mys_id': mys_id_}
|
return {'type':'private', 'user_id': user_id_, 'cookie': cookie, 'uid': uid_, 'mys_id': mys_id_}
|
||||||
|
if cache_cookie:
|
||||||
|
if cache_cookie['type'] == 'public':
|
||||||
|
logger.info(f'---派蒙调用{uid}的缓存公共cookie执行{action}操作---')
|
||||||
|
else:
|
||||||
|
logger.info(f'---派蒙调用{uid}的缓存私人cookie执行{action}操作---')
|
||||||
|
return cache_cookie
|
||||||
use_cookie = random.choice(cookies)
|
use_cookie = random.choice(cookies)
|
||||||
logger.info(f'---派蒙调用用户{use_cookie[0]}的uid{use_cookie[2]}私人cookie执行{action}操作---')
|
logger.info(f'---派蒙调用用户{use_cookie[0]}的uid{use_cookie[2]}私人cookie执行{action}操作---')
|
||||||
return {'type':'private', 'user_id': use_cookie[0], 'cookie': use_cookie[1], 'uid': use_cookie[2], 'mys_id': use_cookie[3]}
|
return {'type':'private', 'user_id': use_cookie[0], 'cookie': use_cookie[1], 'uid': use_cookie[2], 'mys_id': use_cookie[3]}
|
||||||
@ -54,7 +61,7 @@ async def get_own_cookie(uid='', mys_id='', action=''):
|
|||||||
|
|
||||||
# 检查数据返回状态,10001为ck过期了,10101为达到每日30次上线了
|
# 检查数据返回状态,10001为ck过期了,10101为达到每日30次上线了
|
||||||
async def check_retcode(data, cookie, uid):
|
async def check_retcode(data, cookie, uid):
|
||||||
if data['retcode'] == 10001:
|
if data['retcode'] == 10001 or data['retcode'] == -100:
|
||||||
await delete_cookie(cookie['cookie'], cookie['type'])
|
await delete_cookie(cookie['cookie'], cookie['type'])
|
||||||
await send_cookie_delete_msg(cookie)
|
await send_cookie_delete_msg(cookie)
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user