1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-07 04:23:49 +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) { func getTicket(u string) (str string) {
id := utils.RandomString(8) 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))) 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() { go func() {
str = readLine() manual <- readLine()
manual <- str
}() }()
ticker := time.NewTicker(time.Second) ticker := time.NewTicker(time.Second)
defer ticker.Stop()
for count := 120; count > 0; count-- { for count := 120; count > 0; count-- {
select { select {
case <-ticker.C: case <-ticker.C:
str = fetchCaptcha(id) str = fetchCaptcha(id)
if str != "" { if str != "" {
ticker.Stop()
return return
} }
case <-manual: case str = <-manual:
ticker.Stop()
return return
} }
} }
ticker.Stop()
log.Warnf("验证超时") log.Warnf("验证超时")
return "" return ""
} }