Compare commits

...

6 Commits

Author SHA1 Message Date
李寻欢
bcdf0a45d2 Merge pull request ' 新增被移除群聊通知' (#71) from hotfix into main
Reviewed-on: https://gitee.ltd/lxh/go-wxhelper/pulls/71
2024-07-10 14:56:49 +08:00
李寻欢
4d3bef7cf5 新增被移除群聊通知 2024-07-10 14:56:11 +08:00
李寻欢
205e34f67e Merge pull request '🎨 逻辑优化' (#70) from hotfix into main
Reviewed-on: https://gitee.ltd/lxh/go-wxhelper/pulls/70
2024-07-09 08:38:51 +08:00
李寻欢
9b5152e294 🎨 逻辑优化 2024-07-09 08:38:16 +08:00
李寻欢
c0f8169588 Merge pull request '🐛 修复加群通知不提醒的BUG' (#69) from hotfix into main
Reviewed-on: https://gitee.ltd/lxh/go-wxhelper/pulls/69
2024-07-08 10:58:22 +08:00
李寻欢
2e5632c203 🐛 修复加群通知不提醒的BUG 2024-07-08 10:57:52 +08:00
5 changed files with 57 additions and 25 deletions

View File

@@ -6,6 +6,7 @@ import (
plugin "go-wechat/plugin" plugin "go-wechat/plugin"
"go-wechat/plugin/plugins" "go-wechat/plugin/plugins"
"go-wechat/service" "go-wechat/service"
"go-wechat/types"
) )
// Plugin // Plugin
@@ -23,6 +24,16 @@ func Plugin() {
return true return true
}, plugins.SaveToDb) }, plugins.SaveToDb)
// 通知邀请入群消息到配置用户
dispatcher.RegisterHandler(func(m *dto.Message) bool {
flag, _ := m.IsInvitationJoinGroup()
return flag
}, plugins.NotifyInvitationJoinGroup)
// 被移除群聊通知到配置用户
dispatcher.RegisterHandler(func(m *dto.Message) bool {
return m.Type == types.MsgTypeSys
}, plugins.NotifyRemoveFromChatroom)
// 私聊指令消息 // 私聊指令消息
dispatcher.RegisterHandler(func(m *dto.Message) bool { dispatcher.RegisterHandler(func(m *dto.Message) bool {
// 私聊消息 或 群聊艾特机器人并且以/开头的消息 // 私聊消息 或 群聊艾特机器人并且以/开头的消息

View File

@@ -209,7 +209,9 @@ func (m Message) IsInvitationJoinGroup() (flag bool, str string) {
if err := xml.Unmarshal([]byte(m.Content), &md); err != nil { if err := xml.Unmarshal([]byte(m.Content), &md); err != nil {
return 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 return
} }

View File

@@ -3,10 +3,8 @@ package mq
import ( import (
"encoding/json" "encoding/json"
"go-wechat/common/current" "go-wechat/common/current"
"go-wechat/config"
"go-wechat/model/dto" "go-wechat/model/dto"
"go-wechat/types" "go-wechat/types"
"go-wechat/utils"
"log" "log"
"strings" "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) 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 { if p := current.GetRobotMessageHandler(); p != nil {
p(&m) p(&m)

View File

@@ -0,0 +1,43 @@
package plugins
import (
"fmt"
"go-wechat/config"
"go-wechat/plugin"
"go-wechat/utils"
"strings"
)
// NotifyInvitationJoinGroup
// @description: 通知邀请入群消息到配置用户
// @param m
func NotifyInvitationJoinGroup(m *plugin.MessageContext) {
// 先回复一条固定句子
utils.SendMessage(m.FromUser, m.GroupUser, "您的邀请消息已收到啦,正在通知我的主人来同意请求。在我加群之后将会进行初始化操作,直到收到我主动发送的消息就是初始化完成咯,在那之前请耐心等待喔~", 0)
// 如果是邀请进群,推送到配置的用户
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)
}
}
}
}
// NotifyRemoveFromChatroom
// @description: 被移除群聊通知到配置用户
// @param m
func NotifyRemoveFromChatroom(m *plugin.MessageContext) {
if strings.HasPrefix(m.Content, "你被\"") && strings.HasSuffix(m.Content, "\"移出群聊") {
// 如果是被移出群聊,推送到配置的用户
for _, user := range config.Conf.System.NewFriendNotify.ToUser {
if user != "" {
// 发送一条新消息
utils.SendMessage(user, "", m.Content, 0)
}
}
}
}

View File

@@ -3,10 +3,8 @@ package tcpserver
import ( import (
"encoding/json" "encoding/json"
"go-wechat/common/current" "go-wechat/common/current"
"go-wechat/config"
"go-wechat/model/dto" "go-wechat/model/dto"
"go-wechat/types" "go-wechat/types"
"go-wechat/utils"
"log" "log"
"net" "net"
"strings" "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) 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 { if p := current.GetRobotMessageHandler(); p != nil {
p(&m) p(&m)