From 4d2b7d9bf903130a26fee5ef8ec8316ee0a73e30 Mon Sep 17 00:00:00 2001 From: Saboteur7 <138805485+Saboteur7@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:47:05 +0800 Subject: [PATCH] Update chat_channel.py --- channel/chat_channel.py | 66 ----------------------------------------- 1 file changed, 66 deletions(-) diff --git a/channel/chat_channel.py b/channel/chat_channel.py index 1923f26..877f5cd 100644 --- a/channel/chat_channel.py +++ b/channel/chat_channel.py @@ -159,72 +159,6 @@ class ChatChannel(Channel): elif context.type == ContextType.VOICE: if "desire_rtype" not in context and conf().get("voice_reply_voice") and ReplyType.VOICE not in self.NOT_SUPPORT_REPLYTYPE: context["desire_rtype"] = ReplyType.VOICE - elif context.type == ContextType.IMAGE: - if first_in and "」\n- - - - - - -" in content: # 初次匹配 过滤引用消息 - logger.debug(content) - logger.debug("[chat_channel]reference query skipped") - return None - - nick_name_black_list = conf().get("nick_name_black_list", []) - if context.get("isgroup", False): # 群聊 - # 校验关键字 - match_prefix = check_prefix(content, conf().get("group_chat_prefix",[""])) - match_contain = check_contain(content, conf().get("group_chat_keyword",[""])) - flag = 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 - if match_prefix: - content = content.replace(match_prefix, "", 1).strip() - if context["msg"].is_at: - nick_name = context["msg"].actual_user_nickname - if nick_name and nick_name in nick_name_black_list: - # 黑名单过滤 - logger.warning(f"[chat_channel] Nickname {nick_name} in In BlackList, ignore") - return None - - logger.info("[chat_channel]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) - 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("[chat_channel]receive group voice, but checkprefix didn't match") - return None - else: # 单聊 - nick_name = context["msg"].from_user_nickname - if nick_name and nick_name in nick_name_black_list: - # 黑名单过滤 - logger.warning(f"[chat_channel] Nickname '{nick_name}' in In BlackList, ignore") - return None - - match_prefix = check_prefix(content, conf().get("single_chat_prefix", [""])) - if match_prefix is not None: # 判断如果匹配到自定义前缀,则返回过滤掉前缀+空格后的内容 - content = content.replace(match_prefix, "", 1).strip() - elif context["origin_ctype"] == ContextType.VOICE: # 如果源消息是私聊的语音消息,允许不匹配前缀,放宽条件 - pass - else: - return None - content = content.strip() - img_match_prefix = check_prefix(content, conf().get("image_create_prefix",[""])) - if img_match_prefix: - content = content.replace(img_match_prefix, "", 1) - context.type = ContextType.IMAGE_CREATE - else: - context.type = ContextType.IMAGE - context.content = content.strip() - if "desire_rtype" not in context and conf().get("always_reply_voice") and ReplyType.VOICE not in self.NOT_SUPPORT_REPLYTYPE: - context["desire_rtype"] = ReplyType.VOICE return context def _handle(self, context: Context):