Skip to content

Commit

Permalink
Merge pull request #338 from Ljzd-PRO/dev
Browse files Browse the repository at this point in the history
更新至 v2.6.0
  • Loading branch information
Ljzd-PRO authored Jul 11, 2024
2 parents dd9a131 + b1da020 commit a0dd139
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 171 deletions.
27 changes: 17 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
### 更新内容

#### 💡 新特性
- 新增日志提示推送超话兑换码信息 - by @Joseandluue
- 适配微博多账号 - by @Joseandluue
- 改进人机验证日志输出 (#299)

- 新增绝区零微博超话兑换 - by @Joseandluue
- 增加微博超话相关参数设置错误提示 - by @Joseandluue
- 调整微博设置功能:补充删除账号 - by @Joseandluue
- 优化多个微博超话有兑换码的消息推送 - by @Joseandluue
- 优化微博签到出错推送 - by @Joseandluue

- 原神体力上限修改 (#308) - by @Joseandluue
- 增加绝区零游戏签到支持 (#332) - by @Yinhaoran1128

#### 🐛 修复
- **修复较新版本的 nonebot2 导入插件失败的问题**
- 补充插件元数据以符合 nonebot 规定
- 微博超话兑换码相关代码优化 - by @Joseandluue
- Windows 下默认不使用多进程生成商品图片 (#282)
- 修复删除兑换计划出错的问题 (#297)
- 修复微博超话签到结果判断逻辑错误 - by @Joseandluue
- 因微博超话签到触发人机验证,每日签到改为检测到超话存在可兑换礼包时才会进行签到 - by @Joseandluue
- 修复微博超话自动签到开关功能缺失 (#327) - by @Joseandluue
- 微博超话签到验证对自动签到进行调整 - by @Joseandluue
- 对于 OneBot 协议,推送米游币任务结果时不再配上图片,以修复米游币任务中途出错导致提前结束的问题 (#323, #309)
- 修复添加兑换计划后的兑换时间错误 (#330)

#### 🔧 杂项
- 替换所有 Workflow 文件,新增插件测试,通过 CI 自动检查插件能否导入成功
- 微博超话签到设置注释补充参数 `c` 为必填(找不到超话列表) (#318, #294) - by @Joseandluue

### 更新方式

Expand All @@ -37,4 +44,4 @@
- `>=v1.0.0, <v2.0.0` 插件配置/数据包含于 `plugin_data.json`
- `< v1.0.0` 插件配置文件为 `pluginConfig.json`

**Full Changelog**: https://github.com/Ljzd-PRO/nonebot-plugin-mystool/compare/v2.4.0…v2.5.0
**Full Changelog**: https://github.com/Ljzd-PRO/nonebot-plugin-mystool/compare/v2.5.0…v2.6.0
173 changes: 92 additions & 81 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-plugin-mystool"
version = "v2.5.0"
version = "v2.6.0"
description = "QQ聊天、频道机器人插件 | 米游社工具-每日米游币任务、游戏签到、商品兑换、免抓包登录、原神崩铁便笺提醒"
license = "MIT"
authors = [
Expand Down
2 changes: 1 addition & 1 deletion src/nonebot_plugin_mystool/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "v2.5.0"
__version__ = "v2.6.0"
22 changes: 21 additions & 1 deletion src/nonebot_plugin_mystool/api/game_sign_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
get_async_retry

__all__ = ["BaseGameSign", "GenshinImpactSign", "HonkaiImpact3Sign", "HoukaiGakuen2Sign", "TearsOfThemisSign",
"StarRailSign"]
"StarRailSign", "ZenlessZoneZeroSign"]


class BaseGameSign:
Expand Down Expand Up @@ -272,8 +272,28 @@ class StarRailSign(BaseGameSign):
game_id = 6


class ZenlessZoneZeroSign(BaseGameSign):
"""
绝区零 游戏签到
"""
name = "绝区零"
act_id = "e202406242138391"
game_id = 8
url_reward = "https://act-nap-api.mihoyo.com/event/luna/zzz/home"
url_info = "https://act-nap-api.mihoyo.com/event/luna/zzz/info"
url_sign = "https://act-nap-api.mihoyo.com/event/luna/zzz/sign"
headers_general = BaseGameSign.headers_general.copy()
headers_reward = BaseGameSign.headers_reward.copy()
for headers in headers_general, headers_reward:
headers["x-rpc-signgame"] = "zzz"
headers["Origin"] = "https://act.mihoyo.com"
headers["Referer"] = "https://act.mihoyo.com/"
headers["Host"] = "act-nap-api.mihoyo.com"


BaseGameSign.available_game_signs.add(GenshinImpactSign)
BaseGameSign.available_game_signs.add(HonkaiImpact3Sign)
BaseGameSign.available_game_signs.add(HoukaiGakuen2Sign)
BaseGameSign.available_game_signs.add(TearsOfThemisSign)
BaseGameSign.available_game_signs.add(StarRailSign)
BaseGameSign.available_game_signs.add(ZenlessZoneZeroSign)
67 changes: 45 additions & 22 deletions src/nonebot_plugin_mystool/api/weibo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import random
import re
import time
from datetime import date
from urllib.parse import unquote

Expand Down Expand Up @@ -53,7 +54,8 @@ def __init__(self, user_data: dict):
"""params: s=xxxxxx; gsid=xxxxxx; aid=xxxxxx; from=xxxxxx"""
self.cookie = Tool.cookie_to_dict(user_data['cookie'])
self.container_id = {'原神': '100808fc439dedbb06ca5fd858848e521b8716',
'崩铁': '100808e1f868bf9980f09ab6908787d7eaf0f0'}
'崩铁': '100808e1f868bf9980f09ab6908787d7eaf0f0',
'绝区零': '100808f303ad099b7730ad1f96ff49726d3ff3'}
self.ua = 'WeiboOverseas/4.4.6 (iPhone; iOS 14.0.1; Scale/2.00)'
self.headers = {'User-Agent': self.ua}
self.follow_data_url = 'https://api.weibo.cn/2/cardlist'
Expand Down Expand Up @@ -106,16 +108,16 @@ async def get_code(self, id: str):
else:
return '获取失败,请重新设置wb_cookie'

async def get_code_list(self):
ticket_id = await self.get_ticket_id # 有活动则返回一个dict,没活动则返回一个str
'''
async def get_code_list(self, ticket_id):
# ticket_id = await self.get_ticket_id # 有活动则返回一个dict,没活动则返回一个str
"""
ticket_id = {
'原神/崩铁': {
'id': [],
'img': ''
}
}
'''
"""
if isinstance(ticket_id, dict):
msg = ""
code = {key: [] for key in ticket_id.keys()}
Expand All @@ -133,7 +135,7 @@ async def get_code_list(self):
"\n2️⃣" \
f" \n{values[1]}" \
"\n3️⃣" \
f" \n{values[2]}"
f" \n{values[2]}\n"
return msg, img
else:
return ticket_id
Expand Down Expand Up @@ -202,6 +204,7 @@ async def ch_list(cls, params_data: dict, wb_userdata: dict):
"cout": 20,
}
params.update(params_data)
params['ul_ctime'] = int(time.time() * 1000)
headers = {
"User-Agent": "Mi+10_12_WeiboIntlAndroid_6020",
"Host": "api.weibo.cn"
Expand All @@ -217,6 +220,8 @@ async def ch_list(cls, params_data: dict, wb_userdata: dict):
return '找不到超话列表'
except IndexError:
return '超话列表为空'
except ValueError:
return '可能是微博相关参数出错,请重新设置'
except Exception as e:
# print(f'{type(e)}: {e}')
return e
Expand All @@ -232,36 +237,54 @@ async def sign(cls, wb_userdata: dict):
}

param_d = Tool.cookie_to_dict(wb_userdata['params'])
cookie = Tool.cookie_to_dict(wb_userdata['cookie'])

params = {
"gsid": param_d['gsid'] if 'gsid' in param_d else None, # 账号身份验证
"s": param_d['s'] if 's' in param_d else None, # 校验参数
"from": param_d['from'] if 'from' in param_d else None, # 客户端身份验证
"c": param_d['c'] if 'c' in param_d else None, # 客户端身份验证
"aid": param_d['aid'] if 'aid' in param_d else None, # 作用未知
"gsid": None, # 账号身份验证
"s": None, # 校验参数
"from": None, # 客户端身份验证
"c": None, # 客户端身份验证
"aid": None, # 作用未知
"ua": "Xiaomi-Mi%2010__weibo__14.2.2__android__android12"
}
params.update(param_d)

msg = f'{date.today()}\n' \
'微博超话签到:\n'
try:
chaohua_list = await cls.ch_list(params, wb_userdata)
chaohua_list = await WeiboSign.ch_list(params, wb_userdata)
if not isinstance(chaohua_list, list):
return f'签到失败请重新签到\n{chaohua_list}'
is_geetest = False
for ch in chaohua_list:
if is_geetest:
break
params_copy = copy.deepcopy(params)
if ch['is_sign'] == '签到':
params_copy['request_url'] = request_url.format(containerid=ch['id'])
async with httpx.AsyncClient() as client:
res = await client.get(url, headers=headers, params=params_copy, timeout=10)
res_data = json.loads(res.text)
if 'msg' in res_data and 'errmsg' not in res_data: # 今日首次签到成功
msg += f"{ch['title_sub']}\n"
elif 'errmsg' in res_data: # 签到出错
# msg = f"{res_data['errmsg']}\n"
msg += f"{ch['title_sub']}\n"
msg += f"--{res_data['errmsg']}\n"
params_copy['ul_ctime'] = int(time.time() * 1000)
pd = True
while pd:
async with httpx.AsyncClient() as client:
res = await client.get(url, headers=headers, cookies=cookie, params=params_copy, timeout=10)
res_data = json.loads(res.text)
logger.info(f'微博签到返回:{res_data}')
if str(res_data.get('result')) == '402004':
msg += '点击链接进行验证后再次签到\n'
msg += res_data.get('scheme')
is_geetest = True
break
elif str(res_data.get('errno')) == '402003':
continue
elif str(res_data.get('result')) == '1':
msg += f"{ch['title_sub']}\n"
pd = False
else:
msg += f"{ch['title_sub']}\n"
msg += f"--{res_data['errmsg'] if res_data.get('errmsg') else res_data['msg']}\n"
pd = False
elif ch['is_sign'] == '已签': # 今日再次进行签到,且之前已经签到成功
msg += f"{ch['title_sub']}\n"
return msg
except Exception as e:
return f'签到失败请重新签到,{e}'
return f'签到失败请重新签到\n{type(e).__name__}:{e}'
91 changes: 54 additions & 37 deletions src/nonebot_plugin_mystool/command/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,18 @@ async def perform_game_sign(
f"\n{award.name} * {award.cnt}" \
f"\n\n📅本月签到次数:{info.total_sign_day}"
img_file = await get_file(award.icon)
onebot_img_msg = OneBotV11MessageSegment.image(img_file)
saa_img = Image(img_file)
qq_guild_img_msg = QQGuildMessageSegment.file_image(img_file)
if img_file:
# onebot_img_msg = OneBotV11MessageSegment.image(img_file)
saa_img = Image(img_file)
qq_guild_img_msg = QQGuildMessageSegment.file_image(img_file)
else:
msg = (f"⚠️账户 {account.display_name} 🎮『{signer.name}』签到失败!请尝试重新签到,"
"若多次失败请尝试重新登录绑定账户")
if matcher:
try:
if isinstance(event, OneBotV11MessageEvent):
await matcher.send(msg + onebot_img_msg)
# await matcher.send(msg + onebot_img_msg)
await matcher.send(msg)
elif isinstance(event, QQGuildMessageEvent):
await matcher.send(msg)
await matcher.send(qq_guild_img_msg)
Expand Down Expand Up @@ -518,7 +520,7 @@ async def genshin_note_check(user: UserData, user_ids: Iterable[str], matcher: M
if note.current_resin >= account.user_resin_threshold:
# 防止重复提醒
if not genshin_notice.current_resin_full:
if note.current_resin == 160:
if note.current_resin == 200:
genshin_notice.current_resin_full = True
msg += '❕您的树脂已经满啦\n'
do_notice = True
Expand Down Expand Up @@ -560,7 +562,7 @@ async def genshin_note_check(user: UserData, user_ids: Iterable[str], matcher: M

msg += "❖原神·实时便笺❖" \
f"\n🆔账户 {account.display_name}" \
f"\n⏳树脂数量:{note.current_resin} / 160" \
f"\n⏳树脂数量:{note.current_resin} / 200" \
f"\n⏱️树脂{note.resin_recovery_text}" \
f"\n🕰️探索派遣:{note.current_expedition_num} / {note.max_expedition_num}" \
f"\n📅每日委托:{4 - note.finished_task_num} 个任务未完成" \
Expand Down Expand Up @@ -678,16 +680,21 @@ async def weibo_sign_check(user: UserData, user_ids: Iterable[str], matcher: Mat
:param user_ids: 发送通知的所有用户ID
:param matcher: nonebot ``Matcher``
"""
for user_data in user.weibo:
msg = await WeiboSign.sign(user_data)
if user.enable_weibo:
for user_data in user.weibo:
msg = await WeiboSign.sign(user_data)
if matcher:
await matcher.send(message=msg)
else:
for user_id in user_ids:
await send_private_msg(user_id=user_id, message=msg)
else:
message = "未开启微博自动签到功能"
if matcher:
await matcher.send(message=msg)
else:
for user_id in user_ids:
await send_private_msg(user_id=user_id, message=msg)
await matcher.send(message)


async def weibo_code_check(user: UserData, user_ids: Iterable[str], matcher: Matcher = None):
async def weibo_code_check(user: UserData, user_ids: Iterable[str], mode=0, matcher: Matcher = None):
"""
是否开启微博兑换码功能的函数,并发送给用户任务执行消息。
Expand All @@ -700,31 +707,41 @@ async def weibo_code_check(user: UserData, user_ids: Iterable[str], matcher: Mat
# account = UserAccount(account)
for user_data in user.weibo:
msg, img = None, None
start = True
weibo = WeiboCode(user_data)
result = await weibo.get_code_list()
try:
if isinstance(result, tuple):
msg, img = result
else:
msg = result
except Exception:
pass
if matcher:
if img:
onebot_img_msg = OneBotV11MessageSegment.image(await get_file(img))
messages = msg + onebot_img_msg
ticket_id = await weibo.get_ticket_id
if mode == 1:
if isinstance(ticket_id, dict):
await weibo_sign_check(user=user, user_ids=user_ids)
else:
messages = msg
await matcher.send(messages)
else:
if img and '无' not in msg:
saa_img = Image(await get_file(img))
messages = msg + saa_img
for user_id in user_ids:
logger.info(f"检测到当前超话有兑换码,正在给{user_id}推送信息中")
await send_private_msg(user_id=user_id, message=messages)
start = False
if start:
try:
for key, value in ticket_id.items():
one_id = {key: value}
result = await weibo.get_code_list(one_id)
if isinstance(result, tuple):
msg, img = result
else:
msg = result
if matcher:
if img:
onebot_img_msg = OneBotV11MessageSegment.image(await get_file(img))
messages = msg + onebot_img_msg
else:
messages = msg
await matcher.send(messages)
else:
if img and '无' not in msg:
saa_img = Image(await get_file(img))
messages = msg + saa_img
for user_id in user_ids:
logger.info(f"检测到当前超话有兑换码,正在给{user_id}推送信息中")
await send_private_msg(user_id=user_id, message=messages)
except Exception:
pass
else:
message = "未开启微博功能"
message = "未开启微博兑换功能"
if matcher:
await matcher.send(message)

Expand Down Expand Up @@ -780,6 +797,6 @@ async def auto_weibo_check():
logger.info(f"{plugin_config.preference.log_head}开始执行微博自动任务")
for user_id, user in get_unique_users():
user_ids = [user_id] + list(get_all_bind(user_id))
await weibo_sign_check(user=user, user_ids=user_ids)
await weibo_code_check(user=user, user_ids=user_ids)
# await weibo_sign_check(user=user, user_ids=user_ids)
await weibo_code_check(user=user, user_ids=user_ids, mode=1)
logger.info(f"{plugin_config.preference.log_head}微博自动任务执行完成")
Loading

0 comments on commit a0dd139

Please sign in to comment.