feat(plugin-schedule): add DB-driven plugin scheduler and xiuren scheduled push
This commit is contained in:
@@ -221,6 +221,76 @@ class XiurenImagePlugin(MessagePluginInterface):
|
||||
self.LOG.error(f"从 Redis 获取并删除随机图片失败: {e}")
|
||||
return None
|
||||
|
||||
def get_schedule_actions(self) -> List[Dict[str, Any]]:
|
||||
"""插件可调度动作定义。"""
|
||||
return [
|
||||
{
|
||||
"action_key": "daily_push",
|
||||
"name": "秀人群发推送",
|
||||
"description": "按调度时间向目标群发送秀人图片",
|
||||
"trigger_type": "at_times",
|
||||
"trigger_config": {"time_list": ["17:30"]},
|
||||
"target_scope": "all_enabled_groups",
|
||||
"target_config": {},
|
||||
"payload": {"max_per_group": 1},
|
||||
"default_enabled": False,
|
||||
}
|
||||
]
|
||||
|
||||
async def run_scheduled_action(self, action_key: str, context: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""执行插件定时动作。"""
|
||||
if action_key != "daily_push":
|
||||
return {
|
||||
"success": False,
|
||||
"summary": f"不支持的动作: {action_key}",
|
||||
"detail": {"action_key": action_key},
|
||||
}
|
||||
|
||||
if not self.bot:
|
||||
return {
|
||||
"success": False,
|
||||
"summary": "bot 未注入,无法执行群发",
|
||||
"detail": {},
|
||||
}
|
||||
|
||||
target_groups = context.get("target_groups") or []
|
||||
if not target_groups:
|
||||
return {
|
||||
"success": False,
|
||||
"summary": "没有可发送的目标群",
|
||||
"detail": {"target_groups": []},
|
||||
}
|
||||
|
||||
payload = context.get("payload") or {}
|
||||
max_per_group = max(1, int(payload.get("max_per_group", 1)))
|
||||
success_groups = []
|
||||
failed_groups = {}
|
||||
|
||||
for group_id in target_groups:
|
||||
try:
|
||||
for _ in range(max_per_group):
|
||||
cached_image = self._get_cached_image()
|
||||
if not cached_image:
|
||||
raise RuntimeError("未找到图片资源")
|
||||
await self.bot.send_image_message(group_id, cached_image["bytes"])
|
||||
success_groups.append(group_id)
|
||||
except Exception as e:
|
||||
failed_groups[group_id] = str(e)
|
||||
|
||||
success_count = len(success_groups)
|
||||
fail_count = len(failed_groups)
|
||||
summary = f"秀人群发完成: 成功 {success_count} 群, 失败 {fail_count} 群"
|
||||
return {
|
||||
"success": fail_count == 0,
|
||||
"summary": summary,
|
||||
"detail": {
|
||||
"target_count": len(target_groups),
|
||||
"success_groups": success_groups,
|
||||
"failed_groups": failed_groups,
|
||||
"max_per_group": max_per_group,
|
||||
},
|
||||
}
|
||||
|
||||
# def _get_random_pic(self) -> Optional[str]:
|
||||
# """获取随机图片路径"""
|
||||
# try:
|
||||
|
||||
Reference in New Issue
Block a user