mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-12-16 13:40:53 +08:00
修改绑定ck方式
This commit is contained in:
parent
e2ef10fcac
commit
80db03614e
@ -1,6 +1,7 @@
|
|||||||
from hoshino import aiorequests
|
from hoshino import aiorequests
|
||||||
from .util import get_headers, cache
|
from .util import get_headers, cache
|
||||||
import datetime
|
import datetime
|
||||||
|
import re
|
||||||
|
|
||||||
@cache(ttl=datetime.timedelta(minutes=30))
|
@cache(ttl=datetime.timedelta(minutes=30))
|
||||||
async def get_abyss_data(uid, cookie, schedule_type = "1", use_cache=True):
|
async def get_abyss_data(uid, cookie, schedule_type = "1", use_cache=True):
|
||||||
@ -93,4 +94,19 @@ async def get_monthinfo_data(uid, month, cookie, use_cache=True):
|
|||||||
"bind_region": server_id
|
"bind_region": server_id
|
||||||
}
|
}
|
||||||
res = await aiorequests.get(url=url, headers=headers, params=params)
|
res = await aiorequests.get(url=url, headers=headers, params=params)
|
||||||
return await res.json()
|
return await res.json()
|
||||||
|
|
||||||
|
async def get_bind_game(cookie):
|
||||||
|
finduid = re.search(r'account_id=(/d*);', cookie)
|
||||||
|
if not finduid:
|
||||||
|
return None
|
||||||
|
uid = finduid.group(1)
|
||||||
|
url = 'https://api-takumi.mihoyo.com/game_record/card/wapi/getGameRecordCard'
|
||||||
|
headers = get_headers(q='uid=' + uid, cookie = cookie)
|
||||||
|
params = {
|
||||||
|
"uid": uid
|
||||||
|
}
|
||||||
|
res = await aiorequests.get(url=url, headers=headers, params=params)
|
||||||
|
return await res.json()
|
||||||
|
|
||||||
|
|
@ -2,59 +2,37 @@ from hoshino import MessageSegment, Service, trigger, priv, CanceledException
|
|||||||
from hoshino.typing import CQEvent, Message
|
from hoshino.typing import CQEvent, Message
|
||||||
from ..util import update_last_query_to_qq, bind_cookie, bind_public_cookie
|
from ..util import update_last_query_to_qq, bind_cookie, bind_public_cookie
|
||||||
from nonebot import message_preprocessor
|
from nonebot import message_preprocessor
|
||||||
|
from ..get_data import get_bind_game
|
||||||
|
|
||||||
sv = Service('原神绑定',visible=False,enable_on_default=True)
|
sv = Service('原神绑定',visible=False,enable_on_default=True)
|
||||||
|
|
||||||
private_prefix = []
|
|
||||||
|
|
||||||
# support private message
|
|
||||||
# @message_preprocessor
|
|
||||||
# async def private_handler(bot, ev, _):
|
|
||||||
# if ev.detail_type != 'private':
|
|
||||||
# return
|
|
||||||
# for t in trigger.chain:
|
|
||||||
# for service in t.find_handler(ev):
|
|
||||||
# sv = service.sv
|
|
||||||
# if sv in private_prefix:
|
|
||||||
# if priv.get_user_priv(ev) >= priv.NORMAL:
|
|
||||||
# try:
|
|
||||||
# await service.func(bot, ev)
|
|
||||||
# except CanceledException:
|
|
||||||
# raise
|
|
||||||
# sv.logger.info(
|
|
||||||
# f'Private Message {ev.message_id} triggered {service.func.__name__}.'
|
|
||||||
# )
|
|
||||||
|
|
||||||
# def support_private(sv):
|
|
||||||
# def wrap(func):
|
|
||||||
# private_prefix.append(sv)
|
|
||||||
# return func
|
|
||||||
# return wrap
|
|
||||||
|
|
||||||
# @support_private(sv)
|
|
||||||
@sv.on_prefix(('原神绑定','ysb'))
|
@sv.on_prefix(('原神绑定','ysb'))
|
||||||
async def bind(bot,ev):
|
async def bind(bot,ev):
|
||||||
msg = ev.message.extract_plain_text().strip().split('#')
|
cookie = ev.message.extract_plain_text().strip()
|
||||||
qq=str(ev.user_id)
|
qq=str(ev.user_id)
|
||||||
if msg[0] == '':
|
if cookie == '':
|
||||||
res = '''请旅行者用[ysb+uid]指令来绑定uid哦,例如ysb100000011\n如果想看全部角色信息和实时便笺等功能,要把cookie也给派蒙\ncookie的获取方法:登录网页版米游社,在地址栏粘贴这段代码:\njavascript:(function(){prompt(document.domain,document.cookie)})();\n弹出来的一大串字符就是cookie(手机要via或chrome浏览器才行)\n然后在uid后面加#和cookie来绑定,例如ysb100000011#cookie_token=asdqwf...'''
|
res = '''旅行者好呀,你可以直接用ys/ysa等指令附上uid来使用派蒙\n如果想看全部角色信息和实时便笺等功能,要把cookie给派蒙哦\ncookie获取方法:登录网页版米游社,在地址栏粘贴代码:\njavascript:(function(){prompt(document.domain,document.cookie)})();\n复制弹窗出来的字符串(手机要via或chrome浏览器才行)\n然后添加派蒙私聊发送ysb接刚刚复制的字符串,例如:ysb UM_distinctid=17d131d...'''
|
||||||
await bot.send(ev,res,at_sender=True)
|
await bot.send(ev,res,at_sender=True)
|
||||||
elif len(msg) == 1:
|
|
||||||
if len(msg[0]) == 9 and msg[0].isdigit():
|
|
||||||
update_last_query_to_qq(qq, msg[0])
|
|
||||||
await bot.send(ev,'成功绑定uid',at_sender=True)
|
|
||||||
else:
|
|
||||||
await bot.send(ev,'请把要绑定的合规uid一起给派蒙',at_sender=True)
|
|
||||||
else:
|
else:
|
||||||
uid = msg[0]
|
cookie_info = await get_bind_game(cookie)
|
||||||
if len(msg[0]) != 9 or not msg[0].isdigit():
|
if cookie_info['retcode'] != 0:
|
||||||
await bot.send(ev,'uid是不是写错了呀?要9位数全数字的uid哦',at_sender=True)
|
await bot.send(ev,'这cookie没有用哦,检查一下是不是复制错了或者过期了(试试重新登录米游社再获取)',at_sender=True)
|
||||||
return
|
if ev.detail_type != 'private':
|
||||||
cookie = msg[1]
|
await bot.send(ev,'当前是在群聊里绑定,建议旅行者添加派蒙好友私聊绑定!',at_sender=True)
|
||||||
res = await bind_cookie(qq,uid,cookie)
|
else:
|
||||||
await bot.send(ev,res,at_sender=True)
|
for data in cookie_info['data']['list']:
|
||||||
|
if data['game_id'] == 2:
|
||||||
|
uid = data['game_role_id']
|
||||||
|
nickname = data['nickname']
|
||||||
|
# level = data['level']
|
||||||
|
break
|
||||||
|
if uid:
|
||||||
|
await bind_cookie(qq,uid,cookie)
|
||||||
|
await bot.send(ev, f'{nickname}绑定成功啦!使用ys/ysa等指令和派蒙互动吧!',at_sender=True)
|
||||||
|
if ev.detail_type != 'private':
|
||||||
|
await bot.send(ev,'当前是在群聊里绑定,建议旅行者把cookie撤回哦!',at_sender=True)
|
||||||
|
|
||||||
|
|
||||||
# @support_private(sv)
|
|
||||||
@sv.on_prefix('添加公共cookie')
|
@sv.on_prefix('添加公共cookie')
|
||||||
async def bing_public(bot,ev):
|
async def bing_public(bot,ev):
|
||||||
cookie = ev.message.extract_plain_text().strip()
|
cookie = ev.message.extract_plain_text().strip()
|
||||||
|
@ -34,14 +34,13 @@ def load_data():
|
|||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
with open(path,'w',encoding='UTF-8') as f:
|
with open(path,'w',encoding='UTF-8') as f:
|
||||||
json.dump(user_cookies_example,f,ensure_ascii=False)
|
json.dump(user_cookies_example,f,ensure_ascii=False)
|
||||||
else:
|
try:
|
||||||
try:
|
with open(path, encoding='utf8') as f:
|
||||||
with open(path, encoding='utf8') as f:
|
data = json.load(f)
|
||||||
data = json.load(f)
|
for k, v in data.items():
|
||||||
for k, v in data.items():
|
user_cookies[k] = v
|
||||||
user_cookies[k] = v
|
except:
|
||||||
except:
|
traceback.print_exc()
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
def save_data():
|
def save_data():
|
||||||
path = os.path.join(os.path.dirname(__file__), 'user_data','user_cookies.json')
|
path = os.path.join(os.path.dirname(__file__), 'user_data','user_cookies.json')
|
||||||
@ -173,21 +172,17 @@ async def bind_cookie(qq, uid, cookie):
|
|||||||
if qq not in user_cookies['私人']:
|
if qq not in user_cookies['私人']:
|
||||||
user_cookies['私人'][qq] = {}
|
user_cookies['私人'][qq] = {}
|
||||||
user_cookies['私人'][qq]['cookies'] = []
|
user_cookies['私人'][qq]['cookies'] = []
|
||||||
if not await check_cookie(cookie):
|
f = False
|
||||||
return '这cookie没有用哦,检查一下是不是复制错了或者过期了(试试重新登录米游社再获取)'
|
for c in user_cookies['私人'][qq]['cookies']:
|
||||||
else:
|
if c['uid'] == uid:
|
||||||
f = False
|
c['cookie'] = cookie
|
||||||
for c in user_cookies['私人'][qq]['cookies']:
|
f = True
|
||||||
if c['uid'] == uid:
|
break
|
||||||
c['cookie'] = cookie
|
if not f:
|
||||||
f = True
|
c = {'cookie':cookie,'uid':uid}
|
||||||
break
|
user_cookies['私人'][qq]['cookies'].append(c)
|
||||||
if not f:
|
user_cookies['私人'][qq]['last_query'] = uid
|
||||||
c = {'cookie':cookie,'uid':uid}
|
save_data()
|
||||||
user_cookies['私人'][qq]['cookies'].append(c)
|
|
||||||
user_cookies['私人'][qq]['last_query'] = uid
|
|
||||||
save_data()
|
|
||||||
return '绑定成功啦!'
|
|
||||||
|
|
||||||
# 绑定cookie到公共cookie池
|
# 绑定cookie到公共cookie池
|
||||||
async def bind_public_cookie(cookie):
|
async def bind_public_cookie(cookie):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user