1
0
forked from lxh/go-wxhelper

🎨 优化传递给AI的消息,去掉艾特机器人那一段字符串

This commit is contained in:
李寻欢 2023-11-17 09:44:14 +08:00
parent 119c2a5359
commit 91d2fc50e2

View File

@ -8,6 +8,8 @@ import (
"go-wechat/entity" "go-wechat/entity"
"go-wechat/utils" "go-wechat/utils"
"log" "log"
"regexp"
"strings"
) )
// handleAtMessage // handleAtMessage
@ -17,6 +19,15 @@ func handleAtMessage(m entity.Message) {
if !config.Conf.Ai.Enable { if !config.Conf.Ai.Enable {
return return
} }
// 预处理一下发送的消息,用正则去掉@机器人的内容
re := regexp.MustCompile(`@([^]+)`)
matches := re.FindStringSubmatch(m.Content)
if len(matches) > 0 {
// 过滤掉第一个匹配到的
m.Content = strings.Replace(m.Content, matches[0], "", 1)
}
// 默认使用AI回复 // 默认使用AI回复
conf := openai.DefaultConfig(config.Conf.Ai.ApiKey) conf := openai.DefaultConfig(config.Conf.Ai.ApiKey)
if config.Conf.Ai.BaseUrl != "" { if config.Conf.Ai.BaseUrl != "" {