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

api: More multiple embed support for send functions (#266)

* api: Adapt Client.EditMessage, SendEmbedReply, and SendMessageReply to take in
  multiple embeds

* api: Fix incorrect use of Client.EditMessage

* api: Make EditMessage omit empty content or embeds from payload
This commit is contained in:
Maximilian von Lindern 2021-08-16 11:25:37 +02:00 committed by diamondburned
parent 19335e5050
commit 525e8d527b
2 changed files with 20 additions and 19 deletions

View file

@ -98,7 +98,7 @@ func TestReactions(t *testing.T) {
msg += fmt.Sprintf(" Total time taken to send all reactions: %v.", time.Now().Sub(now))
m, err = client.EditMessage(cfg.ChannelID, m.ID, msg, nil, false)
m, err = client.EditMessage(cfg.ChannelID, m.ID, msg)
if err != nil {
t.Fatal("Failed to edit message:", err)
}

View file

@ -236,10 +236,10 @@ func (c *Client) SendEmbeds(
// Fires a Message Create Gateway event.
func (c *Client) SendEmbedReply(
channelID discord.ChannelID,
e discord.Embed, referenceID discord.MessageID) (*discord.Message, error) {
referenceID discord.MessageID, embeds ...discord.Embed) (*discord.Message, error) {
return c.SendMessageComplex(channelID, SendMessageData{
Embeds: []discord.Embed{e},
Embeds: embeds,
Reference: &discord.MessageReference{MessageID: referenceID},
})
}
@ -269,15 +269,14 @@ func (c *Client) SendMessage(
// Fires a Message Create Gateway event.
func (c *Client) SendMessageReply(
channelID discord.ChannelID, content string,
embed *discord.Embed, referenceID discord.MessageID) (*discord.Message, error) {
referenceID discord.MessageID, embeds ...discord.Embed) (*discord.Message, error) {
data := SendMessageData{
Content: content,
Reference: &discord.MessageReference{MessageID: referenceID},
Embeds: embeds,
}
if embed != nil {
data.Embeds = []discord.Embed{*embed}
}
return c.SendMessageComplex(channelID, data)
}
@ -333,21 +332,23 @@ func (c *Client) EditEmbeds(
})
}
// EditMessage edits a previously sent message. For more documentation, refer to
// EditMessageComplex.
// EditMessage edits a previously sent message. If content or embeds are empty
// the original content or embed will remain untouched. This means EditMessage
// will only update, but not remove parts of the message.
//
// For more documentation, refer to EditMessageComplex.
func (c *Client) EditMessage(
channelID discord.ChannelID, messageID discord.MessageID, content string,
embed *discord.Embed, suppressEmbeds bool) (*discord.Message, error) {
channelID discord.ChannelID, messageID discord.MessageID,
content string, embeds ...discord.Embed) (*discord.Message, error) {
var data = EditMessageData{
Content: option.NewNullableString(content),
var data EditMessageData
if len(content) > 0 {
data.Content = option.NewNullableString(content)
}
if embed != nil {
data.Embeds = &[]discord.Embed{*embed}
}
if suppressEmbeds {
v := discord.SuppressEmbeds
data.Flags = &v
if len(embeds) > 0 {
data.Embeds = &embeds
}
return c.EditMessageComplex(channelID, messageID, data)