fix: sensitive word check bug #202

This commit is contained in:
zhayujie
2023-03-26 12:01:30 +08:00
parent 794c151a15
commit 427866c7cf

View File

@@ -16,20 +16,15 @@ cache = {}
@robot.text
def hello_world(msg):
with open('sensitive_words.txt', 'r', encoding='utf-8') as f: #加入检测违规词
sensitive_wordss = [msg.content[i:i+2] for i in range(0, len(msg.content), 2)]
sensitive_words = [line.strip() for line in f.readlines()]
found = False
#判断文件是否为空
if not os.path.getsize('sensitive_words.txt'):
found = False
else:
for i in sensitive_wordss:
if i in f.read():
found = True
break
else:
found = False
for word in sensitive_words:
if word in msg.content:
found = True
break
if found:
return '输入内容包含敏感词汇'
return "输入内容敏感词汇"
else:
logger.info('[WX_Public] receive public msg: {}, userId: {}'.format(msg.content, msg.source))
key = msg.content + '|' + msg.source