mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 13:38:43 +00:00
fix(debug): 增加每次增量分析完成后发送的配置,用于调试
This commit is contained in:
@@ -226,6 +226,12 @@
|
|||||||
"default": false,
|
"default": false,
|
||||||
"hint": "启用后,插件会在一天内多次进行小规模分析并累积结果,最终在报告时间汇总输出。适用于消息量大的群聊,可显著提升分析覆盖率和24小时活跃图表准确性。关闭时保持传统的单次全量分析模式。"
|
"hint": "启用后,插件会在一天内多次进行小规模分析并累积结果,最终在报告时间汇总输出。适用于消息量大的群聊,可显著提升分析覆盖率和24小时活跃图表准确性。关闭时保持传统的单次全量分析模式。"
|
||||||
},
|
},
|
||||||
|
"incremental_report_immediately": {
|
||||||
|
"type": "bool",
|
||||||
|
"description": "增量分析立即报告(调试用)",
|
||||||
|
"default": false,
|
||||||
|
"hint": "【调试功能】启用后,每次增量分析完成后都会立即生成并发送一份最终报告。仅建议在调试时开启,生产环境请保持关闭,否则会频繁打扰群友。"
|
||||||
|
},
|
||||||
"incremental_interval_minutes": {
|
"incremental_interval_minutes": {
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"description": "增量分析间隔(分钟)",
|
"description": "增量分析间隔(分钟)",
|
||||||
|
|||||||
@@ -606,6 +606,7 @@ class QQGroupDailyAnalysis(Star):
|
|||||||
- status: 查看当前状态
|
- status: 查看当前状态
|
||||||
- reload: 重新加载配置并重启定时任务
|
- reload: 重新加载配置并重启定时任务
|
||||||
- test: 测试自动分析功能
|
- test: 测试自动分析功能
|
||||||
|
- incremental_debug: 切换增量分析立即报告模式(调试用)
|
||||||
"""
|
"""
|
||||||
group_id = self._get_group_id_from_event(event)
|
group_id = self._get_group_id_from_event(event)
|
||||||
|
|
||||||
@@ -711,6 +712,13 @@ class QQGroupDailyAnalysis(Star):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
yield event.plain_result(f"❌ 自动分析测试失败: {str(e)}")
|
yield event.plain_result(f"❌ 自动分析测试失败: {str(e)}")
|
||||||
|
|
||||||
|
elif action == "incremental_debug":
|
||||||
|
current_state = self.config_manager.get_incremental_report_immediately()
|
||||||
|
new_state = not current_state
|
||||||
|
self.config_manager.set_incremental_report_immediately(new_state)
|
||||||
|
status_text = "已启用" if new_state else "已禁用"
|
||||||
|
yield event.plain_result(f"✅ 增量分析立即报告模式: {status_text}")
|
||||||
|
|
||||||
else: # status
|
else: # status
|
||||||
is_allowed = self.config_manager.is_group_allowed(group_id)
|
is_allowed = self.config_manager.is_group_allowed(group_id)
|
||||||
status = "已启用" if is_allowed else "未启用"
|
status = "已启用" if is_allowed else "未启用"
|
||||||
@@ -738,15 +746,19 @@ class QQGroupDailyAnalysis(Star):
|
|||||||
f"活跃时段{active_start}:00-{active_end}:00)"
|
f"活跃时段{active_start}:00-{active_end}:00)"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
debug_report = self.config_manager.get_incremental_report_immediately()
|
||||||
|
debug_status = "✅ 开启" if debug_report else "❌ 关闭"
|
||||||
|
|
||||||
yield event.plain_result(f"""📊 当前群分析功能状态:
|
yield event.plain_result(f"""📊 当前群分析功能状态:
|
||||||
• 群分析功能: {status} (模式: {mode})
|
• 群分析功能: {status} (模式: {mode})
|
||||||
• 自动分析: {auto_status} ({auto_time})
|
• 自动分析: {auto_status} ({auto_time})
|
||||||
• 增量分析: {incremental_status_text}
|
• 增量分析: {incremental_status_text}
|
||||||
|
• 调试模式: {debug_status} (增量立即报告)
|
||||||
• 输出格式: {output_format}
|
• 输出格式: {output_format}
|
||||||
• PDF 功能: {pdf_status}
|
• PDF 功能: {pdf_status}
|
||||||
• 最小消息数: {min_threshold}
|
• 最小消息数: {min_threshold}
|
||||||
|
|
||||||
💡 可用命令: enable, disable, status, reload, test
|
💡 可用命令: enable, disable, status, reload, test, incremental_debug
|
||||||
💡 支持的输出格式: image, text, pdf (图片和PDF包含活跃度可视化)
|
💡 支持的输出格式: image, text, pdf (图片和PDF包含活跃度可视化)
|
||||||
💡 其他命令: /设置格式, /安装PDF, /增量状态""")
|
💡 其他命令: /设置格式, /安装PDF, /增量状态""")
|
||||||
|
|
||||||
|
|||||||
@@ -121,11 +121,15 @@ class ConfigManager:
|
|||||||
|
|
||||||
def get_user_title_analysis_enabled(self) -> bool:
|
def get_user_title_analysis_enabled(self) -> bool:
|
||||||
"""获取是否启用用户称号分析"""
|
"""获取是否启用用户称号分析"""
|
||||||
return self._get_group("analysis_features").get("user_title_analysis_enabled", True)
|
return self._get_group("analysis_features").get(
|
||||||
|
"user_title_analysis_enabled", True
|
||||||
|
)
|
||||||
|
|
||||||
def get_golden_quote_analysis_enabled(self) -> bool:
|
def get_golden_quote_analysis_enabled(self) -> bool:
|
||||||
"""获取是否启用金句分析"""
|
"""获取是否启用金句分析"""
|
||||||
return self._get_group("analysis_features").get("golden_quote_analysis_enabled", True)
|
return self._get_group("analysis_features").get(
|
||||||
|
"golden_quote_analysis_enabled", True
|
||||||
|
)
|
||||||
|
|
||||||
def get_max_topics(self) -> int:
|
def get_max_topics(self) -> int:
|
||||||
"""获取最大话题数量"""
|
"""获取最大话题数量"""
|
||||||
@@ -216,7 +220,9 @@ class ConfigManager:
|
|||||||
|
|
||||||
def get_user_title_analysis_prompt(self, style: str = "user_title_prompt") -> str:
|
def get_user_title_analysis_prompt(self, style: str = "user_title_prompt") -> str:
|
||||||
"""获取用户称号分析提示词模板"""
|
"""获取用户称号分析提示词模板"""
|
||||||
prompts_config = self._get_group("prompts").get("user_title_analysis_prompts", {})
|
prompts_config = self._get_group("prompts").get(
|
||||||
|
"user_title_analysis_prompts", {}
|
||||||
|
)
|
||||||
prompt = prompts_config.get(style, "")
|
prompt = prompts_config.get(style, "")
|
||||||
if prompt:
|
if prompt:
|
||||||
return prompt
|
return prompt
|
||||||
@@ -226,7 +232,9 @@ class ConfigManager:
|
|||||||
self, style: str = "golden_quote_prompt"
|
self, style: str = "golden_quote_prompt"
|
||||||
) -> str:
|
) -> str:
|
||||||
"""获取金句分析提示词模板"""
|
"""获取金句分析提示词模板"""
|
||||||
prompts_config = self._get_group("prompts").get("golden_quote_analysis_prompts", {})
|
prompts_config = self._get_group("prompts").get(
|
||||||
|
"golden_quote_analysis_prompts", {}
|
||||||
|
)
|
||||||
prompt = prompts_config.get(style, "")
|
prompt = prompts_config.get(style, "")
|
||||||
if prompt:
|
if prompt:
|
||||||
return prompt
|
return prompt
|
||||||
@@ -317,7 +325,9 @@ class ConfigManager:
|
|||||||
|
|
||||||
def set_golden_quote_analysis_enabled(self, enabled: bool):
|
def set_golden_quote_analysis_enabled(self, enabled: bool):
|
||||||
"""设置是否启用金句分析"""
|
"""设置是否启用金句分析"""
|
||||||
self._ensure_group("analysis_features")["golden_quote_analysis_enabled"] = enabled
|
self._ensure_group("analysis_features")["golden_quote_analysis_enabled"] = (
|
||||||
|
enabled
|
||||||
|
)
|
||||||
self.config.save_config()
|
self.config.save_config()
|
||||||
|
|
||||||
def set_max_topics(self, count: int):
|
def set_max_topics(self, count: int):
|
||||||
@@ -364,6 +374,17 @@ class ConfigManager:
|
|||||||
"""获取是否启用增量分析模式"""
|
"""获取是否启用增量分析模式"""
|
||||||
return self._get_group("incremental").get("incremental_enabled", False)
|
return self._get_group("incremental").get("incremental_enabled", False)
|
||||||
|
|
||||||
|
def get_incremental_report_immediately(self) -> bool:
|
||||||
|
"""获取是否启用增量分析立即发送报告(调试用)"""
|
||||||
|
return self._get_group("incremental").get(
|
||||||
|
"incremental_report_immediately", False
|
||||||
|
)
|
||||||
|
|
||||||
|
def set_incremental_report_immediately(self, enabled: bool):
|
||||||
|
"""设置增量分析是否立即发送报告"""
|
||||||
|
self._ensure_group("incremental")["incremental_report_immediately"] = enabled
|
||||||
|
self.config.save_config()
|
||||||
|
|
||||||
def get_incremental_interval_minutes(self) -> int:
|
def get_incremental_interval_minutes(self) -> int:
|
||||||
"""获取增量分析间隔(分钟)"""
|
"""获取增量分析间隔(分钟)"""
|
||||||
return self._get_group("incremental").get("incremental_interval_minutes", 120)
|
return self._get_group("incremental").get("incremental_interval_minutes", 120)
|
||||||
|
|||||||
@@ -202,9 +202,7 @@ class AutoScheduler:
|
|||||||
f"已注册增量分析任务: {hour:02d}:{minute:02d} (Job ID: {job_id})"
|
f"已注册增量分析任务: {hour:02d}:{minute:02d} (Job ID: {job_id})"
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(f"注册增量分析任务失败 ({hour:02d}:{minute:02d}): {e}")
|
||||||
f"注册增量分析任务失败 ({hour:02d}:{minute:02d}): {e}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# 注册最终报告生成任务(使用配置的自动分析时间点)
|
# 注册最终报告生成任务(使用配置的自动分析时间点)
|
||||||
time_config = self.config_manager.get_auto_analysis_time()
|
time_config = self.config_manager.get_auto_analysis_time()
|
||||||
@@ -227,9 +225,7 @@ class AutoScheduler:
|
|||||||
misfire_grace_time=60,
|
misfire_grace_time=60,
|
||||||
)
|
)
|
||||||
self.scheduler_job_ids.append(job_id)
|
self.scheduler_job_ids.append(job_id)
|
||||||
logger.info(
|
logger.info(f"已注册增量最终报告任务: {t_str} (Job ID: {job_id})")
|
||||||
f"已注册增量最终报告任务: {t_str} (Job ID: {job_id})"
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"注册增量最终报告任务失败 ({t_str}): {e}")
|
logger.error(f"注册增量最终报告任务失败 ({t_str}): {e}")
|
||||||
|
|
||||||
@@ -478,10 +474,26 @@ class AutoScheduler:
|
|||||||
# 按索引交错延迟,均匀分散 API 压力
|
# 按索引交错延迟,均匀分散 API 压力
|
||||||
if idx > 0 and stagger > 0:
|
if idx > 0 and stagger > 0:
|
||||||
await asyncio.sleep(stagger * idx)
|
await asyncio.sleep(stagger * idx)
|
||||||
return await self._perform_incremental_analysis_for_group_with_timeout(
|
|
||||||
gid, pid
|
result = (
|
||||||
|
await self._perform_incremental_analysis_for_group_with_timeout(
|
||||||
|
gid, pid
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 检查是否需要立即发送报告(调试模式)
|
||||||
|
if self.config_manager.get_incremental_report_immediately():
|
||||||
|
if isinstance(result, dict) and result.get("success"):
|
||||||
|
logger.info(
|
||||||
|
f"增量分析立即报告模式生效,正在为群 {gid} 生成报告..."
|
||||||
|
)
|
||||||
|
# 立即生成最终报告
|
||||||
|
await self._perform_incremental_final_report_for_group_with_timeout(
|
||||||
|
gid, pid
|
||||||
|
)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
analysis_tasks = []
|
analysis_tasks = []
|
||||||
for idx, (gid, pid) in enumerate(target_list):
|
for idx, (gid, pid) in enumerate(target_list):
|
||||||
task = asyncio.create_task(
|
task = asyncio.create_task(
|
||||||
@@ -586,9 +598,7 @@ class AutoScheduler:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(f"群 {group_id} 增量分析执行失败: {e}", exc_info=True)
|
||||||
f"群 {group_id} 增量分析执行失败: {e}", exc_info=True
|
|
||||||
)
|
|
||||||
return {"success": False, "reason": str(e)}
|
return {"success": False, "reason": str(e)}
|
||||||
finally:
|
finally:
|
||||||
logger.debug(f"群 {group_id} 增量分析流程结束")
|
logger.debug(f"群 {group_id} 增量分析流程结束")
|
||||||
@@ -707,9 +717,7 @@ class AutoScheduler:
|
|||||||
|
|
||||||
# 检查平台状态
|
# 检查平台状态
|
||||||
if not self.bot_manager.is_ready_for_auto_analysis():
|
if not self.bot_manager.is_ready_for_auto_analysis():
|
||||||
logger.warning(
|
logger.warning(f"群 {group_id} 最终报告跳过:bot管理器未就绪")
|
||||||
f"群 {group_id} 最终报告跳过:bot管理器未就绪"
|
|
||||||
)
|
|
||||||
return {"success": False, "reason": "bot_not_ready"}
|
return {"success": False, "reason": "bot_not_ready"}
|
||||||
|
|
||||||
# 委派给应用层服务执行最终报告用例
|
# 委派给应用层服务执行最终报告用例
|
||||||
@@ -756,9 +764,7 @@ class AutoScheduler:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(f"群 {group_id} 最终报告执行失败: {e}", exc_info=True)
|
||||||
f"群 {group_id} 最终报告执行失败: {e}", exc_info=True
|
|
||||||
)
|
|
||||||
return {"success": False, "reason": str(e)}
|
return {"success": False, "reason": str(e)}
|
||||||
finally:
|
finally:
|
||||||
logger.debug(f"群 {group_id} 最终报告流程结束")
|
logger.debug(f"群 {group_id} 最终报告流程结束")
|
||||||
@@ -787,9 +793,7 @@ class AutoScheduler:
|
|||||||
adapter_ids = list(self.bot_manager._adapters.keys())
|
adapter_ids = list(self.bot_manager._adapters.keys())
|
||||||
|
|
||||||
# 调试模式下记录详细信息,INFO级别仅显示概览
|
# 调试模式下记录详细信息,INFO级别仅显示概览
|
||||||
logger.debug(
|
logger.debug(f"[AutoScheduler] Bot实例: {bot_ids}, 适配器: {adapter_ids}")
|
||||||
f"[AutoScheduler] Bot实例: {bot_ids}, 适配器: {adapter_ids}"
|
|
||||||
)
|
|
||||||
|
|
||||||
if not bot_ids:
|
if not bot_ids:
|
||||||
logger.warning("[AutoScheduler] 自动发现后未找到任何Bot实例")
|
logger.warning("[AutoScheduler] 自动发现后未找到任何Bot实例")
|
||||||
|
|||||||
Reference in New Issue
Block a user