From 24be2cda0b3a2d817f67897e2656938423711a3d Mon Sep 17 00:00:00 2001 From: Bruce Marriner Date: Fri, 11 Mar 2016 15:58:38 -0600 Subject: [PATCH] Added ApplicationBotCreate function --- endpoints.go | 7 ++++--- oauth2.go | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/endpoints.go b/endpoints.go index 40d4be2..00d71bc 100644 --- a/endpoints.go +++ b/endpoints.go @@ -86,7 +86,8 @@ var ( EMOJI = func(eID string) string { return API + "emojis/" + eID + ".png" } - OAUTH2 = API + "oauth2/" - APPLICATIONS = OAUTH2 + "applications" - APPLICATION = func(aID string) string { return APPLICATIONS + "/" + aID } + OAUTH2 = API + "oauth2/" + APPLICATIONS = OAUTH2 + "applications" + APPLICATION = func(aID string) string { return APPLICATIONS + "/" + aID } + APPLICATIONS_BOT = func(aID string) string { return APPLICATIONS + "/" + aID + "/bot" } ) diff --git a/oauth2.go b/oauth2.go index 9cb094a..526767a 100644 --- a/oauth2.go +++ b/oauth2.go @@ -5,7 +5,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// This file contains functions related to Discord OAuth2 applications +// This file contains functions related to Discord OAuth2 endpoints package discordgo @@ -13,6 +13,10 @@ import ( "fmt" ) +// ------------------------------------------------------------------------------------------------ +// Code specific to Discord OAuth2 Applications +// ------------------------------------------------------------------------------------------------ + // An Application struct stores values for a Discord OAuth2 Application type Application struct { ID string `json:"id,omitempty"` @@ -132,3 +136,30 @@ func (a *Application) Delete() (err error) { func (a *Application) DeleteB(s *Session) (err error) { return s.ApplicationDelete(a.ID) } + +// ------------------------------------------------------------------------------------------------ +// Code specific to Discord OAuth2 Application Bots +// ------------------------------------------------------------------------------------------------ + +// ApplicationBotCreate creates an Application Bot Account +// +// appID : The ID of an Application +// token : The authentication Token for a user account to convert into +// a bot account. This is optional, if omited a new account +// is created using the name of the application. +// +// NOTE: func name may change, if I can think up something better. +func (s *Session) ApplicationBotCreate(appID, token string) (st *User, err error) { + + data := struct { + Token string `json:"token,omitempty"` + }{token} + + body, err := s.Request("POST", APPLICATIONS_BOT(appID), data) + if err != nil { + return + } + + err = unmarshal(body, &st) + return +}