From 349d0e6bc0a8d61a7323d54e7b8803a7a130aebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Mon, 22 Jul 2024 09:19:17 +0800 Subject: [PATCH 1/2] =?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 --- tasks/friends/friends.go | 46 ++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/tasks/friends/friends.go b/tasks/friends/friends.go index 80bf35f..052197c 100644 --- a/tasks/friends/friends.go +++ b/tasks/friends/friends.go @@ -42,6 +42,19 @@ func Sync() { nowIds := []string{} + // 取出已存在的成员信息 + var oldData []entity.Friend + err = tx.Find(&oldData).Error + if err != nil { + log.Printf("查询好友列表失败: %s", err.Error()) + return + } + // 将历史数据整理成map + oldMap := make(map[string]bool) + for _, item := range oldData { + oldMap[item.Wxid] = item.IsOk + } + // 新增的成员,用于通知给指定的人 var newItmes = make(map[string]string) @@ -57,12 +70,7 @@ func Sync() { nowIds = append(nowIds, friend.Wxid) // 判断是否存在,不存在的话就新增,存在就修改一下名字 - var count int64 - err = tx.Model(&entity.Friend{}).Where("wxid = ?", friend.Wxid).Count(&count).Error - if err != nil { - continue - } - if count == 0 { + if _, e := oldMap[friend.Wxid]; !e { // 新增 err = tx.Create(&entity.Friend{ CustomAccount: friend.CustomAccount, @@ -120,6 +128,32 @@ func Sync() { log.Printf("修改好友失败: %s", err.Error()) continue } + // 如果已存在但是是已退出的群,也通知一下 + if !oldMap[friend.Wxid] { + newItmes[friend.Wxid] = friend.Nickname + } + // 通知一下,初始化完成 + if conf, ok := config.Conf.Resource["introduce"]; ok { + // 发送一条新消息 + switch conf.Type { + case "text": + // 文字类型 + utils.SendMessage(friend.Wxid, "", conf.Path, 0) + case "image": + // 图片类型 + utils.SendImage(friend.Wxid, conf.Path, 0) + case "emotion": + // 表情类型 + utils.SendEmotion(friend.Wxid, conf.Path, 0) + } + } + // 发送配置网页 + if config.Conf.System.Domain != "" { + title := "欢迎使用微信机器人" + desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可" + url := config.Conf.System.Domain + "/manager.html?id=" + friend.Wxid + utils.SendPublicMsg(friend.Wxid, title, desc, url, 0) + } } // 群成员,同步一下成员信息 From 7a5b46858d2769161d219ddec0855acf47c621a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Mon, 22 Jul 2024 09:19:38 +0800 Subject: [PATCH 2/2] =?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 --- tasks/friends/friends.go | 43 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/tasks/friends/friends.go b/tasks/friends/friends.go index 052197c..a371f7c 100644 --- a/tasks/friends/friends.go +++ b/tasks/friends/friends.go @@ -131,28 +131,29 @@ func Sync() { // 如果已存在但是是已退出的群,也通知一下 if !oldMap[friend.Wxid] { newItmes[friend.Wxid] = friend.Nickname - } - // 通知一下,初始化完成 - if conf, ok := config.Conf.Resource["introduce"]; ok { - // 发送一条新消息 - switch conf.Type { - case "text": - // 文字类型 - utils.SendMessage(friend.Wxid, "", conf.Path, 0) - case "image": - // 图片类型 - utils.SendImage(friend.Wxid, conf.Path, 0) - case "emotion": - // 表情类型 - utils.SendEmotion(friend.Wxid, conf.Path, 0) + + // 通知一下,初始化完成 + if conf, ok := config.Conf.Resource["introduce"]; ok { + // 发送一条新消息 + switch conf.Type { + case "text": + // 文字类型 + utils.SendMessage(friend.Wxid, "", conf.Path, 0) + case "image": + // 图片类型 + utils.SendImage(friend.Wxid, conf.Path, 0) + case "emotion": + // 表情类型 + utils.SendEmotion(friend.Wxid, conf.Path, 0) + } + } + // 发送配置网页 + if config.Conf.System.Domain != "" { + title := "欢迎使用微信机器人" + desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可" + url := config.Conf.System.Domain + "/manager.html?id=" + friend.Wxid + utils.SendPublicMsg(friend.Wxid, title, desc, url, 0) } - } - // 发送配置网页 - if config.Conf.System.Domain != "" { - title := "欢迎使用微信机器人" - desc := "点我可以配置功能喔,提示非微信官方网页,点击继续访问即可" - url := config.Conf.System.Domain + "/manager.html?id=" + friend.Wxid - utils.SendPublicMsg(friend.Wxid, title, desc, url, 0) } }