Skip to content

Commit

Permalink
Add more snapshot fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 committed Aug 30, 2024
1 parent 47dd91b commit e676986
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions discord/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ func (m *Message) UnmarshalJSON(data []byte) error {
*m = Message(v.message)

if len(v.Components) > 0 {
m.Components = make([]ContainerComponent, len(v.Components))
for i := range v.Components {
m.Components[i] = v.Components[i].Component.(ContainerComponent)
}
m.Components = unmarshalComponents(v.Components)
}

if m.Member != nil && m.GuildID != nil {
Expand Down Expand Up @@ -428,15 +425,38 @@ type MessageSnapshot struct {
}

type PartialMessage struct {
Type MessageType `json:"type"`
Content string `json:"content,omitempty"`
Embeds []Embed `json:"embeds,omitempty"`
Attachments []Attachment `json:"attachments"`
CreatedAt time.Time `json:"timestamp"`
EditedTimestamp *time.Time `json:"edited_timestamp"`
Flags MessageFlags `json:"flags"`
Mentions []User `json:"mentions"`
MentionRoles []snowflake.ID `json:"mention_roles"`
Type MessageType `json:"type"`
Content string `json:"content,omitempty"`
Embeds []Embed `json:"embeds,omitempty"`
Attachments []Attachment `json:"attachments"`
CreatedAt time.Time `json:"timestamp"`
EditedTimestamp *time.Time `json:"edited_timestamp"`
Flags MessageFlags `json:"flags"`
Mentions []User `json:"mentions"`
MentionRoles []snowflake.ID `json:"mention_roles"`
Stickers []Sticker `json:"stickers"`
StickerItems []MessageSticker `json:"sticker_items,omitempty"`
Components []ContainerComponent `json:"components,omitempty"`
}

func (m *PartialMessage) UnmarshalJSON(data []byte) error {
type partialMessage PartialMessage
var v struct {
Components []UnmarshalComponent `json:"components"`
partialMessage
}

if err := json.Unmarshal(data, &v); err != nil {
return err
}

*m = PartialMessage(v.partialMessage)

if len(v.Components) > 0 {
m.Components = unmarshalComponents(v.Components)
}

return nil
}

// MessageInteraction is sent on the Message object when the message is a response to an interaction
Expand Down Expand Up @@ -515,3 +535,11 @@ type MessageCall struct {
Participants []snowflake.ID `json:"participants"`
EndedTimestamp *time.Time `json:"ended_timestamp"`
}

func unmarshalComponents(components []UnmarshalComponent) []ContainerComponent {
containerComponents := make([]ContainerComponent, len(components))
for i := range components {
containerComponents[i] = components[i].Component.(ContainerComponent)
}
return containerComponents
}

0 comments on commit e676986

Please sign in to comment.