mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 20:01:04 +00:00
feat: discord 表情支持,和部分调试日志
This commit is contained in:
@@ -9,9 +9,20 @@ from datetime import datetime
|
||||
from .utils import InfoUtils
|
||||
|
||||
|
||||
import re
|
||||
|
||||
|
||||
class UserAnalyzer:
|
||||
"""用户分析器"""
|
||||
|
||||
# Discord 自定义表情正则 <:name:id> 或 <a:name:id>
|
||||
DISCORD_CUSTOM_EMOJI_PATTERN = r"<a?:.+?:\d+>"
|
||||
|
||||
# 简单的 Unicode Emoji 正则范围 (覆盖大多数常见 Emoji)
|
||||
UNICODE_EMOJI_PATTERN = (
|
||||
r"[\U0001F000-\U0001F9FF]|[\U00002600-\U000026FF]|[\U00002700-\U000027BF]"
|
||||
)
|
||||
|
||||
def __init__(self, config_manager):
|
||||
self.config_manager = config_manager
|
||||
|
||||
@@ -53,6 +64,15 @@ class UserAnalyzer:
|
||||
if content.get("type") == "text":
|
||||
text = content.get("data", {}).get("text", "")
|
||||
user_stats[user_id]["char_count"] += len(text)
|
||||
|
||||
# 统计文本中的 Discord 自定义表情
|
||||
discord_emojis = re.findall(self.DISCORD_CUSTOM_EMOJI_PATTERN, text)
|
||||
user_stats[user_id]["emoji_count"] += len(discord_emojis)
|
||||
|
||||
# 统计文本中的 Unicode Emoji
|
||||
unicode_emojis = re.findall(self.UNICODE_EMOJI_PATTERN, text)
|
||||
user_stats[user_id]["emoji_count"] += len(unicode_emojis)
|
||||
|
||||
elif content.get("type") == "face":
|
||||
# QQ基础表情
|
||||
user_stats[user_id]["emoji_count"] += 1
|
||||
|
||||
@@ -105,19 +105,29 @@ def parse_json_response(
|
||||
json_text = json_match.group()
|
||||
logger.debug(f"{data_type}分析JSON原文: {json_text[:500]}...")
|
||||
|
||||
# 2. 修复JSON
|
||||
json_text = fix_json(json_text)
|
||||
logger.debug(f"{data_type}修复后的JSON: {json_text[:300]}...")
|
||||
# 2. 尝试直接解析
|
||||
try:
|
||||
data = json.loads(json_text)
|
||||
logger.info(f"{data_type}直接解析成功,解析到 {len(data)} 条数据")
|
||||
return True, data, None
|
||||
except json.JSONDecodeError:
|
||||
logger.debug(f"{data_type}直接解析失败,尝试修复JSON...")
|
||||
|
||||
# 3. 解析JSON
|
||||
data = json.loads(json_text)
|
||||
logger.info(f"{data_type}分析成功,解析到 {len(data)} 条数据")
|
||||
# 3. 修复JSON
|
||||
fixed_json_text = fix_json(json_text)
|
||||
logger.debug(f"{data_type}修复后的JSON: {fixed_json_text[:300]}...")
|
||||
|
||||
# 4. 解析修复后的JSON
|
||||
data = json.loads(fixed_json_text)
|
||||
logger.info(f"{data_type}修复后解析成功,解析到 {len(data)} 条数据")
|
||||
return True, data, None
|
||||
|
||||
except json.JSONDecodeError as e:
|
||||
error_msg = f"{data_type}JSON解析失败: {e}"
|
||||
logger.warning(error_msg)
|
||||
logger.debug(f"修复后的JSON: {json_text if 'json_text' in locals() else 'N/A'}")
|
||||
logger.debug(
|
||||
f"修复后的JSON: {fixed_json_text if 'fixed_json_text' in locals() else 'N/A'}"
|
||||
)
|
||||
return False, None, error_msg
|
||||
except Exception as e:
|
||||
error_msg = f"{data_type}解析异常: {e}"
|
||||
|
||||
Reference in New Issue
Block a user