feat: 基础信息
This commit is contained in:
@@ -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
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
// 重试机制
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user