1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 19:43:49 +08:00

Fix: set_restart delay不生效的问题

This commit is contained in:
Ink-33 2020-11-17 01:24:16 +08:00
parent e053da62e1
commit e9b39f3379
No known key found for this signature in database
GPG Key ID: 5D8B1D036EFB0D2E
2 changed files with 6 additions and 13 deletions

View File

@ -5,6 +5,7 @@ import (
"crypto/hmac"
"crypto/sha1"
"encoding/hex"
"fmt"
"net/http"
"os"
"strconv"
@ -346,21 +347,13 @@ func SetGroupLeave(s *httpServer, c *gin.Context) {
}
func SetRestart(s *httpServer, c *gin.Context) {
d, t := getParamWithType(c, "delay")
if t == gjson.Null {
d = "0"
}
delay, err := strconv.ParseInt(d, 10, 64)
if err != nil || delay < 0 {
c.JSON(200, Failed(100, "Invalid delay"))
return
}
delay, _ := strconv.ParseInt(getParam(c, "delay"), 10, 64)
c.JSON(200, coolq.MSG{"data": nil, "retcode": 0, "status": "async"})
go func(delay int64) {
var del *time.Duration = (*time.Duration)(unsafe.Pointer(&delay))
time.Sleep(*del * time.Millisecond)
Restart <- struct{}{}
}(delay * time.Hour.Milliseconds())
}(delay)
}

View File

@ -485,13 +485,13 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
var delay int64 = 0
delay = p.Get("delay").Int()
if delay < 0 {
return Failed(100, "Invalid delay")
delay = 0
}
defer func(delay int64) {
var del *time.Duration = (*time.Duration)(unsafe.Pointer(&delay))
time.Sleep(*del * time.Millisecond)
time.Sleep(*del * time.Microsecond)
Restart <- struct{}{}
}(delay * time.Hour.Milliseconds())
}(delay)
return coolq.MSG{"data": nil, "retcode": 0, "status": "async"}
},