Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown Message Component Type 16 #1562

Open
Suhaibinator opened this issue Aug 29, 2024 · 4 comments
Open

Unknown Message Component Type 16 #1562

Suhaibinator opened this issue Aug 29, 2024 · 4 comments

Comments

@Suhaibinator
Copy link
Contributor

I received a Message Create message that is unable to be unmarshalled because it has a Message Component of type 16.

Here is the components field of the message create with identifying information censored

"components": [
    {
      "type": 16,
      "id": 1,
      "content_inventory_entry": {
        "traits": [
          {
            "type": 4,
            "range": 1
          },
          {
            "type": 2,
            "duration_seconds": 81737
          }
        ],
        "participants": [
          "CENSORED"
        ],
        "original_id": "CENSORED",
        "id": "CENSORED",
        "extra": {
          "type": "played_game_extra",
          "platform": 0,
          "game_name": "Red Dead Redemption 2",
          "application_id": "CENSORED"
        },
        "content_type": 3,
        "author_type": 1,
        "author_id": "CENSORED"
      }
    }
  ],

This component prevents the entire message from being unmarshalled because we do an early return if we receive a message component whose type is not handled:

// UnmarshalJSON is a helper function to unmarshal MessageComponent object.

func (umc *unmarshalableMessageComponent) UnmarshalJSON(src []byte) error {
	var v struct {
		Type ComponentType `json:"type"`
	}
	err := json.Unmarshal(src, &v)
	if err != nil {
		return err
	}

	switch v.Type {
	case ActionsRowComponent:
		umc.MessageComponent = &ActionsRow{}
	case ButtonComponent:
		umc.MessageComponent = &Button{}
	case SelectMenuComponent, ChannelSelectMenuComponent, UserSelectMenuComponent,
		RoleSelectMenuComponent, MentionableSelectMenuComponent:
		umc.MessageComponent = &SelectMenu{}
	case TextInputComponent:
		umc.MessageComponent = &TextInput{}
	default:
		return fmt.Errorf("unknown component type: %d", v.Type)
	}
	return json.Unmarshal(src, umc.MessageComponent)
}
@glotchimo
Copy link

Looks like metadata for an Activity Card, part of the Recent Activity beta

@Suhaibinator
Copy link
Contributor Author

@glotchimo if that's the case then it is breaking the marshaling. Should we change the marshaling to be more robust to this? @bwmarrin @FedorLap2006

@glotchimo
Copy link

glotchimo commented Sep 11, 2024

Without documentation (not sure if these have been written/posted by Discord yet, all we have is the known 8 here), it's hard to say what that would look like here. Also, considering how much higher it is than the current max type of 8, has me wondering if it's temporary or if there are 8+ more message component types on the way?

discordgo/components.go

Lines 8 to 21 in 41a66e5

// ComponentType is type of component.
type ComponentType uint
// MessageComponent types.
const (
ActionsRowComponent ComponentType = 1
ButtonComponent ComponentType = 2
SelectMenuComponent ComponentType = 3
TextInputComponent ComponentType = 4
UserSelectMenuComponent ComponentType = 5
RoleSelectMenuComponent ComponentType = 6
MentionableSelectMenuComponent ComponentType = 7
ChannelSelectMenuComponent ComponentType = 8
)

@Suhaibinator
Copy link
Contributor Author

Either way, marshaling ceases completely when an unexpected field is encountered. Seeing as how this can and actually is happening, I believe we should not completely cease marshaling when this happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants