mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-25 22:06:06 +00:00
fix: 匹配规则的内容检查
This commit is contained in:
+13
-8
@@ -30,18 +30,23 @@ def go(func, args=()):
|
|||||||
|
|
||||||
# 检查消息是否符合泛响应匹配机制
|
# 检查消息是否符合泛响应匹配机制
|
||||||
def check_response_rule(text: str) -> (bool, str):
|
def check_response_rule(text: str) -> (bool, str):
|
||||||
|
if not hasattr(config, 'response_rules'):
|
||||||
|
return False, ''
|
||||||
|
|
||||||
rules = config.response_rules
|
rules = config.response_rules
|
||||||
# 检查前缀匹配
|
# 检查前缀匹配
|
||||||
for rule in rules['prefix']:
|
if 'prefix' in rules:
|
||||||
if text.startswith(rule):
|
for rule in rules['prefix']:
|
||||||
return True, text.replace(rule, "", 1)
|
if text.startswith(rule):
|
||||||
|
return True, text.replace(rule, "", 1)
|
||||||
|
|
||||||
# 检查正则表达式匹配
|
# 检查正则表达式匹配
|
||||||
for rule in rules['regex']:
|
if 'regexp' in rules:
|
||||||
import re
|
for rule in rules['regexp']:
|
||||||
match = re.match(rule, text)
|
import re
|
||||||
if match:
|
match = re.match(rule, text)
|
||||||
return True, match.group(1)
|
if match:
|
||||||
|
return True, match.group(1)
|
||||||
|
|
||||||
return False, ""
|
return False, ""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user