From 911b8b2fb20a1f4e3c44f1327484fe997a4c1549 Mon Sep 17 00:00:00 2001 From: Shiitin Date: Sun, 12 Apr 2026 22:03:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(html):=20=E5=A2=9E=E5=8A=A0=E4=BA=86html?= =?UTF-8?q?=5Fonly=5Furl=E9=80=89=E9=A1=B9=EF=BC=8C=E4=BD=BF=E5=9C=A8?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E8=BE=93=E5=87=BA=E6=A0=BC=E5=BC=8F=E4=B8=BA?= =?UTF-8?q?html=E6=97=B6=E5=8F=AF=E4=BB=A5=E5=8D=95=E7=8B=AC=E5=8F=91?= =?UTF-8?q?=E9=80=81BaseURL=20(#166=20@shiitin)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 更改了AstrBot中面板的的设置项,增加了html_only_url选项 * 增加了html_only_url * 增加了单独发送URL 在html_only_url设置被打开且配置了Base URL后,将会单独发送URL * 加入测试日志,尝试解决存在问题 * 加入测试日志,尝试解决存在问题 * 删除了定时触发部分的测试日志 * 修改了手动触发部分的发送HTML的判断 * 修改了main.py的单行长度过长问题 * 修复了dispatcher.py的缩进问题 --- _conf_schema.json | 6 ++++++ main.py | 16 +++++++++++++++ src/infrastructure/config/config_manager.py | 9 +++++++++ src/infrastructure/reporting/dispatcher.py | 22 +++++++++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/_conf_schema.json b/_conf_schema.json index 9ad46f1..e741e2c 100644 --- a/_conf_schema.json +++ b/_conf_schema.json @@ -372,6 +372,12 @@ "default": "", "hint": "HTML报告文件的保存目录,用于存储生成的 HTML 文件和原始 JSON 数据。留空则自动使用插件数据目录(astrbot_path/data/plugin_data/astrbot_plugin_qq_group_daily_analysis/)下的 self_hosted_html_reports 目录。" }, + "html_only_url": { + "type": "bool", + "description": "仅发送外链", + "default": false, + "hint": "勾选后,若配置了外链 Base URL,则发送 HTML 报告时将只发送外链链接,不再发送HTML文件,若未勾选,将保持发送HTML文件。" + }, "html_filename_format": { "type": "string", "description": "HTML文件名格式", diff --git a/main.py b/main.py index e5a16ca..bf2096c 100644 --- a/main.py +++ b/main.py @@ -628,6 +628,22 @@ class GroupDailyAnalysis(Star): nickname_getter=nickname_getter, ) if html_path: + is_only_url = self.config_manager.get_html_only_url() + base_url = self.config_manager.get_html_base_url() + + if is_only_url: + if base_url and base_url.strip(): + filename = os.path.basename(html_path) + report_url = f"{base_url.rstrip('/')}/{filename}" + yield event.plain_result( + f"📊 今日群聊分析报告已生成:\n{report_url}" + ) + return # 拦截成功,直接退出,不再发文件 + else: + logger.warning( + f"手动触发群 {group_id} 开启了仅发送外链,但未配置 html_base_url,回退至发送文件。" + ) + caption = self.report_generator.build_html_caption(html_path) # 发送 HTML 文件 diff --git a/src/infrastructure/config/config_manager.py b/src/infrastructure/config/config_manager.py index e38671f..a371476 100644 --- a/src/infrastructure/config/config_manager.py +++ b/src/infrastructure/config/config_manager.py @@ -266,6 +266,15 @@ class ConfigManager: """获取HTML外链Base URL""" return self._get_group("html").get("html_base_url", "") + def get_html_only_url(self) -> bool: + """获取是否仅输出外链而不发送文件本体""" + return self._get_group("html").get("html_only_url", False) + + def set_html_only_url(self, enabled: bool): + """设置是否仅输出外链而不发送文件本体""" + self._ensure_group("html")["html_only_url"] = enabled + self.config.save_config() + def get_html_filename_format(self) -> str: """获取HTML文件名格式""" return self._get_group("html").get( diff --git a/src/infrastructure/reporting/dispatcher.py b/src/infrastructure/reporting/dispatcher.py index 0326b78..929146b 100644 --- a/src/infrastructure/reporting/dispatcher.py +++ b/src/infrastructure/reporting/dispatcher.py @@ -41,6 +41,7 @@ class ReportDispatcher: """ trace_id = TraceContext.get() output_format = self.config_manager.get_output_format() + logger.info( f"[{trace_id}] 正在分发群 {group_id} 的报告 (格式: {output_format})" ) @@ -125,6 +126,27 @@ class ReportDispatcher: logger.error(f"[{trace_id}] Failed to generate HTML report: {e}") if html_path: + is_only_url = self.config_manager.get_html_only_url() + base_url = self.config_manager.get_html_base_url() + + if is_only_url: + if base_url and base_url.strip(): + filename = os.path.basename(html_path) + report_url = f"{base_url.rstrip('/')}/{filename}" + + sent = await self.message_sender.send_text( + group_id, + f"📊 今日群聊分析报告已生成:\n{report_url}", + platform_id, + ) + + if sent: + return True + else: + logger.warning( + f"[{trace_id}] 群 {group_id} 开启了仅发送外链,但未配置 html_base_url,已进行降级,回退至发送 HTML 文件。" + ) + caption = self.report_generator.build_html_caption(html_path) sent = await self.message_sender.send_file(