防止关键词和regex重复匹配
This commit is contained in:
@@ -115,17 +115,18 @@ class PromptBuilder:
|
|||||||
f"检测到以下关键词之一:{rule.get('keywords', [])},触发反应:{rule.get('reaction', '')}"
|
f"检测到以下关键词之一:{rule.get('keywords', [])},触发反应:{rule.get('reaction', '')}"
|
||||||
)
|
)
|
||||||
keywords_reaction_prompt += rule.get("reaction", "") + ","
|
keywords_reaction_prompt += rule.get("reaction", "") + ","
|
||||||
for pattern in rule.get("regex", []):
|
else:
|
||||||
result = pattern.search(message_txt)
|
for pattern in rule.get("regex", []):
|
||||||
if result:
|
result = pattern.search(message_txt)
|
||||||
reaction = rule.get('reaction', '')
|
if result:
|
||||||
for name, content in result.groupdict().items():
|
reaction = rule.get('reaction', '')
|
||||||
reaction = reaction.replace(f'[{name}]', content)
|
for name, content in result.groupdict().items():
|
||||||
logger.info(
|
reaction = reaction.replace(f'[{name}]', content)
|
||||||
f"匹配到以下正则表达式:{pattern},触发反应:{reaction}"
|
logger.info(
|
||||||
)
|
f"匹配到以下正则表达式:{pattern},触发反应:{reaction}"
|
||||||
keywords_reaction_prompt += reaction + ","
|
)
|
||||||
break
|
keywords_reaction_prompt += reaction + ","
|
||||||
|
break
|
||||||
|
|
||||||
# 中文高手(新加的好玩功能)
|
# 中文高手(新加的好玩功能)
|
||||||
prompt_ger = ""
|
prompt_ger = ""
|
||||||
|
|||||||
@@ -61,17 +61,18 @@ class PromptBuilder:
|
|||||||
f"检测到以下关键词之一:{rule.get('keywords', [])},触发反应:{rule.get('reaction', '')}"
|
f"检测到以下关键词之一:{rule.get('keywords', [])},触发反应:{rule.get('reaction', '')}"
|
||||||
)
|
)
|
||||||
keywords_reaction_prompt += rule.get("reaction", "") + ","
|
keywords_reaction_prompt += rule.get("reaction", "") + ","
|
||||||
for pattern in rule.get("regex", []):
|
else:
|
||||||
result = pattern.search(message_txt)
|
for pattern in rule.get("regex", []):
|
||||||
if result:
|
result = pattern.search(message_txt)
|
||||||
reaction = rule.get('reaction', '')
|
if result:
|
||||||
for name, content in result.groupdict().items():
|
reaction = rule.get('reaction', '')
|
||||||
reaction = reaction.replace(f'[{name}]', content)
|
for name, content in result.groupdict().items():
|
||||||
logger.info(
|
reaction = reaction.replace(f'[{name}]', content)
|
||||||
f"匹配到以下正则表达式:{pattern},触发反应:{reaction}"
|
logger.info(
|
||||||
)
|
f"匹配到以下正则表达式:{pattern},触发反应:{reaction}"
|
||||||
keywords_reaction_prompt += reaction + ","
|
)
|
||||||
break
|
keywords_reaction_prompt += reaction + ","
|
||||||
|
break
|
||||||
|
|
||||||
# 中文高手(新加的好玩功能)
|
# 中文高手(新加的好玩功能)
|
||||||
prompt_ger = ""
|
prompt_ger = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user