This commit is contained in:
UnCLAS-Prommer
2025-04-09 13:52:19 +08:00
5 changed files with 9 additions and 10 deletions

View File

@@ -178,7 +178,6 @@ MaiCore是一个开源项目我们非常欢迎你的参与。你的贡献
## 致谢 ## 致谢
- [nonebot2](https://github.com/nonebot/nonebot2): 跨平台 Python 异步聊天机器人框架
- [NapCat](https://github.com/NapNeko/NapCatQQ): 现代化的基于 NTQQ 的 Bot 协议端实现 - [NapCat](https://github.com/NapNeko/NapCatQQ): 现代化的基于 NTQQ 的 Bot 协议端实现
### 贡献者 ### 贡献者

View File

@@ -421,15 +421,15 @@ class ChatObserver:
logger.error(f"更新消息历史时出错: {str(e)}") logger.error(f"更新消息历史时出错: {str(e)}")
return False return False
def get_message_history(self, limit: int = 50) -> List[Dict[str, Any]]: def get_cached_messages(self, limit: int = 50) -> List[Dict[str, Any]]:
"""获取消息历史 """获取缓存的消息历史
Args: Args:
limit: 获取的最大消息数量 limit: 获取的最大消息数量默认50
Returns: Returns:
List[Dict[str, Any]]: 消息历史列表 List[Dict[str, Any]]: 缓存的消息历史列表
""" """
return self.message_cache[:limit] return self.message_cache[:limit]
def get_last_message(self) -> Optional[Dict[str, Any]]: def get_last_message(self) -> Optional[Dict[str, Any]]:

View File

@@ -204,7 +204,7 @@ class Conversation:
async def _send_timeout_message(self): async def _send_timeout_message(self):
"""发送超时结束消息""" """发送超时结束消息"""
try: try:
messages = self.chat_observer.get_message_history(limit=1) messages = self.chat_observer.get_cached_messages(limit=1)
if not messages: if not messages:
return return
@@ -223,7 +223,7 @@ class Conversation:
logger.warning("没有生成回复") logger.warning("没有生成回复")
return return
messages = self.chat_observer.get_message_history(limit=1) messages = self.chat_observer.get_cached_messages(limit=1)
if not messages: if not messages:
logger.warning("没有最近的消息可以回复") logger.warning("没有最近的消息可以回复")
return return

View File

@@ -198,7 +198,7 @@ class GoalAnalyzer:
return self.goals[1:].copy() return self.goals[1:].copy()
async def analyze_conversation(self, goal, reasoning): async def analyze_conversation(self, goal, reasoning):
messages = self.chat_observer.get_message_history() messages = self.chat_observer.get_cached_messages()
chat_history_text = "" chat_history_text = ""
for msg in messages: for msg in messages:
time_str = datetime.datetime.fromtimestamp(msg["time"]).strftime("%H:%M:%S") time_str = datetime.datetime.fromtimestamp(msg["time"]).strftime("%H:%M:%S")

View File

@@ -33,7 +33,7 @@ class ReplyChecker:
Tuple[bool, str, bool]: (是否合适, 原因, 是否需要重新规划) Tuple[bool, str, bool]: (是否合适, 原因, 是否需要重新规划)
""" """
# 获取最新的消息记录 # 获取最新的消息记录
messages = self.chat_observer.get_message_history(limit=5) messages = self.chat_observer.get_cached_messages(limit=5)
chat_history_text = "" chat_history_text = ""
for msg in messages: for msg in messages:
time_str = datetime.datetime.fromtimestamp(msg["time"]).strftime("%H:%M:%S") time_str = datetime.datetime.fromtimestamp(msg["time"]).strftime("%H:%M:%S")