From 91d2fc50e2ca7d3a4987194fb9db82cac3a6edff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Fri, 17 Nov 2023 09:44:14 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E4=BC=A0=E9=80=92?= =?UTF-8?q?=E7=BB=99AI=E7=9A=84=E6=B6=88=E6=81=AF=EF=BC=8C=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E8=89=BE=E7=89=B9=E6=9C=BA=E5=99=A8=E4=BA=BA=E9=82=A3?= =?UTF-8?q?=E4=B8=80=E6=AE=B5=E5=AD=97=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/at_message.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/handler/at_message.go b/handler/at_message.go index 237a4e39..6fe9be5d 100644 --- a/handler/at_message.go +++ b/handler/at_message.go @@ -8,6 +8,8 @@ import ( "go-wechat/entity" "go-wechat/utils" "log" + "regexp" + "strings" ) // handleAtMessage @@ -17,6 +19,15 @@ func handleAtMessage(m entity.Message) { if !config.Conf.Ai.Enable { return } + + // 预处理一下发送的消息,用正则去掉@机器人的内容 + re := regexp.MustCompile(`@([^ ]+)`) + matches := re.FindStringSubmatch(m.Content) + if len(matches) > 0 { + // 过滤掉第一个匹配到的 + m.Content = strings.Replace(m.Content, matches[0], "", 1) + } + // 默认使用AI回复 conf := openai.DefaultConfig(config.Conf.Ai.ApiKey) if config.Conf.Ai.BaseUrl != "" {