From 5c4b6a3f44f812f6cceedd6c08206682541a691e Mon Sep 17 00:00:00 2001 From: nicklly <1134741727@qq.com> Date: Sun, 12 Jun 2022 14:30:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=AD=A3=E5=8E=9F=E7=A5=9E=E6=97=A5?= =?UTF-8?q?=E5=8E=86=E6=8F=92=E4=BB=B6=E5=90=8D=E5=AD=97=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=BA=91=E5=8E=9F=E7=A5=9E=E7=9B=B8=E5=85=B3=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__init__.py | 0 {Paimon_Calender => Paimon_Calendar}/draw.py | 0 {Paimon_Calender => Paimon_Calendar}/event.py | 0 .../generate.py | 0 Paimon_CloudGenshin/__init__.py | 139 ++++++++++++++++++ Paimon_CloudGenshin/data_source.py | 54 +++++++ 6 files changed, 193 insertions(+) rename {Paimon_Calender => Paimon_Calendar}/__init__.py (100%) rename {Paimon_Calender => Paimon_Calendar}/draw.py (100%) rename {Paimon_Calender => Paimon_Calendar}/event.py (100%) rename {Paimon_Calender => Paimon_Calendar}/generate.py (100%) create mode 100644 Paimon_CloudGenshin/__init__.py create mode 100644 Paimon_CloudGenshin/data_source.py diff --git a/Paimon_Calender/__init__.py b/Paimon_Calendar/__init__.py similarity index 100% rename from Paimon_Calender/__init__.py rename to Paimon_Calendar/__init__.py diff --git a/Paimon_Calender/draw.py b/Paimon_Calendar/draw.py similarity index 100% rename from Paimon_Calender/draw.py rename to Paimon_Calendar/draw.py diff --git a/Paimon_Calender/event.py b/Paimon_Calendar/event.py similarity index 100% rename from Paimon_Calender/event.py rename to Paimon_Calendar/event.py diff --git a/Paimon_Calender/generate.py b/Paimon_Calendar/generate.py similarity index 100% rename from Paimon_Calender/generate.py rename to Paimon_Calendar/generate.py diff --git a/Paimon_CloudGenshin/__init__.py b/Paimon_CloudGenshin/__init__.py new file mode 100644 index 0000000..c858426 --- /dev/null +++ b/Paimon_CloudGenshin/__init__.py @@ -0,0 +1,139 @@ +import json +import re +import uuid +from typing import Union +from nonebot import on_command, require, get_bot +from nonebot.adapters.onebot.v11 import MessageEvent, Message, GroupMessageEvent +from nonebot.params import CommandArg +from .data_source import get_Info, get_Notification, check_token +from LittlePaimon.utils.decorator import exception_handler +from LittlePaimon.utils.file_handler import load_json, save_json +from LittlePaimon.utils.config import config +from LittlePaimon.utils.message_util import get_message_id + +HELP_STR = ''' +云原神相关功能 +云原神 绑定/bind : 绑定云原神的token +云原神 信息/info: 查询云原神账户信息 +'''.strip() + + +cloud_ys = on_command('mhyy', aliases={'云原神', 'mhyy'}, priority=16, block=True) +cloud_ys.__paimon_help__ = { + "usage": "云原神", + "introduce": "查询云原神账户信息, 绑定token进行签到", + "priority": 99 +} +scheduler = require('nonebot_plugin_apscheduler').scheduler +uuid = str(uuid.uuid4()) + + +async def auto_sign(user_id, data): + token = data['token'] + uuid = data['uuid'] + + if await check_token(uuid, token): + """ 签到云原神 """ + d1 = await get_Notification(uuid, token) + """ 获取免费时间 """ + d2 = await get_Info(uuid, token) + """ 解析签到返回信息 """ + signInfo = json.loads(d1['data']['list'][0]['msg']) + if d2['data']['free_time']['free_time'] == '600': + await get_bot().send_private_msg(user_id=user_id, message='免费签到时长已达上限,无法继续签到') + elif not signInfo: + 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已过期,请重新自行抓包并绑定') + + +@cloud_ys.handle() +@exception_handler() +async def _(event: Union[GroupMessageEvent, MessageEvent], msg: Message = CommandArg(), uuid=uuid): + param = msg.extract_plain_text().strip() + user_id = str(event.user_id) + data = load_json('user_data.json') + + action = re.search(r'(?P(信息|info)|(绑定|bind))', param) + + if event.message_type == 'guild': + await cloud_ys.finish('该功能不支持群组或频道推送哦~', at_sender=True) + + if str(get_message_id(event)) not in config.paimon_cloudys_group: + await cloud_ys.finish(f'尚未在群 {str(get_message_id(event))} 开启本功能') + + if not param: + await cloud_ys.finish('请输入具体指令或参数!', at_sender=True) + else: + if action.group('action') in ['绑定', 'bind']: + match = re.search(r'oi=\d+', param.split(" ")[1]) + if match: + uid = str(match.group()).split('=')[1] + + data[user_id] = { + 'uid': uid, + 'uuid': uuid, + 'token': param.split(" ")[1] + } + + if scheduler.get_job('cloud_genshin_' + user_id): + scheduler.remove_job("cloud_genshin_" + user_id) + + """ 保存数据 """ + save_json(data, 'user_data.json') + """ 添加推送任务 """ + scheduler.add_job( + func=auto_sign, + trigger='cron', + hour=4, + id="cloud_genshin_" + user_id, + args=(user_id, data[user_id]), + misfire_grace_time=10 + ) + await cloud_ys.finish(f'[UID:{uid}]已绑定token, 将在每天4点为你自动签到!', at_sender=True) + + elif action.group('action') in ['信息', 'info']: + + token = data[user_id]['token'] + uid = data[user_id]['uid'] + uuid = data[user_id]['uuid'] + + result = await get_Info(uuid, token) + + """ 米云币 """ + coins = result['data']['coin']['coin_num'] + """ 免费时间 """ + free_time = result['data']['free_time']['free_time'] + """ 畅玩卡 """ + card = result['data']['play_card']['short_msg'] + + message = '======== UID: {0} ========\n' \ + '剩余米云币: {1}\n' \ + '剩余免费时间: {2}分钟\n' \ + '畅玩卡状态: {3}'.format(uid, coins, free_time, card) + await cloud_ys.finish(message) + #elif action.group('action') in ['签到', 'sign']: + + # token = data[user_id]['token'] + # uuid = data[user_id]['uuid'] + + # if await check_token(uuid, token): + # d1 = await get_Notification(uuid, token) + # signInfo = json.loads(d1['data']['list'][0]['msg']) + # if not list(d1['data']['list']): + # await cloud_ys.finish('今天已签到了哦~', at_sender=True) + # elif signInfo: + # await cloud_ys.finish(f'签到成功~ {signInfo["msg"]}: {signInfo["num"]}分钟', at_sender=True) + + else: + await cloud_ys.finish('参数错误!', at_sender=True) + + +for user_id, data in load_json('user_data.json').items(): + scheduler.add_job( + func=auto_sign, + trigger='cron', + hour=4, + id="cloud_genshin_" + user_id, + args=(user_id, data), + misfire_grace_time=10 + ) diff --git a/Paimon_CloudGenshin/data_source.py b/Paimon_CloudGenshin/data_source.py new file mode 100644 index 0000000..59f0a78 --- /dev/null +++ b/Paimon_CloudGenshin/data_source.py @@ -0,0 +1,54 @@ +import json +from ..utils.aiorequests import * + +host = 'https://api-cloudgame.mihoyo.com/' + + +def get_header(uuid: str, token: str): + headers = { + 'x-rpc-combo_token': token, + 'x-rpc-client_type': '2', + 'x-rpc-app_version': '2.4.0', + 'x-rpc-sys_version': '10', + 'x-rpc-channel': 'mihoyo', + 'x-rpc-device_id': uuid, + 'x-rpc-device_name': 'Samsung SM-G988N', + 'x-rpc-device_model': 'SM-G988N', + 'x-rpc-app_id': '1953439974', + 'Referer': 'https://app.mihoyo.com', + 'Host': 'api-cloudgame.mihoyo.com', + 'Connection': 'Keep-Alive', + 'Accept-Encoding': 'gzip', + 'User-Agent': 'okhttp/4.9.0' + } + return headers + + +async def check_token(uuid: str, cookie: str): + headers = get_header(uuid, cookie) + req = await post(host + 'hk4e_cg_cn/gamer/api/login', headers=headers) + data = json.loads(req.text) + if data['retcode'] == 0 and data['message'] == 'OK': + return True + return False + + +async def get_Info(uuid: str, cookie: str): + headers = get_header(uuid, cookie) + req = await get(host + 'hk4e_cg_cn/wallet/wallet/get', headers=headers) + return json.loads(req.text) + + +async def get_Announcement(uuid: str, cookie: str): + headers = get_header(uuid, cookie) + req = await get(host + 'hk4e_cg_cn/gamer/api/getAnnouncementInfo', headers=headers) + return json.loads(req.text) + + +async def get_Notification(uuid: str, cookie: str): + headers = get_header(uuid, cookie) + req = await get( + host + 'hk4e_cg_cn/gamer/api/listNotifications?status=NotificationStatusUnread&type=NotificationTypePopup' + '&is_sort=true', + headers=headers) + return json.loads(req.text)