Skip to content

Commit

Permalink
Merge branch 'master' into patch/soundboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian authored May 16, 2024
2 parents 48ee79e + ee8814f commit 83fb472
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 25 deletions.
20 changes: 14 additions & 6 deletions discord/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ 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"`
Guild *InteractionGuild `json:"guild,omitempty"`
GuildID *snowflake.ID `json:"guild_id,omitempty"`
// Deprecated: Use Channel instead
ChannelID snowflake.ID `json:"channel_id,omitempty"`
Channel InteractionChannel `json:"channel,omitempty"`
Expand All @@ -55,6 +56,7 @@ type Interaction interface {
ApplicationID() snowflake.ID
Token() string
Version() int
Guild() *InteractionGuild
GuildID() *snowflake.ID
// Deprecated: Use Interaction.Channel instead
ChannelID() snowflake.ID
Expand Down Expand Up @@ -203,3 +205,9 @@ func (c InteractionChannel) MarshalJSON() ([]byte, error) {

return json.Merge(mData, pData)
}

type InteractionGuild struct {
ID snowflake.ID `json:"id"`
Locale Locale `json:"locale"`
Features []GuildFeature `json:"features"`
}
2 changes: 2 additions & 0 deletions discord/interaction_application_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (i *ApplicationCommandInteraction) UnmarshalJSON(data []byte) error {
i.baseInteraction.applicationID = interaction.ApplicationID
i.baseInteraction.token = interaction.Token
i.baseInteraction.version = interaction.Version
i.baseInteraction.guild = interaction.Guild
i.baseInteraction.guildID = interaction.GuildID
i.baseInteraction.channelID = interaction.ChannelID
i.baseInteraction.channel = interaction.Channel
Expand Down Expand Up @@ -97,6 +98,7 @@ func (i ApplicationCommandInteraction) MarshalJSON() ([]byte, error) {
ApplicationID: i.applicationID,
Token: i.token,
Version: i.version,
Guild: i.guild,
GuildID: i.guildID,
ChannelID: i.channelID,
Channel: i.channel,
Expand Down
2 changes: 2 additions & 0 deletions discord/interaction_autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (i *AutocompleteInteraction) UnmarshalJSON(data []byte) error {
i.baseInteraction.applicationID = interaction.ApplicationID
i.baseInteraction.token = interaction.Token
i.baseInteraction.version = interaction.Version
i.baseInteraction.guild = interaction.Guild
i.baseInteraction.guildID = interaction.GuildID
i.baseInteraction.channelID = interaction.ChannelID
i.baseInteraction.channel = interaction.Channel
Expand Down Expand Up @@ -54,6 +55,7 @@ func (i AutocompleteInteraction) MarshalJSON() ([]byte, error) {
ApplicationID: i.applicationID,
Token: i.token,
Version: i.version,
Guild: i.guild,
GuildID: i.guildID,
ChannelID: i.channelID,
Channel: i.channel,
Expand Down
4 changes: 4 additions & 0 deletions discord/interaction_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type baseInteraction struct {
applicationID snowflake.ID
token string
version int
guild *InteractionGuild
guildID *snowflake.ID
channelID snowflake.ID
channel InteractionChannel
Expand All @@ -36,6 +37,9 @@ func (i baseInteraction) Token() string {
func (i baseInteraction) Version() int {
return i.version
}
func (i baseInteraction) Guild() *InteractionGuild {
return i.guild
}
func (i baseInteraction) GuildID() *snowflake.ID {
return i.guildID
}
Expand Down
2 changes: 2 additions & 0 deletions discord/interaction_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (i *ComponentInteraction) UnmarshalJSON(data []byte) error {
i.baseInteraction.applicationID = interaction.ApplicationID
i.baseInteraction.token = interaction.Token
i.baseInteraction.version = interaction.Version
i.baseInteraction.guild = interaction.Guild
i.baseInteraction.guildID = interaction.GuildID
i.baseInteraction.channelID = interaction.ChannelID
i.baseInteraction.channel = interaction.Channel
Expand Down Expand Up @@ -110,6 +111,7 @@ func (i ComponentInteraction) MarshalJSON() ([]byte, error) {
ApplicationID: i.applicationID,
Token: i.token,
Version: i.version,
Guild: i.guild,
GuildID: i.guildID,
ChannelID: i.channelID,
Channel: i.channel,
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 @@ -24,6 +24,7 @@ func (i *ModalSubmitInteraction) UnmarshalJSON(data []byte) error {
i.baseInteraction.applicationID = interaction.ApplicationID
i.baseInteraction.token = interaction.Token
i.baseInteraction.version = interaction.Version
i.baseInteraction.guild = interaction.Guild
i.baseInteraction.guildID = interaction.GuildID
i.baseInteraction.channelID = interaction.ChannelID
i.baseInteraction.channel = interaction.Channel
Expand Down Expand Up @@ -51,6 +52,7 @@ func (i ModalSubmitInteraction) MarshalJSON() ([]byte, error) {
ApplicationID: i.applicationID,
Token: i.token,
Version: i.version,
Guild: i.guild,
GuildID: i.guildID,
ChannelID: i.channelID,
Channel: i.channel,
Expand Down
3 changes: 3 additions & 0 deletions discord/interaction_ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func (i PingInteraction) Version() int {
func (i PingInteraction) CreatedAt() time.Time {
return i.id.Time()
}
func (PingInteraction) Guild() *InteractionGuild {
return nil
}

func (PingInteraction) GuildID() *snowflake.ID {
return nil
Expand Down
7 changes: 7 additions & 0 deletions discord/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,13 @@ type ReactionCountDetails struct {
Normal int `json:"normal"`
}

type MessageReactionType int

const (
MessageReactionTypeNormal MessageReactionType = iota
MessageReactionTypeBurst
)

// MessageActivityType is the type of MessageActivity https://com/developers/docs/resources/channel#message-object-message-activity-types
type MessageActivityType int

Expand Down
34 changes: 18 additions & 16 deletions gateway/gateway_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,16 @@ func (EventGuildAuditLogEntryCreate) messageData() {}
func (EventGuildAuditLogEntryCreate) eventData() {}

type EventMessageReactionAdd struct {
UserID snowflake.ID `json:"user_id"`
ChannelID snowflake.ID `json:"channel_id"`
MessageID snowflake.ID `json:"message_id"`
GuildID *snowflake.ID `json:"guild_id"`
Member *discord.Member `json:"member"`
Emoji discord.PartialEmoji `json:"emoji"`
MessageAuthorID *snowflake.ID `json:"message_author_id"`
BurstColors []string `json:"burst_colors"`
Burst bool `json:"burst"`
UserID snowflake.ID `json:"user_id"`
ChannelID snowflake.ID `json:"channel_id"`
MessageID snowflake.ID `json:"message_id"`
GuildID *snowflake.ID `json:"guild_id"`
Member *discord.Member `json:"member"`
Emoji discord.PartialEmoji `json:"emoji"`
MessageAuthorID *snowflake.ID `json:"message_author_id"`
BurstColors []string `json:"burst_colors"`
Burst bool `json:"burst"`
Type discord.MessageReactionType `json:"type"`
}

func (e *EventMessageReactionAdd) UnmarshalJSON(data []byte) error {
Expand All @@ -215,13 +216,14 @@ func (EventMessageReactionAdd) messageData() {}
func (EventMessageReactionAdd) eventData() {}

type EventMessageReactionRemove struct {
UserID snowflake.ID `json:"user_id"`
ChannelID snowflake.ID `json:"channel_id"`
MessageID snowflake.ID `json:"message_id"`
GuildID *snowflake.ID `json:"guild_id"`
Emoji discord.PartialEmoji `json:"emoji"`
BurstColors []string `json:"burst_colors"`
Burst bool `json:"burst"`
UserID snowflake.ID `json:"user_id"`
ChannelID snowflake.ID `json:"channel_id"`
MessageID snowflake.ID `json:"message_id"`
GuildID *snowflake.ID `json:"guild_id"`
Emoji discord.PartialEmoji `json:"emoji"`
BurstColors []string `json:"burst_colors"`
Burst bool `json:"burst"`
Type discord.MessageReactionType `json:"type"`
}

func (EventMessageReactionRemove) messageData() {}
Expand Down
2 changes: 2 additions & 0 deletions handlers/guild_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ func gatewayHandlerGuildDelete(client bot.Client, sequenceNumber int, shardID in
client.Caches().RemoveEmojisByGuildID(event.ID)
client.Caches().RemoveStickersByGuildID(event.ID)
client.Caches().RemoveRolesByGuildID(event.ID)
client.Caches().RemoveMembersByGuildID(event.ID)
client.Caches().RemoveStageInstancesByGuildID(event.ID)
client.Caches().RemoveGuildScheduledEventsByGuildID(event.ID)
client.Caches().RemoveGuildSoundboardSoundsByGuildID(event.ID)
client.Caches().RemoveMessagesByGuildID(event.ID)

Expand Down
15 changes: 12 additions & 3 deletions rest/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Channels interface {
BulkDeleteMessages(channelID snowflake.ID, messageIDs []snowflake.ID, opts ...RequestOpt) error
CrosspostMessage(channelID snowflake.ID, messageID snowflake.ID, opts ...RequestOpt) (*discord.Message, error)

GetReactions(channelID snowflake.ID, messageID snowflake.ID, emoji string, opts ...RequestOpt) ([]discord.User, error)
GetReactions(channelID snowflake.ID, messageID snowflake.ID, emoji string, reactionType discord.MessageReactionType, after int, limit int, opts ...RequestOpt) ([]discord.User, error)
AddReaction(channelID snowflake.ID, messageID snowflake.ID, emoji string, opts ...RequestOpt) error
RemoveOwnReaction(channelID snowflake.ID, messageID snowflake.ID, emoji string, opts ...RequestOpt) error
RemoveUserReaction(channelID snowflake.ID, messageID snowflake.ID, emoji string, userID snowflake.ID, opts ...RequestOpt) error
Expand Down Expand Up @@ -184,8 +184,17 @@ func (s *channelImpl) CrosspostMessage(channelID snowflake.ID, messageID snowfla
return
}

func (s *channelImpl) GetReactions(channelID snowflake.ID, messageID snowflake.ID, emoji string, opts ...RequestOpt) (users []discord.User, err error) {
err = s.client.Do(GetReactions.Compile(nil, channelID, messageID, emoji), nil, &users, opts...)
func (s *channelImpl) GetReactions(channelID snowflake.ID, messageID snowflake.ID, emoji string, reactionType discord.MessageReactionType, after int, limit int, opts ...RequestOpt) (users []discord.User, err error) {
values := discord.QueryValues{
"type": reactionType,
}
if after != 0 {
values["after"] = after
}
if limit != 0 {
values["limit"] = limit
}
err = s.client.Do(GetReactions.Compile(values, channelID, messageID, emoji), nil, &users, opts...)
return
}

Expand Down

0 comments on commit 83fb472

Please sign in to comment.