1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 20:13:50 +08:00

fix: fix string racing

This commit is contained in:
Shigma 2022-08-13 01:04:29 +08:00
parent bf5562b6dd
commit 08b0837cab
No known key found for this signature in database
GPG Key ID: 21C89B0B92907E14

View File

@ -221,26 +221,23 @@ func loginResponseProcessor(res *client.LoginResponse) error {
func getTicket(u string) (str string) {
id := utils.RandomString(8)
log.Warnf("请前往该地址验证 -> %v <- 或输入手动抓取的 ticketEnter 提交)", strings.ReplaceAll(u, "https://ssl.captcha.qq.com/template/wireless_mqq_captcha.html?", fmt.Sprintf("https://captcha.go-cqhttp.org/captcha?id=%v&", id)))
manual := make(chan string)
manual := make(chan string, 1)
go func() {
str = readLine()
manual <- str
manual <- readLine()
}()
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
for count := 120; count > 0; count-- {
select {
case <-ticker.C:
str = fetchCaptcha(id)
if str != "" {
ticker.Stop()
return
}
case <-manual:
ticker.Stop()
case str = <-manual:
return
}
}
ticker.Stop()
log.Warnf("验证超时")
return ""
}