From f334491deed4e5069cb7edbc180f0b41b0555edc Mon Sep 17 00:00:00 2001 From: Maximilian von Lindern Date: Tue, 24 Aug 2021 20:23:49 +0200 Subject: [PATCH] api: Mutate validated embeds from discord.Embed.Validate (#271) --- api/interaction.go | 12 ++++++++++-- api/message.go | 5 ++++- api/send.go | 4 +++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/api/interaction.go b/api/interaction.go index c295645..54442f3 100644 --- a/api/interaction.go +++ b/api/interaction.go @@ -123,6 +123,8 @@ func (c *Client) RespondInteraction( if sum > 6000 { return &discord.OverboundError{Count: sum, Max: 6000, Thing: "sum of all text in embeds"} } + + (*resp.Data.Embeds)[i] = embed // embed.Validate changes fields } } } @@ -180,7 +182,7 @@ func (c *Client) EditInteractionResponse( if data.Embeds != nil { sum := 0 - for _, e := range *data.Embeds { + for i, e := range *data.Embeds { if err := e.Validate(); err != nil { return nil, errors.Wrap(err, "embed error") } @@ -188,6 +190,8 @@ func (c *Client) EditInteractionResponse( if sum > 6000 { return nil, &discord.OverboundError{Count: sum, Max: 6000, Thing: "sum of text in embeds"} } + + (*data.Embeds)[i] = e // e.Validate changes fields } } @@ -227,6 +231,8 @@ func (c *Client) CreateInteractionFollowup( if sum > 6000 { return nil, &discord.OverboundError{Count: sum, Max: 6000, Thing: "sum of all text in embeds"} } + + (*data.Embeds)[i] = embed // embed.Validate changes fields } } @@ -247,7 +253,7 @@ func (c *Client) EditInteractionFollowup( if data.Embeds != nil { sum := 0 - for _, e := range *data.Embeds { + for i, e := range *data.Embeds { if err := e.Validate(); err != nil { return nil, errors.Wrap(err, "embed error") } @@ -255,6 +261,8 @@ func (c *Client) EditInteractionFollowup( if sum > 6000 { return nil, &discord.OverboundError{Count: sum, Max: 6000, Thing: "sum of text in embeds"} } + + (*data.Embeds)[i] = e // e.Validate changes fields } } diff --git a/api/message.go b/api/message.go index 344d15e..c5ce328 100644 --- a/api/message.go +++ b/api/message.go @@ -382,10 +382,13 @@ func (c *Client) EditMessageComplex( } sum += embed.Length() if sum > 6000 { - return nil, &discord.OverboundError{sum, 6000, "sum of all text in embeds"} + return nil, &discord.OverboundError{Count: sum, Max: 6000, Thing: "sum of all text in embeds"} } + + (*data.Embeds)[i] = embed // embed.Validate changes fields } } + var msg *discord.Message return msg, sendpart.PATCH(c.Client, data, &msg, EndpointChannels+channelID.String()+"/messages/"+messageID.String()) diff --git a/api/send.go b/api/send.go index 25db45a..02d1d50 100644 --- a/api/send.go +++ b/api/send.go @@ -168,8 +168,10 @@ func (c *Client) SendMessageComplex( } sum += embed.Length() if sum > 6000 { - return nil, &discord.OverboundError{sum, 6000, "sum of all text in embeds"} + return nil, &discord.OverboundError{Count: sum, Max: 6000, Thing: "sum of all text in embeds"} } + + data.Embeds[i] = embed // embed.Validate changes fields } var URL = EndpointChannels + channelID.String() + "/messages"