Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 committed Aug 15, 2024
1 parent 3902c58 commit 16682b6
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 18 deletions.
5 changes: 5 additions & 0 deletions discord/soundboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ type SoundboardSoundUpdate struct {
EmojiID *json.Nullable[snowflake.ID] `json:"emoji_id,omitempty"`
EmojiName *json.Nullable[string] `json:"emoji_name,omitempty"`
}

type SendSoundboardSound struct {
SoundID snowflake.ID `json:"sound_id"`
SourceGuildID *snowflake.ID `json:"source_guild_id,omitempty"`
}
8 changes: 4 additions & 4 deletions events/guild_emoji_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ type EmojisUpdate struct {
gateway.EventGuildEmojisUpdate
}

// GenericEmoji is called upon receiving EmojiCreate , EmojiUpdate or EmojiDelete (requires gateway.IntentGuildEmojisAndStickers)
// GenericEmoji is called upon receiving EmojiCreate , EmojiUpdate or EmojiDelete (requires gateway.IntentGuildExpressions)
type GenericEmoji struct {
*GenericEvent
GuildID snowflake.ID
Emoji discord.Emoji
}

// EmojiCreate indicates that a new discord.Emoji got created in a discord.Guild (requires gateway.IntentGuildEmojisAndStickers)
// EmojiCreate indicates that a new discord.Emoji got created in a discord.Guild (requires gateway.IntentGuildExpressions)
type EmojiCreate struct {
*GenericEmoji
}

// EmojiUpdate indicates that a discord.Emoji got updated in a discord.Guild (requires gateway.IntentGuildEmojisAndStickers)
// EmojiUpdate indicates that a discord.Emoji got updated in a discord.Guild (requires gateway.IntentGuildExpressions)
type EmojiUpdate struct {
*GenericEmoji
OldEmoji discord.Emoji
}

// EmojiDelete indicates that a discord.Emoji got deleted in a discord.Guild (requires gateway.IntentGuildEmojisAndStickers)
// EmojiDelete indicates that a discord.Emoji got deleted in a discord.Guild (requires gateway.IntentGuildExpressions)
type EmojiDelete struct {
*GenericEmoji
}
14 changes: 10 additions & 4 deletions events/guild_soundboard_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,36 @@ import (
"github.com/disgoorg/snowflake/v2"
)

// GenericGuildSoundboardSound is called upon receiving GuildSoundboardSoundCreate and GuildSoundboardSoundUpdate
// GenericGuildSoundboardSound is called upon receiving GuildSoundboardSoundCreate and GuildSoundboardSoundUpdate (requires gateway.IntentGuildExpressions)
type GenericGuildSoundboardSound struct {
*GenericEvent
discord.SoundboardSound
}

// GuildSoundboardSoundCreate indicates that a discord.SoundboardSound was created in a discord.Guild
// GuildSoundboardSoundCreate indicates that a discord.SoundboardSound was created in a discord.Guild (requires gateway.IntentGuildExpressions)
type GuildSoundboardSoundCreate struct {
*GenericGuildSoundboardSound
}

// GuildSoundboardSoundUpdate indicates that a discord.SoundboardSound was updated in a discord.Guild
// GuildSoundboardSoundUpdate indicates that a discord.SoundboardSound was updated in a discord.Guild (requires gateway.IntentGuildExpressions)
type GuildSoundboardSoundUpdate struct {
*GenericGuildSoundboardSound
OldGuildSoundboardSound discord.SoundboardSound
}

// GuildSoundboardSoundDelete indicates that a discord.SoundboardSound was deleted in a discord.Guild
// GuildSoundboardSoundDelete indicates that a discord.SoundboardSound was deleted in a discord.Guild (requires gateway.IntentGuildExpressions)
type GuildSoundboardSoundDelete struct {
*GenericEvent
SoundID snowflake.ID
GuildID snowflake.ID
}

// GuildSoundboardSoundsUpdate indicates when multiple discord.Guild soundboard sounds were updated (requires gateway.IntentGuildExpressions)
type GuildSoundboardSoundsUpdate struct {
*GenericEvent
SoundboardSounds []discord.SoundboardSound
}

// SoundboardSounds is a response to gateway.OpcodeRequestSoundboardSounds
type SoundboardSounds struct {
*GenericEvent
Expand Down
8 changes: 4 additions & 4 deletions events/guild_sticker_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ type StickersUpdate struct {
gateway.EventGuildStickersUpdate
}

// GenericSticker is called upon receiving StickerCreate , StickerUpdate or StickerDelete (requires gateway.IntentGuildEmojisAndStickers)
// GenericSticker is called upon receiving StickerCreate , StickerUpdate or StickerDelete (requires gateway.IntentGuildExpressions)
type GenericSticker struct {
*GenericEvent
GuildID snowflake.ID
Sticker discord.Sticker
}

// StickerCreate indicates that a new discord.Sticker got created in a discord.Guild (requires gateway.IntentGuildEmojisAndStickers)
// StickerCreate indicates that a new discord.Sticker got created in a discord.Guild (requires gateway.IntentGuildExpressions)
type StickerCreate struct {
*GenericSticker
}

// StickerUpdate indicates that a discord.Sticker got updated in a discord.Guild (requires gateway.IntentGuildEmojisAndStickers)
// StickerUpdate indicates that a discord.Sticker got updated in a discord.Guild (requires gateway.IntentGuildExpressions)
type StickerUpdate struct {
*GenericSticker
OldSticker discord.Sticker
}

// StickerDelete indicates that a discord.Sticker got deleted in a discord.Guild (requires gateway.IntentGuildEmojisAndStickers)
// StickerDelete indicates that a discord.Sticker got deleted in a discord.Guild (requires gateway.IntentGuildExpressions)
type StickerDelete struct {
*GenericSticker
}
13 changes: 9 additions & 4 deletions events/listener_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ type ListenerAdapter struct {
OnGuildMessageReactionRemoveAll func(event *GuildMessageReactionRemoveAll)

// Guild Soundboard Events
OnGuildSoundboardSoundCreate func(event *GuildSoundboardSoundCreate)
OnGuildSoundboardSoundUpdate func(event *GuildSoundboardSoundUpdate)
OnGuildSoundboardSoundDelete func(event *GuildSoundboardSoundDelete)
OnSoundboardSounds func(event *SoundboardSounds)
OnGuildSoundboardSoundCreate func(event *GuildSoundboardSoundCreate)
OnGuildSoundboardSoundUpdate func(event *GuildSoundboardSoundUpdate)
OnGuildSoundboardSoundDelete func(event *GuildSoundboardSoundDelete)
OnGuildSoundboardSoundsUpdate func(event *GuildSoundboardSoundsUpdate)
OnSoundboardSounds func(event *SoundboardSounds)

// Guild Voice Events
OnVoiceServerUpdate func(event *VoiceServerUpdate)
Expand Down Expand Up @@ -498,6 +499,10 @@ func (l *ListenerAdapter) OnEvent(event bot.Event) {
if listener := l.OnGuildSoundboardSoundDelete; listener != nil {
listener(e)
}
case *GuildSoundboardSoundsUpdate:
if listener := l.OnGuildSoundboardSoundsUpdate; listener != nil {
listener(e)
}
case *SoundboardSounds:
if listener := l.OnSoundboardSounds; listener != nil {
listener(e)
Expand Down
1 change: 1 addition & 0 deletions gateway/gateway_event_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
EventTypeGuildSoundboardSoundCreate EventType = "GUILD_SOUNDBOARD_SOUND_CREATE"
EventTypeGuildSoundboardSoundUpdate EventType = "GUILD_SOUNDBOARD_SOUND_UPDATE"
EventTypeGuildSoundboardSoundDelete EventType = "GUILD_SOUNDBOARD_SOUND_DELETE"
EventTypeGuildSoundboardSoundsUpdate EventType = "GUILD_SOUNDBOARD_SOUNDS_UPDATE"
EventTypeIntegrationCreate EventType = "INTEGRATION_CREATE"
EventTypeIntegrationUpdate EventType = "INTEGRATION_UPDATE"
EventTypeIntegrationDelete EventType = "INTEGRATION_DELETE"
Expand Down
5 changes: 5 additions & 0 deletions gateway/gateway_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ type EventGuildSoundboardSoundDelete struct {
func (EventGuildSoundboardSoundDelete) messageData() {}
func (EventGuildSoundboardSoundDelete) eventData() {}

type EventGuildSoundboardSoundsUpdate []discord.SoundboardSound

func (EventGuildSoundboardSoundsUpdate) messageData() {}
func (EventGuildSoundboardSoundsUpdate) eventData() {}

type EventInteractionCreate struct {
discord.Interaction
}
Expand Down
7 changes: 5 additions & 2 deletions gateway/gateway_intents.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
IntentGuilds Intents = 1 << iota
IntentGuildMembers
IntentGuildModeration
// Deprecated: Use IntentGuildExpressions instead
IntentGuildEmojisAndStickers
IntentGuildIntegrations
IntentGuildWebhooks
Expand All @@ -34,10 +35,12 @@ const (
IntentGuildMessagePolls
IntentDirectMessagePolls

IntentGuildExpressions = IntentGuildEmojisAndStickers

IntentsGuild = IntentGuilds |
IntentGuildMembers |
IntentGuildModeration |
IntentGuildEmojisAndStickers |
IntentGuildExpressions |
IntentGuildIntegrations |
IntentGuildWebhooks |
IntentGuildInvites |
Expand All @@ -59,7 +62,7 @@ const (

IntentsNonPrivileged = IntentGuilds |
IntentGuildModeration |
IntentGuildEmojisAndStickers |
IntentGuildExpressions |
IntentGuildIntegrations |
IntentGuildWebhooks |
IntentGuildInvites |
Expand Down
5 changes: 5 additions & 0 deletions gateway/gateway_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ func UnmarshalEventData(data []byte, eventType EventType) (EventData, error) {
err = json.Unmarshal(data, &d)
eventData = d

case EventTypeGuildSoundboardSoundsUpdate:
var d EventGuildSoundboardSoundsUpdate
err = json.Unmarshal(data, &d)
eventData = d

case EventTypeIntegrationCreate:
var d EventIntegrationCreate
err = json.Unmarshal(data, &d)
Expand Down
1 change: 1 addition & 0 deletions handlers/all_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ var allEventHandlers = []bot.GatewayEventHandler{
bot.NewGatewayEventHandler(gateway.EventTypeGuildSoundboardSoundCreate, gatewayHandlerGuildSoundboardSoundCreate),
bot.NewGatewayEventHandler(gateway.EventTypeGuildSoundboardSoundUpdate, gatewayHandlerGuildSoundboardSoundUpdate),
bot.NewGatewayEventHandler(gateway.EventTypeGuildSoundboardSoundDelete, gatewayHandlerGuildSoundboardSoundDelete),
bot.NewGatewayEventHandler(gateway.EventTypeGuildSoundboardSoundsUpdate, gatewayHandlerGuildSoundboardSoundsUpdate),
bot.NewGatewayEventHandler(gateway.EventTypeSoundboardSounds, gatewayHandlerSoundboardSounds),

bot.NewGatewayEventHandler(gateway.EventTypeIntegrationCreate, gatewayHandlerIntegrationCreate),
Expand Down
11 changes: 11 additions & 0 deletions handlers/guild_soundboard_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ func gatewayHandlerGuildSoundboardSoundDelete(client bot.Client, sequenceNumber
})
}

func gatewayHandlerGuildSoundboardSoundsUpdate(client bot.Client, sequenceNumber int, shardID int, event gateway.EventGuildSoundboardSoundsUpdate) {
for _, sound := range event {
client.Caches().AddGuildSoundboardSound(sound)
}

client.EventManager().DispatchEvent(&events.GuildSoundboardSoundsUpdate{
GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID),
SoundboardSounds: event,
})
}

func gatewayHandlerSoundboardSounds(client bot.Client, sequenceNumber int, shardID int, event gateway.EventSoundboardSounds) {
client.EventManager().DispatchEvent(&events.SoundboardSounds{
GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID),
Expand Down
4 changes: 4 additions & 0 deletions rest/rest_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ var (
// Sounds
var (
GetSoundboardDefaultSounds = NewEndpoint(http.MethodGet, "/soundboard-default-sounds")
GetGuildSoundboardSounds = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/soundboard-sounds")
CreateGuildSoundboardSound = NewEndpoint(http.MethodPost, "/guilds/{guild.id}/soundboard-sounds")
GetGuildSoundboardSound = NewEndpoint(http.MethodPost, "/guilds/{guild.id}/soundboard-sounds/{sound.id}")
UpdateGuildSoundboardSound = NewEndpoint(http.MethodPatch, "/guilds/{guild.id}/soundboard-sounds/{sound.id}")
DeleteGuildSoundboardSound = NewEndpoint(http.MethodDelete, "/guilds/{guild.id}/soundboard-sounds/{sound.id}")
)
Expand Down Expand Up @@ -184,6 +186,8 @@ var (

GetPollAnswerVotes = NewEndpoint(http.MethodGet, "/channels/{channel.id}/polls/{message.id}/answers/{answer.id}")
ExpirePoll = NewEndpoint(http.MethodPost, "/channels/{channel.id}/polls/{message.id}/expire")

SendSoundboardSound = NewEndpoint(http.MethodPost, "/channels/{channel.id}/send-soundboard-sound")
)

// Threads
Expand Down
25 changes: 25 additions & 0 deletions rest/soundboard_sounds.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ func NewSoundboardSounds(client Client) SoundboardSounds {

type SoundboardSounds interface {
GetSoundboardDefaultSounds(opts ...RequestOpt) ([]discord.SoundboardSound, error)
GetGuildSoundboardSounds(guildID snowflake.ID, opts ...RequestOpt) ([]discord.SoundboardSound, error)
CreateGuildSoundboardSound(guildID snowflake.ID, soundCreate discord.SoundboardSoundCreate, opts ...RequestOpt) (*discord.SoundboardSound, error)
GetGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID, opts ...RequestOpt) (*discord.SoundboardSound, error)
UpdateGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID, soundUpdate discord.SoundboardSoundUpdate, opts ...RequestOpt) (*discord.SoundboardSound, error)
DeleteGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID, opts ...RequestOpt) error
SendSoundboardSound(channelID snowflake.ID, sendSound discord.SendSoundboardSound, opts ...RequestOpt) error
}

type soundsImpl struct {
Expand All @@ -27,11 +30,25 @@ func (s *soundsImpl) GetSoundboardDefaultSounds(opts ...RequestOpt) (sounds []di
return
}

func (s *soundsImpl) GetGuildSoundboardSounds(guildID snowflake.ID, opts ...RequestOpt) (sounds []discord.SoundboardSound, err error) {
var rs soundsResponse
err = s.client.Do(GetGuildSoundboardSounds.Compile(nil, guildID), nil, &rs, opts...)
if err == nil {
sounds = rs.Items
}
return
}

func (s *soundsImpl) CreateGuildSoundboardSound(guildID snowflake.ID, soundCreate discord.SoundboardSoundCreate, opts ...RequestOpt) (sound *discord.SoundboardSound, err error) {
err = s.client.Do(CreateGuildSoundboardSound.Compile(nil, guildID), soundCreate, &sound, opts...)
return
}

func (s *soundsImpl) GetGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID, opts ...RequestOpt) (sound *discord.SoundboardSound, err error) {
err = s.client.Do(GetGuildSoundboardSound.Compile(nil, guildID, soundID), nil, &sound, opts...)
return
}

func (s *soundsImpl) UpdateGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID, soundUpdate discord.SoundboardSoundUpdate, opts ...RequestOpt) (sound *discord.SoundboardSound, err error) {
err = s.client.Do(UpdateGuildSoundboardSound.Compile(nil, guildID, soundID), soundUpdate, &sound, opts...)
return
Expand All @@ -40,3 +57,11 @@ func (s *soundsImpl) UpdateGuildSoundboardSound(guildID snowflake.ID, soundID sn
func (s *soundsImpl) DeleteGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID, opts ...RequestOpt) error {
return s.client.Do(DeleteGuildSoundboardSound.Compile(nil, guildID, soundID), nil, nil, opts...)
}

func (s *soundsImpl) SendSoundboardSound(channelID snowflake.ID, sendSound discord.SendSoundboardSound, opts ...RequestOpt) error {
return s.client.Do(SendSoundboardSound.Compile(nil, channelID), sendSound, nil, opts...)
}

type soundsResponse struct {
Items []discord.SoundboardSound `json:"items"`
}

0 comments on commit 16682b6

Please sign in to comment.