Skip to content

Commit 49b789a

Browse files
committed
支持server酱通知
1 parent 5154cde commit 49b789a

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

conf/conf.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ type Mata struct {
3131
}
3232

3333
type cf struct {
34-
ApiKey string `json:"cf_api_key"`
35-
ZoneID string
36-
BotToken string
37-
ChatID string
38-
TgApiUrl string
39-
Corn int64
40-
Contcp string
41-
Mata []Mata
34+
ApiKey string `json:"cf_api_key"`
35+
ZoneID string
36+
BotToken string
37+
ChatID string
38+
TgApiUrl string
39+
ServerJiang string
40+
Corn int64
41+
Contcp string
42+
Mata []Mata
4243
}
4344

4445
var Config cf

main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,16 @@ func main() {
8989
utils.Dns(mata.Then, dns.ID, mata.Then.ZoneID)
9090
}
9191
}
92-
if send && conf.Config.BotToken != "" && conf.Config.ChatID != "" {
93-
msg = "【" + mata.PS + "】" + msg
94-
go utils.SendMessage("#MATA " + msg)
92+
if send {
93+
// 发送到TG
94+
if conf.Config.BotToken != "" && conf.Config.ChatID != "" {
95+
msg = "【" + mata.PS + "】" + msg
96+
go utils.SendTG("#MATA " + msg)
97+
}
98+
// 发送到Server酱
99+
if conf.Config.ServerJiang != "" {
100+
go utils.SendSJ(msg)
101+
}
95102
}
96103
}
97104
if Once {

mata.sample.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"BotToken": "Telegram Bot Token",
44
"ChatID": "Telegram Chat ID",
55
"TgApiUrl": "https://api.telegram.org",
6+
"ServerJiang": "",
67
"Contcp": "",
78
"Corn": 300,
89
"Mata": [

utils/utils.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func GetDnsRecoid(recoid string, ZoneID string) (bool, conf.OneRes) {
116116
return false, no
117117
}
118118

119-
func SendMessage(text string) {
119+
func SendTG(text string) {
120120
url := fmt.Sprintf(conf.Config.TgApiUrl+"/bot%s/sendMessage", conf.Config.BotToken)
121121
requestBody := fmt.Sprintf(`{"chat_id": "%s", "text": "%s"}`, conf.Config.ChatID, text)
122122
req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(requestBody)))
@@ -139,6 +139,15 @@ func SendMessage(text string) {
139139
}
140140
}
141141

142+
// SendSJ 发送到Server酱
143+
func SendSJ(text string) {
144+
resp, err := http.Get("https://sc.ftqq.com/" + conf.Config.ServerJiang + ".send?text=" + text)
145+
if err != nil {
146+
fmt.Println("Error sending request: ", err)
147+
}
148+
defer resp.Body.Close()
149+
}
150+
142151
func Web() {
143152
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
144153
node := r.URL.Query().Get("node")

0 commit comments

Comments
 (0)