mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-20 21:57:14 +08:00
防止命中前缀导致死循环的情况
This commit is contained in:
@@ -99,25 +99,25 @@ class ChatChannel(Channel):
|
|||||||
match_prefix = check_prefix(content, conf().get("group_chat_prefix"))
|
match_prefix = check_prefix(content, conf().get("group_chat_prefix"))
|
||||||
match_contain = check_contain(content, conf().get("group_chat_keyword"))
|
match_contain = check_contain(content, conf().get("group_chat_keyword"))
|
||||||
flag = False
|
flag = False
|
||||||
if match_prefix is not None or match_contain is not None:
|
if context["msg"].to_user_id != context["msg"].actual_user_id:
|
||||||
flag = True
|
if match_prefix is not None or match_contain is not None:
|
||||||
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):
|
|
||||||
flag = True
|
flag = True
|
||||||
pattern = f"@{re.escape(self.name)}(\u2005|\u0020)"
|
if match_prefix:
|
||||||
subtract_res = re.sub(pattern, r"", content)
|
content = content.replace(match_prefix, "", 1).strip()
|
||||||
for at in context["msg"].at_list:
|
if context["msg"].is_at:
|
||||||
pattern = f"@{re.escape(at)}(\u2005|\u0020)"
|
logger.info("[WX]receive group at")
|
||||||
subtract_res = re.sub(pattern, r"", subtract_res)
|
if not conf().get("group_at_off", False):
|
||||||
if subtract_res == content and context["msg"].self_display_name:
|
flag = True
|
||||||
# 前缀移除后没有变化,使用群昵称再次移除
|
pattern = f"@{re.escape(self.name)}(\u2005|\u0020)"
|
||||||
pattern = f"@{re.escape(context['msg'].self_display_name)}(\u2005|\u0020)"
|
|
||||||
subtract_res = re.sub(pattern, r"", content)
|
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 not flag:
|
||||||
if context["origin_ctype"] == ContextType.VOICE:
|
if context["origin_ctype"] == ContextType.VOICE:
|
||||||
logger.info("[WX]receive group voice, but checkprefix didn't match")
|
logger.info("[WX]receive group voice, but checkprefix didn't match")
|
||||||
|
|||||||
Reference in New Issue
Block a user