From 9fef747b4651969fe79c1300bc05d0a2828954a5 Mon Sep 17 00:00:00 2001 From: clown145 Date: Sat, 3 Jan 2026 00:15:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 +++- main.py | 129 ++++++++++++++++++++++++++++++++++++++------------ metadata.yaml | 2 +- 3 files changed, 109 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index a033d66..b2a3456 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # QQ群日常分析插件 -[![Plugin Version](https://img.shields.io/badge/Latest_Version-v4.4.0-blue.svg?style=for-the-badge&color=76bad9)](https://github.com/SXP-Simon/astrbot-qq-group-daily-analysis) +[![Plugin Version](https://img.shields.io/badge/Latest_Version-v4.5.2-blue.svg?style=for-the-badge&color=76bad9)](https://github.com/SXP-Simon/astrbot-qq-group-daily-analysis) [![AstrBot](https://img.shields.io/badge/AstrBot-Plugin-ff69b4?style=for-the-badge)](https://github.com/AstrBotDevs/AstrBot) [![License](https://img.shields.io/badge/License-MIT-green.svg?style=for-the-badge)](LICENSE) [![](https://img.shields.io/badge/五彩斑斓的Bug群-Bug反馈群&水群-white?style=for-the-badge&color=76bad9&logo=qq&logoColor=76bad9)](https://qm.qq.com/q/oTzIrdDBIc) @@ -111,6 +111,14 @@ retro_futurism 模板效果图
📋 点击展开查看完整更新日志 +### v4.5.2 +- 新增 `/查看模板` 指令,可查看所有模板预览图 +- `/设置模板` 指令现支持通过序号设置模板 +- `/群分析` 指令现可在任意群使用,无需先启用该群 + +### v4.5.1 +- BugFix + ### v4.5.0 - 添加新的模板主题 retro_futurism, 灵感来源明日方舟 孤星 未来复古主义主题;添加模板调试工具 scripts/debug_render.py,方便用户在不启动 AstrBot 的情况下调试模板效果 (@Saramanda9988) diff --git a/main.py b/main.py index 172766c..48f6726 100644 --- a/main.py +++ b/main.py @@ -158,11 +158,6 @@ class QQGroupDailyAnalysis(Star): # 更新bot实例(用于手动命令) bot_manager.update_from_event(event) - # 检查群组权限 - if not config_manager.is_group_allowed(group_id): - yield event.plain_result("❌ 此群未启用日常分析功能") - return - # 设置分析天数 analysis_days = ( days if days and 1 <= days <= 7 else config_manager.get_analysis_days() @@ -323,48 +318,60 @@ class QQGroupDailyAnalysis(Star): @filter.command("设置模板") @filter.permission_type(PermissionType.ADMIN) async def set_report_template( - self, event: AiocqhttpMessageEvent, template_name: str = "" + self, event: AiocqhttpMessageEvent, template_input: str = "" ): """ 设置分析报告模板 - 用法: /设置模板 [模板名称] + 用法: /设置模板 [模板名称或序号] """ if not isinstance(event, AiocqhttpMessageEvent): yield event.plain_result("❌ 此功能仅支持QQ群聊") return - if not template_name: + import os + + # 获取模板目录和可用模板列表 + template_base_dir = os.path.join( + os.path.dirname(__file__), "src", "reports", "templates" + ) + available_templates = [] + if os.path.exists(template_base_dir): + available_templates = sorted([ + d + for d in os.listdir(template_base_dir) + if os.path.isdir(os.path.join(template_base_dir, d)) + and not d.startswith("__") + ]) + + if not template_input: current_template = config_manager.get_report_template() - # 列出可用的模板 - import os - - template_dir = os.path.join( - os.path.dirname(__file__), "src", "reports", "templates" - ) - available_templates = [] - if os.path.exists(template_dir): - available_templates = [ - d - for d in os.listdir(template_dir) - if os.path.isdir(os.path.join(template_dir, d)) - and not d.startswith("__") - ] - - template_list_str = "\n".join([f"• {t}" for t in available_templates]) + # 列出可用的模板(带序号) + template_list_str = "\n".join([ + f"【{i}】{t}" for i, t in enumerate(available_templates, start=1) + ]) yield event.plain_result(f"""🎨 当前报告模板: {current_template} 可用模板: {template_list_str} -用法: /设置模板 [模板名称]""") +用法: /设置模板 [模板名称或序号] +💡 使用 /查看模板 查看预览图""") return - # 检查模板是否存在 - import os + # 判断输入是序号还是模板名称 + template_name = template_input + if template_input.isdigit(): + index = int(template_input) + if 1 <= index <= len(available_templates): + template_name = available_templates[index - 1] + else: + yield event.plain_result( + f"❌ 无效的序号 '{template_input}',有效范围: 1-{len(available_templates)}" + ) + return - template_dir = os.path.join( - os.path.dirname(__file__), "src", "reports", "templates", template_name - ) + # 检查模板是否存在 + template_dir = os.path.join(template_base_dir, template_name) if not os.path.exists(template_dir): yield event.plain_result(f"❌ 模板 '{template_name}' 不存在") return @@ -372,6 +379,68 @@ class QQGroupDailyAnalysis(Star): config_manager.set_report_template(template_name) yield event.plain_result(f"✅ 报告模板已设置为: {template_name}") + @filter.command("查看模板") + @filter.permission_type(PermissionType.ADMIN) + async def view_templates(self, event: AiocqhttpMessageEvent): + """ + 查看所有可用的报告模板及预览图 + 用法: /查看模板 + """ + if not isinstance(event, AiocqhttpMessageEvent): + yield event.plain_result("❌ 此功能仅支持QQ群聊") + return + + import os + import astrbot.api.message_components as Comp + + # 获取模板目录 + template_dir = os.path.join( + os.path.dirname(__file__), "src", "reports", "templates" + ) + assets_dir = os.path.join(os.path.dirname(__file__), "assets") + + # 获取可用模板列表 + available_templates = [] + if os.path.exists(template_dir): + available_templates = sorted([ + d + for d in os.listdir(template_dir) + if os.path.isdir(os.path.join(template_dir, d)) + and not d.startswith("__") + ]) + + if not available_templates: + yield event.plain_result("❌ 未找到任何可用的报告模板") + return + + # 获取当前使用的模板 + current_template = config_manager.get_report_template() + + # 构建消息链:标题 + 每个模板的序号、名称和预览图 + chain = [ + Comp.Plain(f"🎨 可用报告模板列表\n当前使用: {current_template}\n\n") + ] + + for index, template_name in enumerate(available_templates, start=1): + # 标记当前正在使用的模板 + current_mark = " ✅" if template_name == current_template else "" + + # 添加模板名称(带序号) + chain.append(Comp.Plain(f"【{index}】{template_name}{current_mark}\n")) + + # 查找对应的预览图 + preview_image_path = os.path.join(assets_dir, f"{template_name}-demo.jpg") + if os.path.exists(preview_image_path): + chain.append(Comp.Image.fromFileSystem(preview_image_path)) + chain.append(Comp.Plain("\n")) + else: + chain.append(Comp.Plain("(无预览图)\n")) + + # 添加使用说明 + chain.append(Comp.Plain("\n💡 使用 /设置模板 [模板名称] 来切换模板")) + + yield event.chain_result(chain) + @filter.command("安装PDF") @filter.permission_type(PermissionType.ADMIN) async def install_pdf_deps(self, event: AiocqhttpMessageEvent): diff --git a/metadata.yaml b/metadata.yaml index 9aaa02e..a2cd3f1 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -14,6 +14,6 @@ help: | # 插件的帮助信息 命令: /群分析 [天数] - 分析群聊活动 /分析设置 [操作] - 管理设置(enable/disable/status/test) -version: v4.5.1 # 插件版本号。格式:v1.1.1 或者 v1.1 +version: v4.5.2 # 插件版本号。格式:v1.1.1 或者 v1.1 author: SXP-Simon # 作者 repo: https://github.com/SXP-Simon/astrbot-qq-group-daily-analysis # 插件的仓库地址