From f2285c2be0ceac029ae33641c99ba7b67a06de33 Mon Sep 17 00:00:00 2001 From: mei Date: Mon, 6 Oct 2025 18:57:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(signal):=20=E8=A7=A6=E5=8F=91=E5=AF=86?= =?UTF-8?q?=E9=92=A5=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ config.example.json | 8 +++++++- configs/config.go | 1 + internal/github.go | 1 - main.go | 14 ++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f0a2b28..eec755e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,41 @@ # goodBaby 摇篮系统 + +## 他会做什么 + +1. 接受 singnal 请求 +2. 当定时器超时(过长时间没有收到请求)时,触发 `trigger` 函数 +3. 发送消息到QQ +4. 发送邮件 +5. 将 Github 上的遗言仓库设置为 public + +## 配置 + +参照 config.example.json 修改 config.json + +```json +{ + "signal_secret": "", // 发送 signal请求时需要的密钥 + "debug": false, // debug 模式 + "disconnect_duration": 5, // 失连时间,超出后会触发系统 + "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, + "user": "", + "pass": "" + }, + "mail_content": "", // 要附加的邮件内容 + "github_config": { // Github 配置 + "owner": "", + "repos": [""], + "token": "ghp_xxxx" + } +} +``` diff --git a/config.example.json b/config.example.json index b8c502b..2e6fca7 100644 --- a/config.example.json +++ b/config.example.json @@ -1,4 +1,5 @@ { + "signal_secret": "", "debug": false, "disconnect_duration": 5, "cat_bot_url": "", @@ -13,5 +14,10 @@ "user": "", "pass": "" }, - "mail_content": "" + "mail_content": "", + "github_config": { + "owner": "", + "repos": [""], + "token": "ghp_xxxx" + } } \ No newline at end of file diff --git a/configs/config.go b/configs/config.go index 7ee07df..624b519 100644 --- a/configs/config.go +++ b/configs/config.go @@ -6,6 +6,7 @@ import ( ) type Config struct { + SignalSecret string `json:"signal_secret"` Debug bool `json:"debug"` DisconnectDuration int `json:"disconnect_duration"` // Hours CatBotUrl string `json:"cat_bot_url"` diff --git a/internal/github.go b/internal/github.go index acfd2a1..355c114 100644 --- a/internal/github.go +++ b/internal/github.go @@ -15,7 +15,6 @@ func Github() { } for _, repo := range config.GithubConfig.Repos { - // 添加重试机制 maxRetries := 10 for attempt := range maxRetries { err := pkg.MakeRepositoryPublic(config.GithubConfig.Owner, repo, config.GithubConfig.Token) diff --git a/main.go b/main.go index 9fe03da..f32d6de 100644 --- a/main.go +++ b/main.go @@ -38,13 +38,27 @@ func trigger() { } func main() { + config, err := configs.GetConfig() + if err != nil { + log.Printf("获取配置文件失败: %v", err) + } + r := gin.Default() r.GET("/signal", func(c *gin.Context) { + secret := c.Query("secret") + if secret != config.SignalSecret { + c.JSON(403, gin.H{ + "code": 403, + "message": "secret error", + }) + return + } timer.Reset(duration) c.JSON(200, gin.H{ "code": 200, "message": "ok", }) + log.Println("触发信号") }) r.Run(":8088") }