diff --git a/main.go b/main.go index 835c4f1..03ce5ab 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( "runtime" "strconv" "strings" + "syscall" "time" "github.com/Mrs4s/go-cqhttp/server" @@ -97,6 +98,7 @@ func init() { } func main() { + var byteKey []byte var isFastStart = false arg := os.Args @@ -327,7 +329,7 @@ func main() { c := server.Console r := server.Restart go checkUpdate() - signal.Notify(c, os.Interrupt, os.Kill) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) select { case <-c: b.Release() @@ -458,7 +460,7 @@ func selfUpdate(imageUrl string) { } func restart(Args []string) { - cmd := &exec.Cmd{} + var cmd *exec.Cmd if runtime.GOOS == "windows" { file, err := exec.LookPath(Args[0]) if err != nil { diff --git a/server/apiAdmin.go b/server/apiAdmin.go index 3b0aae6..85764d1 100644 --- a/server/apiAdmin.go +++ b/server/apiAdmin.go @@ -5,8 +5,6 @@ import ( "bytes" "encoding/base64" "fmt" - "github.com/Mrs4s/MiraiGo/utils" - "github.com/gin-contrib/pprof" "image" "io/ioutil" "net/http" @@ -14,8 +12,12 @@ import ( "os/signal" "strconv" "strings" + "syscall" "time" + "github.com/Mrs4s/MiraiGo/utils" + "github.com/gin-contrib/pprof" + "github.com/Mrs4s/MiraiGo/client" "github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/global" @@ -91,14 +93,14 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot { log.Error(err) log.Infof("请检查端口是否被占用.") c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt, os.Kill) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) <-c os.Exit(1) } } else { //关闭端口监听 c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt, os.Kill) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) <-c os.Exit(1) } @@ -155,6 +157,10 @@ func (s *webServer) Dologin() { os.Exit(0) } rsp, err = cli.SubmitTicket(ticket) + if err != nil { + log.Warnf("错误: " + err.Error()) + os.Exit(0) + } continue case client.NeedCaptcha: _ = ioutil.WriteFile("captcha.jpg", rsp.CaptchaImage, 0644)