[v1.8.0] (表情数量) 修复表情统计情况

This commit is contained in:
回归天空
2025-09-03 12:03:21 +08:00
parent 84c663df44
commit 347cb94203
5 changed files with 80 additions and 8 deletions
+19 -1
View File
@@ -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)
}
}
+38 -4
View File
@@ -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()
)
+18 -1
View File
@@ -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)