feat(checker): checker

This commit is contained in:
mei
2026-04-06 10:10:31 +08:00
parent 80e427d7c3
commit 189eab8a0a
13 changed files with 181 additions and 12 deletions
+14 -2
View File
@@ -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)
+1 -1
View File
@@ -4,6 +4,6 @@ type BiliAccount struct {
RawCookies string `json:"raw_cookies"`
}
type BiliDynamicRule struct {
type BiliDynamicConfig struct {
Msg string `json:"msg"`
}
+12 -1
View File
@@ -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
}