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 <fe.lap.prog@gmail.com>
This commit is contained in:
Earlopain 2023-05-14 17:53:29 +02:00 committed by GitHub
parent 160605c9c3
commit 1252b71f38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 @<id> mentions with the
// username of the mention.
func (m *Message) ContentWithMentionsReplaced() (content string) {