From 79be4530d49469f37b52bdeddd5bf4c1fa546f83 Mon Sep 17 00:00:00 2001 From: chenzhenkun Date: Fri, 1 Sep 2023 19:18:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E5=91=BD=E4=B8=AD=E5=89=8D?= =?UTF-8?q?=E7=BC=80=E5=AF=BC=E8=87=B4=E6=AD=BB=E5=BE=AA=E7=8E=AF=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- channel/chat_channel.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/channel/chat_channel.py b/channel/chat_channel.py index be75ebb..e83ebe6 100644 --- a/channel/chat_channel.py +++ b/channel/chat_channel.py @@ -99,25 +99,25 @@ class ChatChannel(Channel): match_prefix = check_prefix(content, conf().get("group_chat_prefix")) match_contain = check_contain(content, conf().get("group_chat_keyword")) flag = False - if match_prefix is not None or match_contain is not None: - flag = True - if match_prefix: - content = content.replace(match_prefix, "", 1).strip() - logger.info(f'context["msg"]: {context["msg"].__str__()}') - if context["msg"].is_at and context["msg"].to_user_id != context["msg"].actual_user_id: - logger.info("[WX]receive group at") - if not conf().get("group_at_off", False): + if context["msg"].to_user_id != context["msg"].actual_user_id: + if match_prefix is not None or match_contain is not None: flag = True - pattern = f"@{re.escape(self.name)}(\u2005|\u0020)" - subtract_res = re.sub(pattern, r"", content) - for at in context["msg"].at_list: - pattern = f"@{re.escape(at)}(\u2005|\u0020)" - subtract_res = re.sub(pattern, r"", subtract_res) - if subtract_res == content and context["msg"].self_display_name: - # 前缀移除后没有变化,使用群昵称再次移除 - pattern = f"@{re.escape(context['msg'].self_display_name)}(\u2005|\u0020)" + if match_prefix: + content = content.replace(match_prefix, "", 1).strip() + if context["msg"].is_at: + logger.info("[WX]receive group at") + if not conf().get("group_at_off", False): + flag = True + pattern = f"@{re.escape(self.name)}(\u2005|\u0020)" subtract_res = re.sub(pattern, r"", content) - content = subtract_res + for at in context["msg"].at_list: + pattern = f"@{re.escape(at)}(\u2005|\u0020)" + subtract_res = re.sub(pattern, r"", subtract_res) + if subtract_res == content and context["msg"].self_display_name: + # 前缀移除后没有变化,使用群昵称再次移除 + pattern = f"@{re.escape(context['msg'].self_display_name)}(\u2005|\u0020)" + subtract_res = re.sub(pattern, r"", content) + content = subtract_res if not flag: if context["origin_ctype"] == ContextType.VOICE: logger.info("[WX]receive group voice, but checkprefix didn't match")