diff --git a/README.md b/README.md index 375070a..218191d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # QQ群日常分析插件 -[![Plugin Version](https://img.shields.io/badge/Latest_Version-v1.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-v1.5.0-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) diff --git a/main.py b/main.py index 1ae961b..e870e85 100644 --- a/main.py +++ b/main.py @@ -139,13 +139,6 @@ class GroupStatistics: token_usage: TokenUsage = field(default_factory=TokenUsage) -@register( - "astrbot_qq_group_daily_analysis", - "SXP-Simon", - "QQ群日常分析插件 - 生成精美的群聊日常分析报告", - "1.4.0", - "https://github.com/SXP-Simon/astrbot-qq-group-daily-analysis" -) class QQGroupDailyAnalysis(Star): def __init__(self, context: Context, config: AstrBotConfig): super().__init__(context) @@ -167,10 +160,16 @@ class QQGroupDailyAnalysis(Star): self.max_golden_quotes = config.get("max_golden_quotes", 5) self.max_query_rounds = config.get("max_query_rounds", 35) - # PDF 相关配置 - self.pdf_output_dir = config.get("pdf_output_dir", "data/plugins/astrbot-qq-group-daily-analysis/reports") + # PDF 相关配置 - 使用框架提供的数据目录 + self.data_dir = self.context.get_data_dir() + default_pdf_dir = self.data_dir / "reports" + self.pdf_output_dir = Path(config.get("pdf_output_dir", str(default_pdf_dir))) self.pdf_filename_format = config.get("pdf_filename_format", "群聊分析报告_{group_id}_{date}.pdf") + # 确保 PDF 输出目录存在 + self.pdf_output_dir.mkdir(parents=True, exist_ok=True) + logger.info(f"PDF 输出目录: {self.pdf_output_dir}") + # 启动定时任务 self.scheduler_task = None self.bot_instance = None # 保存bot实例用于自动分析 @@ -303,11 +302,6 @@ class QQGroupDailyAnalysis(Star): yield event.plain_result("❌ 请在群聊中使用此命令") return - # 检查管理员权限 - if not await self._is_admin(event): - yield event.plain_result("❌ 仅群管理员可以修改设置") - return - if not format_type: yield event.plain_result(f"""📊 当前输出格式: {self.output_format} @@ -346,11 +340,6 @@ class QQGroupDailyAnalysis(Star): yield event.plain_result("❌ 此功能仅支持QQ群聊") return - # 检查管理员权限 - if not await self._is_admin(event): - yield event.plain_result("❌ 仅群管理员可以安装依赖") - return - yield event.plain_result("🔄 开始安装 PDF 功能依赖,请稍候...") try: @@ -436,11 +425,6 @@ class QQGroupDailyAnalysis(Star): yield event.plain_result("❌ 请在群聊中使用此命令") return - # 检查管理员权限 - if not await self._is_admin(event): - yield event.plain_result("❌ 仅群管理员可以修改设置") - return - if action == "enable": if group_id not in self.enabled_groups: self.enabled_groups.append(group_id) @@ -517,10 +501,6 @@ class QQGroupDailyAnalysis(Star): except Exception as e: logger.error(f"获取机器人QQ号失败: {e}") - async def _is_admin(self, event: AiocqhttpMessageEvent) -> bool: - """检查是否为管理员 - 已简化为允许所有用户""" - # 允许所有用户使用设置功能 - return True async def _install_package(self, package_name: str) -> bool: """安装 Python 包""" @@ -1402,17 +1382,13 @@ class QQGroupDailyAnalysis(Star): async def _generate_pdf_report(self, analysis_result: Dict, group_id: str) -> Optional[str]: """生成 PDF 格式的分析报告""" try: - # 确保输出目录存在 - output_dir = Path(self.pdf_output_dir) - output_dir.mkdir(parents=True, exist_ok=True) - - # 生成文件名 + # 生成文件名(输出目录已在初始化时创建) current_date = datetime.now().strftime('%Y%m%d') filename = self.pdf_filename_format.format( group_id=group_id, date=current_date ) - pdf_path = output_dir / filename + pdf_path = self.pdf_output_dir / filename # 准备渲染数据 render_data = await self._prepare_render_data(analysis_result) @@ -2056,305 +2032,8 @@ class QQGroupDailyAnalysis(Star): """ - async def _create_html_report(self, analysis_result: Dict) -> str: - """创建HTML报告内容""" - stats = analysis_result["statistics"] - topics = analysis_result["topics"] - user_titles = analysis_result["user_titles"] - # 构建话题HTML - topics_html = "" - for i, topic in enumerate(topics[:self.max_topics], 1): - contributors_str = "、".join(topic.contributors) - topics_html += f""" -
-
- {i} - {topic.topic} -
-
参与者: {contributors_str}
-
{topic.detail}
-
- """ - # 构建用户称号HTML - titles_html = "" - for title in user_titles[:self.max_user_titles]: - titles_html += f""" -
-
-
-
{title.name}
-
-
{title.title}
-
{title.mbti}
-
-
-
-
{title.reason}
-
- """ - - # 构建金句HTML - quotes_html = "" - for i, quote in enumerate(stats.golden_quotes[:self.max_golden_quotes], 1): - quotes_html += f""" -
-
"{quote.content}"
-
—— {quote.sender}
-
{quote.reason}
-
- """ - - # HTML模板 - html_template = f""" - - - - - - 群聊日常分析报告 - - - -
-
-

🎯 群聊日常分析报告

-
{datetime.now().strftime('%Y年%m月%d日')}
-
- -
-
-

📊 基础统计

-
-
-
{stats.message_count}
-
消息总数
-
-
-
{stats.participant_count}
-
参与人数
-
-
-
{stats.total_characters}
-
总字符数
-
-
-
{stats.emoji_count}
-
表情数量
-
-
-
-
-
{stats.most_active_period}
-
最活跃时段
-
-
-
- -
-

💬 热门话题

- {topics_html} -
- -
-

🏆 群友称号

- {titles_html} -
- -
-

💬 群圣经

- {quotes_html} -
-
-
- - - """ - - return html_template async def _generate_text_report(self, analysis_result: Dict) -> str: """生成文本格式的分析报告""" diff --git a/metadata.yaml b/metadata.yaml index 00d6261..d222acd 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -13,6 +13,6 @@ help: | # 插件的帮助信息 命令: /群分析 [天数] - 分析群聊活动 /分析设置 [操作] - 管理设置(enable/disable/status/test) -version: v1.4.0 # 插件版本号。格式:v1.1.1 或者 v1.1 +version: v1.5.0 # 插件版本号。格式:v1.1.1 或者 v1.1 author: SXP-Simon # 作者 repo: https://github.com/SXP-Simon/astrbot-qq-group-daily-analysis # 插件的仓库地址