This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Health.go
60 lines (53 loc) · 1.61 KB
/
Health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package Health
import (
"fmt"
. "github.com/XRSec/Go-Wechaty-Bot/General"
"github.com/XRSec/Go-Wechaty-Bot/Plug/Jinrishici"
"github.com/robfig/cron/v3"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/wechaty/go-wechaty/wechaty"
. "github.com/wechaty/go-wechaty/wechaty"
_interface "github.com/wechaty/go-wechaty/wechaty/interface"
"github.com/wechaty/go-wechaty/wechaty/user"
"time"
)
/*
Health()
健康监测
*/
var v int
func New() *wechaty.Plugin {
plug := wechaty.NewPlugin()
nyc, _ := time.LoadLocation("Asia/Shanghai")
plug.OnLogin(func(context *Context, user *user.ContactSelf) {
if v != 0 {
return
}
c := cron.New(cron.WithLocation(nyc))
if _, err := c.AddFunc("0 23 * * *", func() {
fmt.Println("========================每日一句👇========================")
var roomID _interface.IRoom
//if roomID = bot.Room().Find(&schemas.RoomQueryFilter{Id: "roomID@chatroom"}); roomID == nil {
if roomID = NewGlobleService().GetBot().Room().Find("Debug"); roomID == nil {
DingSend(viper.GetString("Bot.AdminID"), "RoomID Find Error")
log.Infof("RoomID Find Error")
return
}
if _, err := roomID.Say(Jinrishici.Do()); err != nil {
DingSend(viper.GetString("Bot.AdminID"), "failed to send messages")
log.Errorf("onHeartbeat Say Error: [%v]", err)
return
}
log.Infof("Heartbeat Say Success")
}); err != nil {
DingSend(viper.GetString("Bot.AdminID"), "Heartbeat Cron Add Error: "+err.Error())
log.Errorf("Heartbeat Cron Add Error: [%v]", err)
}
log.Infof("Health Cron Start")
// 启动定时器
c.Start()
v += 1
})
return plug
}