初步追加通过json导入messages数组的方式进行情景预设

This commit is contained in:
chordfish
2023-03-09 14:44:33 +08:00
parent 7e5a77f77e
commit 12a0942ddb
13 changed files with 928 additions and 158 deletions
+2 -9
View File
@@ -7,8 +7,6 @@ import logging
class ReplyFilter:
sensitive_words = []
mask = "*"
mask_word = ""
# 默认值( 兼容性考虑 )
baidu_check = False
@@ -16,10 +14,8 @@ class ReplyFilter:
baidu_secret_key = ""
inappropriate_message_tips = "[百度云]请珍惜机器人,当前返回内容不合规"
def __init__(self, sensitive_words: list, mask: str = "*", mask_word: str = ""):
def __init__(self, sensitive_words: list):
self.sensitive_words = sensitive_words
self.mask = mask
self.mask_word = mask_word
import config
if hasattr(config, 'baidu_check') and hasattr(config, 'baidu_api_key') and hasattr(config, 'baidu_secret_key'):
self.baidu_check = config.baidu_check
@@ -40,10 +36,7 @@ class ReplyFilter:
match = re.findall(word, message)
if len(match) > 0:
for i in range(len(match)):
if self.mask_word == "":
message = message.replace(match[i], self.mask * len(match[i]))
else:
message = message.replace(match[i], self.mask_word)
message = message.replace(match[i], "*" * len(match[i]))
# 百度云审核
if self.baidu_check: