From af98b1ececd450285d9a9194bd42e571be10b1ac Mon Sep 17 00:00:00 2001 From: ikaros <327209194@qq.com> Date: Thu, 29 Feb 2024 21:27:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E6=96=87=E6=A1=88=20?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9A=84=E6=96=87=E6=A1=88=E5=86=85=E5=AE=B9?= =?UTF-8?q?=20=E9=BB=98=E8=AE=A4=E8=BF=9B=E8=A1=8C=20=E8=BF=9D=E7=A6=81?= =?UTF-8?q?=E8=AF=8D=E3=80=81=E9=93=BE=E6=8E=A5=E3=80=81=E7=BA=AF=E6=A0=87?= =?UTF-8?q?=E7=82=B9=E7=9A=84=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 +- utils/my_handle.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index bc962761..f76dc653 100644 --- a/main.py +++ b/main.py @@ -623,7 +623,7 @@ async def run_trends_copywriting(): # 空数据判断 if data_json["content"] != None and data_json["content"] != "": # 发给直接复读进行处理 - my_handle.reread_handle(data_json) + my_handle.reread_handle(data_json, filter=True) await asyncio.sleep(config.get("trends_copywriting", "play_interval")) except Exception as e: diff --git a/utils/my_handle.py b/utils/my_handle.py index c9de0256..ee1c50d0 100644 --- a/utils/my_handle.py +++ b/utils/my_handle.py @@ -1007,11 +1007,12 @@ def prohibitions_handle(self, content): # 直接复读 - def reread_handle(self, data): + def reread_handle(self, data, filter=False): """复读处理 Args: data (dict): 包含用户名,弹幕内容 + filter (bool): 是否开启复读内容的过滤 Returns: _type_: 寂寞 @@ -1021,6 +1022,22 @@ def reread_handle(self, data): content = data["content"] logging.info(f"复读内容:{content}") + + if filter: + # 违禁处理 + content = self.prohibitions_handle(content) + if content is None: + return + + # 弹幕格式检查和特殊字符替换 + content = self.comment_check_and_replace(content) + if content is None: + return + + # 判断字符串是否全为标点符号,是的话就过滤 + if My_handle.common.is_punctuation_string(content): + logging.debug(f"用户:{username}],发送纯符号的弹幕,已过滤") + return # 音频合成时需要用到的重要数据 message = {