From 94ede52c0dc058ae8daf278f8a3dc32286ebddb6 Mon Sep 17 00:00:00 2001 From: Duo Date: Wed, 24 Jan 2024 08:40:09 +0800 Subject: [PATCH] Switch the sliding captcha's ticket from automatic to manual input --- go.mod | 2 +- go.sum | 4 ++-- internal/command.go | 47 +++++---------------------------------------- main.go | 2 +- 4 files changed, 9 insertions(+), 46 deletions(-) diff --git a/go.mod b/go.mod index f331745..ba9fda2 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/gabriel-vasile/mimetype v1.4.2 github.com/hashicorp/go-version v1.6.0 github.com/lib/pq v1.10.9 - github.com/mattn/go-sqlite3 v1.14.17 + github.com/mattn/go-sqlite3 v1.14.19 github.com/tidwall/gjson v1.16.0 github.com/wdvxdr1123/go-silk v0.0.0-20220304095002-f67345df09ea golang.org/x/image v0.11.0 diff --git a/go.sum b/go.sum index 03c75ef..36ab460 100644 --- a/go.sum +++ b/go.sum @@ -44,8 +44,8 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM= -github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI= +github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ= github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= diff --git a/internal/command.go b/internal/command.go index e3793fd..cce5f39 100644 --- a/internal/command.go +++ b/internal/command.go @@ -9,10 +9,8 @@ import ( "sort" "strconv" "strings" - "time" "github.com/duo/matrix-qq/internal/types" - "github.com/tidwall/gjson" "github.com/Mrs4s/MiraiGo/client" "golang.org/x/image/draw" @@ -129,17 +127,9 @@ func fnLoginPassword(ce *WrappedCommandEvent) { switch res.Error { case client.SliderNeededError: - ticket := getTicket(ce, res.VerifyUrl) - res, err = ce.User.Client.SubmitTicket(ticket) - if err != nil { - ce.Reply("Failed to log in: %v", err) - return - } - if res.Success { - ce.User.MarkLogin() - ce.Reply("Login successful.") - return - } + ce.Reply(fmt.Sprintf("Please input ticket. (from %s)", res.VerifyUrl)) + switchInput(ce, "ticket", nil) + return case client.NeedCaptcha: ce.User.sendQR(ce, res.CaptchaImage, "") ce.Reply("Please input captcha.") @@ -163,35 +153,6 @@ func fnLoginPassword(ce *WrappedCommandEvent) { } } -func getTicket(ce *WrappedCommandEvent, u string) (str string) { - id := RandomString(8) - replyInfo := fmt.Sprintf("Go to %s for verification.", strings.ReplaceAll(u, "https://ssl.captcha.qq.com/template/wireless_mqq_captcha.html?", fmt.Sprintf("https://captcha.go-cqhttp.org/captcha?id=%v&", id))) - ce.Reply(replyInfo) - ticker := time.NewTicker(time.Second) - defer ticker.Stop() - for count := 120; count > 0; count-- { - <-ticker.C - str = fetchCaptcha(id) - if str != "" { - return - } - } - return "" -} - -func fetchCaptcha(id string) string { - data, err := GetBytes("https://captcha.go-cqhttp.org/captcha/ticket?id=" + id) - if err != nil { - // Failed to fetch ticker - return "" - } - g := gjson.ParseBytes(data) - if g.Get("ticket").Exists() { - return g.Get("ticket").String() - } - return "" -} - func switchInput(ce *WrappedCommandEvent, action string, meta interface{}) { ce.User.SetCommandState(&commands.CommandState{ Action: action, @@ -212,6 +173,8 @@ func getInput(ce *WrappedCommandEvent) { var err error switch state.Action { + case "ticket": + res, err = ce.User.Client.SubmitTicket(ce.Args[0]) case "captcha": res, err = ce.User.Client.SubmitCaptcha(ce.Args[0], state.Meta.([]byte)) case "verify": diff --git a/main.go b/main.go index 12a067d..0c839af 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ func main() { Name: "matrix-qq", URL: "https://github.com/duo/matrix-qq", Description: "A Matrix-QQ puppeting bridge.", - Version: "0.1.9", + Version: "0.1.10", ProtocolName: "QQ", CryptoPickleKey: "github.com/duo/matrix-qq",