From 852adb72a234e4283b164aa71bc736698d7b124f Mon Sep 17 00:00:00 2001 From: B1gM8c <89020353+B1gM8c@users.noreply.github.com> Date: Mon, 20 Mar 2023 01:17:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81Wechaty=E7=9A=84=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=89=8D=E7=BC=80+=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E8=AF=8D=E7=94=9F=E6=88=90AI=E5=9B=BE=E7=89=87=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wechaty判断is_at为True,返回的内容是过滤掉@之后的内容;而is_at为False,则会返回完整的内容 故判断如果匹配到自定义前缀,则返回过滤掉前缀+空格后的内容,用于实现类似自定义+前缀触发生成AI图片的功能 --- channel/wechat/wechaty_channel.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/channel/wechat/wechaty_channel.py b/channel/wechat/wechaty_channel.py index 79ce601..a958d85 100644 --- a/channel/wechat/wechaty_channel.py +++ b/channel/wechat/wechaty_channel.py @@ -147,6 +147,13 @@ class WechatyChannel(Channel): match_prefix = (is_at and not config.get("group_at_off", False)) \ or self.check_prefix(content, config.get('group_chat_prefix')) \ or self.check_contain(content, config.get('group_chat_keyword')) + # Wechaty判断is_at为True,返回的内容是过滤掉@之后的内容;而is_at为False,则会返回完整的内容 + # 故判断如果匹配到自定义前缀,则返回过滤掉前缀+空格后的内容,用于实现类似自定义+前缀触发生成AI图片的功能 + prefixes = config.get('group_chat_prefix') + for prefix in prefixes: + if content.startswith(prefix): + content = content.replace(prefix, '', 1).strip() + break if ('ALL_GROUP' in config.get('group_name_white_list') or room_name in config.get( 'group_name_white_list') or self.check_contain(room_name, config.get( 'group_name_keyword_white_list'))) and match_prefix: