From eae0d06d3358673cf5afa25202e8b704b3a31f92 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Wed, 9 Apr 2025 11:34:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor(PFC):=20=E5=B0=86424=E8=A1=8Cget?= =?UTF-8?q?=5Fmessage=5Fhistory=E6=96=B9=E6=B3=95=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E4=B8=BAget=5Fcached=5Fmessages=E9=98=B2=E6=AD=A2Ruff?= =?UTF-8?q?=E7=82=B8=E6=8E=89=E5=96=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/PFC/chat_observer.py | 10 +++++----- src/plugins/PFC/conversation.py | 4 ++-- src/plugins/PFC/pfc.py | 2 +- src/plugins/PFC/reply_checker.py | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/plugins/PFC/chat_observer.py b/src/plugins/PFC/chat_observer.py index 395b14043..93618cf2d 100644 --- a/src/plugins/PFC/chat_observer.py +++ b/src/plugins/PFC/chat_observer.py @@ -421,15 +421,15 @@ class ChatObserver: logger.error(f"更新消息历史时出错: {str(e)}") 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: - limit: 获取的最大消息数量 + limit: 获取的最大消息数量,默认50 Returns: - List[Dict[str, Any]]: 消息历史列表 - """ + List[Dict[str, Any]]: 缓存的消息历史列表 + """ return self.message_cache[:limit] def get_last_message(self) -> Optional[Dict[str, Any]]: diff --git a/src/plugins/PFC/conversation.py b/src/plugins/PFC/conversation.py index fecac1523..dda380491 100644 --- a/src/plugins/PFC/conversation.py +++ b/src/plugins/PFC/conversation.py @@ -204,7 +204,7 @@ class Conversation: async def _send_timeout_message(self): """发送超时结束消息""" try: - messages = self.chat_observer.get_message_history(limit=1) + messages = self.chat_observer.get_cached_messages(limit=1) if not messages: return @@ -223,7 +223,7 @@ class Conversation: logger.warning("没有生成回复") return - messages = self.chat_observer.get_message_history(limit=1) + messages = self.chat_observer.get_cached_messages(limit=1) if not messages: logger.warning("没有最近的消息可以回复") return diff --git a/src/plugins/PFC/pfc.py b/src/plugins/PFC/pfc.py index 25c4728e0..62b28acb4 100644 --- a/src/plugins/PFC/pfc.py +++ b/src/plugins/PFC/pfc.py @@ -195,7 +195,7 @@ class GoalAnalyzer: return self.goals[1:].copy() async def analyze_conversation(self, goal, reasoning): - messages = self.chat_observer.get_message_history() + messages = self.chat_observer.get_cached_messages() chat_history_text = "" for msg in messages: time_str = datetime.datetime.fromtimestamp(msg["time"]).strftime("%H:%M:%S") diff --git a/src/plugins/PFC/reply_checker.py b/src/plugins/PFC/reply_checker.py index c53feba9b..6889f7ca8 100644 --- a/src/plugins/PFC/reply_checker.py +++ b/src/plugins/PFC/reply_checker.py @@ -33,7 +33,7 @@ class ReplyChecker: 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 = "" for msg in messages: time_str = datetime.datetime.fromtimestamp(msg["time"]).strftime("%H:%M:%S") From a38b8185659e4366c45fd104f8d93af8072073d1 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Wed, 9 Apr 2025 11:48:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=A5=9E=E7=A7=98=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=EF=BC=88=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 67aacb8e0..46e1fb77d 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,6 @@ MaiCore是一个开源项目,我们非常欢迎你的参与。你的贡献, ## 致谢 -- [nonebot2](https://github.com/nonebot/nonebot2): 跨平台 Python 异步聊天机器人框架 - [NapCat](https://github.com/NapNeko/NapCatQQ): 现代化的基于 NTQQ 的 Bot 协议端实现 ### 贡献者