feat: 添加敏感词过滤功能

This commit is contained in:
Rock Chin
2022-12-11 17:17:33 +08:00
parent 76b60a781f
commit d9cc39dedb
4 changed files with 108 additions and 1 deletions

18
pkg/qqbot/filter.py Normal file
View File

@@ -0,0 +1,18 @@
import re
class ReplyFilter:
sensitive_words = []
def __init__(self, sensitive_words: list):
self.sensitive_words = sensitive_words
def process(self, message: str) -> str:
for word in self.sensitive_words:
match = re.findall(word, message)
if len(match) > 0:
for i in range(len(match)):
message = message.replace(match[i], "*" * len(match[i]))
return message