给keywords_reaction增加正则表达式匹配
顺便做了正则表达式预编译
This commit is contained in:
@@ -2,7 +2,6 @@ from src.common.logger import get_module_logger
|
||||
from src.plugins.chat.message import MessageRecv
|
||||
from src.plugins.storage.storage import MessageStorage
|
||||
from src.plugins.config.config import global_config
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
logger = get_module_logger("pfc_message_processor")
|
||||
@@ -28,7 +27,7 @@ class MessageProcessor:
|
||||
def _check_ban_regex(self, text: str, chat, userinfo) -> bool:
|
||||
"""检查消息是否匹配过滤正则表达式"""
|
||||
for pattern in global_config.ban_msgs_regex:
|
||||
if re.search(pattern, text):
|
||||
if pattern.search(text):
|
||||
logger.info(
|
||||
f"[{chat.group_info.group_name if chat.group_info else '私聊'}]{userinfo.user_nickname}:{text}"
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import time
|
||||
from random import random
|
||||
import re
|
||||
|
||||
from typing import List
|
||||
from ...memory_system.Hippocampus import HippocampusManager
|
||||
from ...moods.moods import MoodManager
|
||||
@@ -302,7 +302,7 @@ class ReasoningChat:
|
||||
def _check_ban_regex(self, text: str, chat, userinfo) -> bool:
|
||||
"""检查消息是否匹配过滤正则表达式"""
|
||||
for pattern in global_config.ban_msgs_regex:
|
||||
if re.search(pattern, text):
|
||||
if pattern.search(text):
|
||||
logger.info(
|
||||
f"[{chat.group_info.group_name if chat.group_info else '私聊'}]{userinfo.user_nickname}:{text}"
|
||||
)
|
||||
|
||||
@@ -115,6 +115,17 @@ class PromptBuilder:
|
||||
f"检测到以下关键词之一:{rule.get('keywords', [])},触发反应:{rule.get('reaction', '')}"
|
||||
)
|
||||
keywords_reaction_prompt += rule.get("reaction", "") + ","
|
||||
for pattern in rule.get("regex", []):
|
||||
result = pattern.search(message_txt)
|
||||
if result:
|
||||
reaction = rule.get('reaction', '')
|
||||
for name, content in result.groupdict().items():
|
||||
reaction = reaction.replace(f'[{name}]', content)
|
||||
logger.info(
|
||||
f"匹配到以下正则表达式:{pattern},触发反应:{reaction}"
|
||||
)
|
||||
keywords_reaction_prompt += reaction + ","
|
||||
break
|
||||
|
||||
# 中文高手(新加的好玩功能)
|
||||
prompt_ger = ""
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import time
|
||||
from random import random
|
||||
import re
|
||||
import traceback
|
||||
from typing import List
|
||||
from ...memory_system.Hippocampus import HippocampusManager
|
||||
@@ -388,7 +387,7 @@ class ThinkFlowChat:
|
||||
def _check_ban_regex(self, text: str, chat, userinfo) -> bool:
|
||||
"""检查消息是否匹配过滤正则表达式"""
|
||||
for pattern in global_config.ban_msgs_regex:
|
||||
if re.search(pattern, text):
|
||||
if pattern.search(text):
|
||||
logger.info(
|
||||
f"[{chat.group_info.group_name if chat.group_info else '私聊'}]{userinfo.user_nickname}:{text}"
|
||||
)
|
||||
|
||||
@@ -61,6 +61,17 @@ class PromptBuilder:
|
||||
f"检测到以下关键词之一:{rule.get('keywords', [])},触发反应:{rule.get('reaction', '')}"
|
||||
)
|
||||
keywords_reaction_prompt += rule.get("reaction", "") + ","
|
||||
for pattern in rule.get("regex", []):
|
||||
result = pattern.search(message_txt)
|
||||
if result:
|
||||
reaction = rule.get('reaction', '')
|
||||
for name, content in result.groupdict().items():
|
||||
reaction = reaction.replace(f'[{name}]', content)
|
||||
logger.info(
|
||||
f"匹配到以下正则表达式:{pattern},触发反应:{reaction}"
|
||||
)
|
||||
keywords_reaction_prompt += reaction + ","
|
||||
break
|
||||
|
||||
# 中文高手(新加的好玩功能)
|
||||
prompt_ger = ""
|
||||
|
||||
Reference in New Issue
Block a user