Skip to content

Commit

Permalink
🔥 🎨 统一 cron
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Feb 23, 2022
1 parent 8c40293 commit dc348f8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.17
require (
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220222140454-0d15c275f385
github.com/FloatTech/sqlite v0.2.0
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220222140356-fceefeb900dc
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220223084851-30900a9dfa51
github.com/antchfx/htmlquery v1.2.4
github.com/corona10/goimagehash v1.0.3
github.com/fogleman/gg v1.3.0
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220222140454-0d15c275f385/go.mod
github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ=
github.com/FloatTech/sqlite v0.2.0 h1:x3uls/hExXH1+bbaNLkvilce6ATtWlDx4IqoxBW/bv8=
github.com/FloatTech/sqlite v0.2.0/go.mod h1:xIDWIvpOFl8AXmZm0FC8t3PZjiR6ZutytCpBv2EWCns=
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220222140356-fceefeb900dc h1:4oQAPzmpfzdz+8aTXuQYfcN5/v1rNVIxRpwHNJXqN40=
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220222140356-fceefeb900dc/go.mod h1:tUXu86+Hoi6vcLHfcVwjZa9ZYF4JRoNaCC510EELjfs=
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220223084631-5f53225f25fd h1:ysvDWN/ktQwn6kNBZwBl9meYX3NvB6HXNC0dh+t9d4U=
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220223084631-5f53225f25fd/go.mod h1:kSp2Z3Udn8NBnbfHayj//uX1G38WsX2dGcLG4yoXmI4=
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220223084851-30900a9dfa51 h1:5WB1ZorvJBQ4KBvTpmk5XXTLGOJpdN0cEf8ICzLoh44=
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220223084851-30900a9dfa51/go.mod h1:kSp2Z3Udn8NBnbfHayj//uX1G38WsX2dGcLG4yoXmI4=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0=
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc/go.mod h1:OMmITAib6POA37xCichWM0aRnoVpSMZO1rB/G01wrr0=
Expand Down
9 changes: 4 additions & 5 deletions plugin_bilibili/fansDaily.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

control "github.com/FloatTech/zbputils/control"
"github.com/fumiama/cron"
"github.com/FloatTech/zbputils/process"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"

Expand Down Expand Up @@ -63,10 +63,9 @@ func init() {

// 定时任务每天晚上最后2分钟执行一次
func fansDaily() {
c := cron.New()
_, err := c.AddFunc("58 23 * * *", func() { sendNotice() })
if err == nil {
c.Start()
_, err := process.CronTab.AddFunc("58 23 * * *", func() { sendNotice() })
if err != nil {
panic(err)
}
}

Expand Down
9 changes: 4 additions & 5 deletions plugin_moyu/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"

control "github.com/FloatTech/zbputils/control"
"github.com/fumiama/cron"
"github.com/FloatTech/zbputils/process"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"

Expand All @@ -21,10 +21,9 @@ func init() { // 插件主体
})

// 定时任务每天10点执行一次
c := cron.New()
_, err := c.AddFunc("0 10 * * *", func() { sendNotice() })
if err == nil {
c.Start()
_, err := process.CronTab.AddFunc("0 10 * * *", func() { sendNotice() })
if err != nil {
panic(err)
}
}

Expand Down
21 changes: 12 additions & 9 deletions plugin_moyu_calendar/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"strings"
"time"

"github.com/FloatTech/zbputils/binary"
control "github.com/FloatTech/zbputils/control"
"github.com/fumiama/cron"
"github.com/FloatTech/zbputils/process"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"

Expand All @@ -28,8 +29,7 @@ func init() {
})

// 定时任务每天8点执行一次
c := cron.New()
_, err := c.AddFunc("* 8 * * *", func() {
_, err := process.CronTab.AddFunc("* 8 * * *", func() {
m, ok := control.Lookup("moyucalendar")
if !ok {
return
Expand All @@ -48,8 +48,8 @@ func init() {
return true
})
})
if err == nil {
c.Start()
if err != nil {
panic(err)
}
}

Expand All @@ -76,7 +76,7 @@ func crew() (string, error) {
if err != nil {
return "", err
}
match := newest.FindStringSubmatch(string(b))
match := newest.FindStringSubmatch(binary.BytesToString(b))
if len(match) < 2 {
return "", errors.New("newest not found")
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func crew() (string, error) {
if err != nil {
return "", err
}
matcha := weixin.FindStringSubmatch(string(b))
matcha := weixin.FindStringSubmatch(binary.BytesToString(b))
if len(matcha) < 2 {
continue
}
Expand All @@ -135,11 +135,14 @@ func crew() (string, error) {
return "", errors.New("status not ok")
}
bw, _ := ioutil.ReadAll(respw.Body)
today := regexp.MustCompile(time.Now().Format("2006-01-02"))
today, err := regexp.Compile(time.Now().Format("2006-01-02"))
if err != nil {
return "", err
}
if !today.Match(bw) {
return "", errors.New("calendar not found")
}
matchw := calendar.FindStringSubmatch(string(bw))
matchw := calendar.FindStringSubmatch(binary.BytesToString(bw))
if len(matchw) < 2 {
return "", errors.New("calendar not found")
}
Expand Down

0 comments on commit dc348f8

Please sign in to comment.