github.com/Mrs4s/go-cqhttp@v1.2.0/global/param.go (about) 1 package global 2 3 import ( 4 "regexp" 5 "strconv" 6 7 log "github.com/sirupsen/logrus" 8 ) 9 10 // MSG 消息Map 11 type MSG = map[string]any 12 13 // VersionNameCompare 检查版本名是否需要更新, 仅适用于 go-cqhttp 的版本命名规则 14 // 15 // 例: v0.9.29-fix2 == v0.9.29-fix2 -> false 16 // 17 // v0.9.29-fix1 < v0.9.29-fix2 -> true 18 // 19 // v0.9.29-fix2 > v0.9.29-fix1 -> false 20 // 21 // v0.9.29-fix2 < v0.9.30 -> true 22 // 23 // v1.0.0-alpha2 < v1.0.0-beta1 -> true 24 // 25 // v1.0.0 > v1.0.0-beta1 -> false 26 func VersionNameCompare(current, remote string) bool { 27 defer func() { // 应该不会panic, 为了保险还是加个 28 if err := recover(); err != nil { 29 log.Warn("检查更新失败!") 30 } 31 }() 32 sp := regexp.MustCompile(`v(\d+)\.(\d+)\.(\d+)-?(.+)?`) 33 cur := sp.FindStringSubmatch(current) 34 re := sp.FindStringSubmatch(remote) 35 for i := 1; i <= 3; i++ { 36 curSub, _ := strconv.Atoi(cur[i]) 37 reSub, _ := strconv.Atoi(re[i]) 38 if curSub != reSub { 39 return curSub < reSub 40 } 41 } 42 if cur[4] == "" || re[4] == "" { 43 return re[4] == "" && cur[4] != re[4] 44 } 45 return cur[4] < re[4] 46 }