Selaa lähdekoodia

add option: group_chat_in_one_session

master
Bachery 1 vuosi sitten
vanhempi
commit
32cff41df5
3 muutettua tiedostoa jossa 13 lisäystä ja 7 poistoa
  1. +7
    -3
      channel/wechat/wechat_channel.py
  2. +5
    -3
      channel/wechat/wechaty_channel.py
  3. +1
    -1
      config-template.json

+ 7
- 3
channel/wechat/wechat_channel.py Näytä tiedosto

@@ -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):


+ 5
- 3
channel/wechat/wechaty_channel.py Näytä tiedosto

@@ -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)


+ 1
- 1
config-template.json Näytä tiedosto

@@ -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,


Loading…
Peruuta
Tallenna