feat(checker): checker
This commit is contained in:
@@ -8,12 +8,13 @@ import (
|
||||
"github.com/CuteReimu/bilibili/v2"
|
||||
"github.com/cenkalti/backoff/v5"
|
||||
"github.com/ssdomei232/goodBaby/configs"
|
||||
"github.com/ssdomei232/goodBaby/model"
|
||||
)
|
||||
|
||||
// 在Bilibili动态发送消息
|
||||
//
|
||||
// 暂时没有处理 429 和 403 的区别对待
|
||||
func SendBiliDynamicMsg(biliClient *bilibili.Client, msg string) {
|
||||
func SendBiliDynamicMsg(rule *model.Rule) {
|
||||
config, err := configs.GetConfig()
|
||||
if err != nil {
|
||||
log.Printf("获取配置失败: %v", err)
|
||||
@@ -21,12 +22,23 @@ func SendBiliDynamicMsg(biliClient *bilibili.Client, msg string) {
|
||||
}
|
||||
var timeout time.Duration = time.Duration(config.TimeoutDurationHours) * time.Hour
|
||||
|
||||
biliClient, err := getBiliClient(rule)
|
||||
if err != nil {
|
||||
log.Printf("获取B站客户端失败: %v", err)
|
||||
return
|
||||
}
|
||||
biliDyncmicConfig, err := getBiliDynamicConfig(rule)
|
||||
if err != nil {
|
||||
log.Printf("获取B站动态配置失败: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
var dynamicParams bilibili.CreateDynamicParam
|
||||
dynamicParams = bilibili.CreateDynamicParam{
|
||||
DynamicId: 0,
|
||||
Type: 4,
|
||||
Rid: 0,
|
||||
Content: msg,
|
||||
Content: biliDyncmicConfig.Msg,
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
|
||||
@@ -4,6 +4,6 @@ type BiliAccount struct {
|
||||
RawCookies string `json:"raw_cookies"`
|
||||
}
|
||||
|
||||
type BiliDynamicRule struct {
|
||||
type BiliDynamicConfig struct {
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// 获取 Bilibili Client
|
||||
func GetBiliClient(rule *model.Rule) (*bilibili.Client, error) {
|
||||
func getBiliClient(rule *model.Rule) (*bilibili.Client, error) {
|
||||
client := bilibili.New()
|
||||
gormDB, err := db.GetGormDB()
|
||||
if err != nil {
|
||||
@@ -34,3 +34,14 @@ func GetBiliClient(rule *model.Rule) (*bilibili.Client, error) {
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// 获取 Bilibili Dynamic Config
|
||||
func getBiliDynamicConfig(rule *model.Rule) (*BiliDynamicConfig, error) {
|
||||
var biliDynamicConfig BiliDynamicConfig
|
||||
err := json.Unmarshal([]byte(rule.ConfigJson), &biliDynamicConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &biliDynamicConfig, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user