forked from lxh/go-wxhelper
🆕 新增默认功能权限配置
This commit is contained in:
parent
386e0dd6d3
commit
aa78f3940c
17
config.yaml
17
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接口地址
|
||||
|
@ -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"` // 微信助手
|
||||
|
21
config/system.go
Normal file
21
config/system.go
Normal file
@ -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"` // 是否启用欢迎新成员
|
||||
}
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user