add option: group_chat_in_one_session

This commit is contained in:
Bachery
2023-03-08 13:11:37 +01:00
parent 8eace7e30e
commit 32cff41df5
3 changed files with 13 additions and 7 deletions

View File

@@ -147,14 +147,18 @@ class WechatChannel(Channel):
if not query: if not query:
return return
context = dict() context = dict()
if conf().get("group_chat_in_one_session", False): group_name = msg['User']['NickName']
context['session_id'] = msg['User']['UserName'] 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: else:
context['session_id'] = msg['ActualUserName'] context['session_id'] = msg['ActualUserName']
reply_text = super().build_reply_content(query, context) reply_text = super().build_reply_content(query, context)
if reply_text: if reply_text:
reply_text = '@' + msg['ActualNickName'] + ' ' + reply_text.strip() 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): def check_prefix(self, content, prefix_list):

View File

@@ -109,7 +109,7 @@ class WechatyChannel(Channel):
content = content.split(img_match_prefix, 1)[1].strip() content = content.split(img_match_prefix, 1)[1].strip()
await self._do_send_group_img(content, room_id) await self._do_send_group_img(content, room_id)
else: 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): async def send(self, message: Union[str, Message, FileBox, Contact, UrlLink, MiniProgram], receiver):
logger.info('[WX] sendMsg={}, receiver={}'.format(message, receiver)) logger.info('[WX] sendMsg={}, receiver={}'.format(message, receiver))
@@ -159,11 +159,13 @@ class WechatyChannel(Channel):
except Exception as e: except Exception as e:
logger.exception(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: if not query:
return return
context = dict() 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) context['session_id'] = str(group_id)
else: else:
context['session_id'] = str(group_id) + '-' + str(group_user_id) context['session_id'] = str(group_id) + '-' + str(group_user_id)

View File

@@ -4,7 +4,7 @@
"single_chat_prefix": ["bot", "@bot"], "single_chat_prefix": ["bot", "@bot"],
"single_chat_reply_prefix": "[bot] ", "single_chat_reply_prefix": "[bot] ",
"group_chat_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"], "group_name_white_list": ["ChatGPT测试群", "ChatGPT测试群2"],
"image_create_prefix": ["画", "看", "找"], "image_create_prefix": ["画", "看", "找"],
"conversation_max_tokens": 1000, "conversation_max_tokens": 1000,