mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
fix: 匹配规则的内容检查
This commit is contained in:
parent
42a85ddbb1
commit
0227ff0329
|
@ -30,14 +30,19 @@ def go(func, args=()):
|
|||
|
||||
# 检查消息是否符合泛响应匹配机制
|
||||
def check_response_rule(text: str) -> (bool, str):
|
||||
if not hasattr(config, 'response_rules'):
|
||||
return False, ''
|
||||
|
||||
rules = config.response_rules
|
||||
# 检查前缀匹配
|
||||
if 'prefix' in rules:
|
||||
for rule in rules['prefix']:
|
||||
if text.startswith(rule):
|
||||
return True, text.replace(rule, "", 1)
|
||||
|
||||
# 检查正则表达式匹配
|
||||
for rule in rules['regex']:
|
||||
if 'regexp' in rules:
|
||||
for rule in rules['regexp']:
|
||||
import re
|
||||
match = re.match(rule, text)
|
||||
if match:
|
||||
|
|
Loading…
Reference in New Issue
Block a user