Skip to content

Commit

Permalink
fix: escape regex pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
lanvent committed Apr 22, 2023
1 parent 361f599 commit 4af2c7f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions channel/chat_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def _compose_context(self, ctype: ContextType, content, **kwargs):
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:
Expand Down
4 changes: 2 additions & 2 deletions channel/wechat/wechaty_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def func():
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

Expand Down

0 comments on commit 4af2c7f

Please sign in to comment.