study_xxqg/push/push.go

72 lines
1.8 KiB
Go
Raw Normal View History

package push
import (
2022-08-15 07:07:03 +00:00
"fmt"
log "github.com/sirupsen/logrus"
2022-08-03 10:04:52 +00:00
"github.com/johlanse/study_xxqg/conf"
)
2022-08-15 07:07:03 +00:00
func GetPush(config conf.Config) func(id string, kind string, message string) {
var pushs []func(id, kind, message string)
if config.Push.Ding.Enable {
ding := &Ding{
Secret: config.Push.Ding.Secret,
Token: config.Push.Ding.AccessToken,
}
log.Infoln("已配置钉钉推送")
2022-08-15 07:07:03 +00:00
pushs = append(pushs, ding.Send())
}
if config.Push.PushPlus.Enable {
log.Infoln("已配置pushplus推送")
2022-08-15 07:07:03 +00:00
pushs = append(pushs, (&PushPlus{Token: config.Push.PushPlus.Token}).Init())
}
if config.Wechat.Enable {
log.Infoln("已配置wechat推送")
pushs = append(pushs, func(id, kind, message string) {
defer func() {
err := recover()
if err != nil {
log.Errorln("推送微信消息出现错误")
log.Errorln(err)
}
}()
if kind == "flush" {
sendMsg(id, message)
} else {
if log.GetLevel() == log.DebugLevel {
sendMsg(id, message)
}
}
})
}
if config.TG.Enable {
log.Infoln("已配置tg推送")
2022-08-15 07:07:03 +00:00
pushs = append(pushs, tgPush)
}
2022-08-18 08:18:06 +00:00
if config.PushDeer.Enable {
log.Infoln("已配置pushDeer推送")
pushs = append(pushs, InitPushDeer())
}
2022-11-08 12:22:58 +00:00
if config.QQ.Enable {
log.Infoln("已配置qq推送")
pushs = append(pushs, func(id, kind, message string) {
e := &Event{qq: qq}
e.sendPrivateMsg(conf.GetConfig().QQ.SuperUser, message)
})
}
2022-08-15 07:07:03 +00:00
pushs = append(pushs, func(id, kind, message string) {
log.Debugln(fmt.Sprintf("消息id: %v消息类型%v,消息内容:%v", id, kind, message))
})
return multiPush(pushs...)
}
func multiPush(pushs ...func(id, kind, message string)) func(id, kind, message string) {
return func(id, kind, message string) {
for _, push := range pushs {
push(id, kind, message)
}
}
}