Skip to content

Commit 3942c5f

Browse files
committed
...
1 parent 579887f commit 3942c5f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

main.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func sendMessage(name, text string) {
207207
urlValues := url.Values{
208208
"parse_mode": {"Markdown"},
209209
"chat_id": {tg_chatId},
210-
"text": {"*实例: *" + name + "\n" + "*状态: *" + text},
210+
"text": {"*甲骨文通知*\n名称: " + name + "\n" + "内容: " + text},
211211
}
212212
cli := http.Client{Timeout: 10 * time.Second}
213213
_, err := cli.PostForm(tg_url, urlValues)
@@ -237,10 +237,15 @@ func launchInstance(node *Node) {
237237
}
238238

239239
for {
240+
printYellow("正在尝试新建实例......")
240241
out, err := exec.Command(cmd, args...).CombinedOutput()
241242
ret := string(out)
242-
if err != nil {
243-
text = "抢购失败, Command failed. " + err.Error() + "\n" + ret
243+
// 防止 Ctrl + C 取消误报
244+
if Cancel {
245+
return
246+
}
247+
if err != nil && out == nil {
248+
text = "抢购失败, " + err.Error() + "\n" + ret
244249
printRed(text)
245250
sendMessage(node.Name, text)
246251
return
@@ -254,7 +259,7 @@ func launchInstance(node *Node) {
254259
var result Result
255260
err = json.Unmarshal([]byte(ret), &result)
256261
if err != nil {
257-
text = "抢购失败, Unmarshal failed. " + "\n" + ret
262+
text = "抢购失败, " + "\n" + ret
258263
printRed(text)
259264
sendMessage(node.Name, text)
260265
return
@@ -290,11 +295,14 @@ func random(min, max int) int {
290295
return rand.Intn(max-min) + min
291296
}
292297

298+
var Cancel bool = false
299+
293300
func setCloseHandler() {
294301
c := make(chan os.Signal)
295302
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
296303
go func() {
297304
<-c
305+
Cancel = true
298306
fmt.Printf("\033[1;33;40m%s\033[0m\n", "已停止")
299307
if name != "" {
300308
sendMessage(name, "已停止")

0 commit comments

Comments
 (0)