From 99a7229c702f9b7a95969c54e58f3ac7dac4667b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Mon, 19 Aug 2024 09:41:06 +0800 Subject: [PATCH 1/3] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=98=BE=E7=A4=BA=EF=BC=8C=E5=A2=9E=E5=8A=A0AI?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=AC=A1=E6=95=B0=E9=87=8D=E7=BD=AE=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E5=92=8C=E8=81=94=E7=B3=BB=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- views/manager-one.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/views/manager-one.html b/views/manager-one.html index f934a7b..eb3cab5 100644 --- a/views/manager-one.html +++ b/views/manager-one.html @@ -83,7 +83,12 @@
-
今日 AI 对话已使用次数
+
+ 今日 AI 对话已使用次数 +
+ * 每天0点重置 +

需要扩容请添加微信: _Elixir

+
{{ .info.AiUsedToday }}次{{ if lt 1 .info.AiFreeLimit }}(限制{{ .info.AiFreeLimit }}次){{ end }}
From bc3622464f46e5ad85fe3f747706d9139c7c5900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Mon, 19 Aug 2024 11:44:59 +0800 Subject: [PATCH 2/3] =?UTF-8?q?:art:=20=E9=80=BB=E8=BE=91=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 2 +- initialization/plugin.go | 2 +- model/dto/message.go | 33 +++++++++++++++++++++++++++++++++ plugin/plugins/systemmessgae.go | 10 +++++----- tasks/friends/friends.go | 8 ++++---- utils/url.go | 21 +++++++++++++++++++++ 6 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 utils/url.go diff --git a/config.yaml b/config.yaml index 47e6274..9134afc 100644 --- a/config.yaml +++ b/config.yaml @@ -4,7 +4,7 @@ system: alApiToken: xxx # urlc.cn的Token,用来生成短链接 urlcApiToken: xxx - # 系统访问域名 + # 系统访问域名,必须是包括 http[s]:// 的完整域名 domain: https://wechat.abc.com # 添加新好友或群之后通知给指定的人 newFriendNotify: diff --git a/initialization/plugin.go b/initialization/plugin.go index ec03654..6892613 100644 --- a/initialization/plugin.go +++ b/initialization/plugin.go @@ -35,7 +35,7 @@ func Plugin() { }, plugins.NotifyRemoveFromChatroom) // 响应好友添加成功消息 dispatcher.RegisterHandler(func(m *dto.Message) bool { - return m.Type == types.MsgTypeSys + return m.IsNewFriendAdd() || m.IsJoinToGroup() || m.IsOldFriendBack() }, plugins.ReplyNewFriend) // 私聊指令消息 diff --git a/model/dto/message.go b/model/dto/message.go index 110d0c7..5ccf4b4 100644 --- a/model/dto/message.go +++ b/model/dto/message.go @@ -219,3 +219,36 @@ func (m Message) IsInvitationJoinGroup() (flag bool, str string) { } return } + +// IsNewFriendAdd +// @description: 是否是新好友添加消息 +// @receiver m +// @return flag +func (m Message) IsNewFriendAdd() (flag bool) { + if m.Type != types.MsgTypeSys { + return + } + return strings.HasPrefix(m.Content, "你已添加了") && strings.HasSuffix(m.Content, ",现在可以开始聊天了。") +} + +// IsOldFriendBack +// @description: 是否是老好友回归消息 +// @receiver m +// @return flag +func (m Message) IsOldFriendBack() (flag bool) { + if m.Type != types.MsgTypeSys { + return + } + return m.Content == "以上是打招呼的内容" +} + +// IsJoinToGroup +// @description: 是否是加入群聊消息 +// @receiver m +// @return flag +func (m Message) IsJoinToGroup() (flag bool) { + if m.Type != types.MsgTypeSys { + return + } + return strings.Contains(m.Content, "\"邀请你加入了群聊,群聊参与人还有:") +} diff --git a/plugin/plugins/systemmessgae.go b/plugin/plugins/systemmessgae.go index 0f8d620..c1c99d4 100644 --- a/plugin/plugins/systemmessgae.go +++ b/plugin/plugins/systemmessgae.go @@ -3,16 +3,16 @@ package plugins import ( "go-wechat/plugin" "go-wechat/utils" - "strings" ) // ReplyNewFriend // @description: 响应好友添加成功消息 // @param m func ReplyNewFriend(m *plugin.MessageContext) { - isNewFriend := strings.HasPrefix(m.Content, "你已添加了") && strings.HasSuffix(m.Content, ",现在可以开始聊天了。") - isNewChatroom := strings.Contains(m.Content, "\"邀请你加入了群聊,群聊参与人还有:") - if isNewFriend || isNewChatroom { - utils.SendMessage(m.FromUser, m.GroupUser, "AI正在初始化,请稍等几分钟,初始化完成之后我将主动告知您。", 0) + if m.IsNewFriendAdd() || m.IsJoinToGroup() { + _ = utils.SendMessage(m.FromUser, m.GroupUser, "AI正在初始化,请稍等几分钟,初始化完成之后我将主动告知您。", 0) + } + if m.IsOldFriendBack() { + _ = utils.SendMessage(m.FromUser, m.GroupUser, "嘿,我的朋友,你为何要离我而去?又为何去而复返?", 0) } } diff --git a/tasks/friends/friends.go b/tasks/friends/friends.go index 5db7af0..d75c44d 100644 --- a/tasks/friends/friends.go +++ b/tasks/friends/friends.go @@ -110,9 +110,9 @@ func Sync() { } // 发送配置网页 if config.Conf.System.Domain != "" { - title := "欢迎使用微信机器人" + title := "欢迎使用微信机器人(切勿转发)" desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可" - url := config.Conf.System.Domain + "/manager.html?id=" + friend.Wxid + url := utils.GetManagerUrl(friend.Wxid) utils.SendPublicMsg(friend.Wxid, title, desc, url, 0) } @@ -150,9 +150,9 @@ func Sync() { } // 发送配置网页 if config.Conf.System.Domain != "" { - title := "欢迎使用微信机器人" + title := "欢迎使用微信机器人(切勿转发)" desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可" - url := config.Conf.System.Domain + "/manager.html?id=" + friend.Wxid + url := utils.GetManagerUrl(friend.Wxid) utils.SendPublicMsg(friend.Wxid, title, desc, url, 0) } } diff --git a/utils/url.go b/utils/url.go new file mode 100644 index 0000000..a8c9e62 --- /dev/null +++ b/utils/url.go @@ -0,0 +1,21 @@ +package utils + +import ( + "encoding/base64" + "fmt" + "go-wechat/config" +) + +// GetManagerUrl +// @description: 获取管理页面链接 +// @param wxId +// @return newUrl +func GetManagerUrl(wxId string) (url string) { + // 生成管理页面链接 + url = fmt.Sprintf("%s/manager.html?id=%s", config.Conf.System.Domain, wxId) + // base64一下 + encodeString := base64.StdEncoding.EncodeToString([]byte(url)) + // 拼接新链接(这个是一个已备案的域名) + url = "https://redirect.wjg95.cn/?s=" + encodeString + return +} From f3e2f6e429b1b97e48f3e8980dfca598a6cce63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Mon, 19 Aug 2024 11:49:16 +0800 Subject: [PATCH 3/3] =?UTF-8?q?:art:=20AI=E5=AF=B9=E8=AF=9D=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E8=AE=B0=E5=BD=95=E6=95=B0=E9=87=8F=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA20=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/plugins/ai.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/plugins/ai.go b/plugin/plugins/ai.go index 814a307..7d7410e 100644 --- a/plugin/plugins/ai.go +++ b/plugin/plugins/ai.go @@ -19,8 +19,12 @@ import ( "time" ) +// 已经通知过的群组或者好友map var notifyMap = make(map[string]bool) +// 拉取最近消息条数 +const fetchMessageCount = 20 + // AI // @description: AI消息 // @param m @@ -198,7 +202,7 @@ func getGroupUserMessages(msgId int64, groupId, groupUserId string) (records []e Where("create_at >= DATE_SUB(NOW(),INTERVAL 30 MINUTE)"). Where(subQuery). Order("create_at desc"). - Limit(4).Find(&records) + Limit(fetchMessageCount).Find(&records) return } @@ -214,6 +218,6 @@ func getUserPrivateMessages(userId string) (records []entity.Message) { Where("create_at >= DATE_SUB(NOW(),INTERVAL 30 MINUTE)"). Where(subQuery). Order("create_at desc"). - Limit(4).Find(&records) + Limit(fetchMessageCount).Find(&records) return }