From 4c42136d0c19f560e09854b096f921ca8d38ebec Mon Sep 17 00:00:00 2001 From: zhayujie Date: Fri, 3 Feb 2023 00:59:14 +0800 Subject: [PATCH] feat: adjust some configs to be optional --- README.md | 2 +- bot/openai/open_ai_bot.py | 2 +- channel/wechat/wechat_channel.py | 13 +++++-------- config-template.json | 2 -- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ac07d0f..f02c313 100644 --- a/README.md +++ b/README.md @@ -101,7 +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以更灵活的触发群内的聊天自动回复,增加趣味。 ++ 可选配置: `group_name_keyword_white_list`配置项支持模糊匹配群名称,`group_chat_keyword`配置项则可模糊匹配群消息内容。(Contributed by [evolay][evolay]) **3.其他配置** diff --git a/bot/openai/open_ai_bot.py b/bot/openai/open_ai_bot.py index a8c14c7..a391ac9 100644 --- a/bot/openai/open_ai_bot.py +++ b/bot/openai/open_ai_bot.py @@ -27,7 +27,7 @@ class OpenAIBot(Bot): max_tokens=1200, # 回复最大的字符数 top_p=1, frequency_penalty=0.0, # [-2,2]之间,该值越大则更倾向于产生不同的内容 - presence_penalty=0.6, # [-2,2]之间,该值越大则更倾向于产生不同的内容 + presence_penalty=0.0, # [-2,2]之间,该值越大则更倾向于产生不同的内容 stop=["#"] ) res_content = response.choices[0]["text"].strip() diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index 054c527..c558600 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -48,7 +48,7 @@ class WechatChannel(Channel): match_prefix = self.check_prefix(content, conf().get('single_chat_prefix')) if from_user_id == other_user_id and match_prefix is not None: # 好友向自己发送消息 - if match_prefix is not '': + if match_prefix != '': str_list = content.split(match_prefix, 1) if len(str_list) == 2: content = str_list[1].strip() @@ -90,7 +90,7 @@ class WechatChannel(Channel): config = conf() 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: + if (group_name in config.get('group_name_white_list') or 'ALL_GROUP' in config.get('group_name_white_list') or self.check_contain(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() @@ -154,13 +154,10 @@ class WechatChannel(Channel): return None def check_contain(self, content, keyword_list): + if not keyword_list: + return None for ky in keyword_list: if content.find(ky) != -1: - return ky + return True 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 diff --git a/config-template.json b/config-template.json index c2d9a05..3af5d23 100644 --- a/config-template.json +++ b/config-template.json @@ -3,8 +3,6 @@ "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": ["画", "看", "找"] }