Skip to content

Commit

Permalink
Switch the sliding captcha's ticket from automatic to manual input
Browse files Browse the repository at this point in the history
  • Loading branch information
duo committed Jan 24, 2024
1 parent e66181b commit 94ede52
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 46 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
47 changes: 5 additions & 42 deletions internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.")
Expand All @@ -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,
Expand All @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 94ede52

Please sign in to comment.