Skip to content

Commit

Permalink
fixed unmarshalling of components
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Jul 3, 2021
1 parent 97fc1e4 commit c0f0188
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions api/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,18 @@ type Message struct {
LastUpdated *time.Time `json:"last_updated,omitempty"`
}


// Unmarshal is used to unmarshal a Message we received from discord
func (m *Message) Unmarshal(data []byte) error {
var fullM struct {
Components []UnmarshalComponent `json:"components,omitempty"`
*Message
UnmarshalComponents []UnmarshalComponent `json:"components,omitempty"`
}
err := json.Unmarshal(data, &fullM)
if err != nil {
return err
}
*m = *fullM.Message
for _, component := range fullM.UnmarshalComponents {
for _, component := range fullM.Components {
m.Components = append(m.Components, createComponent(component))
}
return nil
Expand All @@ -218,15 +217,15 @@ func createComponent(unmarshalComponent UnmarshalComponent) Component {
for i, unmarshalC := range unmarshalComponent.Components {
components[i] = createComponent(unmarshalC)
}
return &ActionRow{
return ActionRow{
ComponentImpl: ComponentImpl{
ComponentType: ComponentTypeActionRow,
},
Components: components,
}

case ComponentTypeButton:
return &Button{
return Button{
ComponentImpl: ComponentImpl{
ComponentType: ComponentTypeButton,
},
Expand Down

0 comments on commit c0f0188

Please sign in to comment.