From 4b53d72db18a6b06138ade710f8ea68355d6c7bb Mon Sep 17 00:00:00 2001 From: "diamondburned (Forefront)" Date: Mon, 17 Feb 2020 09:28:52 -0800 Subject: [PATCH] Discord: Removed invalid avatar discriminator URL --- api/message.go | 36 ------------------------------------ api/message_send.go | 34 ++++++++++++++++++++++++++++++++++ discord/user.go | 2 +- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/api/message.go b/api/message.go index 4c763e6..197e7b5 100644 --- a/api/message.go +++ b/api/message.go @@ -1,11 +1,8 @@ package api import ( - "mime/multipart" - "github.com/diamondburned/arikawa/discord" "github.com/diamondburned/arikawa/internal/httputil" - "github.com/pkg/errors" ) // Messages gets all mesesages, automatically paginating. Use with care, as @@ -116,39 +113,6 @@ func (c *Client) SendMessage( }) } -func (c *Client) SendMessageComplex( - channelID discord.Snowflake, - data SendMessageData) (*discord.Message, error) { - - if data.Embed != nil { - if err := data.Embed.Validate(); err != nil { - return nil, errors.Wrap(err, "Embed error") - } - } - - var URL = EndpointChannels + channelID.String() + "/messages" - var msg *discord.Message - - if len(data.Files) == 0 { - // No files, so no need for streaming. - return msg, c.RequestJSON(&msg, "POST", URL, - httputil.WithJSONBody(c, data)) - } - - writer := func(mw *multipart.Writer) error { - return data.WriteMultipart(c, mw) - } - - resp, err := c.MeanwhileMultipart(writer, "POST", URL) - if err != nil { - return nil, err - } - - defer resp.Body.Close() - - return msg, c.DecodeStream(resp.Body, &msg) -} - func (c *Client) EditMessage( channelID, messageID discord.Snowflake, content string, embed *discord.Embed, suppressEmbeds bool) (*discord.Message, error) { diff --git a/api/message_send.go b/api/message_send.go index b2c5715..613a4ba 100644 --- a/api/message_send.go +++ b/api/message_send.go @@ -7,10 +7,44 @@ import ( "strings" "github.com/diamondburned/arikawa/discord" + "github.com/diamondburned/arikawa/internal/httputil" "github.com/diamondburned/arikawa/internal/json" "github.com/pkg/errors" ) +func (c *Client) SendMessageComplex( + channelID discord.Snowflake, + data SendMessageData) (*discord.Message, error) { + + if data.Embed != nil { + if err := data.Embed.Validate(); err != nil { + return nil, errors.Wrap(err, "Embed error") + } + } + + var URL = EndpointChannels + channelID.String() + "/messages" + var msg *discord.Message + + if len(data.Files) == 0 { + // No files, so no need for streaming. + return msg, c.RequestJSON(&msg, "POST", URL, + httputil.WithJSONBody(c, data)) + } + + writer := func(mw *multipart.Writer) error { + return data.WriteMultipart(c, mw) + } + + resp, err := c.MeanwhileMultipart(writer, "POST", URL) + if err != nil { + return nil, err + } + + defer resp.Body.Close() + + return msg, c.DecodeStream(resp.Body, &msg) +} + const AttachmentSpoilerPrefix = "SPOILER_" var quoteEscaper = strings.NewReplacer(`\`, `\\`, `"`, `\"`) diff --git a/discord/user.go b/discord/user.go index ac9a747..45b754f 100644 --- a/discord/user.go +++ b/discord/user.go @@ -31,7 +31,7 @@ func (u User) AvatarURL() string { base := "https://cdn.discordapp.com" if u.Avatar == "" { - return base + "/embed/avatars/" + u.Discriminator + ".png" + return "" } base += "/avatars/" + u.ID.String() + "/" + u.Avatar