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:
parent
bf5562b6dd
commit
08b0837cab
@ -221,26 +221,23 @@ func loginResponseProcessor(res *client.LoginResponse) error {
|
||||
func getTicket(u string) (str string) {
|
||||
id := utils.RandomString(8)
|
||||
log.Warnf("请前往该地址验证 -> %v <- 或输入手动抓取的 ticket:(Enter 提交)", 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 ""
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user