Skip to content

Commit f3d2f7b

Browse files
authored
Add more snapshot fields (#391)
1 parent 814a7e3 commit f3d2f7b

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

discord/message.go

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ func (m *Message) UnmarshalJSON(data []byte) error {
135135
*m = Message(v.message)
136136

137137
if len(v.Components) > 0 {
138-
m.Components = make([]ContainerComponent, len(v.Components))
139-
for i := range v.Components {
140-
m.Components[i] = v.Components[i].Component.(ContainerComponent)
141-
}
138+
m.Components = unmarshalComponents(v.Components)
142139
}
143140

144141
if m.Member != nil && m.GuildID != nil {
@@ -428,15 +425,38 @@ type MessageSnapshot struct {
428425
}
429426

430427
type PartialMessage struct {
431-
Type MessageType `json:"type"`
432-
Content string `json:"content,omitempty"`
433-
Embeds []Embed `json:"embeds,omitempty"`
434-
Attachments []Attachment `json:"attachments"`
435-
CreatedAt time.Time `json:"timestamp"`
436-
EditedTimestamp *time.Time `json:"edited_timestamp"`
437-
Flags MessageFlags `json:"flags"`
438-
Mentions []User `json:"mentions"`
439-
MentionRoles []snowflake.ID `json:"mention_roles"`
428+
Type MessageType `json:"type"`
429+
Content string `json:"content,omitempty"`
430+
Embeds []Embed `json:"embeds,omitempty"`
431+
Attachments []Attachment `json:"attachments"`
432+
CreatedAt time.Time `json:"timestamp"`
433+
EditedTimestamp *time.Time `json:"edited_timestamp"`
434+
Flags MessageFlags `json:"flags"`
435+
Mentions []User `json:"mentions"`
436+
MentionRoles []snowflake.ID `json:"mention_roles"`
437+
Stickers []Sticker `json:"stickers"`
438+
StickerItems []MessageSticker `json:"sticker_items,omitempty"`
439+
Components []ContainerComponent `json:"components,omitempty"`
440+
}
441+
442+
func (m *PartialMessage) UnmarshalJSON(data []byte) error {
443+
type partialMessage PartialMessage
444+
var v struct {
445+
Components []UnmarshalComponent `json:"components"`
446+
partialMessage
447+
}
448+
449+
if err := json.Unmarshal(data, &v); err != nil {
450+
return err
451+
}
452+
453+
*m = PartialMessage(v.partialMessage)
454+
455+
if len(v.Components) > 0 {
456+
m.Components = unmarshalComponents(v.Components)
457+
}
458+
459+
return nil
440460
}
441461

442462
// MessageInteraction is sent on the Message object when the message is a response to an interaction
@@ -515,3 +535,11 @@ type MessageCall struct {
515535
Participants []snowflake.ID `json:"participants"`
516536
EndedTimestamp *time.Time `json:"ended_timestamp"`
517537
}
538+
539+
func unmarshalComponents(components []UnmarshalComponent) []ContainerComponent {
540+
containerComponents := make([]ContainerComponent, len(components))
541+
for i := range components {
542+
containerComponents[i] = components[i].Component.(ContainerComponent)
543+
}
544+
return containerComponents
545+
}

0 commit comments

Comments
 (0)