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:
parent
e053da62e1
commit
e9b39f3379
@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -346,21 +347,13 @@ func SetGroupLeave(s *httpServer, c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetRestart(s *httpServer, c *gin.Context) {
|
func SetRestart(s *httpServer, c *gin.Context) {
|
||||||
d, t := getParamWithType(c, "delay")
|
delay, _ := strconv.ParseInt(getParam(c, "delay"), 10, 64)
|
||||||
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
|
|
||||||
}
|
|
||||||
c.JSON(200, coolq.MSG{"data": nil, "retcode": 0, "status": "async"})
|
c.JSON(200, coolq.MSG{"data": nil, "retcode": 0, "status": "async"})
|
||||||
go func(delay int64) {
|
go func(delay int64) {
|
||||||
var del *time.Duration = (*time.Duration)(unsafe.Pointer(&delay))
|
var del *time.Duration = (*time.Duration)(unsafe.Pointer(&delay))
|
||||||
time.Sleep(*del * time.Millisecond)
|
time.Sleep(*del * time.Millisecond)
|
||||||
Restart <- struct{}{}
|
Restart <- struct{}{}
|
||||||
}(delay * time.Hour.Milliseconds())
|
}(delay)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,13 +485,13 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|||||||
var delay int64 = 0
|
var delay int64 = 0
|
||||||
delay = p.Get("delay").Int()
|
delay = p.Get("delay").Int()
|
||||||
if delay < 0 {
|
if delay < 0 {
|
||||||
return Failed(100, "Invalid delay")
|
delay = 0
|
||||||
}
|
}
|
||||||
defer func(delay int64) {
|
defer func(delay int64) {
|
||||||
var del *time.Duration = (*time.Duration)(unsafe.Pointer(&delay))
|
var del *time.Duration = (*time.Duration)(unsafe.Pointer(&delay))
|
||||||
time.Sleep(*del * time.Millisecond)
|
time.Sleep(*del * time.Microsecond)
|
||||||
Restart <- struct{}{}
|
Restart <- struct{}{}
|
||||||
}(delay * time.Hour.Milliseconds())
|
}(delay)
|
||||||
return coolq.MSG{"data": nil, "retcode": 0, "status": "async"}
|
return coolq.MSG{"data": nil, "retcode": 0, "status": "async"}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user