feat: 基础信息
This commit is contained in:
@@ -16,6 +16,12 @@
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
"basic": {
|
||||||
|
"name": "xx", // 你的名字
|
||||||
|
"qq_number": "123", // QQ号
|
||||||
|
"age": 16, // 你的年龄
|
||||||
|
"cause_stop": "自杀" // 你最可能的死因
|
||||||
|
},
|
||||||
"signal_secret": "", // 发送 signal请求时需要的密钥
|
"signal_secret": "", // 发送 signal请求时需要的密钥
|
||||||
"debug": false, // debug 模式
|
"debug": false, // debug 模式
|
||||||
"disconnect_duration": 5, // 失连时间,超出后会触发系统
|
"disconnect_duration": 5, // 失连时间,超出后会触发系统
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
{
|
{
|
||||||
|
"basic": {
|
||||||
|
"name": "xx",
|
||||||
|
"qq_number": "123",
|
||||||
|
"age": 16,
|
||||||
|
"cause_stop": "自杀"
|
||||||
|
},
|
||||||
"signal_secret": "",
|
"signal_secret": "",
|
||||||
"debug": false,
|
"debug": false,
|
||||||
"disconnect_duration": 5,
|
"disconnect_duration": 5,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ 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
|
||||||
@@ -35,6 +36,13 @@ type GithubConfig struct {
|
|||||||
Token string `json:"token"`
|
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) {
|
func GetConfig() (config Config, err error) {
|
||||||
content, err := os.ReadFile("config.json")
|
content, err := os.ReadFile("config.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -106,6 +107,7 @@ func LoadCookies(client *bilibili.Client) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发送死亡通告
|
||||||
func SendBili(biliClient *bilibili.Client) {
|
func SendBili(biliClient *bilibili.Client) {
|
||||||
config, err := configs.GetConfig()
|
config, err := configs.GetConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -113,12 +115,14 @@ func SendBili(biliClient *bilibili.Client) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stopMsg := fmt.Sprintf("%s\n\n%s\n\n本消息由自动程序发送(摇篮系统)", GetBasicInfo(), config.BiliMsg)
|
||||||
|
|
||||||
var dynamicParams bilibili.CreateDynamicParam
|
var dynamicParams bilibili.CreateDynamicParam
|
||||||
dynamicParams = bilibili.CreateDynamicParam{
|
dynamicParams = bilibili.CreateDynamicParam{
|
||||||
DynamicId: 0,
|
DynamicId: 0,
|
||||||
Type: 4,
|
Type: 4,
|
||||||
Rid: 0,
|
Rid: 0,
|
||||||
Content: config.BiliMsg,
|
Content: stopMsg,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重试机制
|
// 重试机制
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ func SendMail() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stopMsg := fmt.Sprintf("%s\n\n%s\n\n本消息由自动程序发送(摇篮系统)", GetBasicInfo(), config.MailContent)
|
||||||
|
|
||||||
for _, address := range config.MailList {
|
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)
|
return fmt.Errorf("获取配置文件失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mailMsg := fmt.Sprintf("Hello,\nThis is a test email sent from Go!\n%s", msg)
|
|
||||||
|
|
||||||
client, err := mail.NewClient(
|
client, err := mail.NewClient(
|
||||||
config.SMTPConfig.Host,
|
config.SMTPConfig.Host,
|
||||||
mail.WithPort(config.SMTPConfig.Port),
|
mail.WithPort(config.SMTPConfig.Port),
|
||||||
@@ -86,7 +86,7 @@ func sendMailMsg(address string, msg string, title string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message.Subject(title)
|
message.Subject(title)
|
||||||
message.SetBodyString(mail.TypeTextPlain, mailMsg)
|
message.SetBodyString(mail.TypeTextPlain, msg)
|
||||||
|
|
||||||
// 发送邮件
|
// 发送邮件
|
||||||
if err := client.DialAndSend(message); err != nil {
|
if err := client.DialAndSend(message); err != nil {
|
||||||
|
|||||||
@@ -19,9 +19,10 @@ func SendQQ() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/?secret=%s", config.CatBotUrl, config.CatBotKey)
|
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 {
|
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{}
|
payload := &bytes.Buffer{}
|
||||||
writer := multipart.NewWriter(payload)
|
writer := multipart.NewWriter(payload)
|
||||||
_ = writer.WriteField("group_id", strconv.Itoa(groupId))
|
_ = writer.WriteField("group_id", strconv.Itoa(groupId))
|
||||||
_ = writer.WriteField("message", msg) //TODO: 发送死亡区间
|
_ = writer.WriteField("message", msg)
|
||||||
err := writer.Close()
|
err := writer.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user