diff --git a/README.md b/README.md index ec6cb75..0642f57 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # QQ群日常分析插件 -[![Plugin Version](https://img.shields.io/badge/Latest_Version-v1.7.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.8.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) @@ -141,6 +141,9 @@ _✨ 一个基于AstrBot的智能群聊分析插件,能够生成精美的群 - 修复提示 - 解耦化 +### v1.8.0 +- 修复表情统计情况 + ## 许可证 MIT License diff --git a/metadata.yaml b/metadata.yaml index 923eadd..f0d50db 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -13,6 +13,6 @@ help: | # 插件的帮助信息 命令: /群分析 [天数] - 分析群聊活动 /分析设置 [操作] - 管理设置(enable/disable/status/test) -version: v1.7.0 # 插件版本号。格式:v1.1.1 或者 v1.1 +version: v1.8.0 # 插件版本号。格式:v1.1.1 或者 v1.1 author: SXP-Simon # 作者 repo: https://github.com/SXP-Simon/astrbot-qq-group-daily-analysis # 插件的仓库地址 diff --git a/src/analysis/statistics.py b/src/analysis/statistics.py index c53db24..2292268 100644 --- a/src/analysis/statistics.py +++ b/src/analysis/statistics.py @@ -43,7 +43,24 @@ class UserAnalyzer: text = content.get("data", {}).get("text", "") user_stats[user_id]["char_count"] += len(text) elif content.get("type") == "face": + # QQ基础表情 user_stats[user_id]["emoji_count"] += 1 + elif content.get("type") == "mface": + # 动画表情/魔法表情 + user_stats[user_id]["emoji_count"] += 1 + elif content.get("type") == "bface": + # 超级表情 + user_stats[user_id]["emoji_count"] += 1 + elif content.get("type") == "sface": + # 小表情 + user_stats[user_id]["emoji_count"] += 1 + elif content.get("type") == "image": + # 检查是否是动画表情(通过summary字段判断) + data = content.get("data", {}) + summary = data.get("summary", "") + if "动画表情" in summary or "表情" in summary: + # 动画表情(以image形式发送) + user_stats[user_id]["emoji_count"] += 1 elif content.get("type") == "reply": user_stats[user_id]["reply_count"] += 1 @@ -85,4 +102,5 @@ class UserAnalyzer: "most_active_hour": most_active_hour, "night_ratio": night_ratio, "hourly_distribution": dict(hours) - } \ No newline at end of file + } + diff --git a/src/core/message_handler.py b/src/core/message_handler.py index 00376c4..75ee04e 100644 --- a/src/core/message_handler.py +++ b/src/core/message_handler.py @@ -8,7 +8,7 @@ from datetime import datetime, timedelta from typing import List, Dict, Optional from collections import defaultdict from astrbot.api import logger -from ...src.models.data_models import GroupStatistics, TokenUsage +from ...src.models.data_models import GroupStatistics, TokenUsage, EmojiStatistics class MessageHandler: @@ -134,7 +134,7 @@ class MessageHandler: total_chars = 0 participants = set() hour_counts = defaultdict(int) - emoji_count = 0 + emoji_statistics = EmojiStatistics() for msg in messages: sender_id = str(msg.get("sender", {}).get("user_id", "")) @@ -150,7 +150,40 @@ class MessageHandler: text = content.get("data", {}).get("text", "") total_chars += len(text) elif content.get("type") == "face": - emoji_count += 1 + # QQ基础表情 + emoji_statistics.face_count += 1 + face_id = content.get("data", {}).get("id", "unknown") + emoji_statistics.face_details[f"face_{face_id}"] = emoji_statistics.face_details.get(f"face_{face_id}", 0) + 1 + elif content.get("type") == "mface": + # 动画表情/魔法表情 + emoji_statistics.mface_count += 1 + emoji_id = content.get("data", {}).get("emoji_id", "unknown") + emoji_statistics.face_details[f"mface_{emoji_id}"] = emoji_statistics.face_details.get(f"mface_{emoji_id}", 0) + 1 + elif content.get("type") == "bface": + # 超级表情 + emoji_statistics.bface_count += 1 + emoji_id = content.get("data", {}).get("p", "unknown") + emoji_statistics.face_details[f"bface_{emoji_id}"] = emoji_statistics.face_details.get(f"bface_{emoji_id}", 0) + 1 + elif content.get("type") == "sface": + # 小表情 + emoji_statistics.sface_count += 1 + emoji_id = content.get("data", {}).get("id", "unknown") + emoji_statistics.face_details[f"sface_{emoji_id}"] = emoji_statistics.face_details.get(f"sface_{emoji_id}", 0) + 1 + elif content.get("type") == "image": + # 检查是否是动画表情(通过summary字段判断) + data = content.get("data", {}) + summary = data.get("summary", "") + if "动画表情" in summary or "表情" in summary: + # 动画表情(以image形式发送) + emoji_statistics.mface_count += 1 + file_name = data.get("file", "unknown") + emoji_statistics.face_details[f"animated_{file_name}"] = emoji_statistics.face_details.get(f"animated_{file_name}", 0) + 1 + else: + # 普通图片,不计入表情统计 + pass + elif content.get("type") in ["record", "video"] and "emoji" in str(content.get("data", {})).lower(): + # 其他可能的表情类型 + emoji_statistics.other_emoji_count += 1 # 找出最活跃时段 most_active_hour = max(hour_counts.items(), key=lambda x: x[1])[0] if hour_counts else 0 @@ -162,6 +195,7 @@ class MessageHandler: participant_count=len(participants), most_active_period=most_active_period, golden_quotes=[], - emoji_count=emoji_count, + emoji_count=emoji_statistics.total_emoji_count, # 保持向后兼容 + emoji_statistics=emoji_statistics, token_usage=TokenUsage() ) \ No newline at end of file diff --git a/src/models/data_models.py b/src/models/data_models.py index 1c71c2e..9f00cc3 100644 --- a/src/models/data_models.py +++ b/src/models/data_models.py @@ -41,6 +41,22 @@ class TokenUsage: total_tokens: int = 0 +@dataclass +class EmojiStatistics: + """表情统计数据结构""" + face_count: int = 0 # QQ基础表情数量 + mface_count: int = 0 # 动画表情数量 + bface_count: int = 0 # 超级表情数量 + sface_count: int = 0 # 小表情数量 + other_emoji_count: int = 0 # 其他表情数量 + face_details: dict = field(default_factory=dict) # 具体表情ID统计 {face_id: count} + + @property + def total_emoji_count(self) -> int: + """总表情数量""" + return self.face_count + self.mface_count + self.bface_count + self.sface_count + self.other_emoji_count + + @dataclass class GroupStatistics: """群聊统计数据结构""" @@ -49,5 +65,6 @@ class GroupStatistics: participant_count: int most_active_period: str golden_quotes: List[GoldenQuote] - emoji_count: int + emoji_count: int # 保持向后兼容 + emoji_statistics: EmojiStatistics = field(default_factory=EmojiStatistics) token_usage: TokenUsage = field(default_factory=TokenUsage) \ No newline at end of file