12 Commits
Author SHA1 Message Date
mei 2ab9e060eb update: README.md 2026-03-01 16:52:08 +08:00
mei 2321b5ec26 fix(sender/onebot): 修复onebot参数写反的问题 2026-03-01 15:45:26 +08:00
mei 4f305cfeda feat(sender/onebot): 新增onebot协议支持 2026-03-01 15:27:45 +08:00
mei e68d48e816 fix 2026-03-01 09:32:51 +08:00
mei 564e8a920b fix 2026-03-01 09:32:31 +08:00
mei ff949af529 update docker image version 2026-03-01 09:28:31 +08:00
mei 24630223a4 feat: 新前端 2026-03-01 08:56:32 +08:00
mei 0e689a3377 fix 2026-01-18 10:15:58 +08:00
mei bfb0fceb48 fix 2026-01-18 10:15:20 +08:00
mei eef983b1a5 fix 2026-01-18 10:13:47 +08:00
mei c66649c0ca fix 2026-01-18 10:09:53 +08:00
mei 0989fec5c1 fix:docker compose 2026-01-18 10:09:39 +08:00
21 changed files with 343 additions and 365 deletions
+35 -30
View File
@@ -12,47 +12,52 @@
4. 发送邮件 4. 发送邮件
5. 将 Github 上的遗言仓库设置为 public 5. 将 Github 上的遗言仓库设置为 public
6. 发送一条 Bilibili 动态 6. 发送一条 Bilibili 动态
7. 当倒计时小于48小时时,向用钉钉机器人发消息提醒你
## 配置 ## 配置
> [!TIP]
> 更详细的配置注解请前往 [Wiki 页面](https://github.com/ssdomei232/goodBaby/wiki)
参照 config.example.json 修改 config.json 参照 config.example.json 修改 config.json
```json ```json
{ {
"basic": { "signal_secret": "xxx", // 发送 signal请求时需要的密钥
"name": "xx", // 你的名字 "debug": false, // debug 模式
"qq_number": "123", // QQ号 "disconnect_duration": 80, // 失连时间,超出后会触发系统(小时)
"nickname": "", // 网名 "bili_msg": "摇篮系统测试", // 哔哩哔哩动态的附加消息
"age": 16, // 你的年龄 "mail_config": {
"cause_stop": "自杀" // 你最可能的死因 "host": "smtp.example.com",
},
"signal_secret": "", // 发送 signal请求时需要的密钥
"debug": false, // debug 模式
"disconnect_duration": 5, // 失连时间,超出后会触发系统
"enable_qq": true, // 是否启用QQ
"cat_bot_url": "", // CatBot 的 webhook地址(https://github.com/ssdomei232/CatBot)
"cat_bot_key": "", // CatBot 的 key
"qq_send_group": [], // 要发送QQ消息的群号
"qq_msg": "", // 要附加的QQ消息
"mail_list": [], // 要发送的邮箱
"mail_title": "摇篮系统已触发", // 邮件标题
"smtp_config": { // 邮件服务器配置
"host": "",
"port": 465, "port": 465,
"user": "", "user": "xxx",
"pass": "" "pass": "xxx",
"mail_list": ["xxx@example.com", "xxx1@example.com"],// 要发送的邮箱
"mail_title": "摇篮系统已触发", // 邮件标题
"mail_content": "这是摇篮系统的邮件内容。" // 要附加的邮件内容
}, // 邮件配置
"basic": {
"name": "xx", // 你的名字
"qq_number": "123", // 你的QQ号
"nickname": "xx_123", // 网名
"age": 16, // 你的年龄
"cause_stop": "自杀" // 你最可能的死因
}, },
"mail_content": "", // 要附加的邮件内容 "github_config": {
"github_config": { // Github 配置 "owner": "example", // github用户名
"owner": "", "repos": ["example-repo1", "example-repo2"], // 要公开的 github 仓库
"repos": [""], "token": "ghp_xxxx" // github token
"token": "ghp_xxxx"
}, },
"bili_msg": "xxx", // 哔哩哔哩动态的附加消息
"dingtalk_bot": { "dingtalk_bot": {
"access_token": "", // 钉钉机器人的 access_token "access_token": "xxx",
"secret": "" // 钉钉机器人的 secret "secret": "xxx"
} // 钉钉机器人(用于提醒发送signal和bilibili过期提醒) }, // 钉钉机器人(用于提醒发送signal和bilibili过期提醒)
"onebot_config": {
"url": "http://localhost:5700",
"token": "xxx",
"send_groups": [12345678, 87654321], // 要发送到的Onebot群组
"msg": "这是OneBot的消息内容。" // Onebot消息
}
} }
``` ```
+24 -23
View File
@@ -1,36 +1,37 @@
{ {
"signal_secret": "xxx",
"debug": true,
"disconnect_duration": 80,
"bili_msg": "摇篮系统测试",
"mail_config": {
"host": "smtp.example.com",
"port": 465,
"user": "xxx",
"pass": "xxx",
"mail_list": ["xxx@example.com", "xxx1@example.com"],
"mail_title": "摇篮系统已触发",
"mail_content": "这是摇篮系统的邮件内容。"
},
"basic": { "basic": {
"name": "xx", "name": "xx",
"qq_number": "123", "qq_number": "123",
"nickname": "", "nickname": "xx_123",
"age": 16, "age": 16,
"cause_stop": "自杀" "cause_stop": "自杀"
}, },
"signal_secret": "",
"debug": true,
"disconnect_duration": 5,
"enable_qq": true,
"cat_bot_url": "",
"cat_bot_key": "",
"qq_send_group": [],
"qq_msg": "",
"mail_list": [],
"mail_title": "摇篮系统已触发",
"smtp_config": {
"host": "",
"port": 465,
"user": "",
"pass": ""
},
"mail_content": "",
"github_config": { "github_config": {
"owner": "", "owner": "example",
"repos": [""], "repos": ["example-repo1", "example-repo2"],
"token": "ghp_xxxx" "token": "ghp_xxxx"
}, },
"bili_msg": "摇篮系统测试",
"dingtalk_bot": { "dingtalk_bot": {
"access_token": "", "access_token": "xxx",
"secret": "" "secret": "xxx"
},
"onebot_config": {
"url": "http://localhost:5700",
"token": "xxx",
"send_groups": [12345678, 87654321],
"msg": "这是OneBot的消息内容。"
} }
} }
+19 -16
View File
@@ -6,29 +6,25 @@ import (
) )
type Config struct { type Config struct {
Basic Basic `json:"basic"`
SignalSecret string `json:"signal_secret"` SignalSecret string `json:"signal_secret"`
Debug bool `json:"debug"` Debug bool `json:"debug"`
DisconnectDuration int `json:"disconnect_duration"` // Hours DisconnectDuration int `json:"disconnect_duration"` // Hours
EnableQQ bool `json:"enable_qq"`
CatBotUrl string `json:"cat_bot_url"`
CatBotKey string `json:"cat_bot_key"`
QQSendGroup []int `json:"qq_send_group"`
QQMsg string `json:"qq_msg"`
MailList []string `json:"mail_list"`
MailTitle string `json:"mail_title"`
SMTPConfig SMTPConfig `json:"smtp_config"`
MailContent string `json:"mail_content"`
GithubConfig GithubConfig `json:"github_config"`
BiliMsg string `json:"bili_msg"` BiliMsg string `json:"bili_msg"`
Basic Basic `json:"basic"`
MailConfig MailConfig `json:"mail_config"`
GithubConfig GithubConfig `json:"github_config"`
DingtalkBot DingtalkBot `json:"dingtalk_bot"` DingtalkBot DingtalkBot `json:"dingtalk_bot"`
OneBotConfig OneBotConfig `json:"onebot_config"`
} }
type SMTPConfig struct { type MailConfig struct {
Host string `json:"host"` Host string `json:"host"`
Port int `json:"port"` Port int `json:"port"`
User string `json:"user"` User string `json:"user"`
Password string `json:"pass"` Password string `json:"pass"`
MailList []string `json:"mail_list"`
MailTitle string `json:"mail_title"`
MailContent string `json:"mail_content"`
} }
type GithubConfig struct { type GithubConfig struct {
@@ -50,6 +46,13 @@ type DingtalkBot struct {
Secret string `json:"secret"` Secret string `json:"secret"`
} }
type OneBotConfig struct {
URL string `json:"url"` // 例如 "http://localhost:5700"
Token string `json:"token"`
SendGroups []int `json:"send_groups"`
Msg string `json:"msg"`
}
// Get config from json file // Get config from json file
func GetConfig() (config Config, err error) { func GetConfig() (config Config, err error) {
content, err := os.ReadFile("config.json") content, err := os.ReadFile("config.json")
+3 -3
View File
@@ -1,17 +1,17 @@
version: '3.8'
services: services:
goodbaby: goodbaby:
image: mei232/goodbaby:latest image: mei232/goodbaby:v0.2.0
ports: ports:
- "8088:8088" - "8088:8088"
environment: environment:
- TZ=Asia/Shanghai - TZ=Asia/Shanghai
- GIN_MODE=release
restart: unless-stopped restart: unless-stopped
networks: networks:
- app-network - app-network
volumes: volumes:
- ./config.json:/app/config.json:ro - ./config.json:/app/config.json:ro
- ./tmp:/app/tmp
networks: networks:
app-network: app-network:
+3 -2
View File
@@ -1,12 +1,13 @@
module github.com/ssdomei232/goodBaby module github.com/ssdomei232/goodBaby
go 1.24.0 go 1.24.10
require ( require (
github.com/CatchZeng/dingtalk v1.5.0 github.com/CatchZeng/dingtalk v1.5.0
github.com/CuteReimu/bilibili/v2 v2.3.5 github.com/CuteReimu/bilibili/v2 v2.3.5
github.com/gin-gonic/gin v1.11.0 github.com/gin-gonic/gin v1.11.0
github.com/robfig/cron/v3 v3.0.1 github.com/robfig/cron/v3 v3.0.1
github.com/ssdomei232/napcat-http-go-sdk v1.0.0
github.com/wneessen/go-mail v0.7.2 github.com/wneessen/go-mail v0.7.2
) )
@@ -20,7 +21,7 @@ require (
github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.27.0 // indirect github.com/go-playground/validator/v10 v10.27.0 // indirect
github.com/go-resty/resty/v2 v2.16.5 // indirect github.com/go-resty/resty/v2 v2.17.2 // indirect
github.com/goccy/go-json v0.10.2 // indirect github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-yaml v1.18.0 // indirect github.com/goccy/go-yaml v1.18.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
+6 -4
View File
@@ -31,8 +31,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4= github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=
github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
github.com/go-resty/resty/v2 v2.16.5 h1:hBKqmWrr7uRc3euHVqmh1HTHcKn99Smr7o5spptdhTM= github.com/go-resty/resty/v2 v2.17.2 h1:FQW5oHYcIlkCNrMD2lloGScxcHJ0gkjshV3qcQAyHQk=
github.com/go-resty/resty/v2 v2.16.5/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA= github.com/go-resty/resty/v2 v2.17.2/go.mod h1:kCKZ3wWmwJaNc7S29BRtUhJwy7iqmn+2mLtQrOyQlVA=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw= github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
@@ -78,6 +78,8 @@ github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/spf13/cast v1.9.2 h1:SsGfm7M8QOFtEzumm7UZrZdLLquNdzFYfIbEXntcFbE= github.com/spf13/cast v1.9.2 h1:SsGfm7M8QOFtEzumm7UZrZdLLquNdzFYfIbEXntcFbE=
github.com/spf13/cast v1.9.2/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= github.com/spf13/cast v1.9.2/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
github.com/ssdomei232/napcat-http-go-sdk v1.0.0 h1:BY3iqqlZw5letiCwTmfMrhyqsx0a96eL5LpDuinnOSE=
github.com/ssdomei232/napcat-http-go-sdk v1.0.0/go.mod h1:yPsSaMs3OyKMVPXwIs5ZB5G532vRi1GvL/WiWUEwblU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -110,8 +112,8 @@ golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg= golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg=
golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s= golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s=
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw= google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
@@ -1,4 +1,4 @@
package internal package base
import ( import (
"fmt" "fmt"
@@ -1,4 +1,4 @@
package internal package frontend
import ( import (
"html/template" "html/template"
-32
View File
@@ -1,32 +0,0 @@
package internal
import (
"fmt"
"log"
"time"
"github.com/CatchZeng/dingtalk/pkg/dingtalk"
"github.com/ssdomei232/goodBaby/configs"
)
func Reminder() {
config, err := configs.GetConfig()
if err != nil {
log.Printf("获取配置文件失败: %v", err)
}
remainingTime := GlobalTimerManager.GetRemainingTime()
if remainingTime <= 48*time.Hour {
sendMsg := fmt.Sprintf("距离摇篮系统触发还有%d小时,请尽快发送Signal", int(remainingTime.Hours()))
sendDingTalkMsg("摇篮系统触发提醒", sendMsg, config.DingtalkBot.AccessToken, config.DingtalkBot.Secret)
}
}
func sendDingTalkMsg(title string, msg string, accessToken string, secret string) {
client := dingtalk.NewClient(accessToken, secret)
sendMsg := dingtalk.NewMarkdownMessage().SetMarkdown(title, msg)
_, _, err := client.Send(sendMsg)
if err != nil {
log.Printf("发送钉钉消息失败: %v", err)
}
}
+23
View File
@@ -0,0 +1,23 @@
package reminder
import (
"fmt"
"log"
"time"
"github.com/ssdomei232/goodBaby/configs"
"github.com/ssdomei232/goodBaby/internal/sender"
)
func Reminder() {
config, err := configs.GetConfig()
if err != nil {
log.Printf("获取配置文件失败: %v", err)
}
remainingTime := GlobalTimerManager.GetRemainingTime()
if remainingTime <= 48*time.Hour {
sendMsg := fmt.Sprintf("距离摇篮系统触发还有%d小时,请尽快发送Signal", int(remainingTime.Hours()))
sender.SendDingTalkMsg("摇篮系统触发提醒", sendMsg, config.DingtalkBot.AccessToken, config.DingtalkBot.Secret)
}
}
@@ -1,4 +1,4 @@
package internal package reminder
import ( import (
"net/http" "net/http"
-90
View File
@@ -1,90 +0,0 @@
package internal
import (
"bytes"
"fmt"
"log"
"mime/multipart"
"net/http"
"strconv"
"time"
"github.com/ssdomei232/goodBaby/configs"
)
// 在QQ发送死亡通告
func SendQQ() {
config, err := configs.GetConfig()
if err != nil {
log.Printf("获取配置文件失败: %v", err)
return // 添加return避免继续执行
}
url := fmt.Sprintf("%s/?secret=%s", config.CatBotUrl, config.CatBotKey)
stopMsg := fmt.Sprintf("%s\n\n%s\n\n本消息由自动程序发送(摇篮系统)", GetBasicInfo(), config.QQMsg)
for _, groupId := range config.QQSendGroup {
sendQQMsg(url, groupId, stopMsg)
}
}
func sendQQMsg(url string, groupId int, msg string) {
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
// 处理写入字段的错误
if err := writer.WriteField("group_id", strconv.Itoa(groupId)); err != nil {
log.Printf("写入group_id字段失败: %v", err)
return
}
if err := writer.WriteField("message", msg); err != nil {
log.Printf("写入message字段失败: %v", err)
return
}
err := writer.Close()
if err != nil {
log.Printf("关闭multipart writer失败: %v", err)
return
}
client := &http.Client{}
req, err := http.NewRequest(method, url, payload)
if err != nil {
log.Printf("创建HTTP请求失败: %v", err)
return
}
req.Header.Set("Content-Type", writer.FormDataContentType())
var res *http.Response
for i := range maxRetries {
res, err = client.Do(req)
if err == nil {
break // 请求成功,跳出循环
}
if i < maxRetries {
time.Sleep(retryDelay * time.Duration(i+1)) // 递增延迟
}
log.Printf("请求QQ API失败,正在重试... (%d/%d): %v", i+1, maxRetries, err)
}
// 检查res是否为nil,避免panic
if res == nil {
log.Println("QQ API请求失败,无法获取响应")
return
}
// 使用defer确保资源被释放,但要确保res不为nil
defer func() {
if res != nil && res.Body != nil {
res.Body.Close()
}
}()
// 可选:记录响应结果
log.Println("QQ消息发送完成")
}
@@ -1,4 +1,4 @@
package internal package sender
import ( import (
"fmt" "fmt"
@@ -10,6 +10,7 @@ import (
"github.com/CuteReimu/bilibili/v2" "github.com/CuteReimu/bilibili/v2"
"github.com/ssdomei232/goodBaby/configs" "github.com/ssdomei232/goodBaby/configs"
"github.com/ssdomei232/goodBaby/internal/base"
) )
// check tmp dir exist // check tmp dir exist
@@ -134,7 +135,7 @@ func SendBili(biliClient *bilibili.Client) {
return return
} }
stopMsg := fmt.Sprintf("%s\n\n%s\n\n本消息由自动程序发送(摇篮系统)", GetBasicInfo(), config.BiliMsg) stopMsg := fmt.Sprintf("%s\n\n%s\n\n本消息由自动程序发送", base.GetBasicInfo(), config.BiliMsg)
var dynamicParams bilibili.CreateDynamicParam var dynamicParams bilibili.CreateDynamicParam
dynamicParams = bilibili.CreateDynamicParam{ dynamicParams = bilibili.CreateDynamicParam{
@@ -254,7 +255,7 @@ func triggerLoginRequest(biliClient *bilibili.Client) {
// 发送Dingtalk通知 // 发送Dingtalk通知
if config.DingtalkBot.AccessToken != "" && config.DingtalkBot.Secret != "" { if config.DingtalkBot.AccessToken != "" && config.DingtalkBot.Secret != "" {
sendDingTalkMsg(title, msg, config.DingtalkBot.AccessToken, config.DingtalkBot.Secret) SendDingTalkMsg(title, msg, config.DingtalkBot.AccessToken, config.DingtalkBot.Secret)
} }
} }
+16
View File
@@ -0,0 +1,16 @@
package sender
import (
"log"
"github.com/CatchZeng/dingtalk/pkg/dingtalk"
)
func SendDingTalkMsg(title string, msg string, accessToken string, secret string) {
client := dingtalk.NewClient(accessToken, secret)
sendMsg := dingtalk.NewMarkdownMessage().SetMarkdown(title, msg)
_, _, err := client.Send(sendMsg)
if err != nil {
log.Printf("发送钉钉消息失败: %v", err)
}
}
@@ -1,4 +1,4 @@
package internal package sender
import ( import (
"fmt" "fmt"
@@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/ssdomei232/goodBaby/configs" "github.com/ssdomei232/goodBaby/configs"
"github.com/ssdomei232/goodBaby/internal/base"
"github.com/wneessen/go-mail" "github.com/wneessen/go-mail"
) )
@@ -22,10 +23,10 @@ func SendMail() {
return return
} }
stopMsg := fmt.Sprintf("%s\n\n%s\n\n本消息由自动程序发送(摇篮系统)", GetBasicInfo(), config.MailContent) stopMsg := fmt.Sprintf("%s\n\n%s\n\n本消息由自动程序发送", base.GetBasicInfo(), config.MailConfig.MailContent)
for _, address := range config.MailList { for _, address := range config.MailConfig.MailList {
sendMailMsgWithRetry(address, stopMsg, config.MailTitle) sendMailMsgWithRetry(address, stopMsg, config.MailConfig.MailTitle)
} }
} }
@@ -65,11 +66,11 @@ func sendMailMsg(address string, msg string, title string) error {
} }
client, err := mail.NewClient( client, err := mail.NewClient(
config.SMTPConfig.Host, config.MailConfig.Host,
mail.WithPort(config.SMTPConfig.Port), mail.WithPort(config.MailConfig.Port),
mail.WithSSL(), mail.WithSSL(),
mail.WithUsername(config.SMTPConfig.User), mail.WithUsername(config.MailConfig.User),
mail.WithPassword(config.SMTPConfig.Password), mail.WithPassword(config.MailConfig.Password),
mail.WithSMTPAuth(mail.SMTPAuthPlain), mail.WithSMTPAuth(mail.SMTPAuthPlain),
) )
if err != nil { if err != nil {
@@ -78,7 +79,7 @@ func sendMailMsg(address string, msg string, title string) error {
// 创建邮件 // 创建邮件
message := mail.NewMsg() message := mail.NewMsg()
if err := message.From(config.SMTPConfig.User); err != nil { if err := message.From(config.MailConfig.User); err != nil {
return fmt.Errorf("设置发件人失败: %v", err) return fmt.Errorf("设置发件人失败: %v", err)
} }
@@ -1,11 +1,11 @@
package internal package sender
import ( import (
"log" "log"
"time" "time"
"github.com/ssdomei232/goodBaby/configs" "github.com/ssdomei232/goodBaby/configs"
"github.com/ssdomei232/goodBaby/pkg" "github.com/ssdomei232/goodBaby/pkg/github"
) )
// 将repos设置为public // 将repos设置为public
@@ -18,19 +18,18 @@ func Github() {
for _, repo := range config.GithubConfig.Repos { for _, repo := range config.GithubConfig.Repos {
maxRetries := 10 maxRetries := 10
for attempt := range maxRetries { for attempt := range maxRetries {
err := pkg.MakeRepositoryPublic(config.GithubConfig.Owner, repo, config.GithubConfig.Token) err := github.MakeRepositoryPublic(config.GithubConfig.Owner, repo, config.GithubConfig.Token)
if err == nil { if err == nil {
// 成功执行,跳出重试循环
break break
} }
log.Printf("尝试设置仓库 %s 为私有失败 (尝试 %d/%d): %v", repo, attempt+1, maxRetries, err) log.Printf("尝试设置仓库 %s 为公开失败 (尝试 %d/%d): %v", repo, attempt+1, maxRetries, err)
// 如果不是最后一次尝试,则等待一段时间后重试 // 如果不是最后一次尝试,则等待一段时间后重试
if attempt < maxRetries-1 { if attempt < maxRetries-1 {
time.Sleep(time.Duration(attempt+1) * time.Second) // 逐步增加等待时间 time.Sleep(time.Duration(attempt+1) * time.Second) // 逐步增加等待时间
} else { } else {
log.Printf("设置仓库 %s 为私有最终失败", repo) log.Printf("设置仓库 %s 为公开最终失败", repo)
} }
} }
} }
+43
View File
@@ -0,0 +1,43 @@
package sender
import (
"fmt"
"log"
"strconv"
"github.com/ssdomei232/goodBaby/configs"
"github.com/ssdomei232/goodBaby/internal/base"
napcat "github.com/ssdomei232/napcat-http-go-sdk"
)
func SendOneBot() {
config, err := configs.GetConfig()
if err != nil {
log.Printf("获取配置文件失败: %v", err)
return
}
stopMsg := fmt.Sprintf("%s\n\n%s\n\n本消息由自动程序发送", base.GetBasicInfo(), config.OneBotConfig.Msg)
for _, groupId := range config.OneBotConfig.SendGroups {
sendOneBotMsg(groupId, stopMsg)
}
}
// 发送一条消息到OneBot
func sendOneBotMsg(groupID int, msg string) {
config, err := configs.GetConfig()
if err != nil {
log.Printf("获取配置文件失败: %v", err)
return
}
client := napcat.NewClient(config.OneBotConfig.Token, config.OneBotConfig.URL)
err = client.SendGroupMsg(strconv.Itoa(groupID), msg)
if err != nil {
log.Printf("发送消息到OneBot失败: %v", err)
} else {
log.Printf("成功发送消息到OneBot群 %d", groupID)
}
}
+24 -25
View File
@@ -1,4 +1,3 @@
// main.go
package main package main
import ( import (
@@ -12,7 +11,9 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"
"github.com/ssdomei232/goodBaby/configs" "github.com/ssdomei232/goodBaby/configs"
"github.com/ssdomei232/goodBaby/internal" "github.com/ssdomei232/goodBaby/internal/frontend"
"github.com/ssdomei232/goodBaby/internal/reminder"
"github.com/ssdomei232/goodBaby/internal/sender"
) )
//go:embed static/* //go:embed static/*
@@ -27,7 +28,7 @@ var biliClient *bilibili.Client
var cookieCheckTimer *time.Ticker var cookieCheckTimer *time.Ticker
func init() { func init() {
// Get COnfig // 1. 加载配置文件
config, err := configs.GetConfig() config, err := configs.GetConfig()
if err != nil { if err != nil {
log.Printf("获取配置文件失败: %v", err) log.Printf("获取配置文件失败: %v", err)
@@ -39,17 +40,17 @@ func init() {
duration = time.Duration(config.DisconnectDuration) * time.Hour duration = time.Duration(config.DisconnectDuration) * time.Hour
} }
// Check and create tmp dir // 2. 检查并创建tmp目录
if err := internal.EnsureTmpDirectory(); err != nil { if err := sender.EnsureTmpDirectory(); err != nil {
log.Printf("创建tmp目录失败: %v", err) log.Printf("创建tmp目录失败: %v", err)
} }
// Init Bilibili Clinet // 3. 初始化哔哩哔哩和定时器
biliClient = bilibili.New() biliClient = bilibili.New()
internal.InitBilibili(biliClient) sender.InitBilibili(biliClient)
internal.StartCookieChecker(cookieCheckTimer, biliClient) // Check Bilibili cookie sender.StartCookieChecker(cookieCheckTimer, biliClient) // Check Bilibili cookie
internal.InitTimerManager(duration) reminder.InitTimerManager(duration)
timer = time.NewTimer(duration) timer = time.NewTimer(duration)
go func() { go func() {
<-timer.C <-timer.C
@@ -57,15 +58,13 @@ func init() {
}() }()
} }
// trigger // 触发器
func trigger(config configs.Config) { func trigger(config configs.Config) {
if config.EnableQQ { go sender.SendOneBot()
go internal.SendQQ() go sender.SendMail()
} go sender.Github()
go internal.SendMail()
go internal.Github()
if !config.Debug { if !config.Debug {
go internal.SendBili(biliClient) go sender.SendBili(biliClient)
} }
} }
@@ -74,26 +73,26 @@ func main() {
if err != nil { if err != nil {
log.Printf("获取配置文件失败: %v", err) log.Printf("获取配置文件失败: %v", err)
} }
// cron job // 定时任务
internal.Reminder() reminder.Reminder()
c := cron.New() c := cron.New()
if config.Debug { if config.Debug {
c.AddFunc("@every 1s", internal.Reminder) c.AddFunc("@every 1s", reminder.Reminder)
} else { } else {
c.AddFunc("@every 1h", internal.Reminder) c.AddFunc("@every 1h", reminder.Reminder)
} }
c.Start() c.Start()
// Web service // 前端/后端
r := gin.Default() r := gin.Default()
templFS, _ := fs.Sub(templateFiles, "templates") templFS, _ := fs.Sub(templateFiles, "templates")
r.SetHTMLTemplate(internal.LoadTemplates(templFS)) r.SetHTMLTemplate(frontend.LoadTemplates(templFS))
staticFS, _ := fs.Sub(staticFiles, "static") staticFS, _ := fs.Sub(staticFiles, "static")
r.StaticFS("/static", http.FS(staticFS)) r.StaticFS("/static", http.FS(staticFS))
r.GET("/", internal.IndexPage) r.GET("/", frontend.IndexPage)
r.GET("/signal", handleSignal) r.GET("/signal", handleSignal)
r.GET("/timer/status", internal.HandleTimerStatus) r.GET("/timer/status", reminder.HandleTimerStatus)
r.Run(":8088") r.Run(":8088")
} }
@@ -113,7 +112,7 @@ func handleSignal(c *gin.Context) {
return return
} }
timer.Reset(duration) timer.Reset(duration)
internal.GlobalTimerManager.Reset() reminder.GlobalTimerManager.Reset()
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"code": 200, "code": 200,
"message": "ok", "message": "ok",
+1 -1
View File
@@ -1,4 +1,4 @@
package pkg package github
import ( import (
"bytes" "bytes"
+115 -109
View File
@@ -5,45 +5,51 @@
} }
body { body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); background-color: #f8fafc;
color: #334155;
min-height: 100vh; min-height: 100vh;
padding: 20px; padding: 20px;
line-height: 1.6;
} }
.container { .container {
max-width: 800px; max-width: 640px;
margin: 0 auto; margin: 0 auto;
background: white;
border-radius: 12px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
overflow: hidden;
} }
header { header {
text-align: center; text-align: center;
color: white; background: #f1f5f9;
margin-bottom: 30px; padding: 32px 24px;
border-bottom: 1px solid #e2e8f0;
} }
header h1 { header h1 {
font-size: 2.5rem; font-size: 1.875rem;
margin-bottom: 10px; font-weight: 600;
} color: #1e293b;
letter-spacing: -0.025em;
header p {
font-size: 1.2rem;
opacity: 0.9;
} }
.card { .card {
background: rgba(255, 255, 255, 0.95); padding: 32px;
border-radius: 15px; border-bottom: 1px solid #e2e8f0;
padding: 25px; }
margin-bottom: 25px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); .card:last-child {
backdrop-filter: blur(10px); border-bottom: none;
} }
.card h2 { .card h2 {
color: #333; color: #1e293b;
margin-bottom: 20px; font-size: 1.25rem;
font-weight: 600;
margin-bottom: 24px;
display: flex; display: flex;
align-items: center; align-items: center;
gap: 10px; gap: 10px;
@@ -52,143 +58,143 @@ header p {
.form-group { .form-group {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 15px; gap: 16px;
} }
.form-group label { .form-group label {
font-weight: 600; font-weight: 500;
color: #555; color: #334155;
font-size: 0.875rem;
} }
.form-group input { .form-group input {
padding: 12px 15px; padding: 12px 16px;
border: 2px solid #ddd; border: 1px solid #cbd5e1;
border-radius: 8px; border-radius: 6px;
font-size: 16px; font-size: 1rem;
transition: border-color 0.3s; transition: border-color 0.2s, box-shadow 0.2s;
background: #f8fafc;
} }
.form-group input:focus { .form-group input:focus {
outline: none; outline: none;
border-color: #667eea; border-color: #94a3b8;
} box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.1);
.btn-primary, .btn-secondary, .btn-danger {
padding: 12px 20px;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.btn-secondary {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
color: white;
}
.btn-danger {
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
color: white;
padding: 15px 30px;
font-size: 18px;
}
.btn-primary:hover, .btn-secondary:hover, .btn-danger:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
} }
.status-container { .status-container {
text-align: center; display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
} }
.timer-display { .timer-display {
font-size: 3rem; font-size: 2rem;
font-weight: 700; font-weight: 600;
color: #333; color: #1e293b;
margin: 20px 0; font-family: monospace;
font-family: 'Courier New', monospace;
} }
.progress-bar { .progress-bar {
width: 100%; width: 100%;
height: 20px; height: 8px;
background-color: #eee; background: #e2e8f0;
border-radius: 10px; border-radius: 4px;
overflow: hidden; overflow: hidden;
margin: 20px 0;
} }
.progress-fill { .progress-fill {
height: 100%; height: 100%;
background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%); background: #3b82f6;
width: 0%; width: 0%;
transition: width 0.5s ease; transition: width 0.3s ease;
} }
.controls { .controls {
display: flex;
flex-direction: column;
align-items: center;
gap: 16px;
}
.btn-primary, .btn-secondary, .btn-danger {
padding: 12px 24px;
border: none;
border-radius: 6px;
font-size: 0.95rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
text-align: center; text-align: center;
} }
.btn-primary {
background: #3b82f6;
color: white;
}
.btn-primary:hover {
background: #2563eb;
}
.btn-secondary {
background: #64748b;
color: white;
}
.btn-secondary:hover {
background: #475569;
}
.btn-danger {
background: #ef4444;
color: white;
padding: 12px 24px;
font-weight: 500;
}
.btn-danger:hover {
background: #dc2626;
}
.hint { .hint {
color: #666; font-size: 0.875rem;
margin-top: 15px; color: #64748b;
font-style: italic; margin-top: 4px;
} }
footer { footer {
text-align: center; text-align: center;
color: white; padding: 24px;
margin-top: 30px; color: #64748b;
opacity: 0.8; font-size: 0.875rem;
background: #f1f5f9;
} }
.notification { .notification {
position: fixed; position: fixed;
top: 20px; top: 20px;
right: 20px; right: 20px;
padding: 15px 25px; padding: 12px 20px;
border-radius: 8px; border-radius: 6px;
color: white; color: white;
font-weight: 600; font-size: 0.875rem;
transform: translateX(400px); transform: translateX(200%);
transition: transform 0.3s ease; transition: transform 0.3s ease;
z-index: 1000; z-index: 1000;
max-width: 300px;
word-wrap: break-word;
}
.notification.success {
background: #22c55e;
}
.notification.error {
background: #ef4444;
} }
.notification.show { .notification.show {
transform: translateX(0); transform: translateX(0);
}
.notification.success {
background: linear-gradient(135deg, #56ab2f 0%, #a8e6cf 100%);
}
.notification.error {
background: linear-gradient(135deg, #ff416c 0%, #ff4b2b 100%);
}
@media (max-width: 768px) {
.container {
padding: 10px;
}
header h1 {
font-size: 2rem;
}
.card {
padding: 20px;
}
.timer-display {
font-size: 2rem;
}
} }
+9 -9
View File
@@ -9,21 +9,21 @@
<body> <body>
<div class="container"> <div class="container">
<header> <header>
<h1>GoodBaby控制面板</h1> <h1>GoodBaby</h1>
</header> </header>
<main> <main>
<section class="card"> <section class="card">
<h2>🔐 身份验证</h2> <h2>访问设置</h2>
<div class="form-group"> <div class="form-group">
<label for="secret">请输入密钥:</label> <label for="secret">密钥</label>
<input type="password" id="secret" placeholder="输入您的访问密钥"> <input type="password" id="secret" placeholder="输入您的访问密钥">
<button id="save-secret" class="btn-secondary">保存密钥</button> <button id="save-secret" class="btn-secondary">保存</button>
</div> </div>
</section> </section>
<section class="card"> <section class="card">
<h2>📊 定时器状态</h2> <h2>状态信息</h2>
<div class="status-container"> <div class="status-container">
<div class="timer-display"> <div class="timer-display">
<span id="remaining-time">--:--:--</span> <span id="remaining-time">--:--:--</span>
@@ -31,21 +31,21 @@
<div class="progress-bar"> <div class="progress-bar">
<div id="progress-fill" class="progress-fill"></div> <div id="progress-fill" class="progress-fill"></div>
</div> </div>
<button id="refresh-status" class="btn-primary">🔄 刷新状态</button> <button id="refresh-status" class="btn-primary">刷新状态</button>
</div> </div>
</section> </section>
<section class="card"> <section class="card">
<h2>⚡ 操作控制</h2> <h2>执行操作</h2>
<div class="controls"> <div class="controls">
<button id="send-signal" class="btn-danger">📡 发送信号</button> <button id="send-signal" class="btn-danger">发送信号</button>
<p class="hint">点击按钮重置定时器</p> <p class="hint">点击按钮重置定时器</p>
</div> </div>
</section> </section>
</main> </main>
<footer> <footer>
<p>© 2025 GoodBaby</p> <p>© 2026 GoodBaby</p>
</footer> </footer>
</div> </div>