From 968112fb53ce741d0c26b9d6a20dfbac0505bf33 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Wed, 17 Feb 2021 17:41:19 -0800 Subject: [PATCH] Discord: typed snowflake for Interaction --- api/interaction.go | 2 +- discord/snowflake.go | 14 ++++++++++++++ gateway/events.go | 18 +++++++++--------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/api/interaction.go b/api/interaction.go index 4d3ccbf..23bbc24 100644 --- a/api/interaction.go +++ b/api/interaction.go @@ -34,7 +34,7 @@ type InteractionResponseData struct { // RespondInteraction responds to an incoming interaction. It is also known as // an "interaction callback". func (c *Client) RespondInteraction( - id discord.Snowflake, token string, data InteractionResponse) error { + id discord.InteractionID, token string, data InteractionResponse) error { return c.FastRequest( "POST", diff --git a/discord/snowflake.go b/discord/snowflake.go index 39ab19f..151eef7 100644 --- a/discord/snowflake.go +++ b/discord/snowflake.go @@ -193,6 +193,20 @@ func (s IntegrationID) Worker() uint8 { return Snowflake(s).Work func (s IntegrationID) PID() uint8 { return Snowflake(s).PID() } func (s IntegrationID) Increment() uint16 { return Snowflake(s).Increment() } +type InteractionID Snowflake + +const NullInteractionID = InteractionID(NullSnowflake) + +func (s InteractionID) MarshalJSON() ([]byte, error) { return Snowflake(s).MarshalJSON() } +func (s *InteractionID) UnmarshalJSON(v []byte) error { return (*Snowflake)(s).UnmarshalJSON(v) } +func (s InteractionID) String() string { return Snowflake(s).String() } +func (s InteractionID) IsValid() bool { return Snowflake(s).IsValid() } +func (s InteractionID) IsNull() bool { return Snowflake(s).IsNull() } +func (s InteractionID) Time() time.Time { return Snowflake(s).Time() } +func (s InteractionID) Worker() uint8 { return Snowflake(s).Worker() } +func (s InteractionID) PID() uint8 { return Snowflake(s).PID() } +func (s InteractionID) Increment() uint16 { return Snowflake(s).Increment() } + type GuildID Snowflake const NullGuildID = GuildID(NullSnowflake) diff --git a/gateway/events.go b/gateway/events.go index 4f3c415..11ff4b2 100644 --- a/gateway/events.go +++ b/gateway/events.go @@ -371,14 +371,14 @@ type ( // https://discord.com/developers/docs/topics/gateway#interactions type ( InteractionCreateEvent struct { - ID discord.Snowflake `json:"id"` - Type InteractionType `json:"type"` - Data InteractionData `json:"data"` - GuildID discord.GuildID `json:"guild_id"` - ChannelID discord.ChannelID `json:"channel_id"` - Member discord.Member `json:"member"` - Token string `json:"token"` - Version int `json:"version"` + ID discord.InteractionID `json:"id"` + Type InteractionType `json:"type"` + Data InteractionData `json:"data"` + GuildID discord.GuildID `json:"guild_id"` + ChannelID discord.ChannelID `json:"channel_id"` + Member discord.Member `json:"member"` + Token string `json:"token"` + Version int `json:"version"` } ) @@ -390,7 +390,7 @@ const ( ) type InteractionData struct { - ID discord.Snowflake `json:"id"` + ID discord.CommandID `json:"id"` Name string `json:"name"` Options []InteractionOption `json:"options"` }