From 2e5632c2031a302935c38a3c8020d57a77fc9aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Mon, 8 Jul 2024 10:57:52 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E5=8A=A0=E7=BE=A4?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E4=B8=8D=E6=8F=90=E9=86=92=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- initialization/plugin.go | 6 ++++++ model/dto/message.go | 4 +++- mq/handler.go | 12 ------------ plugin/plugins/notify2configuser.go | 24 ++++++++++++++++++++++++ tcpserver/parse.go | 12 ------------ 5 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 plugin/plugins/notify2configuser.go diff --git a/initialization/plugin.go b/initialization/plugin.go index 2daded4c..9ddbd350 100644 --- a/initialization/plugin.go +++ b/initialization/plugin.go @@ -23,6 +23,12 @@ func Plugin() { return true }, plugins.SaveToDb) + // 通知邀请入群消息到配置用户 + dispatcher.RegisterHandler(func(m *dto.Message) bool { + flag, _ := m.IsInvitationJoinGroup() + return flag + }, plugins.NotifyInvitationJoinGroup) + // 私聊指令消息 dispatcher.RegisterHandler(func(m *dto.Message) bool { // 私聊消息 或 群聊艾特机器人并且以/开头的消息 diff --git a/model/dto/message.go b/model/dto/message.go index 09e39ec7..60c462b8 100644 --- a/model/dto/message.go +++ b/model/dto/message.go @@ -209,7 +209,9 @@ func (m Message) IsInvitationJoinGroup() (flag bool, str string) { if err := xml.Unmarshal([]byte(m.Content), &md); err != nil { return } - return md.AppMsg.Type == "5" && strings.Contains(md.AppMsg.Content, "邀请你加入群聊"), md.AppMsg.Des + flag = md.AppMsg.Type == "5" && md.AppMsg.Title == "邀请你加入群聊" + str = strings.ReplaceAll(md.AppMsg.Des, ",进入可查看详情。", "") + return } return } diff --git a/mq/handler.go b/mq/handler.go index 94839896..c6698998 100644 --- a/mq/handler.go +++ b/mq/handler.go @@ -3,10 +3,8 @@ package mq import ( "encoding/json" "go-wechat/common/current" - "go-wechat/config" "go-wechat/model/dto" "go-wechat/types" - "go-wechat/utils" "log" "strings" ) @@ -39,16 +37,6 @@ func parse(msg []byte) { } log.Printf("收到新微信消息\n消息来源: %s\n群成员: %s\n消息类型: %v\n消息内容: %s", m.FromUser, m.GroupUser, m.Type, m.Content) - // 如果是邀请进群,推送到配置的用户 - if flag, dec := m.IsInvitationJoinGroup(); flag { - for _, user := range config.Conf.System.NewFriendNotify.ToUser { - if user != "" { - // 发送一条新消息 - utils.SendMessage(user, "", dec, 0) - } - } - } - // 插件不为空,开始执行 if p := current.GetRobotMessageHandler(); p != nil { p(&m) diff --git a/plugin/plugins/notify2configuser.go b/plugin/plugins/notify2configuser.go new file mode 100644 index 00000000..64aa0048 --- /dev/null +++ b/plugin/plugins/notify2configuser.go @@ -0,0 +1,24 @@ +package plugins + +import ( + "fmt" + "go-wechat/config" + "go-wechat/plugin" + "go-wechat/utils" +) + +// NotifyInvitationJoinGroup +// @description: 通知邀请入群消息到配置用户 +// @param m +func NotifyInvitationJoinGroup(m *plugin.MessageContext) { + // 如果是邀请进群,推送到配置的用户 + if flag, dec := m.IsInvitationJoinGroup(); flag { + for _, user := range config.Conf.System.NewFriendNotify.ToUser { + if user != "" { + // 发送一条新消息 + dec = fmt.Sprintf("#邀请入群提醒\n\n%s", dec) + utils.SendMessage(user, "", dec, 0) + } + } + } +} diff --git a/tcpserver/parse.go b/tcpserver/parse.go index cc58f43d..cf7d84ab 100644 --- a/tcpserver/parse.go +++ b/tcpserver/parse.go @@ -3,10 +3,8 @@ package tcpserver import ( "encoding/json" "go-wechat/common/current" - "go-wechat/config" "go-wechat/model/dto" "go-wechat/types" - "go-wechat/utils" "log" "net" "strings" @@ -40,16 +38,6 @@ func parse(remoteAddr net.Addr, msg []byte) { } log.Printf("%s\n消息来源: %s\n群成员: %s\n消息类型: %v\n消息内容: %s", remoteAddr, m.FromUser, m.GroupUser, m.Type, m.Content) - // 如果是邀请进群,推送到配置的用户 - if flag, dec := m.IsInvitationJoinGroup(); flag { - for _, user := range config.Conf.System.NewFriendNotify.ToUser { - if user != "" { - // 发送一条新消息 - utils.SendMessage(user, "", dec, 0) - } - } - } - // 插件不为空,开始执行 if p := current.GetRobotMessageHandler(); p != nil { p(&m)