Skip to content

Commit

Permalink
Add Channel to interactions (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 committed Apr 6, 2023
1 parent f689ccb commit a3e65bd
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 10 deletions.
5 changes: 5 additions & 0 deletions discord/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,11 @@ type FollowChannel struct {
ChannelID snowflake.ID `json:"webhook_channel_id"`
}

type PartialChannel struct {
ID snowflake.ID `json:"id"`
Type ChannelType `json:"type"`
}

// VideoQualityMode https://com/developers/docs/resources/channel#channel-object-video-quality-modes
type VideoQualityMode int

Expand Down
15 changes: 9 additions & 6 deletions discord/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ const (
)

type rawInteraction struct {
ID snowflake.ID `json:"id"`
Type InteractionType `json:"type"`
ApplicationID snowflake.ID `json:"application_id"`
Token string `json:"token"`
Version int `json:"version"`
GuildID *snowflake.ID `json:"guild_id,omitempty"`
ID snowflake.ID `json:"id"`
Type InteractionType `json:"type"`
ApplicationID snowflake.ID `json:"application_id"`
Token string `json:"token"`
Version int `json:"version"`
GuildID *snowflake.ID `json:"guild_id,omitempty"`
// Deprecated: Use Channel instead
ChannelID snowflake.ID `json:"channel_id,omitempty"`
Channel *PartialChannel `json:"channel,omitempty"`
Locale Locale `json:"locale,omitempty"`
GuildLocale *Locale `json:"guild_locale,omitempty"`
Member *ResolvedMember `json:"member,omitempty"`
Expand All @@ -44,6 +46,7 @@ type Interaction interface {
Version() int
GuildID() *snowflake.ID
ChannelID() snowflake.ID
Channel() *PartialChannel
Locale() Locale
GuildLocale() *Locale
Member() *ResolvedMember
Expand Down
2 changes: 2 additions & 0 deletions discord/interaction_application_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (i *ApplicationCommandInteraction) UnmarshalJSON(data []byte) error {
i.baseInteraction.version = interaction.Version
i.baseInteraction.guildID = interaction.GuildID
i.baseInteraction.channelID = interaction.ChannelID
i.baseInteraction.channel = interaction.Channel
i.baseInteraction.locale = interaction.Locale
i.baseInteraction.guildLocale = interaction.GuildLocale
i.baseInteraction.member = interaction.Member
Expand All @@ -95,6 +96,7 @@ func (i ApplicationCommandInteraction) MarshalJSON() ([]byte, error) {
Version: i.version,
GuildID: i.guildID,
ChannelID: i.channelID,
Channel: i.channel,
Locale: i.locale,
GuildLocale: i.guildLocale,
Member: i.member,
Expand Down
2 changes: 2 additions & 0 deletions discord/interaction_autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (i *AutocompleteInteraction) UnmarshalJSON(data []byte) error {
i.baseInteraction.version = interaction.Version
i.baseInteraction.guildID = interaction.GuildID
i.baseInteraction.channelID = interaction.ChannelID
i.baseInteraction.channel = interaction.Channel
i.baseInteraction.locale = interaction.Locale
i.baseInteraction.guildLocale = interaction.GuildLocale
i.baseInteraction.member = interaction.Member
Expand All @@ -52,6 +53,7 @@ func (i AutocompleteInteraction) MarshalJSON() ([]byte, error) {
Version: i.version,
GuildID: i.guildID,
ChannelID: i.channelID,
Channel: i.channel,
Locale: i.locale,
GuildLocale: i.guildLocale,
Member: i.member,
Expand Down
6 changes: 6 additions & 0 deletions discord/interaction_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type baseInteraction struct {
version int
guildID *snowflake.ID
channelID snowflake.ID
channel *PartialChannel
locale Locale
guildLocale *Locale
member *ResolvedMember
Expand All @@ -35,9 +36,14 @@ func (i baseInteraction) Version() int {
func (i baseInteraction) GuildID() *snowflake.ID {
return i.guildID
}

// Deprecated: Use Channel() instead
func (i baseInteraction) ChannelID() snowflake.ID {
return i.channelID
}
func (i baseInteraction) Channel() *PartialChannel {
return i.channel
}
func (i baseInteraction) Locale() Locale {
return i.locale
}
Expand Down
2 changes: 2 additions & 0 deletions discord/interaction_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (i *ComponentInteraction) UnmarshalJSON(data []byte) error {
i.baseInteraction.version = interaction.Version
i.baseInteraction.guildID = interaction.GuildID
i.baseInteraction.channelID = interaction.ChannelID
i.baseInteraction.channel = interaction.Channel
i.baseInteraction.locale = interaction.Locale
i.baseInteraction.guildLocale = interaction.GuildLocale
i.baseInteraction.member = interaction.Member
Expand All @@ -108,6 +109,7 @@ func (i ComponentInteraction) MarshalJSON() ([]byte, error) {
Version: i.version,
GuildID: i.guildID,
ChannelID: i.channelID,
Channel: i.channel,
Locale: i.locale,
GuildLocale: i.guildLocale,
Member: i.member,
Expand Down
2 changes: 2 additions & 0 deletions discord/interaction_modal_submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (i *ModalSubmitInteraction) UnmarshalJSON(data []byte) error {
i.baseInteraction.version = interaction.Version
i.baseInteraction.guildID = interaction.GuildID
i.baseInteraction.channelID = interaction.ChannelID
i.baseInteraction.channel = interaction.Channel
i.baseInteraction.locale = interaction.Locale
i.baseInteraction.guildLocale = interaction.GuildLocale
i.baseInteraction.member = interaction.Member
Expand All @@ -49,6 +50,7 @@ func (i ModalSubmitInteraction) MarshalJSON() ([]byte, error) {
Version: i.version,
GuildID: i.guildID,
ChannelID: i.channelID,
Channel: i.channel,
Locale: i.locale,
GuildLocale: i.guildLocale,
Member: i.member,
Expand Down
4 changes: 4 additions & 0 deletions discord/interaction_ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func (PingInteraction) ChannelID() snowflake.ID {
return 0
}

func (PingInteraction) Channel() *PartialChannel {
return nil
}

func (PingInteraction) Locale() Locale {
return ""
}
Expand Down
8 changes: 4 additions & 4 deletions events/interaction_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (e *ApplicationCommandInteractionCreate) Guild() (discord.Guild, bool) {
// Channel returns the discord.GuildMessageChannel that the interaction happened in.
// This only returns cached channels.
func (e *ApplicationCommandInteractionCreate) Channel() (discord.GuildMessageChannel, bool) {
return e.Client().Caches().GuildMessageChannel(e.ChannelID())
return e.Client().Caches().GuildMessageChannel(e.ApplicationCommandInteraction.Channel().ID)
}

// CreateMessage responds to the interaction with a new message.
Expand Down Expand Up @@ -93,7 +93,7 @@ func (e *ComponentInteractionCreate) Guild() (discord.Guild, bool) {
// Channel returns the discord.GuildMessageChannel that the interaction happened in.
// This only returns cached channels.
func (e *ComponentInteractionCreate) Channel() (discord.GuildMessageChannel, bool) {
return e.Client().Caches().GuildMessageChannel(e.ChannelID())
return e.Client().Caches().GuildMessageChannel(e.ComponentInteraction.Channel().ID)
}

// CreateMessage responds to the interaction with a new message.
Expand Down Expand Up @@ -145,7 +145,7 @@ func (e *AutocompleteInteractionCreate) Guild() (discord.Guild, bool) {
// Channel returns the discord.GuildMessageChannel that the interaction happened in.
// This only returns cached channels.
func (e *AutocompleteInteractionCreate) Channel() (discord.GuildMessageChannel, bool) {
return e.Client().Caches().GuildMessageChannel(e.ChannelID())
return e.Client().Caches().GuildMessageChannel(e.AutocompleteInteraction.Channel().ID)
}

// Result responds to the interaction with a slice of choices.
Expand Down Expand Up @@ -173,7 +173,7 @@ func (e *ModalSubmitInteractionCreate) Guild() (discord.Guild, bool) {
// Channel returns the discord.GuildMessageChannel that the interaction happened in.
// This only returns cached channels.
func (e *ModalSubmitInteractionCreate) Channel() (discord.GuildMessageChannel, bool) {
return e.Client().Caches().GuildMessageChannel(e.ChannelID())
return e.Client().Caches().GuildMessageChannel(e.ModalSubmitInteraction.Channel().ID)
}

// CreateMessage responds to the interaction with a new message.
Expand Down

0 comments on commit a3e65bd

Please sign in to comment.