From 9a7490bc2f79cdd1e747a2fa61e9fce7bdb578d1 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Sun, 5 Mar 2023 10:49:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=8B=92=E7=BB=9D?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E5=8C=85=E5=90=AB=E6=95=8F=E6=84=9F=E8=AF=8D?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E9=97=AE=20(#210)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config-template.py | 4 ++++ pkg/qqbot/filter.py | 6 ++++++ pkg/qqbot/process.py | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/config-template.py b/config-template.py index 347f7d52..73f50354 100644 --- a/config-template.py +++ b/config-template.py @@ -102,6 +102,10 @@ ignore_rules = { "regexp": [] } +# 是否检查收到的消息中是否包含敏感词 +# 若收到的消息无法通过下方指定的敏感词检查策略,则发送提示信息 +income_msg_check = False + # 敏感词过滤开关,以同样数量的*代替敏感词回复 # 请在sensitive.json中添加敏感词 sensitive_word_filter = True diff --git a/pkg/qqbot/filter.py b/pkg/qqbot/filter.py index e5ee8794..6ed83329 100644 --- a/pkg/qqbot/filter.py +++ b/pkg/qqbot/filter.py @@ -23,6 +23,12 @@ class ReplyFilter: self.baidu_secret_key = config.baidu_secret_key self.inappropriate_message_tips = config.inappropriate_message_tips + def is_illegal(self, message: str) -> bool: + processed = self.process(message) + if processed != message: + return True + return False + def process(self, message: str) -> str: # 本地关键词屏蔽 diff --git a/pkg/qqbot/process.py b/pkg/qqbot/process.py index c5b55866..3ca275ac 100644 --- a/pkg/qqbot/process.py +++ b/pkg/qqbot/process.py @@ -66,6 +66,11 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes result.mute_time_remaining)) return reply + import config + if hasattr(config, 'income_msg_check') and config.income_msg_check: + if mgr.reply_filter.is_illegal(text_message): + return MessageChain(Plain("[bot] 你的提问中有不合适的内容, 请更换措辞~")) + pkg.openai.session.get_session(session_name).acquire_response_lock() text_message = text_message.strip()