mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-10-21 16:27:15 +08:00
commit
dbf3ee113f
@ -2,8 +2,10 @@ import json
|
|||||||
import re
|
import re
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Union
|
from typing import Union
|
||||||
from nonebot import on_command, require, get_bot
|
from nonebot import on_command, require, get_bot, logger
|
||||||
from nonebot.adapters.onebot.v11 import MessageEvent, Message, GroupMessageEvent
|
from nonebot.adapters.onebot.v11 import MessageEvent, Message, GroupMessageEvent
|
||||||
|
from nonebot.internal.matcher import Matcher
|
||||||
|
from nonebot.internal.params import ArgPlainText
|
||||||
from nonebot.params import CommandArg
|
from nonebot.params import CommandArg
|
||||||
from .data_source import get_Info, get_Notification, check_token
|
from .data_source import get_Info, get_Notification, check_token
|
||||||
from utils.decorator import exception_handler
|
from utils.decorator import exception_handler
|
||||||
@ -15,33 +17,73 @@ HELP_STR = '''
|
|||||||
云原神 信息/info: 查询云原神账户信息
|
云原神 信息/info: 查询云原神账户信息
|
||||||
'''.strip()
|
'''.strip()
|
||||||
|
|
||||||
|
cloud_ys = on_command('云原神', aliases={'云原神', 'yys'}, priority=16, block=True)
|
||||||
cloud_ys = on_command('mhyy', aliases={'云原神', 'mhyy'}, priority=16, block=True)
|
rm_cloud_ys = on_command('云原神解绑', aliases={'yys解绑', 'yys解除绑定', 'yysdel'}, priority=16, block=True)
|
||||||
cloud_ys.__paimon_help__ = {
|
cloud_ys.__paimon_help__ = {
|
||||||
"usage": "云原神",
|
"usage": "云原神",
|
||||||
"introduce": "查询云原神账户信息, 绑定token进行签到",
|
"introduce": "查询云原神账户信息, 绑定token进行签到",
|
||||||
"priority": 99
|
"priority": 99
|
||||||
}
|
}
|
||||||
|
rm_cloud_ys.__paimon_help__ = {
|
||||||
|
"usage": "云原神解绑",
|
||||||
|
"introduce": "解绑cookie并取消自动签到",
|
||||||
|
"priority": 99
|
||||||
|
}
|
||||||
scheduler = require('nonebot_plugin_apscheduler').scheduler
|
scheduler = require('nonebot_plugin_apscheduler').scheduler
|
||||||
uuid = str(uuid.uuid4())
|
uuid = str(uuid.uuid4())
|
||||||
|
|
||||||
|
|
||||||
async def auto_sign(user_id, data):
|
@rm_cloud_ys.handle()
|
||||||
|
async def _handle(event: Union[GroupMessageEvent, MessageEvent], match: Matcher, args: Message = CommandArg()):
|
||||||
|
plan_text = args.extract_plain_text()
|
||||||
|
if plan_text:
|
||||||
|
match.set_arg('choice', plan_text)
|
||||||
|
|
||||||
|
|
||||||
|
@rm_cloud_ys.got('choice', prompt='是否要解绑token并取消自动签到?\n请输入 是/否 来进行操作')
|
||||||
|
async def _(event: Union[GroupMessageEvent, MessageEvent], choice: str = ArgPlainText('choice')):
|
||||||
|
if choice == '是':
|
||||||
|
user_id = str(event.user_id)
|
||||||
|
data = load_json('user_data.json')
|
||||||
|
|
||||||
|
del data[user_id]
|
||||||
|
if scheduler.get_job('cloud_genshin_' + user_id):
|
||||||
|
scheduler.remove_job("cloud_genshin_" + user_id)
|
||||||
|
save_json(data, 'user_data.json')
|
||||||
|
|
||||||
|
await rm_cloud_ys.finish('token已解绑并取消自动签到~', at_sender=True)
|
||||||
|
elif choice == '否':
|
||||||
|
await rm_cloud_ys.finish()
|
||||||
|
else:
|
||||||
|
await rm_cloud_ys.finish()
|
||||||
|
|
||||||
|
|
||||||
|
async def auto_sign_cgn(user_id, data):
|
||||||
token = data['token']
|
token = data['token']
|
||||||
uuid = data['uuid']
|
uuid = data['uuid']
|
||||||
|
|
||||||
if await check_token(uuid, token):
|
if await check_token(uuid, token):
|
||||||
""" 签到云原神 """
|
|
||||||
d1 = await get_Notification(uuid, token)
|
|
||||||
""" 获取免费时间 """
|
""" 获取免费时间 """
|
||||||
d2 = await get_Info(uuid, token)
|
d2 = await get_Info(uuid, token)
|
||||||
""" 解析签到返回信息 """
|
""" 解析签到返回信息 """
|
||||||
signInfo = json.loads(d1['data']['list'][0]['msg'])
|
if d2['data']['free_time']['free_time'] == data['limit']:
|
||||||
if d2['data']['free_time']['free_time'] == '600':
|
|
||||||
await get_bot().send_private_msg(user_id=user_id, message='免费签到时长已达上限,无法继续签到')
|
await get_bot().send_private_msg(user_id=user_id, message='免费签到时长已达上限,无法继续签到')
|
||||||
elif not signInfo:
|
else:
|
||||||
await get_bot().send_private_msg(user_id=user_id, message=f'签到成功~ {signInfo["msg"]}: {signInfo["num"]}分钟')
|
""" 取云原神签到信息 """
|
||||||
await get_bot().send_private_msg(user_id=user_id, message='token已过期,请重新自行抓包并绑定')
|
d1 = await get_Notification(uuid, token)
|
||||||
|
if not list(d1['data']['list']):
|
||||||
|
logger.info(f'UID{data["uid"]} 已经签到云原神')
|
||||||
|
else:
|
||||||
|
signInfo = json.loads(d1['data']['list'][0]['msg'])
|
||||||
|
if signInfo:
|
||||||
|
await get_bot().send_private_msg(
|
||||||
|
user_id=user_id,
|
||||||
|
message=f'签到成功~ {signInfo["msg"]}: {signInfo["num"]}分钟'
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
await get_bot().send_private_msg(user_id=user_id, message='token已过期,请重新自行抓包并重新绑定')
|
||||||
|
|
||||||
|
|
||||||
@cloud_ys.handle()
|
@cloud_ys.handle()
|
||||||
@ -57,7 +99,14 @@ async def _(event: Union[GroupMessageEvent, MessageEvent], msg: Message = Comman
|
|||||||
await cloud_ys.finish('该功能暂不支持频道推送哦~', at_sender=True)
|
await cloud_ys.finish('该功能暂不支持频道推送哦~', at_sender=True)
|
||||||
|
|
||||||
if not param:
|
if not param:
|
||||||
await cloud_ys.finish('请输入具体指令或参数!', at_sender=True)
|
message = f'亲爱的旅行者: {user_id}\n\n' \
|
||||||
|
'本插件食用方法:\n' \
|
||||||
|
'<云原神/yys> [绑定/bind] 绑定云原神token\n' \
|
||||||
|
'<云原神/yys> [信息/info] 查询云原神账户信息\n\n' \
|
||||||
|
'<yys[解绑/解除绑定/del]> 解绑token并取消自动签到\n\n' \
|
||||||
|
'有关如何抓取token的方法:\n' \
|
||||||
|
'请前往 https://blog.ethreal.cn/archives/yysgettoken 查阅'
|
||||||
|
await cloud_ys.finish(message, at_sender=True)
|
||||||
else:
|
else:
|
||||||
if action.group('action') in ['绑定', 'bind']:
|
if action.group('action') in ['绑定', 'bind']:
|
||||||
match = re.search(r'oi=\d+', param.split(" ")[1])
|
match = re.search(r'oi=\d+', param.split(" ")[1])
|
||||||
@ -67,6 +116,8 @@ async def _(event: Union[GroupMessageEvent, MessageEvent], msg: Message = Comman
|
|||||||
data[user_id] = {
|
data[user_id] = {
|
||||||
'uid': uid,
|
'uid': uid,
|
||||||
'uuid': uuid,
|
'uuid': uuid,
|
||||||
|
'limit': 600,
|
||||||
|
'isFullTime': False,
|
||||||
'token': param.split(" ")[1]
|
'token': param.split(" ")[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,14 +128,14 @@ async def _(event: Union[GroupMessageEvent, MessageEvent], msg: Message = Comman
|
|||||||
save_json(data, 'user_data.json')
|
save_json(data, 'user_data.json')
|
||||||
""" 添加推送任务 """
|
""" 添加推送任务 """
|
||||||
scheduler.add_job(
|
scheduler.add_job(
|
||||||
func=auto_sign,
|
func=auto_sign_cgn,
|
||||||
trigger='cron',
|
trigger='cron',
|
||||||
hour=4,
|
hour=6,
|
||||||
id="cloud_genshin_" + user_id,
|
id="cloud_genshin_" + user_id,
|
||||||
args=(user_id, data[user_id]),
|
args=(user_id, data[user_id]),
|
||||||
misfire_grace_time=10
|
misfire_grace_time=10
|
||||||
)
|
)
|
||||||
await cloud_ys.finish(f'[UID:{uid}]已绑定token, 将在每天4点为你自动签到!', at_sender=True)
|
await cloud_ys.finish(f'[UID:{uid}]已绑定token, 将在每天6点为你自动签到!', at_sender=True)
|
||||||
|
|
||||||
elif action.group('action') in ['信息', 'info']:
|
elif action.group('action') in ['信息', 'info']:
|
||||||
|
|
||||||
@ -112,9 +163,9 @@ async def _(event: Union[GroupMessageEvent, MessageEvent], msg: Message = Comman
|
|||||||
|
|
||||||
for user_id, data in load_json('user_data.json').items():
|
for user_id, data in load_json('user_data.json').items():
|
||||||
scheduler.add_job(
|
scheduler.add_job(
|
||||||
func=auto_sign,
|
func=auto_sign_cgn,
|
||||||
trigger='cron',
|
trigger='cron',
|
||||||
hour=4,
|
hour=6,
|
||||||
id="cloud_genshin_" + user_id,
|
id="cloud_genshin_" + user_id,
|
||||||
args=(user_id, data),
|
args=(user_id, data),
|
||||||
misfire_grace_time=10
|
misfire_grace_time=10
|
||||||
|
Loading…
Reference in New Issue
Block a user