Compare commits

...

8 Commits

3 changed files with 43 additions and 0 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
@@ -28,6 +29,10 @@ func Plugin() {
flag, _ := m.IsInvitationJoinGroup() flag, _ := m.IsInvitationJoinGroup()
return flag return flag
}, plugins.NotifyInvitationJoinGroup) }, 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

@@ -4,13 +4,18 @@ import (
"fmt" "fmt"
"go-wechat/config" "go-wechat/config"
"go-wechat/plugin" "go-wechat/plugin"
"go-wechat/service"
"go-wechat/utils" "go-wechat/utils"
"strings"
) )
// NotifyInvitationJoinGroup // NotifyInvitationJoinGroup
// @description: 通知邀请入群消息到配置用户 // @description: 通知邀请入群消息到配置用户
// @param m // @param m
func NotifyInvitationJoinGroup(m *plugin.MessageContext) { func NotifyInvitationJoinGroup(m *plugin.MessageContext) {
// 先回复一条固定句子
utils.SendMessage(m.FromUser, m.GroupUser, "您的邀请消息已收到啦,正在通知我的主人来同意请求。在我加群之后将会进行初始化操作,直到收到我主动发送的消息就是初始化完成咯,在那之前请耐心等待喔~", 0)
// 如果是邀请进群,推送到配置的用户 // 如果是邀请进群,推送到配置的用户
if flag, dec := m.IsInvitationJoinGroup(); flag { if flag, dec := m.IsInvitationJoinGroup(); flag {
for _, user := range config.Conf.System.NewFriendNotify.ToUser { for _, user := range config.Conf.System.NewFriendNotify.ToUser {
@@ -22,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, "\"移出群聊") {
// 取出群名称
groupInfo, err := service.GetFriendInfoById(m.FromUser)
if err != nil {
return
}
// 组装消息
msg := fmt.Sprintf("#移除群聊提醒\n\n群Id: %s\n群名称: %s\n事件: %s", m.FromUser, groupInfo.Nickname, 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 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 // GetAllEnableAI
// @description: 取出所有启用了AI的好友或群组 // @description: 取出所有启用了AI的好友或群组
// @return []entity.Friend // @return []entity.Friend