Arise error when user has 2FA (#359)

* Arise error when user has 2FA

* Fixed error message

* Removed ticket
This commit is contained in:
LEGOlord208 2017-04-19 06:35:17 +02:00 committed by Chris Rhodes
parent 17b21b989c
commit 65f0cb9f73
3 changed files with 12 additions and 1 deletions

View file

@ -14,6 +14,7 @@
package discordgo package discordgo
import ( import (
"errors"
"fmt" "fmt"
"net/http" "net/http"
"time" "time"
@ -22,6 +23,9 @@ import (
// VERSION of Discordgo, follows Symantic Versioning. (http://semver.org/) // VERSION of Discordgo, follows Symantic Versioning. (http://semver.org/)
const VERSION = "0.16.0-dev" 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 // New creates a new Discord session and will automate some startup
// tasks if given enough information to do so. Currently you can pass zero // tasks if given enough information to do so. Currently you can pass zero
// arguments and it will return an empty Discord session. // arguments and it will return an empty Discord session.
@ -119,7 +123,11 @@ func New(args ...interface{}) (s *Session, err error) {
} else { } else {
err = s.Login(auth, pass) err = s.Login(auth, pass)
if err != nil || s.Token == "" { 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 return
} }
} }

View file

@ -187,6 +187,7 @@ func (s *Session) Login(email, password string) (err error) {
temp := struct { temp := struct {
Token string `json:"token"` Token string `json:"token"`
MFA bool `json:"mfa"`
}{} }{}
err = unmarshal(response, &temp) err = unmarshal(response, &temp)
@ -195,6 +196,7 @@ func (s *Session) Login(email, password string) (err error) {
} }
s.Token = temp.Token s.Token = temp.Token
s.MFA = temp.MFA
return return
} }

View file

@ -29,6 +29,7 @@ type Session struct {
// Authentication token for this session // Authentication token for this session
Token string Token string
MFA bool
// Debug for printing JSON request/responses // Debug for printing JSON request/responses
Debug bool // Deprecated, will be removed. Debug bool // Deprecated, will be removed.