Compare commits

...

4 Commits

Author SHA1 Message Date
李寻欢
23ca86e75c Merge pull request '🎨 优化被移除群聊通知逻辑' (#72) from hotfix into main
Reviewed-on: https://gitee.ltd/lxh/go-wxhelper/pulls/72
2024-07-10 16:32:39 +08:00
李寻欢
1d41fc5a6b 🎨 优化被移除群聊通知逻辑 2024-07-10 16:32:18 +08:00
李寻欢
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
3 changed files with 40 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import (
plugin "go-wechat/plugin"
"go-wechat/plugin/plugins"
"go-wechat/service"
"go-wechat/types"
)
// Plugin
@@ -28,6 +29,10 @@ func Plugin() {
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 {

View File

@@ -4,7 +4,9 @@ import (
"fmt"
"go-wechat/config"
"go-wechat/plugin"
"go-wechat/service"
"go-wechat/utils"
"strings"
)
// NotifyInvitationJoinGroup
@@ -25,3 +27,26 @@ func NotifyInvitationJoinGroup(m *plugin.MessageContext) {
}
}
}
// NotifyRemoveFromChatroom
// @description: 被移除群聊通知到配置用户
// @param m
func NotifyRemoveFromChatroom(m *plugin.MessageContext) {
// 如果是被移出群聊,推送到配置的用户
if strings.HasPrefix(m.Content, "你被\"") && strings.HasSuffix(m.Content, "\"移出群聊") {
// 取出群名称
groupName, err := service.GetFriendInfoById(m.FromUser)
if err != nil {
return
}
// 组装消息
msg := fmt.Sprintf("#移除群聊提醒\n\n群Id: %s\n群名称: %s\n事件: %s", m.FromUser, groupName, m.Content)
for _, user := range config.Conf.System.NewFriendNotify.ToUser {
if user != "" {
// 发送一条新消息
utils.SendMessage(user, "", msg, 0)
}
}
}
}

View File

@@ -37,6 +37,16 @@ func GetAllFriend() (friends, groups []vo.FriendItem, err error) {
return
}
// GetFriendInfoById
// @description: 通过wxId获取好友信息
// @param wxId
// @return ent
// @return err
func GetFriendInfoById(wxId string) (ent entity.Friend, err error) {
err = client.MySQL.Where("wxid = ?", wxId).First(&ent).Error
return
}
// GetAllEnableAI
// @description: 取出所有启用了AI的好友或群组
// @return []entity.Friend