mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-01-08 04:57:31 +00:00
api: Update SendMessageData.Embed to .Embeds (#248)
* Update SendMessageData.Embed to .Embeds Related: https://github.com/discord/discord-api-docs/pull/3105 Closes #239 * Fix test
This commit is contained in:
parent
30b69eab93
commit
2bc4bb656f
|
@ -230,7 +230,7 @@ func (c *Client) SendEmbed(
|
|||
channelID discord.ChannelID, e discord.Embed) (*discord.Message, error) {
|
||||
|
||||
return c.SendMessageComplex(channelID, SendMessageData{
|
||||
Embed: &e,
|
||||
Embeds: []discord.Embed{e},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ func (c *Client) SendEmbedReply(
|
|||
referenceID discord.MessageID) (*discord.Message, error) {
|
||||
|
||||
return c.SendMessageComplex(channelID, SendMessageData{
|
||||
Embed: &e,
|
||||
Embeds: []discord.Embed{e},
|
||||
Reference: &discord.MessageReference{MessageID: referenceID},
|
||||
})
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ func (c *Client) SendMessage(
|
|||
|
||||
return c.SendMessageComplex(channelID, SendMessageData{
|
||||
Content: content,
|
||||
Embed: embed,
|
||||
Embeds: []discord.Embed{*embed},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -275,12 +275,12 @@ func (c *Client) SendMessage(
|
|||
func (c *Client) SendMessageReply(
|
||||
channelID discord.ChannelID,
|
||||
content string,
|
||||
embed *discord.Embed,
|
||||
embed discord.Embed,
|
||||
referenceID discord.MessageID) (*discord.Message, error) {
|
||||
|
||||
return c.SendMessageComplex(channelID, SendMessageData{
|
||||
Content: content,
|
||||
Embed: embed,
|
||||
Embeds: []discord.Embed{embed},
|
||||
Reference: &discord.MessageReference{MessageID: referenceID},
|
||||
})
|
||||
}
|
||||
|
|
12
api/send.go
12
api/send.go
|
@ -100,7 +100,7 @@ type SendMessageData struct {
|
|||
// TTS is true if this is a TTS message.
|
||||
TTS bool `json:"tts,omitempty"`
|
||||
// Embed is embedded rich content.
|
||||
Embed *discord.Embed `json:"embed,omitempty"`
|
||||
Embeds []discord.Embed `json:"embeds,omitempty"`
|
||||
|
||||
// Files is the list of file attachments to be uploaded. To reference a file
|
||||
// in an embed, use (sendpart.File).AttachmentURI().
|
||||
|
@ -148,7 +148,7 @@ func (data SendMessageData) WriteMultipart(body *multipart.Writer) error {
|
|||
func (c *Client) SendMessageComplex(
|
||||
channelID discord.ChannelID, data SendMessageData) (*discord.Message, error) {
|
||||
|
||||
if data.Content == "" && data.Embed == nil && len(data.Files) == 0 {
|
||||
if data.Content == "" && len(data.Embeds) == 0 && len(data.Files) == 0 {
|
||||
return nil, ErrEmptyMessage
|
||||
}
|
||||
|
||||
|
@ -158,9 +158,11 @@ func (c *Client) SendMessageComplex(
|
|||
}
|
||||
}
|
||||
|
||||
if data.Embed != nil {
|
||||
if err := data.Embed.Validate(); err != nil {
|
||||
return nil, errors.Wrap(err, "embed error")
|
||||
if len(data.Embeds) != 0 {
|
||||
for _, embed := range data.Embeds {
|
||||
if err := embed.Validate(); err != nil {
|
||||
return nil, errors.Wrap(err, "embed error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,6 @@ func TestSendMessage(t *testing.T) {
|
|||
t.Run("empty", func(t *testing.T) {
|
||||
var empty = SendMessageData{
|
||||
Content: "",
|
||||
Embed: nil,
|
||||
}
|
||||
|
||||
if err := send(empty); err != ErrEmptyMessage {
|
||||
|
@ -135,11 +134,12 @@ func TestSendMessage(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("invalid embed", func(t *testing.T) {
|
||||
embed := discord.Embed{
|
||||
// max 256
|
||||
Title: spaces(257),
|
||||
}
|
||||
var data = SendMessageData{
|
||||
Embed: &discord.Embed{
|
||||
// max 256
|
||||
Title: spaces(257),
|
||||
},
|
||||
Embeds: []discord.Embed{embed},
|
||||
}
|
||||
|
||||
err := send(data)
|
||||
|
|
|
@ -131,7 +131,7 @@ func (ctx *Context) callMessageCreate(
|
|||
case string:
|
||||
data.Content = v
|
||||
case *discord.Embed:
|
||||
data.Embed = v
|
||||
data.Embeds = []discord.Embed{*v}
|
||||
case *api.SendMessageData:
|
||||
data = *v
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue