refactor: 将多个方法修改为静态方法以提高代码可读性和一致性

This commit is contained in:
春河晴
2025-04-17 15:39:49 +09:00
parent 73da67fce8
commit dc96e26ca5
37 changed files with 248 additions and 174 deletions

View File

@@ -37,7 +37,8 @@ class ReasoningChat:
self.mood_manager = MoodManager.get_instance()
self.mood_manager.start_mood_update()
async def _create_thinking_message(self, message, chat, userinfo, messageinfo):
@staticmethod
async def _create_thinking_message(message, chat, userinfo, messageinfo):
"""创建思考消息"""
bot_user_info = UserInfo(
user_id=global_config.BOT_QQ,
@@ -59,7 +60,8 @@ class ReasoningChat:
return thinking_id
async def _send_response_messages(self, message, chat, response_set: List[str], thinking_id) -> MessageSending:
@staticmethod
async def _send_response_messages(message, chat, response_set: List[str], thinking_id) -> MessageSending:
"""发送回复消息"""
container = message_manager.get_container(chat.stream_id)
thinking_message = None
@@ -104,7 +106,8 @@ class ReasoningChat:
return first_bot_msg
async def _handle_emoji(self, message, chat, response):
@staticmethod
async def _handle_emoji(message, chat, response):
"""处理表情包"""
if random() < global_config.emoji_chance:
emoji_raw = await emoji_manager.get_emoji_for_text(response)
@@ -291,7 +294,8 @@ class ReasoningChat:
# 意愿管理器注销当前message信息
willing_manager.delete(message.message_info.message_id)
def _check_ban_words(self, text: str, chat, userinfo) -> bool:
@staticmethod
def _check_ban_words(text: str, chat, userinfo) -> bool:
"""检查消息中是否包含过滤词"""
for word in global_config.ban_words:
if word in text:
@@ -302,7 +306,8 @@ class ReasoningChat:
return True
return False
def _check_ban_regex(self, text: str, chat, userinfo) -> bool:
@staticmethod
def _check_ban_regex(text: str, chat, userinfo) -> bool:
"""检查消息是否匹配过滤正则表达式"""
for pattern in global_config.ban_msgs_regex:
if pattern.search(text):

View File

@@ -188,7 +188,8 @@ class ResponseGenerator:
logger.debug(f"获取情感标签时出错: {e}")
return "中立", "平静" # 出错时返回默认值
async def _process_response(self, content: str) -> Tuple[List[str], List[str]]:
@staticmethod
async def _process_response(content: str) -> Tuple[List[str], List[str]]:
"""处理响应内容,返回处理后的内容和情感标签"""
if not content:
return None, []

View File

@@ -373,8 +373,9 @@ class PromptBuilder:
logger.info(f"知识库检索总耗时: {time.time() - start_time:.3f}")
return related_info
@staticmethod
def get_info_from_db(
self, query_embedding: list, limit: int = 1, threshold: float = 0.5, return_raw: bool = False
query_embedding: list, limit: int = 1, threshold: float = 0.5, return_raw: bool = False
) -> Union[str, list]:
if not query_embedding:
return "" if not return_raw else []