2021-11-17 09:39:48 +00:00
|
|
|
|
package push
|
|
|
|
|
|
|
|
|
|
import (
|
2022-08-15 07:07:03 +00:00
|
|
|
|
"fmt"
|
|
|
|
|
|
2021-11-17 09:39:48 +00:00
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
|
2022-12-14 07:43:39 +00:00
|
|
|
|
"github.com/sjkhsl/study_xxqg/conf"
|
2021-11-17 09:39:48 +00:00
|
|
|
|
)
|
|
|
|
|
|
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)
|
2021-11-17 09:39:48 +00:00
|
|
|
|
if config.Push.Ding.Enable {
|
|
|
|
|
ding := &Ding{
|
|
|
|
|
Secret: config.Push.Ding.Secret,
|
|
|
|
|
Token: config.Push.Ding.AccessToken,
|
|
|
|
|
}
|
2021-11-24 14:05:37 +00:00
|
|
|
|
log.Infoln("已配置钉钉推送")
|
2022-08-15 07:07:03 +00:00
|
|
|
|
pushs = append(pushs, ding.Send())
|
|
|
|
|
}
|
|
|
|
|
if config.Push.PushPlus.Enable {
|
2021-11-24 14:05:37 +00:00
|
|
|
|
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 {
|
2022-08-18 07:47:32 +00:00
|
|
|
|
log.Infoln("已配置tg推送")
|
2022-08-15 07:07:03 +00:00
|
|
|
|
pushs = append(pushs, tgPush)
|
2021-11-17 09:39:48 +00:00
|
|
|
|
}
|
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}
|
2022-11-09 00:20:20 +00:00
|
|
|
|
if kind == "flush" {
|
|
|
|
|
e.sendPrivateMsg(conf.GetConfig().QQ.SuperUser, message)
|
|
|
|
|
} else {
|
|
|
|
|
if log.GetLevel() == log.DebugLevel {
|
|
|
|
|
e.sendPrivateMsg(conf.GetConfig().QQ.SuperUser, message)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-08 12:22:58 +00:00
|
|
|
|
})
|
|
|
|
|
}
|
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)
|
|
|
|
|
}
|
2021-11-17 09:39:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|