mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-23 04:09:59 +00:00
feat(logger)
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
from typing import Optional, List, Dict, Any
|
||||
from dataclasses import dataclass
|
||||
|
||||
from astrbot.api import logger
|
||||
from ..utils.logger import logger
|
||||
|
||||
from ..domain.value_objects.unified_message import UnifiedMessage
|
||||
from ..domain.value_objects.platform_capabilities import PlatformCapabilities
|
||||
@@ -23,6 +23,7 @@ from .message_converter import MessageConverter
|
||||
@dataclass
|
||||
class AnalysisConfig:
|
||||
"""分析操作配置"""
|
||||
|
||||
days: int = 1
|
||||
max_messages: int = 1000
|
||||
min_messages_threshold: int = 10
|
||||
@@ -32,13 +33,13 @@ class AnalysisConfig:
|
||||
class AnalysisOrchestrator:
|
||||
"""
|
||||
分析编排器 - 协调分析工作流。
|
||||
|
||||
|
||||
职责:
|
||||
1. 使用 PlatformAdapter 获取消息(DDD 方式)
|
||||
2. 转换消息以兼容现有分析器
|
||||
3. 协调分析流程
|
||||
4. 提供平台能力检查
|
||||
|
||||
|
||||
此类作为以下组件之间的桥梁:
|
||||
- 新的 DDD 基础设施(PlatformAdapter, UnifiedMessage)
|
||||
- 现有分析逻辑(MessageHandler, LLMAnalyzer 等)
|
||||
@@ -51,7 +52,7 @@ class AnalysisOrchestrator:
|
||||
):
|
||||
"""
|
||||
初始化编排器。
|
||||
|
||||
|
||||
参数:
|
||||
adapter: 用于消息操作的平台适配器
|
||||
config: 分析配置
|
||||
@@ -69,13 +70,13 @@ class AnalysisOrchestrator:
|
||||
) -> Optional["AnalysisOrchestrator"]:
|
||||
"""
|
||||
工厂方法 - 为特定平台创建编排器。
|
||||
|
||||
|
||||
参数:
|
||||
platform_name: 平台名称(如 "aiocqhttp", "telegram")
|
||||
bot_instance: 来自 AstrBot 的 bot 实例
|
||||
config: 平台特定配置
|
||||
analysis_config: 分析配置
|
||||
|
||||
|
||||
返回:
|
||||
AnalysisOrchestrator 或 None(如果平台不支持)
|
||||
"""
|
||||
@@ -83,7 +84,7 @@ class AnalysisOrchestrator:
|
||||
if adapter is None:
|
||||
logger.warning(f"平台 '{platform_name}' 不支持分析功能")
|
||||
return None
|
||||
|
||||
|
||||
return cls(adapter, analysis_config)
|
||||
|
||||
def get_capabilities(self) -> PlatformCapabilities:
|
||||
@@ -106,29 +107,26 @@ class AnalysisOrchestrator:
|
||||
) -> List[UnifiedMessage]:
|
||||
"""
|
||||
使用平台适配器获取消息。
|
||||
|
||||
|
||||
参数:
|
||||
group_id: 要获取消息的群组 ID
|
||||
days: 天数(默认使用配置值)
|
||||
max_count: 最大消息数量(默认使用配置值)
|
||||
|
||||
|
||||
返回:
|
||||
UnifiedMessage 列表
|
||||
"""
|
||||
days = days or self.config.days
|
||||
max_count = max_count or self.config.max_messages
|
||||
|
||||
|
||||
# 应用平台能力限制
|
||||
caps = self.adapter.get_capabilities()
|
||||
effective_days = caps.get_effective_days(days)
|
||||
effective_count = caps.get_effective_count(max_count)
|
||||
|
||||
|
||||
if effective_days < days:
|
||||
logger.info(
|
||||
f"平台限制:请求 {days} 天,"
|
||||
f"实际使用 {effective_days} 天"
|
||||
)
|
||||
|
||||
logger.info(f"平台限制:请求 {days} 天,实际使用 {effective_days} 天")
|
||||
|
||||
return await self.adapter.fetch_messages(
|
||||
group_id=group_id,
|
||||
days=effective_days,
|
||||
@@ -143,15 +141,15 @@ class AnalysisOrchestrator:
|
||||
) -> List[dict]:
|
||||
"""
|
||||
获取消息并转换为原始字典格式。
|
||||
|
||||
|
||||
此方法提供与现有分析器的向后兼容性,
|
||||
这些分析器期望原始字典格式的消息。
|
||||
|
||||
|
||||
参数:
|
||||
group_id: 要获取消息的群组 ID
|
||||
days: 天数
|
||||
max_count: 最大消息数量
|
||||
|
||||
|
||||
返回:
|
||||
原始消息字典列表(通用格式,由适配器决定具体格式)
|
||||
"""
|
||||
@@ -178,11 +176,11 @@ class AnalysisOrchestrator:
|
||||
# }
|
||||
# for msg in unified_messages
|
||||
# ]
|
||||
|
||||
|
||||
# 暂时直接使用适配器获取 raw 格式,如果适配器支持
|
||||
# 这是为了确保现有逻辑完全兼容,因为 convert_to_raw_format 可能有损
|
||||
# 但我们希望尽可能使用新的 fetch_messages
|
||||
|
||||
|
||||
unified_messages = await self.fetch_messages(group_id, days, max_count)
|
||||
return self.adapter.convert_to_raw_format(unified_messages)
|
||||
|
||||
@@ -197,11 +195,11 @@ class AnalysisOrchestrator:
|
||||
) -> Dict[str, Optional[str]]:
|
||||
"""
|
||||
批量获取用户头像 URL。
|
||||
|
||||
|
||||
参数:
|
||||
user_ids: 用户 ID 列表
|
||||
size: 头像尺寸
|
||||
|
||||
|
||||
返回:
|
||||
用户 ID 到头像 URL 的映射字典(URL 可能为 None)
|
||||
"""
|
||||
@@ -232,10 +230,10 @@ class AnalysisOrchestrator:
|
||||
def validate_message_count(self, messages: List[UnifiedMessage]) -> bool:
|
||||
"""
|
||||
检查消息数量是否达到最小阈值。
|
||||
|
||||
|
||||
参数:
|
||||
messages: 消息列表
|
||||
|
||||
|
||||
返回:
|
||||
如果数量足够返回 True
|
||||
"""
|
||||
@@ -244,10 +242,10 @@ class AnalysisOrchestrator:
|
||||
def get_analysis_text(self, messages: List[UnifiedMessage]) -> str:
|
||||
"""
|
||||
将消息转换为 LLM 分析文本格式。
|
||||
|
||||
|
||||
参数:
|
||||
messages: UnifiedMessage 列表
|
||||
|
||||
|
||||
返回:
|
||||
格式化的 LLM 分析文本
|
||||
"""
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from astrbot.api import logger
|
||||
from ..utils.logger import logger
|
||||
|
||||
from ..domain.services import ReportGenerator
|
||||
from ..domain.value_objects.topic import Topic
|
||||
@@ -78,7 +78,9 @@ class ReportingService:
|
||||
statistics=statistics,
|
||||
topics=topics if self.config.get_include_topics() else [],
|
||||
user_titles=user_titles if self.config.get_include_user_titles() else [],
|
||||
golden_quotes=golden_quotes if self.config.get_include_golden_quotes() else [],
|
||||
golden_quotes=golden_quotes
|
||||
if self.config.get_include_golden_quotes()
|
||||
else [],
|
||||
include_header=True,
|
||||
include_footer=True,
|
||||
)
|
||||
|
||||
@@ -9,10 +9,14 @@ import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any, Callable, Dict, List, Optional, Set
|
||||
|
||||
from astrbot.api import logger
|
||||
from ..utils.logger import logger
|
||||
|
||||
from ..infrastructure.config import ConfigManager
|
||||
from ..shared.constants import TASK_STATE_PENDING, TASK_STATE_RUNNING, TASK_STATE_COMPLETED
|
||||
from ..shared.constants import (
|
||||
TASK_STATE_PENDING,
|
||||
TASK_STATE_RUNNING,
|
||||
TASK_STATE_COMPLETED,
|
||||
)
|
||||
|
||||
|
||||
class ScheduledTask:
|
||||
|
||||
Reference in New Issue
Block a user