feat: 基础信息

This commit is contained in:
mei
2025-10-06 21:05:06 +08:00
parent 5566c929c8
commit 1d153274f4
8 changed files with 56 additions and 8 deletions
+6
View File
@@ -16,6 +16,12 @@
```json
{
"basic": {
"name": "xx", // 你的名字
"qq_number": "123", // QQ号
"age": 16, // 你的年龄
"cause_stop": "自杀" // 你最可能的死因
},
"signal_secret": "", // 发送 signal请求时需要的密钥
"debug": false, // debug 模式
"disconnect_duration": 5, // 失连时间,超出后会触发系统
+6
View File
@@ -1,4 +1,10 @@
{
"basic": {
"name": "xx",
"qq_number": "123",
"age": 16,
"cause_stop": "自杀"
},
"signal_secret": "",
"debug": false,
"disconnect_duration": 5,
+8
View File
@@ -6,6 +6,7 @@ import (
)
type Config struct {
Basic Basic `json:"basic"`
SignalSecret string `json:"signal_secret"`
Debug bool `json:"debug"`
DisconnectDuration int `json:"disconnect_duration"` // Hours
@@ -35,6 +36,13 @@ type GithubConfig struct {
Token string `json:"token"`
}
type Basic struct {
Name string `json:"name"`
Age int `json:"age"`
QQNumber string `json:"qq_number"`
CauseStop string `json:"cause_stop"`
}
func GetConfig() (config Config, err error) {
content, err := os.ReadFile("config.json")
if err != nil {
+23
View File
@@ -0,0 +1,23 @@
package internal
import (
"fmt"
"log"
"time"
"github.com/ssdomei232/goodBaby/configs"
)
func GetBasicInfo() string {
config, err := configs.GetConfig()
if err != nil {
log.Printf("获取配置文件失败: %v", err)
return "获取配置文件失败"
}
now := time.Now()
lastSignalTime := now.Add(-time.Duration(config.DisconnectDuration) * time.Hour).Format("2006-01-02 15:04:05")
return fmt.Sprintf("%s(QQ号:%s)已于%s至%s(UTC+8)之间去世,享年%d岁,死因可能为%s(此死因为推测最可能的死因,请勿完全相信,请等待后续消息)",
config.Basic.Name, config.Basic.QQNumber, lastSignalTime, time.Now().Format("2006-01-02 15:04:05"), config.Basic.Age, config.Basic.CauseStop)
}
+5 -1
View File
@@ -1,6 +1,7 @@
package internal
import (
"fmt"
"log"
"net/http"
"os"
@@ -106,6 +107,7 @@ func LoadCookies(client *bilibili.Client) bool {
return true
}
// 发送死亡通告
func SendBili(biliClient *bilibili.Client) {
config, err := configs.GetConfig()
if err != nil {
@@ -113,12 +115,14 @@ func SendBili(biliClient *bilibili.Client) {
return
}
stopMsg := fmt.Sprintf("%s\n\n%s\n\n本消息由自动程序发送(摇篮系统)", GetBasicInfo(), config.BiliMsg)
var dynamicParams bilibili.CreateDynamicParam
dynamicParams = bilibili.CreateDynamicParam{
DynamicId: 0,
Type: 4,
Rid: 0,
Content: config.BiliMsg,
Content: stopMsg,
}
// 重试机制
+4 -4
View File
@@ -21,8 +21,10 @@ func SendMail() {
return
}
stopMsg := fmt.Sprintf("%s\n\n%s\n\n本消息由自动程序发送(摇篮系统)", GetBasicInfo(), config.MailContent)
for _, address := range config.MailList {
sendMailMsgWithRetry(address, config.MailContent, config.MailTitle)
sendMailMsgWithRetry(address, stopMsg, config.MailTitle)
}
}
@@ -61,8 +63,6 @@ func sendMailMsg(address string, msg string, title string) error {
return fmt.Errorf("获取配置文件失败: %v", err)
}
mailMsg := fmt.Sprintf("Hello,\nThis is a test email sent from Go!\n%s", msg)
client, err := mail.NewClient(
config.SMTPConfig.Host,
mail.WithPort(config.SMTPConfig.Port),
@@ -86,7 +86,7 @@ func sendMailMsg(address string, msg string, title string) error {
}
message.Subject(title)
message.SetBodyString(mail.TypeTextPlain, mailMsg)
message.SetBodyString(mail.TypeTextPlain, msg)
// 发送邮件
if err := client.DialAndSend(message); err != nil {
+3 -2
View File
@@ -19,9 +19,10 @@ func SendQQ() {
}
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, config.QQMsg)
sendQQMsg(url, groupId, stopMsg)
}
}
@@ -31,7 +32,7 @@ func sendQQMsg(url string, groupId int, msg string) {
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
_ = writer.WriteField("group_id", strconv.Itoa(groupId))
_ = writer.WriteField("message", msg) //TODO: 发送死亡区间
_ = writer.WriteField("message", msg)
err := writer.Close()
if err != nil {
log.Println(err)
+1 -1
View File
@@ -43,7 +43,7 @@ func trigger() {
go internal.SendQQ()
go internal.SendMail()
go internal.Github()
go internal.SendBili(biliClient)
// go internal.SendBili(biliClient)
}
func main() {