mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-02-19 09:07:02 +08:00
increase group_chat_keyword and group_name_keyword_white_list into config.json to support fuzzy matching on group chat.
This commit is contained in:
@@ -84,7 +84,9 @@ cp config-template.json config.json
|
||||
"single_chat_prefix": ["bot", "@bot"], # 私聊时文本需要包含该前缀才能触发机器人回复
|
||||
"single_chat_reply_prefix": "[bot] ", # 私聊时自动回复的前缀,用于区分真人
|
||||
"group_chat_prefix": ["@bot"], # 群聊时包含该前缀则会触发机器人回复
|
||||
"group_chat_keyword": ["为什么", "why", "Why", "?", "请教"], # 群聊内容包含其中任意字符串,将会触发机器人回复
|
||||
"group_name_white_list": ["ChatGPT测试群", "ChatGPT测试群2"], # 开启自动回复的群名称列表
|
||||
"group_name_keyword_white_list": ["相亲相爱", "瞎侃"], # 开启自动回复的群名称关键字列表(群名称含关键字即可匹配上)
|
||||
"image_create_prefix": ["画", "看", "找"] # 开启图片回复的前缀
|
||||
}
|
||||
```
|
||||
@@ -99,6 +101,7 @@ cp config-template.json config.json
|
||||
|
||||
+ 群组聊天中,群名称需配置在 `group_name_white_list ` 中才能开启群聊自动回复。如果想对所有群聊生效,可以直接填写 `"group_name_white_list": "ALL_GROUP"`
|
||||
+ 默认只要被人 @ 就会触发机器人自动回复;另外群聊天中只要检测到以 "@bot" 开头的内容,同样会自动回复(方便自己触发),这对应配置项 `group_chat_prefix`
|
||||
+ 新增group_name_keyword_white_list以应对某些群名称中包含非主流或常常变动,只匹配部分关键字将使配置简单。+ 新增group_chat_keyword以更灵活的触发群内的聊天自动回复,增加趣味。
|
||||
|
||||
**3.其他配置**
|
||||
|
||||
@@ -133,4 +136,4 @@ FAQs: <https://github.com/zhayujie/chatgpt-on-wechat/wiki/FAQs>
|
||||
|
||||
欢迎提交 PR、Issues。程序运行遇到问题优先查看 [常见问题列表](https://github.com/zhayujie/chatgpt-on-wechat/wiki/FAQs) ,其次前往 [Issues](https://github.com/zhayujie/chatgpt-on-wechat/issues) 中搜索,没有相似问题则创建Issue,一段时间内无回复可加微信 zhayujie_com 交流。
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -89,8 +89,8 @@ class WechatChannel(Channel):
|
||||
content = content_list[1]
|
||||
|
||||
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') or 'ALL_GROUP' in config.get('group_name_white_list')) and match_prefix:
|
||||
match_prefix = msg['IsAt'] or self.check_prefix(origin_content, config.get('group_chat_prefix')) or self.check_contain(origin_content, config.get('group_chat_keyword'))
|
||||
if (group_name in config.get('group_name_white_list') or 'ALL_GROUP' in config.get('group_name_white_list') or self.fuzzy_match_group_name(group_name, config.get('group_name_keyword_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()
|
||||
@@ -152,3 +152,15 @@ class WechatChannel(Channel):
|
||||
if content.startswith(prefix):
|
||||
return prefix
|
||||
return None
|
||||
|
||||
def check_contain(self, content, keyword_list):
|
||||
for ky in keyword_list:
|
||||
if content.find(ky) != -1:
|
||||
return ky
|
||||
return None
|
||||
|
||||
def fuzzy_match_group_name(self, group_name, keyword_list):
|
||||
for ky in keyword_list:
|
||||
if group_name.find(ky) != -1:
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
"single_chat_prefix": ["bot", "@bot"],
|
||||
"single_chat_reply_prefix": "[bot] ",
|
||||
"group_chat_prefix": ["@bot"],
|
||||
"group_chat_keyword": ["为什么", "why", "Why", "?", "请教"],
|
||||
"group_name_white_list": ["ChatGPT测试群", "ChatGPT测试群2"],
|
||||
"group_name_keyword_white_list": ["相亲相爱", "瞎侃"],
|
||||
"image_create_prefix": ["画", "看", "找"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user