2025-10-06 16:23:56 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"log"
|
|
|
|
|
"time"
|
|
|
|
|
|
2025-10-06 20:02:47 +08:00
|
|
|
"github.com/CuteReimu/bilibili/v2"
|
2025-10-06 16:23:56 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"github.com/ssdomei232/goodBaby/configs"
|
|
|
|
|
"github.com/ssdomei232/goodBaby/internal"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var timer *time.Timer
|
|
|
|
|
var duration time.Duration
|
2025-10-06 20:02:47 +08:00
|
|
|
var biliClient *bilibili.Client
|
2025-10-06 20:23:46 +08:00
|
|
|
var cookieCheckTimer *time.Ticker
|
2025-10-06 16:23:56 +08:00
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
config, err := configs.GetConfig()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("获取配置文件失败: %v", err)
|
|
|
|
|
}
|
2025-10-06 17:26:00 +08:00
|
|
|
|
2025-10-06 17:18:44 +08:00
|
|
|
if config.Debug {
|
|
|
|
|
duration = time.Duration(config.DisconnectDuration) * time.Second
|
|
|
|
|
} else {
|
|
|
|
|
duration = time.Duration(config.DisconnectDuration) * time.Hour
|
|
|
|
|
}
|
2025-10-06 17:26:00 +08:00
|
|
|
|
2025-10-06 22:21:03 +08:00
|
|
|
// 初始化bilibili客户端
|
|
|
|
|
biliClient = bilibili.New()
|
|
|
|
|
initBilibili()
|
|
|
|
|
startCookieChecker() // 启动定期检查cookie有效性
|
|
|
|
|
|
2025-10-06 16:23:56 +08:00
|
|
|
timer = time.NewTimer(duration)
|
|
|
|
|
go func() {
|
|
|
|
|
<-timer.C
|
2025-10-06 22:15:35 +08:00
|
|
|
trigger(config)
|
2025-10-06 16:23:56 +08:00
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-06 22:16:35 +08:00
|
|
|
func trigger(config configs.Config) {
|
2025-10-06 22:15:35 +08:00
|
|
|
if config.EnableQQ {
|
|
|
|
|
go internal.SendQQ()
|
|
|
|
|
}
|
2025-10-06 17:14:54 +08:00
|
|
|
go internal.SendMail()
|
2025-10-06 18:44:49 +08:00
|
|
|
go internal.Github()
|
2025-10-06 21:10:41 +08:00
|
|
|
go internal.SendBili(biliClient)
|
2025-10-06 16:23:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
2025-10-06 18:57:53 +08:00
|
|
|
config, err := configs.GetConfig()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("获取配置文件失败: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-06 16:23:56 +08:00
|
|
|
r := gin.Default()
|
|
|
|
|
r.GET("/signal", func(c *gin.Context) {
|
2025-10-06 18:57:53 +08:00
|
|
|
secret := c.Query("secret")
|
|
|
|
|
if secret != config.SignalSecret {
|
|
|
|
|
c.JSON(403, gin.H{
|
|
|
|
|
"code": 403,
|
|
|
|
|
"message": "secret error",
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-10-06 16:23:56 +08:00
|
|
|
timer.Reset(duration)
|
|
|
|
|
c.JSON(200, gin.H{
|
|
|
|
|
"code": 200,
|
|
|
|
|
"message": "ok",
|
|
|
|
|
})
|
2025-10-06 18:57:53 +08:00
|
|
|
log.Println("触发信号")
|
2025-10-06 16:23:56 +08:00
|
|
|
})
|
|
|
|
|
r.Run(":8088")
|
|
|
|
|
}
|
2025-10-06 20:02:47 +08:00
|
|
|
|
|
|
|
|
func initBilibili() {
|
|
|
|
|
// 尝试加载已存储的cookie
|
|
|
|
|
if !internal.LoadCookies(biliClient) {
|
|
|
|
|
// 如果没有有效cookie,则进行二维码登录
|
|
|
|
|
internal.LoginWithQRCode(biliClient)
|
|
|
|
|
} else {
|
|
|
|
|
log.Println("使用已存储的有效cookie登录")
|
|
|
|
|
}
|
2025-10-06 20:23:46 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 启动cookie定期检查
|
|
|
|
|
func startCookieChecker() {
|
|
|
|
|
// 每小时检查一次cookie有效性
|
|
|
|
|
cookieCheckTimer = time.NewTicker(1 * time.Hour)
|
|
|
|
|
go func() {
|
|
|
|
|
for {
|
|
|
|
|
<-cookieCheckTimer.C
|
|
|
|
|
internal.CheckCookieValidity(biliClient)
|
|
|
|
|
}
|
|
|
|
|
}()
|
2025-10-06 20:02:47 +08:00
|
|
|
}
|