From 2bc4bb656feb8e225f66728a9a80d2f541dda08d Mon Sep 17 00:00:00 2001 From: rigormorrtiss Date: Mon, 2 Aug 2021 13:05:14 +0400 Subject: [PATCH] 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 --- api/message.go | 10 +++++----- api/send.go | 12 +++++++----- api/send_test.go | 10 +++++----- bot/ctx_call.go | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/api/message.go b/api/message.go index 0974f20..cfd7200 100644 --- a/api/message.go +++ b/api/message.go @@ -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}, }) } diff --git a/api/send.go b/api/send.go index 772935a..6a00c85 100644 --- a/api/send.go +++ b/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") + } } } diff --git a/api/send_test.go b/api/send_test.go index 11c863d..06b9c84 100644 --- a/api/send_test.go +++ b/api/send_test.go @@ -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) diff --git a/bot/ctx_call.go b/bot/ctx_call.go index 20b129a..bfebb59 100644 --- a/bot/ctx_call.go +++ b/bot/ctx_call.go @@ -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: