ソースを参照

feat: single chat without prefix and group chat fully open #15

zhayujie 3 年 前
コミット
ccf6b11162
2 ファイル変更19 行追加8 行削除
  1. 13 3
      README.md
  2. 6 5
      channel/wechat/wechat_channel.py

+ 13 - 3
README.md

@@ -89,9 +89,19 @@ cp config-template.json config.json
 ```
 **配置说明:**
 
-+ 个人聊天中,需要以 "bot" 或 "@bot" 为开头的内容触发机器人,对应配置中的 `single_chat_prefix`;机器人回复的内容会以 "[bot]" 作为前缀, 以区分真人,对应的配置为 `single_chat_reply_prefix`
-+ 群组聊天中,群名称需配置在 `group_name_white_list ` 中才能开启群聊自动回复,默认只要被@就会触发机器人自动回复;另外群聊天中只要检测到以 "@bot" 开头的内容,同样会自动回复(方便自己触发),这对应配置 `group_chat_prefix`
-+ 对于图像生成,在满足个人或群组触发条件外,还需要额外的关键词,对应配置 `image_create_prefix `
+**个人聊天**
+
++ 个人聊天中,需要以 "bot"或"@bot" 为开头的内容触发机器人,对应配置项 `single_chat_prefix` (如果不需要以前缀触发可以填写  `"single_chat_prefix": [""]`)
++ 机器人回复的内容会以 "[bot] " 作为前缀, 以区分真人,对应的配置项为 `single_chat_reply_prefix` (如果不需要前缀可以填写 `"single_chat_reply_prefix": ""`)
+
+**群组聊天**
+
++ 群组聊天中,群名称需配置在 `group_name_white_list ` 中才能开启群聊自动回复。如果想对所有群聊生效,可以直接填写 `"group_name_white_list": "ALL_GROUP"`
++ 默认只要被人 @ 就会触发机器人自动回复;另外群聊天中只要检测到以 "@bot" 开头的内容,同样会自动回复(方便自己触发),这对应配置项 `group_chat_prefix`
+
+**其他配置**:
+
++ 对于图像生成,在满足个人或群组触发条件外,还需要额外的关键词前缀来触发,对应配置 `image_create_prefix `
 + 关于OpenAI对话及图片接口的参数配置(内容自由度、回复字数限制、图片大小等),可以参考 [对话接口](https://beta.openai.com/docs/api-reference/completions) 和 [图像接口](https://beta.openai.com/docs/api-reference/completions)  文档直接在 [代码](https://github.com/zhayujie/chatgpt-on-wechat/blob/master/bot/openai/open_ai_bot.py) `bot/openai/open_ai_bot.py` 中进行调整。
 
 

+ 6 - 5
channel/wechat/wechat_channel.py

@@ -46,11 +46,12 @@ class WechatChannel(Channel):
         other_user_id = msg['User']['UserName']     # 对手方id
         content = msg['Text']
         match_prefix = self.check_prefix(content, conf().get('single_chat_prefix'))
-        if from_user_id == other_user_id and match_prefix:
+        if from_user_id == other_user_id and match_prefix is not None:
             # 好友向自己发送消息
-            str_list = content.split(match_prefix, 1)
-            if len(str_list) == 2:
-                content = str_list[1].strip()
+            if match_prefix is not '':
+                str_list = content.split(match_prefix, 1)
+                if len(str_list) == 2:
+                    content = str_list[1].strip()
 
             img_match_prefix = self.check_prefix(content, conf().get('image_create_prefix'))
             if img_match_prefix:
@@ -89,7 +90,7 @@ class WechatChannel(Channel):
 
         config = conf()
         match_prefix = msg['IsAt'] or self.check_prefix(origin_content, config.get('group_chat_prefix'))
-        if group_name in config.get('group_name_white_list') and match_prefix:
+        if (group_name in config.get('group_name_white_list') or 'ALL_GROUP' in config.get('group_name_white_list')) and match_prefix:
             img_match_prefix = self.check_prefix(content, conf().get('image_create_prefix'))
             if img_match_prefix:
                 content = content.split(img_match_prefix, 1)[1].strip()