From 4af2c7f3d761bd9b0ee41ee3e41ab78ab1be119f Mon Sep 17 00:00:00 2001 From: lanvent Date: Sat, 22 Apr 2023 11:39:59 +0800 Subject: [PATCH] fix: escape regex pattern --- channel/chat_channel.py | 4 ++-- channel/wechat/wechaty_message.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/channel/chat_channel.py b/channel/chat_channel.py index 3667cf7..04a9496 100644 --- a/channel/chat_channel.py +++ b/channel/chat_channel.py @@ -114,8 +114,8 @@ class ChatChannel(Channel): logger.info("[WX]receive group at") if not conf().get("group_at_off", False): flag = True - pattern = f"@{self.name}(\u2005|\u0020)" - content = re.sub(re.escape(pattern), r"", content) + pattern = f"@{re.escape(self.name)}(\u2005|\u0020)" + content = re.sub(pattern, r"", content) if not flag: if context["origin_ctype"] == ContextType.VOICE: diff --git a/channel/wechat/wechaty_message.py b/channel/wechat/wechaty_message.py index fe4adb7..94896f1 100644 --- a/channel/wechat/wechaty_message.py +++ b/channel/wechat/wechaty_message.py @@ -86,8 +86,8 @@ class WechatyMessage(ChatMessage, aobject): self.is_at = await wechaty_msg.mention_self() if not self.is_at: # 有时候复制粘贴的消息,不算做@,但是内容里面会有@xxx,这里做一下兼容 name = wechaty_msg.wechaty.user_self().name - pattern = f"@{name}(\u2005|\u0020)" - if re.search(re.escape(pattern), self.content): + pattern = f"@{re.escape(name)}(\u2005|\u0020)" + if re.search(pattern, self.content): logger.debug(f"wechaty message {self.msg_id} include at") self.is_at = True