mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-08 05:10:01 +08:00
✨ feat(core): 增强定时任务与群组标签管理,重构调度核心 (#2068)
* ✨ feat(core): 更新群组信息、Markdown 样式与 Pydantic 兼容层 - 【group】添加更新所有群组信息指令,并同步群组控制台数据 - 【markdown】支持合并 Markdown 的 CSS 来源 - 【pydantic-compat】提供 model_validate 兼容函数 * ✨ feat(core): 增强定时任务与群组标签管理,重构调度核心 ✨ 新功能 * **标签 (tags)**: 引入群组标签服务。 * 支持静态标签和动态标签 (基于 Alconna 规则自动匹配群信息)。 * 支持黑名单模式及 `@all` 特殊标签。 * 提供 `tag_manage` 超级用户插件 (list, create, edit, delete 等)。 * 群成员变动时自动失效动态标签缓存。 * **调度 (scheduler)**: 增强定时任务。 * 重构 `ScheduledJob` 模型,支持 `TAG`, `ALL_GROUPS` 等多种目标类型。 * 新增任务别名 (`name`)、创建者、权限、来源等字段。 * 支持一次性任务 (`schedule_once`) 和 Alconna 命令行参数 (`--params-cli`)。 * 新增执行选项 (`jitter`, `spread`) 和并发策略 (`ALLOW`, `SKIP`, `QUEUE`)。 * 支持批量获取任务状态。 ♻️ 重构优化 * **调度器核心**: * 拆分 `service.py` 为 `manager.py` (API) 和 `types.py` (模型)。 * 合并 `adapter.py` / `job.py` 至 `engine.py` (统一调度引擎)。 * 引入 `targeting.py` 模块管理任务目标解析。 * **调度器插件 (scheduler_admin)**: * 迁移命令参数校验逻辑至 `ArparmaBehavior`。 * 引入 `dependencies.py` 和 `data_source.py` 解耦业务逻辑与依赖注入。 * 适配新的任务目标类型展示。 * 🐛 fix(tag): 修复黑名单标签解析逻辑并优化标签详情展示 * ✨ feat(scheduler): 为多目标定时任务添加固定间隔串行执行选项 * ✨ feat(schedulerAdmin): 允许定时任务删除、暂停、恢复命令支持多ID操作 * 🚨 auto fix by pre-commit hooks --------- Co-authored-by: webjoin111 <455457521@qq.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
webjoin111
pre-commit-ci[bot]
parent
eb6d90ae88
commit
70bde00757
@@ -48,13 +48,13 @@ class TimeUtils:
|
||||
@classmethod
|
||||
def parse_time_string(cls, time_str: str) -> int:
|
||||
"""
|
||||
将带有单位的时间字符串 (e.g., "10s", "5m", "1h") 解析为总秒数。
|
||||
将带有单位的时间字符串 (e.g., "10s", "5m", "1h", "1d") 解析为总秒数。
|
||||
"""
|
||||
time_str = time_str.lower().strip()
|
||||
match = re.match(r"^(\d+)([smh])$", time_str)
|
||||
match = re.match(r"^(\d+)([smhd])$", time_str)
|
||||
if not match:
|
||||
raise ValueError(
|
||||
f"无效的时间格式: '{time_str}'。请使用如 '30s', '10m', '2h' 的格式。"
|
||||
f"无效的时间格式: '{time_str}'。请使用如 '30s', '10m', '2h', '1d'的格式"
|
||||
)
|
||||
|
||||
value, unit = int(match.group(1)), match.group(2)
|
||||
@@ -65,8 +65,34 @@ class TimeUtils:
|
||||
return value * 60
|
||||
if unit == "h":
|
||||
return value * 3600
|
||||
if unit == "d":
|
||||
return value * 86400
|
||||
return 0
|
||||
|
||||
@classmethod
|
||||
def parse_interval_to_dict(cls, interval_str: str) -> dict:
|
||||
"""
|
||||
将时间间隔字符串解析为 APScheduler 的 interval 触发器所需的字典。
|
||||
"""
|
||||
time_str_lower = interval_str.lower().strip()
|
||||
match = re.match(r"^(\d+)([smhd])$", time_str_lower)
|
||||
if not match:
|
||||
raise ValueError(
|
||||
"时间间隔格式错误, 请使用如 '30m', '2h', '1d', '10s' 的格式。"
|
||||
)
|
||||
|
||||
value, unit = int(match.group(1)), match.group(2)
|
||||
|
||||
if unit == "s":
|
||||
return {"seconds": value}
|
||||
if unit == "m":
|
||||
return {"minutes": value}
|
||||
if unit == "h":
|
||||
return {"hours": value}
|
||||
if unit == "d":
|
||||
return {"days": value}
|
||||
return {}
|
||||
|
||||
@classmethod
|
||||
def format_duration(cls, seconds: float) -> str:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user