1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-02-12 14:33:26 +00:00

api: Mutate validated embeds from discord.Embed.Validate (#271)

This commit is contained in:
Maximilian von Lindern 2021-08-24 20:23:49 +02:00 committed by GitHub
parent 1e9eb4a473
commit f334491dee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View file

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

View file

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

View file

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