1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-30 18:53:30 +00:00

Discord: Removed invalid avatar discriminator URL

This commit is contained in:
diamondburned (Forefront) 2020-02-17 09:28:52 -08:00
parent 4e9bd53b0f
commit 4b53d72db1
3 changed files with 35 additions and 37 deletions

View file

@ -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) {

View file

@ -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(`\`, `\\`, `"`, `\"`)

View file

@ -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