Procházet zdrojové kódy

feat: drop email-password session authentication.

This commit drops old email/password authentication for New function.
It violates Discord ToS and due to recent changes in rules for community resources on Discord API Docs it needs to be dropped.
Fedor Lapshin před 3 roky
rodič
revize
6ff665e56e
1 změnil soubory, kde provedl 8 přidání a 107 odebrání
  1. 8 107
      discord.go

+ 8 - 107
discord.go

@@ -24,32 +24,12 @@ import (
 // VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/)
 const VERSION = "0.23.0"
 
-// 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.
-// There are 3 ways to call New:
-//     With a single auth token - All requests will use the token blindly
-//         (just tossing it into the HTTP Authorization header);
-//         no verification of the token will be done and requests may fail.
-//         IF THE TOKEN IS FOR A BOT, IT MUST BE PREFIXED WITH `BOT `
-//         eg: `"Bot <token>"`
-//         IF IT IS AN OAUTH2 ACCESS TOKEN, IT MUST BE PREFIXED WITH `Bearer `
-//         eg: `"Bearer <token>"`
-//     With an email and password - Discord will sign in with the provided
-//         credentials.
-//     With an email, password and auth token - Discord will verify the auth
-//         token, if it is invalid it will sign in with the provided
-//         credentials. This is the Discord recommended way to sign in.
-//
-// NOTE: While email/pass authentication is supported by DiscordGo it is
-// HIGHLY DISCOURAGED by Discord. Please only use email/pass to obtain a token
-// and then use that authentication token for all future connections.
-// Also, doing any form of automation with a user (non Bot) account may result
-// in that account being permanently banned from Discord.
-func New(args ...interface{}) (s *Session, err error) {
+// New creates a new Discord session with provided token.
+// If the token is for a bot, it must be prefixed with "Bot ".
+// 		e.g. "Bot ..."
+// Or if it is an OAuth2 token, it must be prefixed with "Bearer "
+//		e.g. "Bearer ..."
+func New(token string) (s *Session, err error) {
 
 	// Create an empty Session interface.
 	s = &Session{
@@ -75,87 +55,8 @@ func New(args ...interface{}) (s *Session, err error) {
 	s.Identify.Properties.OS = runtime.GOOS
 	s.Identify.Properties.Browser = "DiscordGo v" + VERSION
 	s.Identify.Intents = MakeIntent(IntentsAllWithoutPrivileged)
-
-	// If no arguments are passed return the empty Session interface.
-	if args == nil {
-		return
-	}
-
-	// Variables used below when parsing func arguments
-	var auth, pass string
-
-	// Parse passed arguments
-	for _, arg := range args {
-
-		switch v := arg.(type) {
-
-		case []string:
-			if len(v) > 3 {
-				err = fmt.Errorf("too many string parameters provided")
-				return
-			}
-
-			// First string is either token or username
-			if len(v) > 0 {
-				auth = v[0]
-			}
-
-			// If second string exists, it must be a password.
-			if len(v) > 1 {
-				pass = v[1]
-			}
-
-			// If third string exists, it must be an auth token.
-			if len(v) > 2 {
-				s.Identify.Token = v[2]
-				s.Token = v[2] // TODO: Remove, Deprecated - Kept for backwards compatibility.
-			}
-
-		case string:
-			// First string must be either auth token or username.
-			// Second string must be a password.
-			// Only 2 input strings are supported.
-
-			if auth == "" {
-				auth = v
-			} else if pass == "" {
-				pass = v
-			} else if s.Token == "" {
-				s.Identify.Token = v
-				s.Token = v // TODO: Remove, Deprecated - Kept for backwards compatibility.
-			} else {
-				err = fmt.Errorf("too many string parameters provided")
-				return
-			}
-
-			//		case Config:
-			// TODO: Parse configuration struct
-
-		default:
-			err = fmt.Errorf("unsupported parameter type provided")
-			return
-		}
-	}
-
-	// If only one string was provided, assume it is an auth token.
-	// Otherwise get auth token from Discord, if a token was specified
-	// Discord will verify it for free, or log the user in if it is
-	// invalid.
-	if pass == "" {
-		s.Identify.Token = auth
-		s.Token = auth // TODO: Remove, Deprecated - Kept for backwards compatibility.
-	} else {
-		err = s.Login(auth, pass)
-		// TODO: Remove last s.Token part, Deprecated - Kept for backwards compatibility.
-		if err != nil || s.Identify.Token == "" || s.Token == "" {
-			if s.MFA {
-				err = ErrMFA
-			} else {
-				err = fmt.Errorf("Unable to fetch discord authentication token. %v", err)
-			}
-			return
-		}
-	}
+	s.Identify.Token = token
+	s.Token = token
 
 	return
 }