From 63f5080edc826f2b737ea005429610a8df0728b1 Mon Sep 17 00:00:00 2001 From: CM-Edelweiss <2633668472@qq.com> Date: Thu, 23 Mar 2023 23:05:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0`=E6=9F=A5=E7=9C=8B=E6=8A=BD?= =?UTF-8?q?=E5=8D=A1=E8=AE=B0=E5=BD=95=E9=93=BE=E6=8E=A5`=E6=8C=87?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/Paimon_Gacha_url/__init__.py | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 LittlePaimon/plugins/Paimon_Gacha_url/__init__.py diff --git a/LittlePaimon/plugins/Paimon_Gacha_url/__init__.py b/LittlePaimon/plugins/Paimon_Gacha_url/__init__.py new file mode 100644 index 0000000..3220daa --- /dev/null +++ b/LittlePaimon/plugins/Paimon_Gacha_url/__init__.py @@ -0,0 +1,80 @@ +from time import time +from urllib.parse import quote +from datetime import datetime +from typing import Union + +from nonebot import on_command +from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, PrivateMessageEvent +from nonebot.adapters.onebot.v11.exception import ActionFailed +from LittlePaimon.utils import logger, scheduler + +from LittlePaimon.utils.message import CommandUID +from LittlePaimon.utils.api import get_authkey_by_stoken + +gacha_url = on_command( + '查看抽卡记录链接', + aliases={'导出抽卡记录链接'}, + priority=11, + block=True, + state={ + 'pm_name': '查看抽卡记录链接', + 'pm_description': '*获取你的抽卡记录链接', + 'pm_usage': '查看抽卡记录链接(uid)', + 'pm_priority': 1, + }, +) + + +async def withdraw(bot: Bot, message_id: int) -> None: + """撤回消息任务""" + await bot.delete_msg(message_id=message_id) + + +@gacha_url.handle() +async def _( + bot: Bot, + event: Union[GroupMessageEvent, PrivateMessageEvent], + uid=CommandUID() +): + await gacha_url.send("正在获取抽卡记录链接") + logger.info('获取抽卡记录链接', '开始执行') + authkey, state, _ = await get_authkey_by_stoken(event.user_id, uid) + if not state: + return authkey + if authkey == {}: + await gacha_url.finish(authkey, at_sender=True) + now = time() + region = 'cn_qd01' if uid[0] == '5' else 'cn_gf01' + msgs = [] + url = ( + f"https://hk4e-api.mihoyo.com/event/gacha_info/api/getGachaLog?" + f"authkey_ver=1&sign_type=2&auth_appid=webview_gacha&init_type=301&" + f"gacha_id=fecafa7b6560db5f3182222395d88aaa6aaac1bc" + f"×tamp={str(int(now))}" + f"&lang=zh-cn&device_type=mobile&plat_type=ios®ion={region}" + f"&authkey={quote(authkey,'utf-8')}" + f"&game_biz=hk4e_cn&gacha_type=301&page=1&size=5&end_id=0" + ) + msgs.append({"type": "node", "data": {"name": '抽卡记录', + "uin": event.user_id, "content": f"uid:{uid}的抽卡记录链接为:"}}) + msgs.append({"type": "node", "data": {"name": '抽卡记录', + "uin": event.user_id, "content": url}}) + try: + if isinstance(event, PrivateMessageEvent): + msg = await bot.call_api( + "send_private_forward_msg", user_id=event.user_id, messages=msgs + ) + else: + msg = await bot.call_api( + "send_group_forward_msg", group_id=event.group_id, messages=msgs + ) + scheduler.add_job( + withdraw, + "date", + args=[bot, dict(msg)["message_id"]], + run_date=datetime.fromtimestamp(time() + 90), + ) + except ActionFailed: + logger.info('获取抽卡记录链接', '➤', '', '发送失败', False) + except Exception as e: + logger.info('获取抽卡记录链接', '➤', e, '撤回任务异常!', False)