mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 13:38:43 +00:00
fix(tg): 修复 Telegram 平台自动分析就绪检查失败以及 ID 匹配诊断逻辑
- 优化 BotManager 的 is_ready_for_auto_analysis 逻辑:将其改为非硬性限制。即使未成功提取机器人 ID (bot_self_ids),也允许定时任务继续运行,从而解决了 Telegram 在 Docker 部署下因 ID 获取延迟导致报告被跳过的问题。 - 强化日志诊断:在 Telegram 消息拦截 (save)、平台发现 (discovery) 和消息拉取 (fetch) 的关键路径中增加 platform_id 显式日志,方便排查多账号环境下的 ID 冲突。 - 在 BotManager 就绪检查中加入调试输出,明确告知分析任务被跳过的具体原因。
This commit is contained in:
@@ -91,8 +91,8 @@ class MessageProcessingService:
|
||||
f"platform_id={platform_id} group_id={group_id} error={e}"
|
||||
)
|
||||
|
||||
logger.debug(
|
||||
f"[{platform_id}] 已缓存群 {group_id} 的消息 (发送者: {sender_name})"
|
||||
logger.info(
|
||||
f"[Telegram] [{platform_id}] 已缓存群 {group_id} 的消息 (发送者: {sender_name})"
|
||||
)
|
||||
|
||||
def _get_group_id_from_event(self, event: AstrMessageEvent) -> str | None:
|
||||
|
||||
@@ -184,6 +184,9 @@ class TelegramAdapter(PlatformAdapter):
|
||||
history_mgr = self._context.message_history_manager
|
||||
|
||||
platform_id = self._get_platform_id()
|
||||
logger.info(
|
||||
f"[Telegram] 正在获取群 {group_id} 的历史消息,使用 platform_id: {platform_id}"
|
||||
)
|
||||
before_id_int: int | None = None
|
||||
if before_id:
|
||||
try:
|
||||
|
||||
@@ -195,8 +195,22 @@ class BotManager:
|
||||
return bool(self._bot_self_ids)
|
||||
|
||||
def is_ready_for_auto_analysis(self) -> bool:
|
||||
"""检查是否准备好进行自动分析"""
|
||||
return self.has_bot_instance() and self.has_bot_self_id()
|
||||
"""检查是否准备好进行了自动分析"""
|
||||
if not self.has_bot_instance():
|
||||
logger.debug("[BotManager] 自动分析就绪检查失败:没有可用的 bot 实例。")
|
||||
return False
|
||||
|
||||
if not self.has_bot_self_id():
|
||||
# 允许在没有配置/自动提取到 ID 的情况下尝试,但记录调试信息
|
||||
# 这有助于诊断某些平台(如 Telegram)自动获取 ID 失败的情况
|
||||
logger.debug(
|
||||
"[BotManager] 自动分析就绪检查警告:bot_self_ids 列表为空。可能会影响消息过滤能力。"
|
||||
)
|
||||
# 为了解决 #128 及其后续反馈,我们将此检查放宽
|
||||
# 只要有 bot 实例就可以尝试运行
|
||||
return True
|
||||
|
||||
return True
|
||||
|
||||
def _get_platform_id_from_instance(self, bot_instance):
|
||||
"""从bot实例获取平台ID"""
|
||||
@@ -368,6 +382,9 @@ class BotManager:
|
||||
self._platforms[platform_id] = platform
|
||||
|
||||
if bot_client:
|
||||
logger.info(
|
||||
f"[BotManager] 为平台 {platform_id} ({platform_name}) 注册 bot 实例"
|
||||
)
|
||||
self.set_bot_instance(bot_client, platform_id, platform_name)
|
||||
discovered[platform_id] = bot_client
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user