Skip to content

Commit

Permalink
Merge pull request #239 from Ljzd-PRO/dev
Browse files Browse the repository at this point in the history
更新至 v1.4.4
  • Loading branch information
Ljzd-PRO authored Dec 28, 2023
2 parents ffdb078 + 4b0c8fd commit 2cd8427
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 19 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@

## 📣 更新内容

### 2023.12.2 - v1.4.4
- 增加管理员名单,管理员可为指定的用户执行游戏签到和米游币任务 #238
- 需要设置配置文件中 `preference.enable_admin_list``true` 以开启
- 默认管理员名单文件路径:`data/nonebot-plugin-mystool/admin_list.txt`
> 配置文件目录:`data/nonebot-plugin-mystool/plugin_data.json` \
> 更多请参考 [插件偏好设置 - enable_admin_list](https://github.com/Ljzd-PRO/nonebot-plugin-mystool/wiki/Configuration-Preference#enable_admin_list)
- 修复未绑定米游社账户时执行米游社任务命令可能出现异常的问题

### 2023.12.2 - v1.4.3
- 修复米游社任务和账号设置相关Bug #226 by @SaYa-t
- 修改“崩坏:星穹铁道”便笺体力提醒阈值默认值 by @Joseandluue
- 解决“崩坏:星穹铁道”实训/宇宙在凌晨推送通知的问题 by @Joseandluue

### 2023.12.2 - v1.4.2
- 修复“崩坏:星穹铁道”米游币任务实际在“综合”频道执行的问题 by @Yinhaoran1128
- 增加“绝区零”频道米游币任务支持
- “大别野”频道名更改为“综合”
- “原神”游戏签到API更新,解决无法签到的问题 by @Joseandluue @Yinhaoran1128
- 修复无法从 adapter-qq 适配器响应命令事件的问题 by @JaniQuiz

### 2023.11.13 - v1.4.0
- 跟进QQ频道适配器的变更,已更换停止维护的 `nonebot-adapter-qqguild` 适配器为 `nonebot-adapter-qq`

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-plugin-mystool"
version = "v1.4.3"
version = "v1.4.4"
description = "QQ聊天、频道机器人插件 | 米游社工具-每日米游币任务、游戏签到、商品兑换、免抓包登录、原神崩铁便笺提醒"
license = "MIT"
authors = [
Expand All @@ -24,7 +24,7 @@ packages = [

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
httpx = ">=0.24.1,<0.26.0"
httpx = ">=0.24.1,<0.27.0"
nonebot_plugin_apscheduler = ">=0.2.0"
ntplib = "^0.4.0"
Pillow = ">=9.5,<11.0"
Expand All @@ -42,7 +42,7 @@ nonebot2 = { version = "^2.0.1", extras = ["fastapi", "httpx", "websockets"] }
nonebug = "^0.3.4"
pytest = "^7.4.0"
pytest-html = ">=3.2,<5.0"
pytest-asyncio = "^0.21.0"
pytest-asyncio = ">=0.21,<0.24"
flake8 = "^6.1.0"

[tool.poetry.group.test]
Expand Down
69 changes: 61 additions & 8 deletions src/nonebot_plugin_mystool/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from nonebot.adapters.qq.exception import AuditException
from nonebot.exception import ActionFailed
from nonebot.internal.matcher import Matcher
from nonebot.params import CommandArg
from nonebot_plugin_apscheduler import scheduler
from pydantic import BaseModel

Expand All @@ -24,7 +25,7 @@
from .simple_api import genshin_note, get_game_record, starrail_note
from .user_data import UserData
from .utils import get_file, logger, COMMAND_BEGIN, GeneralMessageEvent, send_private_msg, get_all_bind, \
get_unique_users, get_validate
get_unique_users, get_validate, read_admin_list

_conf = PluginDataManager.plugin_data

Expand All @@ -34,16 +35,43 @@


@manually_game_sign.handle()
async def _(event: Union[GeneralMessageEvent], matcher: Matcher):
async def _(event: Union[GeneralMessageEvent], matcher: Matcher, command_arg=CommandArg()):
"""
手动游戏签到函数
"""
user_id = event.get_user_id()
user = _conf.users.get(user_id)
if not user or not user.accounts:
await manually_game_sign.finish(f"⚠️你尚未绑定米游社账户,请先使用『{COMMAND_BEGIN}登录』进行登录")
await manually_game_sign.send("⏳开始游戏签到...")
await perform_game_sign(user=user, user_ids=[user_id], matcher=matcher, event=event)
if command_arg:
if (specified_user_id := str(command_arg)) == "*" or specified_user_id.isdigit():
if user_id not in read_admin_list():
await manually_game_sign.finish("⚠️你暂无权限执行此操作,只有管理员名单中的用户可以执行此操作")
else:
if specified_user_id == "*":
await manually_game_sign.send("⏳开始为所有用户执行游戏签到...")
for user_id_, user_ in get_unique_users():
await manually_game_sign.send(f"⏳开始为用户 {user_id_} 执行游戏签到...")
await perform_game_sign(
user=user_,
user_ids=[],
matcher=matcher,
event=event
)
else:
specified_user = _conf.users.get(specified_user_id)
if not specified_user:
await manually_game_sign.finish(f"⚠️未找到用户 {specified_user_id}")
await manually_game_sign.send(f"⏳开始为用户 {specified_user_id} 执行游戏签到...")
await perform_game_sign(
user=specified_user,
user_ids=[],
matcher=matcher,
event=event
)
else:
await manually_game_sign.send("⏳开始游戏签到...")
await perform_game_sign(user=user, user_ids=[user_id], matcher=matcher, event=event)


manually_bbs_sign = on_command(_conf.preference.command_start + '任务', priority=5, block=True)
Expand All @@ -52,16 +80,41 @@ async def _(event: Union[GeneralMessageEvent], matcher: Matcher):


@manually_bbs_sign.handle()
async def _(event: Union[GeneralMessageEvent], matcher: Matcher):
async def _(event: Union[GeneralMessageEvent], matcher: Matcher, command_arg=CommandArg()):
"""
手动米游币任务函数
"""
user_id = event.get_user_id()
user = _conf.users.get(user_id)
if not user or not user.accounts:
await manually_game_sign.finish(f"⚠️你尚未绑定米游社账户,请先使用『{COMMAND_BEGIN}登录』进行登录")
await manually_game_sign.send("⏳开始执行米游币任务...")
await perform_bbs_sign(user=user, user_ids=[user_id], matcher=matcher)
await manually_bbs_sign.finish(f"⚠️你尚未绑定米游社账户,请先使用『{COMMAND_BEGIN}登录』进行登录")
if command_arg:
if (specified_user_id := str(command_arg)) == "*" or specified_user_id.isdigit():
if user_id not in read_admin_list():
await manually_bbs_sign.finish("⚠️你暂无权限执行此操作,只有管理员名单中的用户可以执行此操作")
else:
if specified_user_id == "*":
await manually_bbs_sign.send("⏳开始为所有用户执行米游币任务...")
for user_id_, user_ in get_unique_users():
await manually_bbs_sign.send(f"⏳开始为用户 {user_id_} 执行米游币任务...")
await perform_bbs_sign(
user=user_,
user_ids=[],
matcher=matcher
)
else:
specified_user = _conf.users.get(specified_user_id)
if not specified_user:
await manually_bbs_sign.finish(f"⚠️未找到用户 {specified_user_id}")
await manually_bbs_sign.send(f"⏳开始为用户 {specified_user_id} 执行米游币任务...")
await perform_bbs_sign(
user=specified_user,
user_ids=[],
matcher=matcher
)
else:
await manually_bbs_sign.send("⏳开始执行米游币任务...")
await perform_bbs_sign(user=user, user_ids=[user_id], matcher=matcher)


class GenshinNoteNotice(GenshinNote):
Expand Down
6 changes: 5 additions & 1 deletion src/nonebot_plugin_mystool/plugin_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from . import user_data
from .user_data import UserData, UserAccount

VERSION = "v1.4.3"
VERSION = "v1.4.4"
"""程序当前版本"""

ROOT_PATH = Path(__name__).parent.absolute()
Expand Down Expand Up @@ -106,6 +106,10 @@ class Preference(BaseSettings, extra=Extra.ignore):
"""是否启用用户白名单"""
whitelist_path: Optional[Path] = DATA_PATH / "whitelist.txt"
"""用户白名单文件路径"""
enable_admin_list: bool = False
"""是否启用管理员名单"""
admin_list_path: Optional[Path] = DATA_PATH / "admin_list.txt"
"""管理员名单文件路径"""

@validator("log_path", allow_reuse=True)
def _(cls, v: Optional[Path]):
Expand Down
9 changes: 9 additions & 0 deletions src/nonebot_plugin_mystool/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,12 @@ def read_whitelist() -> List[str]:
:return: 白名单中的所有用户ID
"""
return _read_user_list(_conf.preference.whitelist_path) if _conf.preference.enable_whitelist else []


def read_admin_list() -> List[str]:
"""
读取白名单
:return: 管理员名单中的所有用户ID
"""
return _read_user_list(_conf.preference.admin_list_path) if _conf.preference.enable_admin_list else []

0 comments on commit 2cd8427

Please sign in to comment.