From aa78f3940c3822bc7c5527d9b18b28c590a51691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Tue, 14 May 2024 12:08:30 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20=E6=96=B0=E5=A2=9E=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=9D=83=E9=99=90=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 17 +++++++++++++++++ config/config.go | 1 + config/system.go | 21 +++++++++++++++++++++ tasks/friends/friends.go | 37 ++++++++++++++++++++++++++++++------- 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 config/system.go diff --git a/config.yaml b/config.yaml index e4505ba7..9358b3bd 100644 --- a/config.yaml +++ b/config.yaml @@ -1,3 +1,20 @@ +system: + # 添加新好友或群之后通知给指定的人 + newFriendNotify: + enable: true + toUser: + - "wxid_xxx" + # 默认AI等配置 + defaultRule: + # 默认是否开启AI + ai: true + # 默认是否开启水群排行榜 + chatRank: true + # 默认是否开启聊天记录总结 + summary: true + # 默认是否开启新成员加群欢迎 + welcome: true + # 微信HOOK配置 wechat: # 微信HOOK接口地址 diff --git a/config/config.go b/config/config.go index 9cbae533..04192c9f 100644 --- a/config/config.go +++ b/config/config.go @@ -6,6 +6,7 @@ var Conf conf // Config // @description: 配置 type conf struct { + System system `json:"system" yaml:"system"` // 系统配置 Task task `json:"task" yaml:"task"` // 定时任务配置 MySQL mysql `json:"mysql" yaml:"mysql"` // MySQL 配置 Wechat wechat `json:"wechat" yaml:"wechat"` // 微信助手 diff --git a/config/system.go b/config/system.go new file mode 100644 index 00000000..97d93411 --- /dev/null +++ b/config/system.go @@ -0,0 +1,21 @@ +package config + +// 系统配置 +type system struct { + NewFriendNotify newFriendNotify `json:"newFriendNotify" yaml:"newFriendNotify"` // 新好友通知 + DefaultRule defaultRule `json:"defaultRule" yaml:"defaultRule"` // 默认规则 +} + +// 添加新好友或群之后通知给指定的人 +type newFriendNotify struct { + Enable bool `json:"enable" yaml:"enable"` // 是否启用 + ToUser []string `json:"toUser" yaml:"toUser"` // 通知给谁 +} + +// 默认规则 +type defaultRule struct { + Ai bool `json:"ai" yaml:"ai"` // 是否启用AI + ChatRank bool `json:"chatRank" yaml:"chatRank"` // 是否启用聊天排行榜 + Summary bool `json:"summary" yaml:"summary"` // 是否启用聊天总结 + Welcome bool `json:"welcome" yaml:"welcome"` // 是否启用欢迎新成员 +} diff --git a/tasks/friends/friends.go b/tasks/friends/friends.go index a58eeb26..b5e96ee6 100644 --- a/tasks/friends/friends.go +++ b/tasks/friends/friends.go @@ -41,6 +41,9 @@ func Sync() { nowIds := []string{} + // 新增的成员,用于通知给指定的人 + var newItmes = make(map[string]string) + for _, friend := range base.Data { if strings.Contains(friend.Wxid, "gh_") || strings.Contains(friend.Wxid, "@openim") { continue @@ -61,18 +64,23 @@ func Sync() { if count == 0 { // 新增 err = tx.Create(&entity.Friend{ - CustomAccount: friend.CustomAccount, - Nickname: friend.Nickname, - Pinyin: friend.Pinyin, - PinyinAll: friend.PinyinAll, - Wxid: friend.Wxid, - IsOk: true, - LastActive: time.Now().Local(), + CustomAccount: friend.CustomAccount, + Nickname: friend.Nickname, + Pinyin: friend.Pinyin, + PinyinAll: friend.PinyinAll, + Wxid: friend.Wxid, + IsOk: true, + EnableAi: config.Conf.System.DefaultRule.Ai, + EnableChatRank: config.Conf.System.DefaultRule.ChatRank, + EnableSummary: config.Conf.System.DefaultRule.Summary, + EnableWelcome: config.Conf.System.DefaultRule.Welcome, + LastActive: time.Now().Local(), }).Error if err != nil { log.Printf("新增好友失败: %s", err.Error()) continue } + newItmes[friend.Wxid] = friend.Nickname if conf, ok := config.Conf.Resource["introduce"]; ok { // 发送一条新消息 switch conf.Type { @@ -107,6 +115,21 @@ func Sync() { } } + // 通知有新成员 + if len(newItmes) > 0 && config.Conf.System.NewFriendNotify.Enable { + // 组装成一句话 + msg := []string{"#新好友通知\n"} + for wxId, nickname := range newItmes { + msg = append(msg, "微信Id: "+wxId+" -> 昵称: "+nickname) + } + for _, user := range config.Conf.System.NewFriendNotify.ToUser { + if user != "" { + // 发送一条新消息 + utils.SendMessage(user, "", strings.Join(msg, "\n"), 0) + } + } + } + // 清理不在列表中的好友 err = tx.Model(&entity.Friend{}).Where("wxid NOT IN (?)", nowIds).Update("is_ok", false).Error