diff --git a/control/cd.go b/control/cd.go index 1b2ab286..9744d7f5 100644 --- a/control/cd.go +++ b/control/cd.go @@ -10,6 +10,7 @@ import ( "github.com/wdvxdr1123/ZeroBot/message" "github.com/wdvxdr1123/ZeroBot/utils/helper" + "github.com/FloatTech/ZeroBot-Plugin/utils/math" "github.com/FloatTech/ZeroBot-Plugin/utils/process" ) @@ -87,7 +88,7 @@ func isValidToken(tok string) (yes bool) { if err == nil { timebytes := make([]byte, 1, 8) timebytes = append(timebytes, b14.Decode(s)...) - yes = time.Now().Unix()-int64(binary.BigEndian.Uint64(timebytes)) < 10 + yes = math.Abs64(time.Now().Unix()-int64(binary.BigEndian.Uint64(timebytes))) < 10 } return } diff --git a/utils/math/math.go b/utils/math/math.go index abe6b0a3..cdd1fc42 100644 --- a/utils/math/math.go +++ b/utils/math/math.go @@ -24,3 +24,11 @@ func Abs(x int) int { } return x } + +// Abs64 返回绝对值,该函数将被内联 +func Abs64(x int64) int64 { + if x < 0 { + return -x + } + return x +}