From 08b0837cab325dee51845fd271aeafcfb709a870 Mon Sep 17 00:00:00 2001 From: Shigma Date: Sat, 13 Aug 2022 01:04:29 +0800 Subject: [PATCH] fix: fix string racing --- cmd/gocq/login.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/gocq/login.go b/cmd/gocq/login.go index 38770c7..d963d25 100644 --- a/cmd/gocq/login.go +++ b/cmd/gocq/login.go @@ -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 "" }