Skip to content

Commit

Permalink
discord: Add message_snapshot support (#453)
Browse files Browse the repository at this point in the history
* Add new type field

https://discord.com/developers/docs/resources/message#message-reference-structure

* Update with changes

* Add message_snapshot

* fixup

* fixup

* Convert Message to MessageSnapshotMessage
  • Loading branch information
hi117 authored Oct 14, 2024
1 parent 6f5a530 commit 9e83b0e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
65 changes: 65 additions & 0 deletions discord/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type Message struct {
// Flags are the MessageFlags.
Flags MessageFlags `json:"flags"`

// The message associated with the message_reference. This is a minimal subset of fields in a message (e.g. author is excluded.)
MessageSnapshots []MessageSnapshot `json:"message_snapshots,omitempty"`

// TTS specifies whether the was a TTS message.
TTS bool `json:"tts"`
// Pinned specifies whether the message is pinned.
Expand Down Expand Up @@ -365,6 +368,65 @@ func (m MessageApplication) CreatedAt() time.Time {
return m.ID.Time()
}

// https://discord.com/developers/docs/resources/message#message-snapshot-object
type MessageSnapshotMessage struct {
// Type is the type of message.
Type MessageType `json:"type"`

// Content contains the contents of the message.
Content string `json:"content"`

// Embeds contains any embedded content.
Embeds []Embed `json:"embeds"`

// Attachments contains any attached files.
Attachments []Attachment `json:"attachments"`

// Timestamp specifies when the message was sent
Timestamp Timestamp `json:"timestamp,omitempty"`

// EditedTimestamp specifies when this message was edited.
//
// IsValid() will return false, if the messages hasn't been edited.
EditedTimestamp Timestamp `json:"edited_timestamp,omitempty"`

// Flags are the MessageFlags.
Flags MessageFlags `json:"flags"`

// Mentions contains the users specifically mentioned in the message.
//
// The user objects in the mentions array will only have the partial
// member field present in MESSAGE_CREATE and MESSAGE_UPDATE events from
// text-based guild channels.
Mentions []GuildUser `json:"mentions"`

// MentionRoleIDs contains the ids of the roles specifically mentioned in
// the message.
MentionRoleIDs []RoleID `json:"mention_roles"`

// Stickers contains the sticker "items" sent with the message.
Stickers []StickerItem `json:"sticker_items,omitempty"`

// Components contains any attached components.
Components ContainerComponents `json:"components,omitempty"`
}

// https://discord.com/developers/docs/resources/message#message-snapshot-object
type MessageSnapshot struct {
// The embedded partial message object
Message *MessageSnapshotMessage `json:"message"`
}

const (
// A standard reference used by replies.
MessageReferenceTypeDefault MessageReferenceType = iota
// Reference used to point to a message at a point in time.
MessageReferenceTypeForward
)

// Type of message reference
type MessageReferenceType int

// MessageReference is used in four situations:
//
// # Crosspost messages
Expand Down Expand Up @@ -396,6 +458,9 @@ func (m MessageApplication) CreatedAt() time.Time {
// When sending, only MessageID is required.
// https://discord.com/developers/docs/resources/channel#message-object-message-reference-structure
type MessageReference struct {
// If type is unset, DEFAULT can be assumed in order to match the behaviour before message reference
// had types. In future API versions this will become a required field.
Type MessageReferenceType `json:"type"`
// MessageID is the id of the originating message.
MessageID MessageID `json:"message_id,omitempty"`
// ChannelID is the id of the originating message's channel.
Expand Down
9 changes: 6 additions & 3 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
github.com/diamondburned/arikawa/v3 v3.0.0-rc.6/go.mod h1:5jBSNnp82Z/EhsKa6Wk9FsOqSxfVkNZDTDBPOj47LpY=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/sys v0.0.0-20211001092434-39dca1131b70/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=

0 comments on commit 9e83b0e

Please sign in to comment.