/
refresh.go
54 lines (47 loc) · 1.18 KB
/
refresh.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
package main
import (
"github.com/starudream/go-lib/bot"
"github.com/starudream/go-lib/config"
"github.com/starudream/go-lib/cronx"
"github.com/starudream/go-lib/log"
"github.com/starudream/douyu-task/ws"
)
// NewRefresh 刷新背包荧光棒
func NewRefresh() *Refresh {
r := &Refresh{
room: config.GetInt("douyu.room"),
stk: config.GetString("douyu.stk"),
ltkid: config.GetString("douyu.ltkid"),
username: config.GetString("douyu.username"),
}
if r.stk == "" || r.ltkid == "" || r.username == "" {
log.Fatal().Msgf("douyu refresh missing config")
}
return r
}
type Refresh struct {
room int
stk string // cookie: acf_stk
ltkid string // cookie: acf_ltkid
username string // cookie: acf_username
}
var _ cronx.Job = (*Refresh)(nil)
func (r *Refresh) Name() string {
return "refresh"
}
func (r *Refresh) Run() {
_, _ = NewRenewal().Gifts()
err := ws.Login(ws.LoginParams{
Room: r.room,
Stk: r.stk,
Ltkid: r.ltkid,
Username: r.username,
})
if err != nil {
log.Error().Msgf("refresh: %v", err)
_ = bot.Send("刷新背包失败:" + err.Error())
} else {
_ = bot.Send("刷新背包成功")
}
_, _ = NewRenewal().Gifts()
}