From 32cff41df51c5967defbdbae14f195687169619e Mon Sep 17 00:00:00 2001 From: Bachery Date: Wed, 8 Mar 2023 13:11:37 +0100 Subject: [PATCH] add option: group_chat_in_one_session --- channel/wechat/wechat_channel.py | 10 +++++++--- channel/wechat/wechaty_channel.py | 8 +++++--- config-template.json | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index c7cbe82..e930fe9 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -147,14 +147,18 @@ class WechatChannel(Channel): if not query: return context = dict() - if conf().get("group_chat_in_one_session", False): - context['session_id'] = msg['User']['UserName'] + group_name = msg['User']['NickName'] + group_id = msg['User']['UserName'] + if ('ALL_GROUP' in conf().get('group_chat_in_one_session') or \ + group_name in conf().get('group_chat_in_one_session')) or \ + self.check_contain(group_name, conf().get('group_chat_in_one_session')): + context['session_id'] = group_id else: context['session_id'] = msg['ActualUserName'] reply_text = super().build_reply_content(query, context) if reply_text: reply_text = '@' + msg['ActualNickName'] + ' ' + reply_text.strip() - self.send(conf().get("group_chat_reply_prefix", "") + reply_text, msg['User']['UserName']) + self.send(conf().get("group_chat_reply_prefix", "") + reply_text, group_id) def check_prefix(self, content, prefix_list): diff --git a/channel/wechat/wechaty_channel.py b/channel/wechat/wechaty_channel.py index 240d2a7..331bc57 100644 --- a/channel/wechat/wechaty_channel.py +++ b/channel/wechat/wechaty_channel.py @@ -109,7 +109,7 @@ class WechatyChannel(Channel): content = content.split(img_match_prefix, 1)[1].strip() await self._do_send_group_img(content, room_id) else: - await self._do_send_group(content, room_id, from_user_id, from_user_name) + await self._do_send_group(content, room_id, room_name, from_user_id, from_user_name) async def send(self, message: Union[str, Message, FileBox, Contact, UrlLink, MiniProgram], receiver): logger.info('[WX] sendMsg={}, receiver={}'.format(message, receiver)) @@ -159,11 +159,13 @@ class WechatyChannel(Channel): except Exception as e: logger.exception(e) - async def _do_send_group(self, query, group_id, group_user_id, group_user_name): + async def _do_send_group(self, query, group_id, group_name, group_user_id, group_user_name): if not query: return context = dict() - if conf().get("group_chat_in_one_session", False): + if ('ALL_GROUP' in conf().get('group_chat_in_one_session') or \ + group_name in conf().get('group_chat_in_one_session') or \ + self.check_contain(group_name, conf().get('group_chat_in_one_session'))): context['session_id'] = str(group_id) else: context['session_id'] = str(group_id) + '-' + str(group_user_id) diff --git a/config-template.json b/config-template.json index 1dd5539..3e8f492 100644 --- a/config-template.json +++ b/config-template.json @@ -4,7 +4,7 @@ "single_chat_prefix": ["bot", "@bot"], "single_chat_reply_prefix": "[bot] ", "group_chat_prefix": ["@bot"], - "group_chat_in_one_session": "True", + "group_chat_in_one_session": ["ChatGPT测试群"], "group_name_white_list": ["ChatGPT测试群", "ChatGPT测试群2"], "image_create_prefix": ["画", "看", "找"], "conversation_max_tokens": 1000,