修复了定时任务不推送消息的问题
This commit is contained in:
parent
6b74ec2de4
commit
57e2aef0c2
15
lib/score.go
15
lib/score.go
|
@ -130,3 +130,18 @@ func FormatScore(score Score) string {
|
|||
)
|
||||
return result
|
||||
}
|
||||
|
||||
func FormatScoreShort(score Score) string {
|
||||
result := ""
|
||||
result += fmt.Sprintf("当前学习总积分:%d </br> 今日得分:%d</br>", score.TotalScore, score.TodayScore)
|
||||
result += fmt.Sprintf("登录:%v/%v</br> 文章学习:%v/%v</br> 视频学习:%v/%v</br> 视频时长:%v/%v</br>每日答题:%v/%v</br> 每周答题:%v/%v</br> 专项答题:%v/%v",
|
||||
score.Content["login"].CurrentScore, score.Content["login"].MaxScore,
|
||||
score.Content["article"].CurrentScore, score.Content["article"].MaxScore,
|
||||
score.Content["video"].CurrentScore, score.Content["video"].MaxScore,
|
||||
score.Content["video_time"].CurrentScore, score.Content["video_time"].MaxScore,
|
||||
score.Content["daily"].CurrentScore, score.Content["daily"].MaxScore,
|
||||
score.Content["weekly"].CurrentScore, score.Content["weekly"].MaxScore,
|
||||
score.Content["special"].CurrentScore, score.Content["special"].MaxScore,
|
||||
)
|
||||
return result
|
||||
}
|
||||
|
|
12
main.go
12
main.go
|
@ -92,6 +92,8 @@ func main() {
|
|||
core.Quit()
|
||||
return
|
||||
}
|
||||
getPush := push.GetPush(config)
|
||||
getPush("flush", "学习强国助手已上线")
|
||||
|
||||
go update.CheckUpdate(VERSION)
|
||||
|
||||
|
@ -207,6 +209,7 @@ func do(m string) {
|
|||
log.Infoln("检测到模式", config.Model)
|
||||
|
||||
getPush := push.GetPush(config)
|
||||
getPush("flush", "学习强国助手已上线")
|
||||
core := &lib.Core{ShowBrowser: config.ShowBrowser, Push: getPush}
|
||||
defer core.Quit()
|
||||
core.Init()
|
||||
|
@ -220,7 +223,7 @@ func do(m string) {
|
|||
log.Errorln(err)
|
||||
}
|
||||
}()
|
||||
|
||||
startTime := time.Now()
|
||||
core2.LearnArticle(u)
|
||||
core2.LearnVideo(u)
|
||||
if config.Model == 2 {
|
||||
|
@ -230,6 +233,7 @@ func do(m string) {
|
|||
core2.RespondDaily(u, "weekly")
|
||||
core2.RespondDaily(u, "special")
|
||||
}
|
||||
endTime := time.Now()
|
||||
score, err := lib.GetUserScore(u.ToCookies())
|
||||
if err != nil {
|
||||
log.Errorln("获取成绩失败")
|
||||
|
@ -237,14 +241,14 @@ func do(m string) {
|
|||
return
|
||||
}
|
||||
|
||||
score, _ = lib.GetUserScore(user.ToCookies())
|
||||
score, _ = lib.GetUserScore(u.ToCookies())
|
||||
content := lib.FormatScore(score)
|
||||
err = push.PushMessage(user.Nick+"学习情况", user.Nick+"学习情况"+content, "score", user.PushId)
|
||||
err = push.PushMessage(u.Nick+"学习情况", u.Nick+"学习情况"+content, "score", u.PushId)
|
||||
if err != nil {
|
||||
log.Errorln(err.Error())
|
||||
err = nil
|
||||
}
|
||||
message := u.Nick + " 学习完成:今日得分:" + lib.PrintScore(score)
|
||||
message := fmt.Sprintf("%v 学习完成,用时%.1f分钟</br>%v", u.Nick, endTime.Sub(startTime).Minutes(), lib.FormatScoreShort(score))
|
||||
core2.Push("flush", message)
|
||||
}
|
||||
|
||||
|
|
11
push/ding.go
11
push/ding.go
|
@ -8,6 +8,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/guonaihong/gout"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Ding struct {
|
||||
|
@ -18,7 +19,7 @@ type Ding struct {
|
|||
func (d *Ding) Send() func(kind string, message string) {
|
||||
s := TypeSecret{Secret: d.Secret, Webhook: d.Token}
|
||||
return func(kind string, message string) {
|
||||
if kind == "markdown" {
|
||||
if kind == "flush" {
|
||||
err := s.SendMessage(map[string]interface{}{
|
||||
"msgtype": "markdown",
|
||||
"markdown": map[string]string{
|
||||
|
@ -30,9 +31,11 @@ func (d *Ding) Send() func(kind string, message string) {
|
|||
return
|
||||
}
|
||||
} else {
|
||||
err := s.SendMessage(Text(message))
|
||||
if err != nil {
|
||||
return
|
||||
if log.GetLevel() == log.DebugLevel {
|
||||
err := s.SendMessage(Text(message))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue