diff --git a/main.go b/main.go index effe151..9d87e59 100644 --- a/main.go +++ b/main.go @@ -213,8 +213,8 @@ func do(m string) { } } - //switch { - //case len(users) < 1: + // switch { + // case len(users) < 1: // log.Infoln("未检测到有效用户信息,将采用登录模式") // u, err := core.L(config.Retry.Times) // if err != nil { @@ -259,4 +259,5 @@ func do(m string) { } message := "学习完成:今日得分:" + strconv.Itoa(score.TodayScore) core.Push("markdown", message) + core.Push("flush", "学习完成") } diff --git a/push/pushPlus.go b/push/pushPlus.go index a906d96..187ab31 100644 --- a/push/pushPlus.go +++ b/push/pushPlus.go @@ -2,6 +2,7 @@ package push import ( "fmt" + "strings" "github.com/guonaihong/gout" log "github.com/sirupsen/logrus" @@ -12,14 +13,13 @@ type PushPlus struct { } func (p *PushPlus) Init() func(kind, message string) { - return func(kind, message string) { - if kind == "image" { - message = fmt.Sprintf("![](%v)", "data:image/png;base64,"+message) - } + var datas []string + + send := func(data string) { err := gout.POST("http://www.pushplus.plus/send").SetJSON(gout.H{ "token": p.Token, "title": "study_xxqg", - "content": message, + "content": data, "template": "markdown", "channel": "wechat", }).Do() @@ -28,4 +28,18 @@ func (p *PushPlus) Init() func(kind, message string) { return } } + + return func(kind, message string) { + if kind == "image" { + message = fmt.Sprintf("![](%v)", "data:image/png;base64,"+message) + send(message) + } else if kind == "flush" { + send(strings.Join(datas, "\n")) + } else { + datas = append(datas, message) + if len(datas) > 10 { + send(strings.Join(datas, "\n")) + } + } + } }