From 1252b71f3800ea7c084e53b93ec45ab8bf087b12 Mon Sep 17 00:00:00 2001 From: Earlopain Date: Sun, 14 May 2023 17:53:29 +0200 Subject: [PATCH] feat(MessageReference): add fail_if_not_exists (#1376) * Add fail_if_not_exists to MessageReference * Add SoftReference function to Message --------- Co-authored-by: Fedor Lapshin --- message.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/message.go b/message.go index 90a66ca..94a9f08 100644 --- a/message.go +++ b/message.go @@ -461,20 +461,32 @@ type MessageApplication struct { // MessageReference contains reference data sent with crossposted messages type MessageReference struct { - MessageID string `json:"message_id"` - ChannelID string `json:"channel_id,omitempty"` - GuildID string `json:"guild_id,omitempty"` + MessageID string `json:"message_id"` + ChannelID string `json:"channel_id,omitempty"` + GuildID string `json:"guild_id,omitempty"` + FailIfNotExists *bool `json:"fail_if_not_exists,omitempty"` } -// Reference returns MessageReference of given message -func (m *Message) Reference() *MessageReference { +func (m *Message) reference(failIfNotExists bool) *MessageReference { return &MessageReference{ - GuildID: m.GuildID, - ChannelID: m.ChannelID, - MessageID: m.ID, + GuildID: m.GuildID, + ChannelID: m.ChannelID, + MessageID: m.ID, + FailIfNotExists: &failIfNotExists, } } +// Reference returns a MessageReference of the given message. +func (m *Message) Reference() *MessageReference { + return m.reference(true) +} + +// SoftReference returns a MessageReference of the given message. +// If the message doesn't exist it will instead be sent as a non-reply message. +func (m *Message) SoftReference() *MessageReference { + return m.reference(false) +} + // ContentWithMentionsReplaced will replace all @ mentions with the // username of the mention. func (m *Message) ContentWithMentionsReplaced() (content string) {