Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import (
"github.com/highesttt/matrix-line-messenger/pkg/line"
)

const (
loginTooManyAttemptsReason = "Too many login attempts"
loginTooManyAttemptsInstructions = "Too many login attempts. LINE has locked login for this account temporarily."
)

type LineConnector struct {
br *bridgev2.Bridge
}
Expand Down Expand Up @@ -230,6 +235,9 @@ func loginErrorInstructions(message string) string {
if message == "" {
return "Could not log in to LINE. Please check your email and password and try again."
}
if strings.EqualFold(message, loginTooManyAttemptsReason) || isBlockedUserLoginError(message) {
return loginTooManyAttemptsInstructions
}
if strings.EqualFold(message, "Account ID or password is invalid") {
return "LINE rejected the email or password. Make sure you used the email from LINE Settings -> Account -> Email Address, then try again."
}
Expand All @@ -248,13 +256,25 @@ func loginErrorReason(err error) string {
}
var payload struct {
Data struct {
Reason string `json:"reason"`
Message string `json:"message"`
Reason string `json:"reason"`
} `json:"data"`
}
if err := json.Unmarshal([]byte(msg[start:end+1]), &payload); err != nil {
return ""
}
return payload.Data.Reason
reason := payload.Data.Reason
if reason == "" {
reason = payload.Data.Message
}
if isBlockedUserLoginError(reason) {
return loginTooManyAttemptsReason
}
return reason
}

func isBlockedUserLoginError(message string) bool {
return strings.EqualFold(strings.TrimSpace(message), "blocked user")
}

func (ll *LineEmailLogin) Wait(ctx context.Context) (*bridgev2.LoginStep, error) {
Expand Down
Loading