From 93b2b847efdae3d3b753ae563145269a3e374344 Mon Sep 17 00:00:00 2001 From: SXP-Simon Date: Tue, 7 Apr 2026 22:27:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(output=5Fformat):=20=E6=94=B9=E4=B8=BA=20op?= =?UTF-8?q?tions=20=E5=BD=A2=E5=BC=8F=E5=A4=84=E7=90=86=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E5=8D=87=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _conf_schema.json | 7 ++- main.py | 52 ++++++++++++++------- src/infrastructure/config/config_manager.py | 6 ++- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/_conf_schema.json b/_conf_schema.json index e629cb1..9ad46f1 100644 --- a/_conf_schema.json +++ b/_conf_schema.json @@ -60,8 +60,13 @@ "output_format": { "type": "string", "description": "输出格式", + "options": [ + "image", + "text", + "html" + ], "default": "image", - "hint": "分析报告的输出格式:image(图片)、text(文本)、html(HTML文件)。" + "hint": "选择分析报告的输出方式:image(图片)、text(纯文本摘要)、html(可交互式网页文件)" }, "report_template": { "type": "string", diff --git a/main.py b/main.py index b404982..be6a60e 100644 --- a/main.py +++ b/main.py @@ -660,36 +660,56 @@ class GroupDailyAnalysis(Star): @filter.command("设置格式", alias={"set_format"}) @filter.permission_type(PermissionType.ADMIN) - async def set_output_format(self, event: AstrMessageEvent, format_type: str = ""): + async def set_output_format(self, event: AstrMessageEvent, format_input: str = ""): """ 设置分析报告输出格式(跨平台支持) - 用法: /设置格式 [image|text|pdf|html] + 用法: /设置格式 [格式名称或序号] """ - group_id = self._get_group_id_from_event(event) + # 命令由插件处理,禁用默认 LLM 回退。 + event.should_call_llm(True) - if not group_id: - yield event.plain_result("❌ 请在群聊中使用此命令") - return + available_formats = ["image", "text", "html"] + format_display_names = { + "image": "图片格式 (默认)", + "text": "文本格式", + "html": "交互式 HTML 网页" + } - if not format_type: + if not format_input: current_format = self.config_manager.get_output_format() + format_list_str = "\n".join( + [f"【{i}】{f} - {format_display_names[f]}" for i, f in enumerate(available_formats, start=1)] + ) yield event.plain_result(f"""📊 当前输出格式: {current_format} 可用格式: -• image - 图片格式 (默认) -• text - 文本格式 -• html - HTML 格式 +{format_list_str} -用法: /设置格式 [格式名称]""") +用法: /设置格式 [名称或序号]""") return - format_type = format_type.lower() - if format_type not in ["image", "text", "html"]: - yield event.plain_result("❌ 无效的格式类型,支持: image, text, html") + target_format = None + # 尝试由序号选择 + if format_input.isdigit(): + idx = int(format_input) - 1 + if 0 <= idx < len(available_formats): + target_format = available_formats[idx] + + # 尝试按名称选择 + if not target_format: + input_lower = format_input.lower() + if input_lower in available_formats: + target_format = input_lower + + if not target_format: + yield event.plain_result(f"❌ 无效的格式类型 '{format_input}'。可用: {', '.join(available_formats)} 或序号 1-{len(available_formats)}") return - self.config_manager.set_output_format(format_type) - yield event.plain_result(f"✅ 输出格式已设置为: {format_type}") + try: + self.config_manager.set_output_format(target_format) + yield event.plain_result(f"✅ 输出格式已设置为: {target_format}") + except Exception as e: + yield event.plain_result(f"❌ 设置失败: {e}") @filter.command("设置模板", alias={"set_template"}) @filter.permission_type(PermissionType.ADMIN) diff --git a/src/infrastructure/config/config_manager.py b/src/infrastructure/config/config_manager.py index 502e361..bea0493 100644 --- a/src/infrastructure/config/config_manager.py +++ b/src/infrastructure/config/config_manager.py @@ -429,7 +429,11 @@ class ConfigManager: def set_output_format(self, format_type: str): """设置输出格式""" - self._ensure_group("basic")["output_format"] = format_type + valid_formats = ["image", "text", "html"] + if format_type.lower() not in valid_formats: + raise ValueError(f"无效的输出格式: {format_type}。有效选项: {valid_formats}") + + self._ensure_group("basic")["output_format"] = format_type.lower() self.config.save_config() def set_group_list_mode(self, mode: str):