Merge pull request #1087 from FedorLap2006/master

Dropping user account endpoints and functionality
This commit is contained in:
Fedor Lapshin 2022-02-15 23:43:56 +03:00 committed by GitHub
commit 6fe303cd29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 521 deletions

View file

@ -14,8 +14,6 @@
package discordgo package discordgo
import ( import (
"errors"
"fmt"
"net/http" "net/http"
"runtime" "runtime"
"time" "time"
@ -24,32 +22,12 @@ import (
// VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/) // VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/)
const VERSION = "0.23.0" const VERSION = "0.23.0"
// ErrMFA will be risen by New when the user has 2FA. // New creates a new Discord session with provided token.
var ErrMFA = errors.New("account has 2FA enabled") // If the token is for a bot, it must be prefixed with "Bot "
// e.g. "Bot ..."
// New creates a new Discord session and will automate some startup // Or if it is an OAuth2 token, it must be prefixed with "Bearer "
// tasks if given enough information to do so. Currently you can pass zero // e.g. "Bearer ..."
// arguments and it will return an empty Discord session. func New(token string) (s *Session, err error) {
// 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) {
// Create an empty Session interface. // Create an empty Session interface.
s = &Session{ s = &Session{
@ -74,88 +52,9 @@ func New(args ...interface{}) (s *Session, err error) {
s.Identify.GuildSubscriptions = true s.Identify.GuildSubscriptions = true
s.Identify.Properties.OS = runtime.GOOS s.Identify.Properties.OS = runtime.GOOS
s.Identify.Properties.Browser = "DiscordGo v" + VERSION s.Identify.Properties.Browser = "DiscordGo v" + VERSION
s.Identify.Intents = MakeIntent(IntentsAllWithoutPrivileged) s.Identify.Intents = IntentsAllWithoutPrivileged
s.Identify.Token = token
// If no arguments are passed return the empty Session interface. s.Token = token
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
}
}
return return
} }

View file

@ -40,30 +40,6 @@ func init() {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////// START OF TESTS /////////////////////////////////////////////////////////////// START OF TESTS
// TestNew tests the New() function without any arguments. This should return
// a valid Session{} struct and no errors.
func TestNew(t *testing.T) {
_, err := New()
if err != nil {
t.Errorf("New() returned error: %+v", err)
}
}
// TestInvalidToken tests the New() function with an invalid token
func TestInvalidToken(t *testing.T) {
d, err := New("asjkldhflkjasdh")
if err != nil {
t.Fatalf("New(InvalidToken) returned error: %+v", err)
}
// New with just a token does not do any communication, so attempt an api call.
_, err = d.UserSettings()
if err == nil {
t.Errorf("New(InvalidToken), d.UserSettings returned nil error.")
}
}
// TestNewToken tests the New() function with a Token. // TestNewToken tests the New() function with a Token.
func TestNewToken(t *testing.T) { func TestNewToken(t *testing.T) {

View file

@ -41,26 +41,10 @@ var (
EndpointCDNChannelIcons = EndpointCDN + "channel-icons/" EndpointCDNChannelIcons = EndpointCDN + "channel-icons/"
EndpointCDNBanners = EndpointCDN + "banners/" EndpointCDNBanners = EndpointCDN + "banners/"
EndpointAuth = EndpointAPI + "auth/"
EndpointLogin = EndpointAuth + "login"
EndpointLogout = EndpointAuth + "logout"
EndpointVerify = EndpointAuth + "verify"
EndpointVerifyResend = EndpointAuth + "verify/resend"
EndpointForgotPassword = EndpointAuth + "forgot"
EndpointResetPassword = EndpointAuth + "reset"
EndpointRegister = EndpointAuth + "register"
EndpointVoice = EndpointAPI + "/voice/" EndpointVoice = EndpointAPI + "/voice/"
EndpointVoiceRegions = EndpointVoice + "regions" EndpointVoiceRegions = EndpointVoice + "regions"
EndpointVoiceIce = EndpointVoice + "ice"
EndpointTutorial = EndpointAPI + "tutorial/" // TODO: EndpointUserGuildMember
EndpointTutorialIndicators = EndpointTutorial + "indicators"
EndpointTrack = EndpointAPI + "track"
EndpointSso = EndpointAPI + "sso"
EndpointReport = EndpointAPI + "report"
EndpointIntegrations = EndpointAPI + "integrations"
EndpointUser = func(uID string) string { return EndpointUsers + uID } EndpointUser = func(uID string) string { return EndpointUsers + uID }
EndpointUserAvatar = func(uID, aID string) string { return EndpointCDNAvatars + uID + "/" + aID + ".png" } EndpointUserAvatar = func(uID, aID string) string { return EndpointCDNAvatars + uID + "/" + aID + ".png" }
@ -69,51 +53,45 @@ var (
uDiscriminatorInt, _ := strconv.Atoi(uDiscriminator) uDiscriminatorInt, _ := strconv.Atoi(uDiscriminator)
return EndpointCDN + "embed/avatars/" + strconv.Itoa(uDiscriminatorInt%5) + ".png" return EndpointCDN + "embed/avatars/" + strconv.Itoa(uDiscriminatorInt%5) + ".png"
} }
EndpointUserSettings = func(uID string) string { return EndpointUsers + uID + "/settings" } EndpointUserGuilds = func(uID string) string { return EndpointUsers + uID + "/guilds" }
EndpointUserGuilds = func(uID string) string { return EndpointUsers + uID + "/guilds" } EndpointUserGuild = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID }
EndpointUserGuild = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID } EndpointUserChannels = func(uID string) string { return EndpointUsers + uID + "/channels" }
EndpointUserGuildSettings = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID + "/settings" } EndpointUserConnections = func(uID string) string { return EndpointUsers + uID + "/connections" }
EndpointUserChannels = func(uID string) string { return EndpointUsers + uID + "/channels" }
EndpointUserDevices = func(uID string) string { return EndpointUsers + uID + "/devices" }
EndpointUserConnections = func(uID string) string { return EndpointUsers + uID + "/connections" }
EndpointUserNotes = func(uID string) string { return EndpointUsers + "@me/notes/" + uID }
EndpointGuild = func(gID string) string { return EndpointGuilds + gID } EndpointGuild = func(gID string) string { return EndpointGuilds + gID }
EndpointGuildPreview = func(gID string) string { return EndpointGuilds + gID + "/preview" } EndpointGuildPreview = func(gID string) string { return EndpointGuilds + gID + "/preview" }
EndpointGuildChannels = func(gID string) string { return EndpointGuilds + gID + "/channels" } EndpointGuildChannels = func(gID string) string { return EndpointGuilds + gID + "/channels" }
EndpointGuildMembers = func(gID string) string { return EndpointGuilds + gID + "/members" } EndpointGuildMembers = func(gID string) string { return EndpointGuilds + gID + "/members" }
EndpointGuildMember = func(gID, uID string) string { return EndpointGuilds + gID + "/members/" + uID } EndpointGuildMember = func(gID, uID string) string { return EndpointGuilds + gID + "/members/" + uID }
EndpointGuildMemberRole = func(gID, uID, rID string) string { return EndpointGuilds + gID + "/members/" + uID + "/roles/" + rID } EndpointGuildMemberRole = func(gID, uID, rID string) string { return EndpointGuilds + gID + "/members/" + uID + "/roles/" + rID }
EndpointGuildBans = func(gID string) string { return EndpointGuilds + gID + "/bans" } EndpointGuildBans = func(gID string) string { return EndpointGuilds + gID + "/bans" }
EndpointGuildBan = func(gID, uID string) string { return EndpointGuilds + gID + "/bans/" + uID } EndpointGuildBan = func(gID, uID string) string { return EndpointGuilds + gID + "/bans/" + uID }
EndpointGuildIntegrations = func(gID string) string { return EndpointGuilds + gID + "/integrations" } EndpointGuildIntegrations = func(gID string) string { return EndpointGuilds + gID + "/integrations" }
EndpointGuildIntegration = func(gID, iID string) string { return EndpointGuilds + gID + "/integrations/" + iID } EndpointGuildIntegration = func(gID, iID string) string { return EndpointGuilds + gID + "/integrations/" + iID }
EndpointGuildIntegrationSync = func(gID, iID string) string { return EndpointGuilds + gID + "/integrations/" + iID + "/sync" } EndpointGuildRoles = func(gID string) string { return EndpointGuilds + gID + "/roles" }
EndpointGuildRoles = func(gID string) string { return EndpointGuilds + gID + "/roles" } EndpointGuildRole = func(gID, rID string) string { return EndpointGuilds + gID + "/roles/" + rID }
EndpointGuildRole = func(gID, rID string) string { return EndpointGuilds + gID + "/roles/" + rID } EndpointGuildInvites = func(gID string) string { return EndpointGuilds + gID + "/invites" }
EndpointGuildInvites = func(gID string) string { return EndpointGuilds + gID + "/invites" } EndpointGuildWidget = func(gID string) string { return EndpointGuilds + gID + "/widget" }
EndpointGuildWidget = func(gID string) string { return EndpointGuilds + gID + "/widget" } EndpointGuildEmbed = EndpointGuildWidget
EndpointGuildEmbed = EndpointGuildWidget EndpointGuildPrune = func(gID string) string { return EndpointGuilds + gID + "/prune" }
EndpointGuildPrune = func(gID string) string { return EndpointGuilds + gID + "/prune" } EndpointGuildIcon = func(gID, hash string) string { return EndpointCDNIcons + gID + "/" + hash + ".png" }
EndpointGuildIcon = func(gID, hash string) string { return EndpointCDNIcons + gID + "/" + hash + ".png" } EndpointGuildIconAnimated = func(gID, hash string) string { return EndpointCDNIcons + gID + "/" + hash + ".gif" }
EndpointGuildIconAnimated = func(gID, hash string) string { return EndpointCDNIcons + gID + "/" + hash + ".gif" } EndpointGuildSplash = func(gID, hash string) string { return EndpointCDNSplashes + gID + "/" + hash + ".png" }
EndpointGuildSplash = func(gID, hash string) string { return EndpointCDNSplashes + gID + "/" + hash + ".png" } EndpointGuildWebhooks = func(gID string) string { return EndpointGuilds + gID + "/webhooks" }
EndpointGuildWebhooks = func(gID string) string { return EndpointGuilds + gID + "/webhooks" } EndpointGuildAuditLogs = func(gID string) string { return EndpointGuilds + gID + "/audit-logs" }
EndpointGuildAuditLogs = func(gID string) string { return EndpointGuilds + gID + "/audit-logs" } EndpointGuildEmojis = func(gID string) string { return EndpointGuilds + gID + "/emojis" }
EndpointGuildEmojis = func(gID string) string { return EndpointGuilds + gID + "/emojis" } EndpointGuildEmoji = func(gID, eID string) string { return EndpointGuilds + gID + "/emojis/" + eID }
EndpointGuildEmoji = func(gID, eID string) string { return EndpointGuilds + gID + "/emojis/" + eID } EndpointGuildBanner = func(gID, hash string) string { return EndpointCDNBanners + gID + "/" + hash + ".png" }
EndpointGuildBanner = func(gID, hash string) string { return EndpointCDNBanners + gID + "/" + hash + ".png" } EndpointGuildStickers = func(gID string) string { return EndpointGuilds + gID + "/stickers" }
EndpointGuildStickers = func(gID string) string { return EndpointGuilds + gID + "/stickers" } EndpointGuildSticker = func(gID, sID string) string { return EndpointGuilds + gID + "/stickers/" + sID }
EndpointGuildSticker = func(gID, sID string) string { return EndpointGuilds + gID + "/stickers/" + sID }
EndpointChannel = func(cID string) string { return EndpointChannels + cID } EndpointChannel = func(cID string) string { return EndpointChannels + cID }
EndpointChannelPermissions = func(cID string) string { return EndpointChannels + cID + "/permissions" } EndpointChannelPermissions = func(cID string) string { return EndpointChannels + cID + "/permissions" }
EndpointChannelPermission = func(cID, tID string) string { return EndpointChannels + cID + "/permissions/" + tID } EndpointChannelPermission = func(cID, tID string) string { return EndpointChannelPermissions(cID) + "/" + tID }
EndpointChannelInvites = func(cID string) string { return EndpointChannels + cID + "/invites" } EndpointChannelInvites = func(cID string) string { return EndpointChannels + cID + "/invites" }
EndpointChannelTyping = func(cID string) string { return EndpointChannels + cID + "/typing" } EndpointChannelTyping = func(cID string) string { return EndpointChannels + cID + "/typing" }
EndpointChannelMessages = func(cID string) string { return EndpointChannels + cID + "/messages" } EndpointChannelMessages = func(cID string) string { return EndpointChannels + cID + "/messages" }
EndpointChannelMessage = func(cID, mID string) string { return EndpointChannels + cID + "/messages/" + mID } EndpointChannelMessage = func(cID, mID string) string { return EndpointChannels + cID + "/messages/" + mID }
EndpointChannelMessageAck = func(cID, mID string) string { return EndpointChannels + cID + "/messages/" + mID + "/ack" }
EndpointChannelMessagesBulkDelete = func(cID string) string { return EndpointChannel(cID) + "/messages/bulk-delete" } EndpointChannelMessagesBulkDelete = func(cID string) string { return EndpointChannel(cID) + "/messages/bulk-delete" }
EndpointChannelMessagesPins = func(cID string) string { return EndpointChannel(cID) + "/pins" } EndpointChannelMessagesPins = func(cID string) string { return EndpointChannel(cID) + "/pins" }
EndpointChannelMessagePin = func(cID, mID string) string { return EndpointChannel(cID) + "/pins/" + mID } EndpointChannelMessagePin = func(cID, mID string) string { return EndpointChannel(cID) + "/pins/" + mID }
@ -171,16 +149,10 @@ var (
return EndpointWebhookMessage(aID, iToken, mID) return EndpointWebhookMessage(aID, iToken, mID)
} }
EndpointRelationships = func() string { return EndpointUsers + "@me" + "/relationships" }
EndpointRelationship = func(uID string) string { return EndpointRelationships() + "/" + uID }
EndpointRelationshipsMutual = func(uID string) string { return EndpointUsers + uID + "/relationships" }
EndpointGuildCreate = EndpointAPI + "guilds" EndpointGuildCreate = EndpointAPI + "guilds"
EndpointInvite = func(iID string) string { return EndpointAPI + "invites/" + iID } EndpointInvite = func(iID string) string { return EndpointAPI + "invites/" + iID }
EndpointIntegrationsJoin = func(iID string) string { return EndpointAPI + "integrations/" + iID + "/join" }
EndpointEmoji = func(eID string) string { return EndpointCDN + "emojis/" + eID + ".png" } EndpointEmoji = func(eID string) string { return EndpointCDN + "emojis/" + eID + ".png" }
EndpointEmojiAnimated = func(eID string) string { return EndpointCDN + "emojis/" + eID + ".gif" } EndpointEmojiAnimated = func(eID string) string { return EndpointCDN + "emojis/" + eID + ".gif" }

View file

@ -182,91 +182,6 @@ func unmarshal(data []byte, v interface{}) error {
return nil return nil
} }
// ------------------------------------------------------------------------------------------------
// Functions specific to Discord Sessions
// ------------------------------------------------------------------------------------------------
// Login asks the Discord server for an authentication token.
//
// 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 (s *Session) Login(email, password string) (err error) {
data := struct {
Email string `json:"email"`
Password string `json:"password"`
}{email, password}
response, err := s.RequestWithBucketID("POST", EndpointLogin, data, EndpointLogin)
if err != nil {
return
}
temp := struct {
Token string `json:"token"`
MFA bool `json:"mfa"`
}{}
err = unmarshal(response, &temp)
if err != nil {
return
}
s.Token = temp.Token
s.MFA = temp.MFA
return
}
// Register sends a Register request to Discord, and returns the authentication token
// Note that this account is temporary and should be verified for future use.
// Another option is to save the authentication token external, but this isn't recommended.
func (s *Session) Register(username string) (token string, err error) {
data := struct {
Username string `json:"username"`
}{username}
response, err := s.RequestWithBucketID("POST", EndpointRegister, data, EndpointRegister)
if err != nil {
return
}
temp := struct {
Token string `json:"token"`
}{}
err = unmarshal(response, &temp)
if err != nil {
return
}
token = temp.Token
return
}
// Logout sends a logout request to Discord.
// This does not seem to actually invalidate the token. So you can still
// make API calls even after a Logout. So, it seems almost pointless to
// even use.
func (s *Session) Logout() (err error) {
// _, err = s.Request("POST", LOGOUT, `{"token": "` + s.Token + `"}`)
if s.Token == "" {
return
}
data := struct {
Token string `json:"token"`
}{s.Token}
_, err = s.RequestWithBucketID("POST", EndpointLogout, data, EndpointLogout)
return
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Functions specific to Discord Users // Functions specific to Discord Users
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -307,8 +222,8 @@ func (s *Session) UserAvatarDecode(u *User) (img image.Image, err error) {
return return
} }
// UserUpdate updates a users settings. // UserUpdate updates current user settings.
func (s *Session) UserUpdate(email, password, username, avatar, newPassword string) (st *User, err error) { func (s *Session) UserUpdate(username, avatar string) (st *User, err error) {
// NOTE: Avatar must be either the hash/id of existing Avatar or // NOTE: Avatar must be either the hash/id of existing Avatar or
// data:image/png;base64,BASE64_STRING_OF_NEW_AVATAR_PNG // data:image/png;base64,BASE64_STRING_OF_NEW_AVATAR_PNG
@ -316,12 +231,9 @@ func (s *Session) UserUpdate(email, password, username, avatar, newPassword stri
// If left blank, avatar will be set to null/blank // If left blank, avatar will be set to null/blank
data := struct { data := struct {
Email string `json:"email,omitempty"` Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"` Avatar string `json:"avatar,omitempty"`
Username string `json:"username,omitempty"` }{username, avatar}
Avatar string `json:"avatar,omitempty"`
NewPassword string `json:"new_password,omitempty"`
}{email, password, username, avatar, newPassword}
body, err := s.RequestWithBucketID("PATCH", EndpointUser("@me"), data, EndpointUsers) body, err := s.RequestWithBucketID("PATCH", EndpointUser("@me"), data, EndpointUsers)
if err != nil { if err != nil {
@ -332,39 +244,6 @@ func (s *Session) UserUpdate(email, password, username, avatar, newPassword stri
return return
} }
// UserSettings returns the settings for a given user
func (s *Session) UserSettings() (st *Settings, err error) {
body, err := s.RequestWithBucketID("GET", EndpointUserSettings("@me"), nil, EndpointUserSettings(""))
if err != nil {
return
}
err = unmarshal(body, &st)
return
}
// UserUpdateStatus update the user status
// status : The new status (Actual valid status are 'online','idle','dnd','invisible')
func (s *Session) UserUpdateStatus(status Status) (st *Settings, err error) {
if status == StatusOffline {
err = ErrStatusOffline
return
}
data := struct {
Status Status `json:"status"`
}{status}
body, err := s.RequestWithBucketID("PATCH", EndpointUserSettings("@me"), data, EndpointUserSettings(""))
if err != nil {
return
}
err = unmarshal(body, &st)
return
}
// UserConnections returns the user's connections // UserConnections returns the user's connections
func (s *Session) UserConnections() (conn []*UserConnection, err error) { func (s *Session) UserConnections() (conn []*UserConnection, err error) {
response, err := s.RequestWithBucketID("GET", EndpointUserConnections("@me"), nil, EndpointUserConnections("@me")) response, err := s.RequestWithBucketID("GET", EndpointUserConnections("@me"), nil, EndpointUserConnections("@me"))
@ -380,19 +259,6 @@ func (s *Session) UserConnections() (conn []*UserConnection, err error) {
return return
} }
// UserChannels returns an array of Channel structures for all private
// channels.
func (s *Session) UserChannels() (st []*Channel, err error) {
body, err := s.RequestWithBucketID("GET", EndpointUserChannels("@me"), nil, EndpointUserChannels(""))
if err != nil {
return
}
err = unmarshal(body, &st)
return
}
// UserChannelCreate creates a new User (Private) Channel with another User // UserChannelCreate creates a new User (Private) Channel with another User
// recipientID : A user ID for the user to which this channel is opened with. // recipientID : A user ID for the user to which this channel is opened with.
func (s *Session) UserChannelCreate(recipientID string) (st *Channel, err error) { func (s *Session) UserChannelCreate(recipientID string) (st *Channel, err error) {
@ -443,20 +309,6 @@ func (s *Session) UserGuilds(limit int, beforeID, afterID string) (st []*UserGui
return return
} }
// UserGuildSettingsEdit Edits the users notification settings for a guild
// guildID : The ID of the guild to edit the settings on
// settings : The settings to update
func (s *Session) UserGuildSettingsEdit(guildID string, settings *UserGuildSettingsEdit) (st *UserGuildSettings, err error) {
body, err := s.RequestWithBucketID("PATCH", EndpointUserGuildSettings("@me", guildID), settings, EndpointUserGuildSettings("", guildID))
if err != nil {
return
}
err = unmarshal(body, &st)
return
}
// UserChannelPermissions returns the permission of a user in a channel. // UserChannelPermissions returns the permission of a user in a channel.
// userID : The ID of the user to calculate permissions for. // userID : The ID of the user to calculate permissions for.
// channelID : The ID of the channel to calculate permission for. // channelID : The ID of the channel to calculate permission for.
@ -1248,15 +1100,6 @@ func (s *Session) GuildIntegrationDelete(guildID, integrationID string) (err err
return return
} }
// GuildIntegrationSync syncs an integration.
// guildID : The ID of a Guild.
// integrationID : The ID of an integration.
func (s *Session) GuildIntegrationSync(guildID, integrationID string) (err error) {
_, err = s.RequestWithBucketID("POST", EndpointGuildIntegrationSync(guildID, integrationID), nil, EndpointGuildIntegration(guildID, ""))
return
}
// GuildIcon returns an image.Image of a guild icon. // GuildIcon returns an image.Image of a guild icon.
// guildID : The ID of a Guild. // guildID : The ID of a Guild.
func (s *Session) GuildIcon(guildID string) (img image.Image, err error) { func (s *Session) GuildIcon(guildID string) (img image.Image, err error) {
@ -1536,21 +1379,6 @@ func (s *Session) ChannelMessage(channelID, messageID string) (st *Message, err
return return
} }
// ChannelMessageAck acknowledges and marks the given message as read
// channeld : The ID of a Channel
// messageID : the ID of a Message
// lastToken : token returned by last ack
func (s *Session) ChannelMessageAck(channelID, messageID, lastToken string) (st *Ack, err error) {
body, err := s.RequestWithBucketID("POST", EndpointChannelMessageAck(channelID, messageID), &Ack{Token: lastToken}, EndpointChannelMessageAck(channelID, ""))
if err != nil {
return
}
err = unmarshal(body, &st)
return
}
// ChannelMessageSend sends a message to the given channel. // ChannelMessageSend sends a message to the given channel.
// channelID : The ID of a Channel. // channelID : The ID of a Channel.
// content : The message to send. // content : The message to send.
@ -1958,18 +1786,6 @@ func (s *Session) VoiceRegions() (st []*VoiceRegion, err error) {
return return
} }
// VoiceICE returns the voice server ICE information
func (s *Session) VoiceICE() (st *VoiceICE, err error) {
body, err := s.RequestWithBucketID("GET", EndpointVoiceIce, nil, EndpointVoiceIce)
if err != nil {
return
}
err = unmarshal(body, &st)
return
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Functions specific to Discord Websockets // Functions specific to Discord Websockets
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -2348,86 +2164,6 @@ func (s *Session) MessageReactions(channelID, messageID, emojiID string, limit i
return return
} }
// ------------------------------------------------------------------------------------------------
// Functions specific to user notes
// ------------------------------------------------------------------------------------------------
// UserNoteSet sets the note for a specific user.
func (s *Session) UserNoteSet(userID string, message string) (err error) {
data := struct {
Note string `json:"note"`
}{message}
_, err = s.RequestWithBucketID("PUT", EndpointUserNotes(userID), data, EndpointUserNotes(""))
return
}
// ------------------------------------------------------------------------------------------------
// Functions specific to Discord Relationships (Friends list)
// ------------------------------------------------------------------------------------------------
// RelationshipsGet returns an array of all the relationships of the user.
func (s *Session) RelationshipsGet() (r []*Relationship, err error) {
body, err := s.RequestWithBucketID("GET", EndpointRelationships(), nil, EndpointRelationships())
if err != nil {
return
}
err = unmarshal(body, &r)
return
}
// relationshipCreate creates a new relationship. (I.e. send or accept a friend request, block a user.)
// relationshipType : 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
func (s *Session) relationshipCreate(userID string, relationshipType int) (err error) {
data := struct {
Type int `json:"type"`
}{relationshipType}
_, err = s.RequestWithBucketID("PUT", EndpointRelationship(userID), data, EndpointRelationships())
return
}
// RelationshipFriendRequestSend sends a friend request to a user.
// userID: ID of the user.
func (s *Session) RelationshipFriendRequestSend(userID string) (err error) {
err = s.relationshipCreate(userID, 4)
return
}
// RelationshipFriendRequestAccept accepts a friend request from a user.
// userID: ID of the user.
func (s *Session) RelationshipFriendRequestAccept(userID string) (err error) {
err = s.relationshipCreate(userID, 1)
return
}
// RelationshipUserBlock blocks a user.
// userID: ID of the user.
func (s *Session) RelationshipUserBlock(userID string) (err error) {
err = s.relationshipCreate(userID, 2)
return
}
// RelationshipDelete removes the relationship with a user.
// userID: ID of the user.
func (s *Session) RelationshipDelete(userID string) (err error) {
_, err = s.RequestWithBucketID("DELETE", EndpointRelationship(userID), nil, EndpointRelationships())
return
}
// RelationshipsMutualGet returns an array of all the users both @me and the given user is friends with.
// userID: ID of the user.
func (s *Session) RelationshipsMutualGet(userID string) (mf []*User, err error) {
body, err := s.RequestWithBucketID("GET", EndpointRelationshipsMutual(userID), nil, EndpointRelationshipsMutual(userID))
if err != nil {
return
}
err = unmarshal(body, &mf)
return
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Functions specific to application (slash) commands // Functions specific to application (slash) commands
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View file

@ -99,17 +99,6 @@ func TestUserChannelCreate(t *testing.T) {
// TODO make sure the channel was added // TODO make sure the channel was added
} }
func TestUserChannels(t *testing.T) {
if dg == nil {
t.Skip("Cannot TestUserChannels, dg not set.")
}
_, err := dg.UserChannels()
if err != nil {
t.Errorf(err.Error())
}
}
func TestUserGuilds(t *testing.T) { func TestUserGuilds(t *testing.T) {
if dg == nil { if dg == nil {
t.Skip("Cannot TestUserGuilds, dg not set.") t.Skip("Cannot TestUserGuilds, dg not set.")
@ -121,41 +110,6 @@ func TestUserGuilds(t *testing.T) {
} }
} }
func TestUserSettings(t *testing.T) {
if dg == nil {
t.Skip("Cannot TestUserSettings, dg not set.")
}
_, err := dg.UserSettings()
if err != nil {
t.Errorf(err.Error())
}
}
func TestUserUpdateStatus(t *testing.T) {
if dg == nil {
t.Skip("Cannot TestUserSettings, dg not set.")
}
_, err := dg.UserUpdateStatus(StatusDoNotDisturb)
if err != nil {
t.Errorf(err.Error())
}
}
// TestLogout tests the Logout() function. This should not return an error.
func TestLogout(t *testing.T) {
if dg == nil {
t.Skip("Cannot TestLogout, dg not set.")
}
err := dg.Logout()
if err != nil {
t.Errorf("Logout() returned error: %+v", err)
}
}
func TestGateway(t *testing.T) { func TestGateway(t *testing.T) {
if dg == nil { if dg == nil {
@ -178,18 +132,6 @@ func TestGatewayBot(t *testing.T) {
} }
} }
func TestVoiceICE(t *testing.T) {
if dg == nil {
t.Skip("Skipping, dg not set.")
}
_, err := dg.VoiceICE()
if err != nil {
t.Errorf("VoiceICE() returned error: %+v", err)
}
}
func TestVoiceRegions(t *testing.T) { func TestVoiceRegions(t *testing.T) {
if dg == nil { if dg == nil {