mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-13 01:06:03 +00:00
feat: 添加敏感词过滤功能
This commit is contained in:
18
pkg/qqbot/filter.py
Normal file
18
pkg/qqbot/filter.py
Normal 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
|
||||
Reference in New Issue
Block a user