From 2edece11ea7befcbca5036878ce175bbb46a73e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E6=B2=B3=E6=99=B4?= Date: Tue, 10 Jun 2025 16:18:57 +0900 Subject: [PATCH] ruff --- src/chat/actions/plugin_api/database_api.py | 4 +++- src/chat/actions/plugin_api/message_api.py | 5 ++--- src/chat/focus_chat/expressors/exprssion_learner.py | 4 ++-- src/chat/focus_chat/heartFC_chat.py | 3 --- src/chat/focus_chat/heartFC_sender.py | 4 ++-- src/chat/focus_chat/info_processors/self_processor.py | 7 ------- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/chat/actions/plugin_api/database_api.py b/src/chat/actions/plugin_api/database_api.py index d9c7703bf..313ef3fe9 100644 --- a/src/chat/actions/plugin_api/database_api.py +++ b/src/chat/actions/plugin_api/database_api.py @@ -125,6 +125,8 @@ class DatabaseAPI: ) """ try: + if query_type not in ["get", "create", "update", "delete", "count"]: + raise ValueError("query_type must be 'get' or 'create' or 'update' or 'delete' or 'count'") # 构建基本查询 if query_type in ["get", "update", "delete", "count"]: query = model_class.select() @@ -198,7 +200,7 @@ class DatabaseAPI: return None if single_result else [] elif query_type in ["create", "update", "delete", "count"]: return None - raise "unknown query type" + return None async def db_raw_query( self, sql: str, params: List[Any] = None, fetch_results: bool = True diff --git a/src/chat/actions/plugin_api/message_api.py b/src/chat/actions/plugin_api/message_api.py index ca4c7e1cf..0b4b97f1b 100644 --- a/src/chat/actions/plugin_api/message_api.py +++ b/src/chat/actions/plugin_api/message_api.py @@ -53,7 +53,7 @@ class MessageAPI: if is_group: # 群聊:从数据库查找对应的聊天流 target_stream = None - for stream_id, stream in chat_manager.streams.items(): + for _, stream in chat_manager.streams.items(): if ( stream.group_info and str(stream.group_info.group_id) == str(target_id) @@ -68,7 +68,7 @@ class MessageAPI: else: # 私聊:从数据库查找对应的聊天流 target_stream = None - for stream_id, stream in chat_manager.streams.items(): + for _, stream in chat_manager.streams.items(): if ( not stream.group_info and str(stream.user_info.user_id) == str(target_id) @@ -87,7 +87,6 @@ class MessageAPI: # 生成消息ID和thinking_id current_time = time.time() message_id = f"plugin_msg_{int(current_time * 1000)}" - thinking_id = f"plugin_thinking_{int(current_time * 1000)}" # 构建机器人用户信息 bot_user_info = UserInfo( diff --git a/src/chat/focus_chat/expressors/exprssion_learner.py b/src/chat/focus_chat/expressors/exprssion_learner.py index e210cf7ed..ac2206fec 100644 --- a/src/chat/focus_chat/expressors/exprssion_learner.py +++ b/src/chat/focus_chat/expressors/exprssion_learner.py @@ -140,12 +140,12 @@ class ExpressionLearner: continue # 学习新的表达方式(这里会进行局部衰减) - for i in range(3): + for _ in range(3): learnt_style: Optional[List[Tuple[str, str, str]]] = await self.learn_and_store(type="style", num=25) if not learnt_style: return [] - for j in range(1): + for _ in range(1): learnt_grammar: Optional[List[Tuple[str, str, str]]] = await self.learn_and_store(type="grammar", num=10) if not learnt_grammar: return [] diff --git a/src/chat/focus_chat/heartFC_chat.py b/src/chat/focus_chat/heartFC_chat.py index 4ab767a15..9dee93d6e 100644 --- a/src/chat/focus_chat/heartFC_chat.py +++ b/src/chat/focus_chat/heartFC_chat.py @@ -562,9 +562,6 @@ class HeartFChatting: tuple[bool, str, str]: (是否执行了动作, 思考消息ID, 命令) """ try: - action_time = time.time() - action_id = f"{action_time}_{thinking_id}" - # 使用工厂创建动作处理器实例 try: action_handler = self.action_manager.create_action( diff --git a/src/chat/focus_chat/heartFC_sender.py b/src/chat/focus_chat/heartFC_sender.py index 528d5802d..b2e4849bd 100644 --- a/src/chat/focus_chat/heartFC_sender.py +++ b/src/chat/focus_chat/heartFC_sender.py @@ -88,10 +88,10 @@ class HeartFCSender: """ if not message.chat_stream: logger.error("消息缺少 chat_stream,无法发送") - raise "消息缺少 chat_stream,无法发送" + raise Exception("消息缺少 chat_stream,无法发送") if not message.message_info or not message.message_info.message_id: logger.error("消息缺少 message_info 或 message_id,无法发送") - raise "消息缺少 message_info 或 message_id,无法发送" + raise Exception("消息缺少 message_info 或 message_id,无法发送") chat_id = message.chat_stream.stream_id message_id = message.message_info.message_id diff --git a/src/chat/focus_chat/info_processors/self_processor.py b/src/chat/focus_chat/info_processors/self_processor.py index 0f75b6686..a296dbe86 100644 --- a/src/chat/focus_chat/info_processors/self_processor.py +++ b/src/chat/focus_chat/info_processors/self_processor.py @@ -100,13 +100,6 @@ class SelfProcessor(BaseProcessor): tuple: (current_mind, past_mind, prompt) 当前想法、过去的想法列表和使用的prompt """ - for observation in observations: - if isinstance(observation, ChattingObservation): - is_group_chat = observation.is_group_chat - chat_target_info = observation.chat_target_info - chat_target_name = "对方" # 私聊默认名称 - person_list = observation.person_list - if observations is None: observations = [] for observation in observations: