1
0
forked from lug/matterbridge

Fancy replies using rich embeds on Discord side

This commit is contained in:
2025-11-03 15:17:34 -08:00
parent 186d28858b
commit f73bee90ab
17 changed files with 1706 additions and 128 deletions

View File

@@ -135,11 +135,19 @@ type Message struct {
// If the field exists but is null, the referenced message was deleted.
ReferencedMessage *Message `json:"referenced_message"`
// The message associated with the message_reference.
// This is a minimal subset of fields in a message (e.g. Author is excluded)
// NOTE: This field is only returned when referenced when MessageReference.Type is MessageReferenceTypeForward.
MessageSnapshots []MessageSnapshot `json:"message_snapshots"`
// Deprecated, use InteractionMetadata.
// Is sent when the message is a response to an Interaction, without an existing message.
// This means responses to message component interactions do not include this property,
// instead including a MessageReference, as components exist on preexisting messages.
Interaction *MessageInteraction `json:"interaction"`
InteractionMetadata *MessageInteractionMetadata `json:"interaction_metadata"`
// The flags of the message, which describe extra features of a message.
// This is a combination of bit masks; the presence of a certain permission can
// be checked by performing a bitwise AND between this int and the flag.
@@ -150,6 +158,9 @@ type Message struct {
// An array of StickerItem objects, representing sent stickers, if there were any.
StickerItems []*StickerItem `json:"sticker_items"`
// A poll object.
Poll *Poll `json:"poll"`
}
// UnmarshalJSON is a helper function to unmarshal the Message.
@@ -219,6 +230,8 @@ const (
MessageFlagsSuppressNotifications MessageFlags = 1 << 12
// MessageFlagsIsVoiceMessage this message is a voice message.
MessageFlagsIsVoiceMessage MessageFlags = 1 << 13
// MessageFlagsIsComponentsV2 this message uses the new components system. Disables the ability of sending `content` & `embeds`
MessageFlagsIsComponentsV2 MessageFlags = 1 << 15
)
// File stores info about files you e.g. send in messages.
@@ -239,6 +252,7 @@ type MessageSend struct {
Reference *MessageReference `json:"message_reference,omitempty"`
StickerIDs []string `json:"sticker_ids"`
Flags MessageFlags `json:"flags,omitempty"`
Poll *Poll `json:"poll,omitempty"`
// TODO: Remove this when compatibility is not required.
File *File `json:"-"`
@@ -338,17 +352,28 @@ type MessageAllowedMentions struct {
// A MessageAttachment stores data for message attachments.
type MessageAttachment struct {
ID string `json:"id"`
URL string `json:"url"`
ProxyURL string `json:"proxy_url"`
Filename string `json:"filename"`
ContentType string `json:"content_type"`
Width int `json:"width"`
Height int `json:"height"`
Size int `json:"size"`
Ephemeral bool `json:"ephemeral"`
ID string `json:"id"`
URL string `json:"url"`
ProxyURL string `json:"proxy_url"`
Filename string `json:"filename"`
ContentType string `json:"content_type"`
Width int `json:"width"`
Height int `json:"height"`
Size int `json:"size"`
Ephemeral bool `json:"ephemeral"`
DurationSecs float64 `json:"duration_secs"`
Waveform string `json:"waveform"`
Flags MessageAttachmentFlags `json:"flags"`
}
// MessageAttachmentFlags is the flags of a message attachment.
type MessageAttachmentFlags int
// Valid MessageAttachmentFlags values.
const (
MessageAttachmentFlagsIsRemix MessageAttachmentFlags = 1 << 2
)
// MessageEmbedFooter is a part of a MessageEmbed struct.
type MessageEmbedFooter struct {
Text string `json:"text,omitempty"`
@@ -464,16 +489,34 @@ type MessageApplication struct {
Name string `json:"name"`
}
// 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"`
FailIfNotExists *bool `json:"fail_if_not_exists,omitempty"`
// MessageSnapshot represents a snapshot of a forwarded message.
// https://discord.com/developers/docs/resources/message#message-snapshot-object
type MessageSnapshot struct {
Message *Message `json:"message"`
}
func (m *Message) reference(failIfNotExists bool) *MessageReference {
// MessageReferenceType is a type of MessageReference
type MessageReferenceType int
// Known valid MessageReferenceType values
// https://discord.com/developers/docs/resources/message#message-reference-types
const (
MessageReferenceTypeDefault MessageReferenceType = 0
MessageReferenceTypeForward MessageReferenceType = 1
)
// MessageReference contains reference data sent with crossposted messages
type MessageReference struct {
Type MessageReferenceType `json:"type,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"`
}
func (m *Message) reference(refType MessageReferenceType, failIfNotExists bool) *MessageReference {
return &MessageReference{
Type: refType,
GuildID: m.GuildID,
ChannelID: m.ChannelID,
MessageID: m.ID,
@@ -483,13 +526,18 @@ func (m *Message) reference(failIfNotExists bool) *MessageReference {
// Reference returns a MessageReference of the given message.
func (m *Message) Reference() *MessageReference {
return m.reference(true)
return m.reference(MessageReferenceTypeDefault, 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)
return m.reference(MessageReferenceTypeDefault, false)
}
// Forward returns a MessageReference for a forwarded message.
func (m *Message) Forward() *MessageReference {
return m.reference(MessageReferenceTypeForward, true)
}
// ContentWithMentionsReplaced will replace all @<id> mentions with the
@@ -567,3 +615,24 @@ type MessageInteraction struct {
// Member is only present when the interaction is from a guild.
Member *Member `json:"member"`
}
// MessageInteractionMetadata contains metadata of an interaction, including relevant user info.
type MessageInteractionMetadata struct {
// ID of the interaction.
ID string `json:"id"`
// Type of the interaction.
Type InteractionType `json:"type"`
// User who triggered the interaction.
User *User `json:"user"`
// IDs for installation context(s) related to an interaction.
AuthorizingIntegrationOwners map[ApplicationIntegrationType]string `json:"authorizing_integration_owners"`
// ID of the original response message.
// NOTE: present only on followup messages.
OriginalResponseMessageID string `json:"original_response_message_id,omitempty"`
// ID of the message that contained interactive component.
// NOTE: present only on message component interactions.
InteractedMessageID string `json:"interacted_message_id,omitempty"`
// Metadata for interaction that was used to open a modal.
// NOTE: present only on modal submit interactions.
TriggeringInteractionMetadata *MessageInteractionMetadata `json:"triggering_interaction_metadata,omitempty"`
}