From 65f0cb9f73480ae639d40f25737e8803e3549165 Mon Sep 17 00:00:00 2001 From: LEGOlord208 Date: Wed, 19 Apr 2017 06:35:17 +0200 Subject: [PATCH] Arise error when user has 2FA (#359) * Arise error when user has 2FA * Fixed error message * Removed ticket --- discord.go | 10 +++++++++- restapi.go | 2 ++ structs.go | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/discord.go b/discord.go index 7b4b5aa..0d34535 100644 --- a/discord.go +++ b/discord.go @@ -14,6 +14,7 @@ package discordgo import ( + "errors" "fmt" "net/http" "time" @@ -22,6 +23,9 @@ import ( // VERSION of Discordgo, follows Symantic Versioning. (http://semver.org/) const VERSION = "0.16.0-dev" +// ErrMFA will be risen by New when the user has 2FA. +var ErrMFA = errors.New("account has 2FA enabled") + // New creates a new Discord session and will automate some startup // tasks if given enough information to do so. Currently you can pass zero // arguments and it will return an empty Discord session. @@ -119,7 +123,11 @@ func New(args ...interface{}) (s *Session, err error) { } else { err = s.Login(auth, pass) if err != nil || s.Token == "" { - err = fmt.Errorf("Unable to fetch discord authentication token. %v", err) + if s.MFA { + err = ErrMFA + } else { + err = fmt.Errorf("Unable to fetch discord authentication token. %v", err) + } return } } diff --git a/restapi.go b/restapi.go index 8d9c20a..95e3f21 100644 --- a/restapi.go +++ b/restapi.go @@ -187,6 +187,7 @@ func (s *Session) Login(email, password string) (err error) { temp := struct { Token string `json:"token"` + MFA bool `json:"mfa"` }{} err = unmarshal(response, &temp) @@ -195,6 +196,7 @@ func (s *Session) Login(email, password string) (err error) { } s.Token = temp.Token + s.MFA = temp.MFA return } diff --git a/structs.go b/structs.go index b0aadf8..3a6ec05 100644 --- a/structs.go +++ b/structs.go @@ -29,6 +29,7 @@ type Session struct { // Authentication token for this session Token string + MFA bool // Debug for printing JSON request/responses Debug bool // Deprecated, will be removed.