Jelajahi Sumber

Merge pull request #1390 from scut-chenzk/chenzk

Chenzk
zhayujie 2 tahun lalu
induk
melakukan
125fe2a026
2 mengubah file dengan 21 tambahan dan 18 penghapusan
  1. 18 17
      channel/chat_channel.py
  2. 3 1
      channel/wework/wework_message.py

+ 18 - 17
channel/chat_channel.py

@@ -99,25 +99,26 @@ 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()
-                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)
-                    if isinstance(context["msg"].at_list, list):
-                        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
+                        if isinstance(context["msg"].at_list, list):
+                            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")

+ 3 - 1
channel/wework/wework_message.py

@@ -157,7 +157,9 @@ class WeworkMessage(ChatMessage):
                     at_list = tmp_list
                     logger.debug(f"at_list: {at_list}")
                     logger.debug(f"nickname: {nickname}")
-                    self.is_at = nickname in at_list
+                    self.is_at = False
+                    if nickname in at_list or login_info['nickname'] in at_list or login_info['username'] in at_list:
+                        self.is_at = True
                     self.at_list = at_list
 
                     # 检查消息内容是否包含@用户名。处理复制粘贴的消息,这类消息可能不会触发@通知,但内容中可能包含 "@用户名"。