From acadcd4c7c5fd4a95ef33595b3f8c449af8274fd Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 16:10:22 +0200 Subject: [PATCH 01/36] Add GuildVoiceChannelEffectSend --- discord/soundboard.go | 8 ++++++++ events/guild_voice_events.go | 5 +++++ gateway/gateway_event_type.go | 1 + gateway/gateway_events.go | 15 +++++++++++++++ gateway/gateway_messages.go | 5 +++++ handlers/all_handlers.go | 1 + handlers/voice_handlers.go | 7 +++++++ 7 files changed, 42 insertions(+) create mode 100644 discord/soundboard.go diff --git a/discord/soundboard.go b/discord/soundboard.go new file mode 100644 index 000000000..a18b3a09f --- /dev/null +++ b/discord/soundboard.go @@ -0,0 +1,8 @@ +package discord + +type SoundboardAnimationType int + +const ( + SoundboardAnimationTypePremium SoundboardAnimationType = iota + SoundboardAnimationTypeBasic +) diff --git a/events/guild_voice_events.go b/events/guild_voice_events.go index bc3a5cbbb..cc1aba9f8 100644 --- a/events/guild_voice_events.go +++ b/events/guild_voice_events.go @@ -5,6 +5,11 @@ import ( "github.com/disgoorg/disgo/gateway" ) +type GuildVoiceChannelEffectSend struct { + *GenericEvent + gateway.EventVoiceChannelEffectSend +} + // GenericGuildVoiceState is called upon receiving GuildVoiceJoin , GuildVoiceMove , GuildVoiceLeave type GenericGuildVoiceState struct { *GenericEvent diff --git a/gateway/gateway_event_type.go b/gateway/gateway_event_type.go index 88ebd49c4..33d0402a8 100644 --- a/gateway/gateway_event_type.go +++ b/gateway/gateway_event_type.go @@ -66,6 +66,7 @@ const ( EventTypeStageInstanceUpdate EventType = "STAGE_INSTANCE_UPDATE" EventTypeTypingStart EventType = "TYPING_START" EventTypeUserUpdate EventType = "USER_UPDATE" + EventTypeVoiceChannelEffectSend EventType = "VOICE_CHANNEL_EFFECT_SEND" EventTypeVoiceStateUpdate EventType = "VOICE_STATE_UPDATE" EventTypeVoiceServerUpdate EventType = "VOICE_SERVER_UPDATE" EventTypeWebhooksUpdate EventType = "WEBHOOKS_UPDATE" diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index 3793f8050..5011c2e6c 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -563,6 +563,21 @@ type EventUserUpdate struct { func (EventUserUpdate) messageData() {} func (EventUserUpdate) eventData() {} +type EventVoiceChannelEffectSend struct { + ChannelID snowflake.ID `json:"channel_id"` + GuildID snowflake.ID `json:"guild_id"` + UserID snowflake.ID `json:"user_id"` + Emoji *discord.Emoji `json:"emoji"` + AnimationType *discord.SoundboardAnimationType `json:"animation_type,omitempty"` + AnimationID *int `json:"animation_id,omitempty"` + SoundID *snowflake.ID `json:"sound_id,omitempty"` + SoundOverridePath *string `json:"sound_override_path"` + SoundVolume *float64 `json:"sound_volume,omitempty"` +} + +func (EventVoiceChannelEffectSend) messageData() {} +func (EventVoiceChannelEffectSend) eventData() {} + type EventVoiceStateUpdate struct { discord.VoiceState Member discord.Member `json:"member"` diff --git a/gateway/gateway_messages.go b/gateway/gateway_messages.go index 686d6d06f..4866eaac0 100644 --- a/gateway/gateway_messages.go +++ b/gateway/gateway_messages.go @@ -394,6 +394,11 @@ func UnmarshalEventData(data []byte, eventType EventType) (EventData, error) { err = json.Unmarshal(data, &d) eventData = d + case EventTypeVoiceChannelEffectSend: + var d EventVoiceChannelEffectSend + err = json.Unmarshal(data, &d) + eventData = d + case EventTypeVoiceStateUpdate: var d EventVoiceStateUpdate err = json.Unmarshal(data, &d) diff --git a/handlers/all_handlers.go b/handlers/all_handlers.go index 5e1f2b5b0..26bc2131a 100644 --- a/handlers/all_handlers.go +++ b/handlers/all_handlers.go @@ -111,6 +111,7 @@ var allEventHandlers = []bot.GatewayEventHandler{ bot.NewGatewayEventHandler(gateway.EventTypeTypingStart, gatewayHandlerTypingStart), bot.NewGatewayEventHandler(gateway.EventTypeUserUpdate, gatewayHandlerUserUpdate), + bot.NewGatewayEventHandler(gateway.EventTypeVoiceChannelEffectSend, gatewayHandlerVoiceChannelEffectSend), bot.NewGatewayEventHandler(gateway.EventTypeVoiceStateUpdate, gatewayHandlerVoiceStateUpdate), bot.NewGatewayEventHandler(gateway.EventTypeVoiceServerUpdate, gatewayHandlerVoiceServerUpdate), diff --git a/handlers/voice_handlers.go b/handlers/voice_handlers.go index ea906ccc3..687f64f8c 100644 --- a/handlers/voice_handlers.go +++ b/handlers/voice_handlers.go @@ -6,6 +6,13 @@ import ( "github.com/disgoorg/disgo/gateway" ) +func gatewayHandlerVoiceChannelEffectSend(client bot.Client, sequenceNumber int, shardID int, event gateway.EventVoiceChannelEffectSend) { + client.EventManager().DispatchEvent(&events.GuildVoiceChannelEffectSend{ + GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), + EventVoiceChannelEffectSend: event, + }) +} + func gatewayHandlerVoiceStateUpdate(client bot.Client, sequenceNumber int, shardID int, event gateway.EventVoiceStateUpdate) { member := event.Member From 1bef49cff019b883f759cb0f3b6a97ffe9c79365 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 17:47:52 +0200 Subject: [PATCH 02/36] Add Soundboard --- discord/guild.go | 1 + discord/sound.go | 59 ++++++++++++++++++++++++++++++++++++++++++ discord/soundboard.go | 43 ++++++++++++++++++++++++++++++ discord/url.go | 10 +++++++ rest/rest.go | 3 +++ rest/rest_endpoints.go | 8 ++++++ rest/sounds.go | 42 ++++++++++++++++++++++++++++++ 7 files changed, 166 insertions(+) create mode 100644 discord/sound.go create mode 100644 rest/sounds.go diff --git a/discord/guild.go b/discord/guild.go index 5ca15bc52..081697b85 100644 --- a/discord/guild.go +++ b/discord/guild.go @@ -114,6 +114,7 @@ const ( GuildFeaturePreviewEnabled GuildFeature = "PREVIEW_ENABLED" GuildFeatureRaidAlertsDisabled GuildFeature = "RAID_ALERTS_DISABLED" GuildFeatureRoleIcons GuildFeature = "ROLE_ICONS" + GuildFeatureSoundboard GuildFeature = "SOUNDBOARD" GuildFeatureTicketedEventsEnabled GuildFeature = "TICKETED_EVENTS_ENABLED" GuildFeatureVanityURL GuildFeature = "VANITY_URL" GuildFeatureVerified GuildFeature = "VERIFIED" diff --git a/discord/sound.go b/discord/sound.go new file mode 100644 index 000000000..18d05250f --- /dev/null +++ b/discord/sound.go @@ -0,0 +1,59 @@ +package discord + +import ( + "encoding/base64" + "fmt" + "io" + + "github.com/disgoorg/json" +) + +type SoundType string + +const ( + SoundTypeMP3 SoundType = "audio/mpeg" + SoundTypeOGG SoundType = "audio/ogg" + SoundTypeWAV SoundType = "audio/wav" + SoundTypeUnknown = SoundTypeMP3 +) + +func (t SoundType) GetMIME() string { + return string(t) +} + +func (t SoundType) GetHeader() string { + return "data:" + string(t) + ";base64" +} + +var _ json.Marshaler = (*Sound)(nil) +var _ fmt.Stringer = (*Sound)(nil) + +func NewSound(soundType SoundType, reader io.Reader) (*Sound, error) { + data, err := io.ReadAll(reader) + if err != nil { + return nil, err + } + return NewSoundRaw(soundType, data), nil +} + +func NewSoundRaw(soundType SoundType, src []byte) *Sound { + data := make([]byte, base64.StdEncoding.EncodedLen(len(src))) + base64.StdEncoding.Encode(data, src) + return &Sound{Type: soundType, Data: data} +} + +type Sound struct { + Type SoundType + Data []byte +} + +func (s Sound) MarshalJSON() ([]byte, error) { + return json.Marshal(s.String()) +} + +func (s Sound) String() string { + if len(s.Data) == 0 { + return "" + } + return s.Type.GetHeader() + "," + string(s.Data) +} diff --git a/discord/soundboard.go b/discord/soundboard.go index a18b3a09f..943311787 100644 --- a/discord/soundboard.go +++ b/discord/soundboard.go @@ -1,8 +1,51 @@ package discord +import ( + "github.com/disgoorg/json" + "github.com/disgoorg/snowflake/v2" +) + type SoundboardAnimationType int const ( SoundboardAnimationTypePremium SoundboardAnimationType = iota SoundboardAnimationTypeBasic ) + +type SoundboardSound struct { + Name string `json:"name"` + SoundID snowflake.ID `json:"sound_id"` + ID *snowflake.ID `json:"id"` + Volume float64 `json:"volume"` + EmojiID *snowflake.ID `json:"emoji_id"` + EmojiName *string `json:"emoji_name"` + OverridePath *string `json:"override_path"` + GuildID *snowflake.ID `json:"guild_id,omitempty"` + UserID snowflake.ID `json:"user_id"` + Available *bool `json:"available,omitempty"` + User *User `json:"user"` +} + +// FileURL returns the URL for this sound +func (s SoundboardSound) FileURL() string { + if s.ID != nil { + return SoundboardSoundURL(*s.ID) + } else { + return SoundboardDefaultSoundURL(*s.OverridePath) + } +} + +type SoundboardSoundCreate struct { + Name string `json:"name"` + Sound Sound `json:"sound"` + Volume *float64 `json:"volume,omitempty"` + EmojiID snowflake.ID `json:"emoji_id,omitempty"` + EmojiName string `json:"emoji_name,omitempty"` +} + +type SoundboardSoundUpdate struct { + Name *string `json:"name,omitempty"` + Volume *json.Nullable[float64] `json:"volume,omitempty"` + EmojiID *json.Nullable[snowflake.ID] `json:"emoji_id,omitempty"` + EmojiName *json.Nullable[string] `json:"emoji_name,omitempty"` +} diff --git a/discord/url.go b/discord/url.go index 651ec216b..d17d9ea41 100644 --- a/discord/url.go +++ b/discord/url.go @@ -50,3 +50,13 @@ func AuthorizeURL(values QueryValues) string { } return "https://discord.com/oauth2/authorize" + query } + +// SoundboardSoundURL returns the url of a custom soundboard sound +func SoundboardSoundURL(soundID snowflake.ID) string { + return urlPrint(CDN+"/soundboard-sounds/{sound.id}", soundID) +} + +// SoundboardDefaultSoundURL returns the url of a default soundboard sound +func SoundboardDefaultSoundURL(path string) string { + return urlPrint(CDN+"/soundboard-default-sounds/{sound.override.path}", path) +} diff --git a/rest/rest.go b/rest/rest.go index 850b2bf57..c80b28f03 100644 --- a/rest/rest.go +++ b/rest/rest.go @@ -18,6 +18,7 @@ type Rest interface { Users Voice Webhooks + Sounds StageInstances Emojis Stickers @@ -44,6 +45,7 @@ func New(client Client) Rest { Users: NewUsers(client), Voice: NewVoice(client), Webhooks: NewWebhooks(client), + Sounds: NewSounds(client), StageInstances: NewStageInstances(client), Emojis: NewEmojis(client), Stickers: NewStickers(client), @@ -68,6 +70,7 @@ type restImpl struct { Users Voice Webhooks + Sounds StageInstances Emojis Stickers diff --git a/rest/rest_endpoints.go b/rest/rest_endpoints.go index 7160b62cc..bb87a09a0 100644 --- a/rest/rest_endpoints.go +++ b/rest/rest_endpoints.go @@ -135,6 +135,14 @@ var ( GetGuildScheduledEventUsers = NewEndpoint(http.MethodGet, "/guilds/{guild.id}/scheduled-events/{guild_scheduled_event.id}/users") ) +// Sounds +var ( + GetSoundboardDefaultSounds = NewEndpoint(http.MethodGet, "/soundboard-default-sounds") + CreateGuildSoundboardSound = NewEndpoint(http.MethodPost, "/guilds/{guild.id}/soundboard-sounds") + UpdateGuildSoundboardSound = NewEndpoint(http.MethodPatch, "/guilds/{guild.id}/soundboard-sounds/{sound.id}") + DeleteGuildSoundboardSound = NewEndpoint(http.MethodDelete, "/guilds/{guild.id}/soundboard-sounds/{sound.id}") +) + // StageInstance var ( GetStageInstance = NewEndpoint(http.MethodGet, "/stage-instances/{channel.id}") diff --git a/rest/sounds.go b/rest/sounds.go new file mode 100644 index 000000000..77a314fc5 --- /dev/null +++ b/rest/sounds.go @@ -0,0 +1,42 @@ +package rest + +import ( + "github.com/disgoorg/disgo/discord" + "github.com/disgoorg/snowflake/v2" +) + +var _ Sounds = (*soundsImpl)(nil) + +func NewSounds(client Client) Sounds { + return &soundsImpl{client: client} +} + +type Sounds interface { + GetSoundboardDefaultSounds(opts ...RequestOpt) ([]discord.SoundboardSound, error) + CreateGuildSoundboardSound(guildID snowflake.ID, soundCreate discord.SoundboardSoundCreate, 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 +} + +type soundsImpl struct { + client Client +} + +func (s *soundsImpl) GetSoundboardDefaultSounds(opts ...RequestOpt) (sounds []discord.SoundboardSound, err error) { + err = s.client.Do(GetSoundboardDefaultSounds.Compile(nil), nil, &sounds, opts...) + 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) 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 +} + +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...) +} From 1b5d51d7aeba4fa9a2ee6ef9d71604234f1dd682 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 17:51:18 +0200 Subject: [PATCH 03/36] add event to ListenerAdapter --- events/listener_adapter.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/events/listener_adapter.go b/events/listener_adapter.go index ca82951ef..50cf37f0b 100644 --- a/events/listener_adapter.go +++ b/events/listener_adapter.go @@ -104,11 +104,12 @@ type ListenerAdapter struct { OnGuildMessageReactionRemoveAll func(event *GuildMessageReactionRemoveAll) // Guild Voice Events - OnVoiceServerUpdate func(event *VoiceServerUpdate) - OnGuildVoiceStateUpdate func(event *GuildVoiceStateUpdate) - OnGuildVoiceJoin func(event *GuildVoiceJoin) - OnGuildVoiceMove func(event *GuildVoiceMove) - OnGuildVoiceLeave func(event *GuildVoiceLeave) + OnVoiceServerUpdate func(event *VoiceServerUpdate) + OnGuildVoiceChannelEffectSend func(event *GuildVoiceChannelEffectSend) + OnGuildVoiceStateUpdate func(event *GuildVoiceStateUpdate) + OnGuildVoiceJoin func(event *GuildVoiceJoin) + OnGuildVoiceMove func(event *GuildVoiceMove) + OnGuildVoiceLeave func(event *GuildVoiceLeave) // Guild StageInstance Events OnStageInstanceCreate func(event *StageInstanceCreate) @@ -449,6 +450,10 @@ func (l *ListenerAdapter) OnEvent(event bot.Event) { if listener := l.OnVoiceServerUpdate; listener != nil { listener(e) } + case *GuildVoiceChannelEffectSend: + if listener := l.OnGuildVoiceChannelEffectSend; listener != nil { + listener(e) + } case *GuildVoiceStateUpdate: if listener := l.OnGuildVoiceStateUpdate; listener != nil { listener(e) From 5fa89c9bf01a381ddd26a4b462f2bce4ed0d0e79 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 18:22:43 +0200 Subject: [PATCH 04/36] add soundboard sound events --- events/guild_soundboard_sound_events.go | 29 ++++++++++++++++++ events/listener_adapter.go | 19 ++++++++++++ gateway/gateway_event_type.go | 3 ++ gateway/gateway_events.go | 22 ++++++++++++++ gateway/gateway_messages.go | 15 ++++++++++ handlers/all_handlers.go | 4 +++ handlers/guild_soundboard_sound_handlers.go | 33 +++++++++++++++++++++ 7 files changed, 125 insertions(+) create mode 100644 events/guild_soundboard_sound_events.go create mode 100644 handlers/guild_soundboard_sound_handlers.go diff --git a/events/guild_soundboard_sound_events.go b/events/guild_soundboard_sound_events.go new file mode 100644 index 000000000..ad567a511 --- /dev/null +++ b/events/guild_soundboard_sound_events.go @@ -0,0 +1,29 @@ +package events + +import ( + "github.com/disgoorg/disgo/discord" + "github.com/disgoorg/snowflake/v2" +) + +// GenericGuildSoundboardSound is called upon receiving GuildSoundboardSoundCreate and GuildSoundboardSoundUpdate +type GenericGuildSoundboardSound struct { + *GenericEvent + discord.SoundboardSound +} + +// GuildSoundboardSoundCreate indicates that a discord.SoundboardSound was created in a discord.Guild +type GuildSoundboardSoundCreate struct { + *GenericGuildSoundboardSound +} + +// GuildSoundboardSoundUpdate indicates that a discord.SoundboardSound was updated in a discord.Guild +type GuildSoundboardSoundUpdate struct { + *GenericGuildSoundboardSound +} + +// GuildSoundboardSoundDelete indicates that a discord.SoundboardSound was deleted in a discord.Guild +type GuildSoundboardSoundDelete struct { + *GenericEvent + SoundID snowflake.ID + GuildID snowflake.ID +} diff --git a/events/listener_adapter.go b/events/listener_adapter.go index 50cf37f0b..151ec0e61 100644 --- a/events/listener_adapter.go +++ b/events/listener_adapter.go @@ -103,6 +103,11 @@ type ListenerAdapter struct { OnGuildMessageReactionRemoveEmoji func(event *GuildMessageReactionRemoveEmoji) OnGuildMessageReactionRemoveAll func(event *GuildMessageReactionRemoveAll) + // Guild Soundboard Sound Events + OnGuildSoundboardSoundCreate func(event *GuildSoundboardSoundCreate) + OnGuildSoundboardSoundUpdate func(event *GuildSoundboardSoundUpdate) + OnGuildSoundboardSoundDelete func(event *GuildSoundboardSoundDelete) + // Guild Voice Events OnVoiceServerUpdate func(event *VoiceServerUpdate) OnGuildVoiceChannelEffectSend func(event *GuildVoiceChannelEffectSend) @@ -445,6 +450,20 @@ func (l *ListenerAdapter) OnEvent(event bot.Event) { listener(e) } + // Guild Soundboard Sound Events + case *GuildSoundboardSoundCreate: + if listener := l.OnGuildSoundboardSoundCreate; listener != nil { + listener(e) + } + case *GuildSoundboardSoundUpdate: + if listener := l.OnGuildSoundboardSoundUpdate; listener != nil { + listener(e) + } + case *GuildSoundboardSoundDelete: + if listener := l.OnGuildSoundboardSoundDelete; listener != nil { + listener(e) + } + // Guild Voice Events case *VoiceServerUpdate: if listener := l.OnVoiceServerUpdate; listener != nil { diff --git a/gateway/gateway_event_type.go b/gateway/gateway_event_type.go index 33d0402a8..5ca2c4c03 100644 --- a/gateway/gateway_event_type.go +++ b/gateway/gateway_event_type.go @@ -46,6 +46,9 @@ const ( EventTypeGuildScheduledEventDelete EventType = "GUILD_SCHEDULED_EVENT_DELETE" EventTypeGuildScheduledEventUserAdd EventType = "GUILD_SCHEDULED_EVENT_USER_ADD" EventTypeGuildScheduledEventUserRemove EventType = "GUILD_SCHEDULED_EVENT_USER_REMOVE" + EventTypeGuildSoundboardSoundCreate EventType = "GUILD_SOUNDBOARD_SOUND_CREATE" + EventTypeGuildSoundboardSoundUpdate EventType = "GUILD_SOUNDBOARD_SOUND_UPDATE" + EventTypeGuildSoundboardSoundDelete EventType = "GUILD_SOUNDBOARD_SOUND_DELETE" EventTypeIntegrationCreate EventType = "INTEGRATION_CREATE" EventTypeIntegrationUpdate EventType = "INTEGRATION_UPDATE" EventTypeIntegrationDelete EventType = "INTEGRATION_DELETE" diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index 5011c2e6c..5ae478ce0 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -434,6 +434,28 @@ type EventGuildScheduledEventUserRemove struct { func (EventGuildScheduledEventUserRemove) messageData() {} func (EventGuildScheduledEventUserRemove) eventData() {} +type EventGuildSoundboardSoundCreate struct { + discord.SoundboardSound +} + +func (EventGuildSoundboardSoundCreate) messageData() {} +func (EventGuildSoundboardSoundCreate) eventData() {} + +type EventGuildSoundboardSoundUpdate struct { + discord.SoundboardSound +} + +func (EventGuildSoundboardSoundUpdate) messageData() {} +func (EventGuildSoundboardSoundUpdate) eventData() {} + +type EventGuildSoundboardSoundDelete struct { + SoundID snowflake.ID `json:"sound_id"` + GuildID snowflake.ID `json:"guild_id"` +} + +func (EventGuildSoundboardSoundDelete) messageData() {} +func (EventGuildSoundboardSoundDelete) eventData() {} + type EventInteractionCreate struct { discord.Interaction } diff --git a/gateway/gateway_messages.go b/gateway/gateway_messages.go index 4866eaac0..d63129c92 100644 --- a/gateway/gateway_messages.go +++ b/gateway/gateway_messages.go @@ -294,6 +294,21 @@ func UnmarshalEventData(data []byte, eventType EventType) (EventData, error) { err = json.Unmarshal(data, &d) eventData = d + case EventTypeGuildSoundboardSoundCreate: + var d EventGuildSoundboardSoundCreate + err = json.Unmarshal(data, &d) + eventData = d + + case EventTypeGuildSoundboardSoundUpdate: + var d EventGuildSoundboardSoundUpdate + err = json.Unmarshal(data, &d) + eventData = d + + case EventTypeGuildSoundboardSoundDelete: + var d EventGuildSoundboardSoundDelete + err = json.Unmarshal(data, &d) + eventData = d + case EventTypeIntegrationCreate: var d EventIntegrationCreate err = json.Unmarshal(data, &d) diff --git a/handlers/all_handlers.go b/handlers/all_handlers.go index 26bc2131a..ffbac419b 100644 --- a/handlers/all_handlers.go +++ b/handlers/all_handlers.go @@ -83,6 +83,10 @@ var allEventHandlers = []bot.GatewayEventHandler{ bot.NewGatewayEventHandler(gateway.EventTypeGuildScheduledEventUserAdd, gatewayHandlerGuildScheduledEventUserAdd), bot.NewGatewayEventHandler(gateway.EventTypeGuildScheduledEventUserRemove, gatewayHandlerGuildScheduledEventUserRemove), + bot.NewGatewayEventHandler(gateway.EventTypeGuildSoundboardSoundCreate, gatewayHandlerGuildSoundboardSoundCreate), + bot.NewGatewayEventHandler(gateway.EventTypeGuildSoundboardSoundUpdate, gatewayHandlerGuildSoundboardSoundUpdate), + bot.NewGatewayEventHandler(gateway.EventTypeGuildSoundboardSoundDelete, gatewayHandlerGuildSoundboardSoundDelete), + bot.NewGatewayEventHandler(gateway.EventTypeIntegrationCreate, gatewayHandlerIntegrationCreate), bot.NewGatewayEventHandler(gateway.EventTypeIntegrationUpdate, gatewayHandlerIntegrationUpdate), bot.NewGatewayEventHandler(gateway.EventTypeIntegrationDelete, gatewayHandlerIntegrationDelete), diff --git a/handlers/guild_soundboard_sound_handlers.go b/handlers/guild_soundboard_sound_handlers.go new file mode 100644 index 000000000..ffe821c28 --- /dev/null +++ b/handlers/guild_soundboard_sound_handlers.go @@ -0,0 +1,33 @@ +package handlers + +import ( + "github.com/disgoorg/disgo/bot" + "github.com/disgoorg/disgo/events" + "github.com/disgoorg/disgo/gateway" +) + +func gatewayHandlerGuildSoundboardSoundCreate(client bot.Client, sequenceNumber int, shardID int, event gateway.EventGuildSoundboardSoundCreate) { + client.EventManager().DispatchEvent(&events.GuildSoundboardSoundCreate{ + GenericGuildSoundboardSound: &events.GenericGuildSoundboardSound{ + GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), + SoundboardSound: event.SoundboardSound, + }, + }) +} + +func gatewayHandlerGuildSoundboardSoundUpdate(client bot.Client, sequenceNumber int, shardID int, event gateway.EventGuildSoundboardSoundUpdate) { + client.EventManager().DispatchEvent(&events.GuildSoundboardSoundUpdate{ + GenericGuildSoundboardSound: &events.GenericGuildSoundboardSound{ + GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), + SoundboardSound: event.SoundboardSound, + }, + }) +} + +func gatewayHandlerGuildSoundboardSoundDelete(client bot.Client, sequenceNumber int, shardID int, event gateway.EventGuildSoundboardSoundDelete) { + client.EventManager().DispatchEvent(&events.GuildSoundboardSoundDelete{ + GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), + SoundID: event.SoundID, + GuildID: event.GuildID, + }) +} From cc81f22303826579dd76f1f4c468ad27c8269cf4 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 18:25:41 +0200 Subject: [PATCH 05/36] rename file --- rest/{sounds.go => soundboard_sounds.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename rest/{sounds.go => soundboard_sounds.go} (100%) diff --git a/rest/sounds.go b/rest/soundboard_sounds.go similarity index 100% rename from rest/sounds.go rename to rest/soundboard_sounds.go From ecd808654aeec195abb347c0a3a6d644a080d3ab Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 18:27:03 +0200 Subject: [PATCH 06/36] rename interface --- rest/rest.go | 6 +++--- rest/soundboard_sounds.go | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/rest/rest.go b/rest/rest.go index c80b28f03..eef2c3fe8 100644 --- a/rest/rest.go +++ b/rest/rest.go @@ -18,7 +18,7 @@ type Rest interface { Users Voice Webhooks - Sounds + SoundboardSounds StageInstances Emojis Stickers @@ -45,7 +45,7 @@ func New(client Client) Rest { Users: NewUsers(client), Voice: NewVoice(client), Webhooks: NewWebhooks(client), - Sounds: NewSounds(client), + SoundboardSounds: NewSoundboardSounds(client), StageInstances: NewStageInstances(client), Emojis: NewEmojis(client), Stickers: NewStickers(client), @@ -70,7 +70,7 @@ type restImpl struct { Users Voice Webhooks - Sounds + SoundboardSounds StageInstances Emojis Stickers diff --git a/rest/soundboard_sounds.go b/rest/soundboard_sounds.go index 77a314fc5..916f70cc1 100644 --- a/rest/soundboard_sounds.go +++ b/rest/soundboard_sounds.go @@ -5,38 +5,38 @@ import ( "github.com/disgoorg/snowflake/v2" ) -var _ Sounds = (*soundsImpl)(nil) +var _ SoundboardSounds = (*soundboardSoundsImpl)(nil) -func NewSounds(client Client) Sounds { - return &soundsImpl{client: client} +func NewSoundboardSounds(client Client) SoundboardSounds { + return &soundboardSoundsImpl{client: client} } -type Sounds interface { +type SoundboardSounds interface { GetSoundboardDefaultSounds(opts ...RequestOpt) ([]discord.SoundboardSound, error) CreateGuildSoundboardSound(guildID snowflake.ID, soundCreate discord.SoundboardSoundCreate, 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 } -type soundsImpl struct { +type soundboardSoundsImpl struct { client Client } -func (s *soundsImpl) GetSoundboardDefaultSounds(opts ...RequestOpt) (sounds []discord.SoundboardSound, err error) { +func (s *soundboardSoundsImpl) GetSoundboardDefaultSounds(opts ...RequestOpt) (sounds []discord.SoundboardSound, err error) { err = s.client.Do(GetSoundboardDefaultSounds.Compile(nil), nil, &sounds, opts...) return } -func (s *soundsImpl) CreateGuildSoundboardSound(guildID snowflake.ID, soundCreate discord.SoundboardSoundCreate, opts ...RequestOpt) (sound *discord.SoundboardSound, err error) { +func (s *soundboardSoundsImpl) 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) UpdateGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID, soundUpdate discord.SoundboardSoundUpdate, opts ...RequestOpt) (sound *discord.SoundboardSound, err error) { +func (s *soundboardSoundsImpl) 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 } -func (s *soundsImpl) DeleteGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID, opts ...RequestOpt) error { +func (s *soundboardSoundsImpl) DeleteGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID, opts ...RequestOpt) error { return s.client.Do(DeleteGuildSoundboardSound.Compile(nil, guildID, soundID), nil, nil, opts...) } From 99920e61b2c7ccbe2ab49eac8e9b19cd35d88da8 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 18:54:42 +0200 Subject: [PATCH 07/36] add sound fetching --- bot/client.go | 6 ++++++ ...ound_events.go => guild_soundboard_events.go} | 7 +++++++ events/listener_adapter.go | 7 ++++++- gateway/gateway_event_type.go | 1 + gateway/gateway_events.go | 8 ++++++++ gateway/gateway_messages.go | 16 ++++++++++++++++ gateway/gateway_opcodes.go | 1 + handlers/all_handlers.go | 1 + ..._handlers.go => guild_soundboard_handlers.go} | 8 ++++++++ 9 files changed, 54 insertions(+), 1 deletion(-) rename events/{guild_soundboard_sound_events.go => guild_soundboard_events.go} (81%) rename handlers/{guild_soundboard_sound_handlers.go => guild_soundboard_handlers.go} (79%) diff --git a/bot/client.go b/bot/client.go index 3ef9a888d..d71c90223 100644 --- a/bot/client.go +++ b/bot/client.go @@ -278,6 +278,12 @@ func (c *clientImpl) RequestMembersWithQuery(ctx context.Context, guildID snowfl }) } +func (c *clientImpl) RequestSoundboardSounds(ctx context.Context, guildIDs []snowflake.ID) error { + return c.gateway.Send(ctx, gateway.OpcodeRequestSoundboardSounds, gateway.MessageDataRequestSoundboardSounds{ + GuildIDs: guildIDs, + }) +} + func (c *clientImpl) SetPresence(ctx context.Context, opts ...gateway.PresenceOpt) error { if !c.HasGateway() { return discord.ErrNoGateway diff --git a/events/guild_soundboard_sound_events.go b/events/guild_soundboard_events.go similarity index 81% rename from events/guild_soundboard_sound_events.go rename to events/guild_soundboard_events.go index ad567a511..3d10523ac 100644 --- a/events/guild_soundboard_sound_events.go +++ b/events/guild_soundboard_events.go @@ -27,3 +27,10 @@ type GuildSoundboardSoundDelete struct { SoundID snowflake.ID GuildID snowflake.ID } + +// SoundboardSounds is a response to gateway.OpcodeRequestSoundboardSounds +type SoundboardSounds struct { + *GenericEvent + SoundboardSounds []discord.SoundboardSound + GuildID snowflake.ID +} diff --git a/events/listener_adapter.go b/events/listener_adapter.go index 151ec0e61..3d177baf8 100644 --- a/events/listener_adapter.go +++ b/events/listener_adapter.go @@ -103,10 +103,11 @@ type ListenerAdapter struct { OnGuildMessageReactionRemoveEmoji func(event *GuildMessageReactionRemoveEmoji) OnGuildMessageReactionRemoveAll func(event *GuildMessageReactionRemoveAll) - // Guild Soundboard Sound Events + // Guild Soundboard Events OnGuildSoundboardSoundCreate func(event *GuildSoundboardSoundCreate) OnGuildSoundboardSoundUpdate func(event *GuildSoundboardSoundUpdate) OnGuildSoundboardSoundDelete func(event *GuildSoundboardSoundDelete) + OnSoundboardSounds func(event *SoundboardSounds) // Guild Voice Events OnVoiceServerUpdate func(event *VoiceServerUpdate) @@ -463,6 +464,10 @@ func (l *ListenerAdapter) OnEvent(event bot.Event) { if listener := l.OnGuildSoundboardSoundDelete; listener != nil { listener(e) } + case *SoundboardSounds: + if listener := l.OnSoundboardSounds; listener != nil { + listener(e) + } // Guild Voice Events case *VoiceServerUpdate: diff --git a/gateway/gateway_event_type.go b/gateway/gateway_event_type.go index 5ca2c4c03..a04a56639 100644 --- a/gateway/gateway_event_type.go +++ b/gateway/gateway_event_type.go @@ -64,6 +64,7 @@ const ( EventTypeMessageReactionRemoveAll EventType = "MESSAGE_REACTION_REMOVE_ALL" EventTypeMessageReactionRemoveEmoji EventType = "MESSAGE_REACTION_REMOVE_EMOJI" EventTypePresenceUpdate EventType = "PRESENCE_UPDATE" + EventTypeSoundboardSounds EventType = "SOUNDBOARD_SOUNDS" EventTypeStageInstanceCreate EventType = "STAGE_INSTANCE_CREATE" EventTypeStageInstanceDelete EventType = "STAGE_INSTANCE_DELETE" EventTypeStageInstanceUpdate EventType = "STAGE_INSTANCE_UPDATE" diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index 5ae478ce0..7e61302af 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -531,6 +531,14 @@ type EventPresenceUpdate struct { func (EventPresenceUpdate) messageData() {} func (EventPresenceUpdate) eventData() {} +type EventSoundboardSounds struct { + SoundboardSounds []discord.SoundboardSound `json:"soundboard_sounds"` + GuildID snowflake.ID `json:"guild_id"` +} + +func (EventSoundboardSounds) messageData() {} +func (EventSoundboardSounds) eventData() {} + type EventStageInstanceCreate struct { discord.StageInstance } diff --git a/gateway/gateway_messages.go b/gateway/gateway_messages.go index d63129c92..06ed52614 100644 --- a/gateway/gateway_messages.go +++ b/gateway/gateway_messages.go @@ -80,6 +80,11 @@ func (e *Message) UnmarshalJSON(data []byte) error { case OpcodeHeartbeatACK: + case OpcodeRequestSoundboardSounds: + var d MessageDataRequestSoundboardSounds + err = json.Unmarshal(v.D, &d) + messageData = d + default: var d MessageDataUnknown err = json.Unmarshal(v.D, &d) @@ -384,6 +389,11 @@ func UnmarshalEventData(data []byte, eventType EventType) (EventData, error) { err = json.Unmarshal(data, &d) eventData = d + case EventTypeSoundboardSounds: + var d EventSoundboardSounds + err = json.Unmarshal(data, &d) + eventData = d + case EventTypeStageInstanceCreate: var d EventStageInstanceCreate err = json.Unmarshal(data, &d) @@ -593,3 +603,9 @@ type MessageDataHello struct { } func (MessageDataHello) messageData() {} + +type MessageDataRequestSoundboardSounds struct { + GuildIDs []snowflake.ID `json:"guild_ids"` +} + +func (MessageDataRequestSoundboardSounds) messageData() {} diff --git a/gateway/gateway_opcodes.go b/gateway/gateway_opcodes.go index 85413d550..d6c8e045d 100644 --- a/gateway/gateway_opcodes.go +++ b/gateway/gateway_opcodes.go @@ -17,6 +17,7 @@ const ( OpcodeInvalidSession OpcodeHello OpcodeHeartbeatACK + OpcodeRequestSoundboardSounds Opcode = 31 ) type CloseEventCode struct { diff --git a/handlers/all_handlers.go b/handlers/all_handlers.go index ffbac419b..f6c61f1c1 100644 --- a/handlers/all_handlers.go +++ b/handlers/all_handlers.go @@ -86,6 +86,7 @@ var allEventHandlers = []bot.GatewayEventHandler{ bot.NewGatewayEventHandler(gateway.EventTypeGuildSoundboardSoundCreate, gatewayHandlerGuildSoundboardSoundCreate), bot.NewGatewayEventHandler(gateway.EventTypeGuildSoundboardSoundUpdate, gatewayHandlerGuildSoundboardSoundUpdate), bot.NewGatewayEventHandler(gateway.EventTypeGuildSoundboardSoundDelete, gatewayHandlerGuildSoundboardSoundDelete), + bot.NewGatewayEventHandler(gateway.EventTypeSoundboardSounds, gatewayHandlerSoundboardSounds), bot.NewGatewayEventHandler(gateway.EventTypeIntegrationCreate, gatewayHandlerIntegrationCreate), bot.NewGatewayEventHandler(gateway.EventTypeIntegrationUpdate, gatewayHandlerIntegrationUpdate), diff --git a/handlers/guild_soundboard_sound_handlers.go b/handlers/guild_soundboard_handlers.go similarity index 79% rename from handlers/guild_soundboard_sound_handlers.go rename to handlers/guild_soundboard_handlers.go index ffe821c28..48e91da03 100644 --- a/handlers/guild_soundboard_sound_handlers.go +++ b/handlers/guild_soundboard_handlers.go @@ -31,3 +31,11 @@ func gatewayHandlerGuildSoundboardSoundDelete(client bot.Client, sequenceNumber GuildID: event.GuildID, }) } + +func gatewayHandlerSoundboardSounds(client bot.Client, sequenceNumber int, shardID int, event gateway.EventSoundboardSounds) { + client.EventManager().DispatchEvent(&events.SoundboardSounds{ + GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), + SoundboardSounds: event.SoundboardSounds, + GuildID: event.GuildID, + }) +} From a7d8b8888d90fc2431b5a23dcf437d468031996a Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 18:57:37 +0200 Subject: [PATCH 08/36] add check for gateway --- bot/client.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bot/client.go b/bot/client.go index d71c90223..45296945a 100644 --- a/bot/client.go +++ b/bot/client.go @@ -279,6 +279,9 @@ func (c *clientImpl) RequestMembersWithQuery(ctx context.Context, guildID snowfl } func (c *clientImpl) RequestSoundboardSounds(ctx context.Context, guildIDs []snowflake.ID) error { + if !c.HasGateway() { + return discord.ErrNoGateway + } return c.gateway.Send(ctx, gateway.OpcodeRequestSoundboardSounds, gateway.MessageDataRequestSoundboardSounds{ GuildIDs: guildIDs, }) From abefae701f9d986838bfbcc260229488b526d31b Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 19:00:41 +0200 Subject: [PATCH 09/36] add docs for GuildVoiceChannelEffectSend --- events/guild_voice_events.go | 1 + 1 file changed, 1 insertion(+) diff --git a/events/guild_voice_events.go b/events/guild_voice_events.go index cc1aba9f8..b9543ee9a 100644 --- a/events/guild_voice_events.go +++ b/events/guild_voice_events.go @@ -5,6 +5,7 @@ import ( "github.com/disgoorg/disgo/gateway" ) +// GuildVoiceChannelEffectSend indicates that a discord.User sent an effect in a discord.GuildVoiceChannel type GuildVoiceChannelEffectSend struct { *GenericEvent gateway.EventVoiceChannelEffectSend From 21a233ab2884af026af1b9c5b1afa71ef3737ea0 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 20:15:18 +0200 Subject: [PATCH 10/36] rename SoundboardAnimationType to SoundboardEffectAnimationType --- discord/soundboard.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/discord/soundboard.go b/discord/soundboard.go index a18b3a09f..37f769d8d 100644 --- a/discord/soundboard.go +++ b/discord/soundboard.go @@ -1,8 +1,8 @@ package discord -type SoundboardAnimationType int +type SoundboardEffectAnimationType int const ( - SoundboardAnimationTypePremium SoundboardAnimationType = iota - SoundboardAnimationTypeBasic + SoundboardEffectAnimationTypePremium SoundboardEffectAnimationType = iota + SoundboardEffectAnimationTypeBasic ) From c5d2a69f88c70edce6d73440f11136bef5b93600 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 20:22:47 +0200 Subject: [PATCH 11/36] bruh --- gateway/gateway_events.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index 5011c2e6c..efc784f28 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -564,15 +564,15 @@ func (EventUserUpdate) messageData() {} func (EventUserUpdate) eventData() {} type EventVoiceChannelEffectSend struct { - ChannelID snowflake.ID `json:"channel_id"` - GuildID snowflake.ID `json:"guild_id"` - UserID snowflake.ID `json:"user_id"` - Emoji *discord.Emoji `json:"emoji"` - AnimationType *discord.SoundboardAnimationType `json:"animation_type,omitempty"` - AnimationID *int `json:"animation_id,omitempty"` - SoundID *snowflake.ID `json:"sound_id,omitempty"` - SoundOverridePath *string `json:"sound_override_path"` - SoundVolume *float64 `json:"sound_volume,omitempty"` + ChannelID snowflake.ID `json:"channel_id"` + GuildID snowflake.ID `json:"guild_id"` + UserID snowflake.ID `json:"user_id"` + Emoji *discord.Emoji `json:"emoji"` + AnimationType *discord.SoundboardEffectAnimationType `json:"animation_type,omitempty"` + AnimationID *int `json:"animation_id,omitempty"` + SoundID *snowflake.ID `json:"sound_id,omitempty"` + SoundOverridePath *string `json:"sound_override_path"` + SoundVolume *float64 `json:"sound_volume,omitempty"` } func (EventVoiceChannelEffectSend) messageData() {} From 1e324fda614f2fb8030b89f6f565960c75be25eb Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 20:57:20 +0200 Subject: [PATCH 12/36] change param to varargs --- bot/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/client.go b/bot/client.go index 45296945a..ddd5b087a 100644 --- a/bot/client.go +++ b/bot/client.go @@ -278,7 +278,7 @@ func (c *clientImpl) RequestMembersWithQuery(ctx context.Context, guildID snowfl }) } -func (c *clientImpl) RequestSoundboardSounds(ctx context.Context, guildIDs []snowflake.ID) error { +func (c *clientImpl) RequestSoundboardSounds(ctx context.Context, guildIDs ...snowflake.ID) error { if !c.HasGateway() { return discord.ErrNoGateway } From bce8b96a8b1f0079c7047b77e6a2c74f30d4c6f0 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 20:59:40 +0200 Subject: [PATCH 13/36] remove pointless else --- discord/soundboard.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discord/soundboard.go b/discord/soundboard.go index 74d83d968..4fdecee4b 100644 --- a/discord/soundboard.go +++ b/discord/soundboard.go @@ -30,9 +30,8 @@ type SoundboardSound struct { func (s SoundboardSound) FileURL() string { if s.ID != nil { return SoundboardSoundURL(*s.ID) - } else { - return SoundboardDefaultSoundURL(*s.OverridePath) } + return SoundboardDefaultSoundURL(*s.OverridePath) } type SoundboardSoundCreate struct { From d1256c54e36568fc5f0e890e9c09517208e276f5 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Wed, 28 Jun 2023 21:33:52 +0200 Subject: [PATCH 14/36] add CDNEndpoint.Path() --- discord/cdn_endpoints.go | 10 +++++++++- discord/url.go | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/discord/cdn_endpoints.go b/discord/cdn_endpoints.go index a5048c96d..a22f127a5 100644 --- a/discord/cdn_endpoints.go +++ b/discord/cdn_endpoints.go @@ -38,6 +38,9 @@ var ( CustomSticker = NewCDN("/stickers/{sticker.id}", ImageFormatPNG, ImageFormatLottie, ImageFormatGIF) AttachmentFile = NewCDN("/attachments/{channel.id}/{attachment.id}/{file.name}", ImageFormatNone) + + SoundboardSoundFile = NewCDN("/soundboard-sounds/{sound.id}", ImageFormatNone) + SoundboardDefaultSoundFile = NewCDN("/soundboard-default-sounds/{sound.override.path}", ImageFormatNone) ) // ImageFormat is the type of image on Discord's CDN (https://discord.com/developers/docs/reference#image-formatting-image-formats) @@ -85,7 +88,12 @@ func (e CDNEndpoint) URL(format ImageFormat, values QueryValues, params ...any) if query != "" { query = "?" + query } - return urlPrint(CDN+e.Route+"."+format.String(), params...) + query + return urlPrint(e.Path()+"."+format.String(), params...) + query +} + +// Path returns the raw Route of this CDNEndpoint +func (e CDNEndpoint) Path() string { + return CDN + e.Route } func DefaultCDNConfig() *CDNConfig { diff --git a/discord/url.go b/discord/url.go index d17d9ea41..273330636 100644 --- a/discord/url.go +++ b/discord/url.go @@ -53,10 +53,10 @@ func AuthorizeURL(values QueryValues) string { // SoundboardSoundURL returns the url of a custom soundboard sound func SoundboardSoundURL(soundID snowflake.ID) string { - return urlPrint(CDN+"/soundboard-sounds/{sound.id}", soundID) + return urlPrint(SoundboardSoundFile.Path(), soundID) } // SoundboardDefaultSoundURL returns the url of a default soundboard sound func SoundboardDefaultSoundURL(path string) string { - return urlPrint(CDN+"/soundboard-default-sounds/{sound.override.path}", path) + return urlPrint(SoundboardDefaultSoundFile.Path(), path) } From e05894b5457bbb3d204221edb2290c47ce64e5b8 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Fri, 30 Jun 2023 15:57:12 +0200 Subject: [PATCH 15/36] shorten impl name --- rest/soundboard_sounds.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rest/soundboard_sounds.go b/rest/soundboard_sounds.go index 916f70cc1..024401184 100644 --- a/rest/soundboard_sounds.go +++ b/rest/soundboard_sounds.go @@ -5,10 +5,10 @@ import ( "github.com/disgoorg/snowflake/v2" ) -var _ SoundboardSounds = (*soundboardSoundsImpl)(nil) +var _ SoundboardSounds = (*soundsImpl)(nil) func NewSoundboardSounds(client Client) SoundboardSounds { - return &soundboardSoundsImpl{client: client} + return &soundsImpl{client: client} } type SoundboardSounds interface { @@ -18,25 +18,25 @@ type SoundboardSounds interface { DeleteGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID, opts ...RequestOpt) error } -type soundboardSoundsImpl struct { +type soundsImpl struct { client Client } -func (s *soundboardSoundsImpl) GetSoundboardDefaultSounds(opts ...RequestOpt) (sounds []discord.SoundboardSound, err error) { +func (s *soundsImpl) GetSoundboardDefaultSounds(opts ...RequestOpt) (sounds []discord.SoundboardSound, err error) { err = s.client.Do(GetSoundboardDefaultSounds.Compile(nil), nil, &sounds, opts...) return } -func (s *soundboardSoundsImpl) CreateGuildSoundboardSound(guildID snowflake.ID, soundCreate discord.SoundboardSoundCreate, opts ...RequestOpt) (sound *discord.SoundboardSound, err error) { +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 *soundboardSoundsImpl) UpdateGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID, soundUpdate discord.SoundboardSoundUpdate, opts ...RequestOpt) (sound *discord.SoundboardSound, err error) { +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 } -func (s *soundboardSoundsImpl) DeleteGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID, opts ...RequestOpt) error { +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...) } From 9197f636d709c4ff0c2edcc331b783c251f04d19 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Sat, 2 Sep 2023 15:58:05 +0200 Subject: [PATCH 16/36] add audit log events --- discord/audit_log.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/discord/audit_log.go b/discord/audit_log.go index 4135c5581..bebc70781 100644 --- a/discord/audit_log.go +++ b/discord/audit_log.go @@ -108,6 +108,12 @@ const ( AuditLogApplicationCommandPermissionUpdate AuditLogEvent = 121 ) +const ( + AuditLogSoundboardSoundCreate AuditLogEvent = iota + 130 + AuditLogSoundboardSoundUpdate + AuditLogSoundboardSoundDelete +) + const ( AuditLogAutoModerationRuleCreate AuditLogEvent = iota + 140 AuditLogAutoModerationRuleUpdate From 540af4459abe6e9074fe2574835e6e959c1d84d2 Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Thu, 16 May 2024 12:42:13 +0200 Subject: [PATCH 17/36] updates --- discord/cdn_endpoints.go | 3 +-- discord/guild.go | 1 + discord/soundboard.go | 8 -------- discord/url.go | 10 ---------- 4 files changed, 2 insertions(+), 20 deletions(-) diff --git a/discord/cdn_endpoints.go b/discord/cdn_endpoints.go index e2ab2cb11..9a908c8be 100644 --- a/discord/cdn_endpoints.go +++ b/discord/cdn_endpoints.go @@ -46,8 +46,7 @@ var ( AttachmentFile = NewCDN("/attachments/{channel.id}/{attachment.id}/{file.name}", FileFormatNone) - SoundboardSoundFile = NewCDN("/soundboard-sounds/{sound.id}", FileFormatNone) - SoundboardDefaultSoundFile = NewCDN("/soundboard-default-sounds/{sound.override.path}", FileFormatNone) + SoundboardSoundFile = NewCDN("/soundboard-sounds/{sound.id}", FileFormatNone) ) // FileFormat is the type of file on Discord's CDN (https://discord.com/developers/docs/reference#image-formatting-image-formats) diff --git a/discord/guild.go b/discord/guild.go index 16dffee7f..ef8cee29d 100644 --- a/discord/guild.go +++ b/discord/guild.go @@ -225,6 +225,7 @@ type GatewayGuild struct { Presences []Presence `json:"presences"` StageInstances []StageInstance `json:"stage_instances"` GuildScheduledEvents []GuildScheduledEvent `json:"guild_scheduled_events"` + SoundboardSounds []SoundboardSound `json:"soundboard_sounds"` } func (g *GatewayGuild) UnmarshalJSON(data []byte) error { diff --git a/discord/soundboard.go b/discord/soundboard.go index 4fdecee4b..d52d3b491 100644 --- a/discord/soundboard.go +++ b/discord/soundboard.go @@ -26,14 +26,6 @@ type SoundboardSound struct { User *User `json:"user"` } -// FileURL returns the URL for this sound -func (s SoundboardSound) FileURL() string { - if s.ID != nil { - return SoundboardSoundURL(*s.ID) - } - return SoundboardDefaultSoundURL(*s.OverridePath) -} - type SoundboardSoundCreate struct { Name string `json:"name"` Sound Sound `json:"sound"` diff --git a/discord/url.go b/discord/url.go index 273330636..651ec216b 100644 --- a/discord/url.go +++ b/discord/url.go @@ -50,13 +50,3 @@ func AuthorizeURL(values QueryValues) string { } return "https://discord.com/oauth2/authorize" + query } - -// SoundboardSoundURL returns the url of a custom soundboard sound -func SoundboardSoundURL(soundID snowflake.ID) string { - return urlPrint(SoundboardSoundFile.Path(), soundID) -} - -// SoundboardDefaultSoundURL returns the url of a default soundboard sound -func SoundboardDefaultSoundURL(path string) string { - return urlPrint(SoundboardDefaultSoundFile.Path(), path) -} From 48ee79e6a30615d059af1cbc4173c422f4b2270f Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Thu, 16 May 2024 17:07:40 +0200 Subject: [PATCH 18/36] add caches --- cache/cache_config.go | 38 +++++++++---- cache/cache_flags.go | 4 +- cache/caches.go | 79 ++++++++++++++++++++++----- events/guild_soundboard_events.go | 1 + handlers/guild_handlers.go | 5 ++ handlers/guild_soundboard_handlers.go | 8 +++ 6 files changed, 108 insertions(+), 27 deletions(-) diff --git a/cache/cache_config.go b/cache/cache_config.go index dc0395452..6ed76a166 100644 --- a/cache/cache_config.go +++ b/cache/cache_config.go @@ -9,18 +9,19 @@ import ( // DefaultConfig returns a Config with sensible defaults. func DefaultConfig() *Config { return &Config{ - GuildCachePolicy: PolicyAll[discord.Guild], - ChannelCachePolicy: PolicyAll[discord.GuildChannel], - StageInstanceCachePolicy: PolicyAll[discord.StageInstance], - GuildScheduledEventCachePolicy: PolicyAll[discord.GuildScheduledEvent], - RoleCachePolicy: PolicyAll[discord.Role], - MemberCachePolicy: PolicyAll[discord.Member], - ThreadMemberCachePolicy: PolicyAll[discord.ThreadMember], - PresenceCachePolicy: PolicyAll[discord.Presence], - VoiceStateCachePolicy: PolicyAll[discord.VoiceState], - MessageCachePolicy: PolicyAll[discord.Message], - EmojiCachePolicy: PolicyAll[discord.Emoji], - StickerCachePolicy: PolicyAll[discord.Sticker], + GuildCachePolicy: PolicyAll[discord.Guild], + ChannelCachePolicy: PolicyAll[discord.GuildChannel], + StageInstanceCachePolicy: PolicyAll[discord.StageInstance], + GuildScheduledEventCachePolicy: PolicyAll[discord.GuildScheduledEvent], + GuildSoundboardSoundCachePolicy: PolicyAll[discord.SoundboardSound], + RoleCachePolicy: PolicyAll[discord.Role], + MemberCachePolicy: PolicyAll[discord.Member], + ThreadMemberCachePolicy: PolicyAll[discord.ThreadMember], + PresenceCachePolicy: PolicyAll[discord.Presence], + VoiceStateCachePolicy: PolicyAll[discord.VoiceState], + MessageCachePolicy: PolicyAll[discord.Message], + EmojiCachePolicy: PolicyAll[discord.Emoji], + StickerCachePolicy: PolicyAll[discord.Sticker], } } @@ -42,6 +43,9 @@ type Config struct { GuildScheduledEventCache GuildScheduledEventCache GuildScheduledEventCachePolicy Policy[discord.GuildScheduledEvent] + GuildSoundboardSoundCache GuildSoundboardSoundCache + GuildSoundboardSoundCachePolicy Policy[discord.SoundboardSound] + RoleCache RoleCache RoleCachePolicy Policy[discord.Role] @@ -90,6 +94,9 @@ func (c *Config) Apply(opts []ConfigOpt) { if c.GuildScheduledEventCache == nil { c.GuildScheduledEventCache = NewGuildScheduledEventCache(NewGroupedCache[discord.GuildScheduledEvent](c.CacheFlags, FlagGuildScheduledEvents, c.GuildScheduledEventCachePolicy)) } + if c.GuildSoundboardSoundCache == nil { + c.GuildSoundboardSoundCache = NewGuildSoundboardSoundCache(NewGroupedCache[discord.SoundboardSound](c.CacheFlags, FlagGuildSoundboardSounds, c.GuildSoundboardSoundCachePolicy)) + } if c.RoleCache == nil { c.RoleCache = NewRoleCache(NewGroupedCache[discord.Role](c.CacheFlags, FlagRoles, c.RoleCachePolicy)) } @@ -179,6 +186,13 @@ func WithGuildScheduledEventCache(guildScheduledEventCache GuildScheduledEventCa } } +// WithGuildSoundboardSoundCache sets the GuildSoundboardSoundCache of the Config. +func WithGuildSoundboardSoundCache(guildSoundboardSoundCache GuildSoundboardSoundCache) ConfigOpt { + return func(config *Config) { + config.GuildSoundboardSoundCache = guildSoundboardSoundCache + } +} + // WithRoleCachePolicy sets the Policy[discord.Role] of the Config. func WithRoleCachePolicy(policy Policy[discord.Role]) ConfigOpt { return func(config *Config) { diff --git a/cache/cache_flags.go b/cache/cache_flags.go index 2be7d5f5f..dc3b80fb4 100644 --- a/cache/cache_flags.go +++ b/cache/cache_flags.go @@ -19,6 +19,7 @@ const ( FlagStickers FlagVoiceStates FlagStageInstances + FlagGuildSoundboardSounds FlagsNone Flags = 0 FlagsAll = FlagGuilds | @@ -32,7 +33,8 @@ const ( FlagEmojis | FlagStickers | FlagVoiceStates | - FlagStageInstances + FlagStageInstances | + FlagGuildSoundboardSounds ) // Add allows you to add multiple bits together, producing a new bit diff --git a/cache/caches.go b/cache/caches.go index dfa05f429..360f4ca5b 100644 --- a/cache/caches.go +++ b/cache/caches.go @@ -273,6 +273,54 @@ func (c *guildScheduledEventCacheImpl) RemoveGuildScheduledEventsByGuildID(guild c.cache.GroupRemove(guildID) } +type GuildSoundboardSoundCache interface { + GuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID) (discord.SoundboardSound, bool) + GuildSoundboardSoundsForEach(guildID snowflake.ID, fn func(sound discord.SoundboardSound)) + GuildSoundboardSoundsAllLen() int + GuildSoundboardSoundsLen(guildID snowflake.ID) int + AddGuildSoundboardSound(sound discord.SoundboardSound) + RemoveGuildSoundboardSound(guildID snowflake.ID, sound snowflake.ID) (discord.SoundboardSound, bool) + RemoveGuildSoundboardSoundsByGuildID(guildID snowflake.ID) +} + +func NewGuildSoundboardSoundCache(cache GroupedCache[discord.SoundboardSound]) GuildSoundboardSoundCache { + return &guildSoundboardSoundCacheImpl{ + cache: cache, + } +} + +type guildSoundboardSoundCacheImpl struct { + cache GroupedCache[discord.SoundboardSound] +} + +func (c *guildSoundboardSoundCacheImpl) GuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID) (discord.SoundboardSound, bool) { + return c.cache.Get(guildID, soundID) +} + +func (c *guildSoundboardSoundCacheImpl) GuildSoundboardSoundsForEach(guildID snowflake.ID, fn func(sound discord.SoundboardSound)) { + c.cache.GroupForEach(guildID, fn) +} + +func (c *guildSoundboardSoundCacheImpl) GuildSoundboardSoundsAllLen() int { + return c.cache.Len() +} + +func (c *guildSoundboardSoundCacheImpl) GuildSoundboardSoundsLen(guildID snowflake.ID) int { + return c.cache.GroupLen(guildID) +} + +func (c *guildSoundboardSoundCacheImpl) AddGuildSoundboardSound(sound discord.SoundboardSound) { + c.cache.Put(*sound.GuildID, sound.SoundID, sound) +} + +func (c *guildSoundboardSoundCacheImpl) RemoveGuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID) (discord.SoundboardSound, bool) { + return c.cache.Remove(guildID, soundID) +} + +func (c *guildSoundboardSoundCacheImpl) RemoveGuildSoundboardSoundsByGuildID(guildID snowflake.ID) { + c.cache.GroupRemove(guildID) +} + type RoleCache interface { Role(guildID snowflake.ID, roleID snowflake.ID) (discord.Role, bool) RolesForEach(guildID snowflake.ID, fn func(role discord.Role)) @@ -678,6 +726,7 @@ type Caches interface { ChannelCache StageInstanceCache GuildScheduledEventCache + GuildSoundboardSoundCache RoleCache MemberCache ThreadMemberCache @@ -759,20 +808,21 @@ func New(opts ...ConfigOpt) Caches { config.Apply(opts) return &cachesImpl{ - config: *config, - SelfUserCache: config.SelfUserCache, - GuildCache: config.GuildCache, - ChannelCache: config.ChannelCache, - StageInstanceCache: config.StageInstanceCache, - GuildScheduledEventCache: config.GuildScheduledEventCache, - RoleCache: config.RoleCache, - MemberCache: config.MemberCache, - ThreadMemberCache: config.ThreadMemberCache, - PresenceCache: config.PresenceCache, - VoiceStateCache: config.VoiceStateCache, - MessageCache: config.MessageCache, - EmojiCache: config.EmojiCache, - StickerCache: config.StickerCache, + config: *config, + SelfUserCache: config.SelfUserCache, + GuildCache: config.GuildCache, + ChannelCache: config.ChannelCache, + StageInstanceCache: config.StageInstanceCache, + GuildScheduledEventCache: config.GuildScheduledEventCache, + GuildSoundboardSoundCache: config.GuildSoundboardSoundCache, + RoleCache: config.RoleCache, + MemberCache: config.MemberCache, + ThreadMemberCache: config.ThreadMemberCache, + PresenceCache: config.PresenceCache, + VoiceStateCache: config.VoiceStateCache, + MessageCache: config.MessageCache, + EmojiCache: config.EmojiCache, + StickerCache: config.StickerCache, } } @@ -783,6 +833,7 @@ type cachesImpl struct { ChannelCache StageInstanceCache GuildScheduledEventCache + GuildSoundboardSoundCache RoleCache MemberCache ThreadMemberCache diff --git a/events/guild_soundboard_events.go b/events/guild_soundboard_events.go index 3d10523ac..863228238 100644 --- a/events/guild_soundboard_events.go +++ b/events/guild_soundboard_events.go @@ -19,6 +19,7 @@ type GuildSoundboardSoundCreate struct { // GuildSoundboardSoundUpdate indicates that a discord.SoundboardSound was updated in a discord.Guild type GuildSoundboardSoundUpdate struct { *GenericGuildSoundboardSound + OldGuildSoundboardSound discord.SoundboardSound } // GuildSoundboardSoundDelete indicates that a discord.SoundboardSound was deleted in a discord.Guild diff --git a/handlers/guild_handlers.go b/handlers/guild_handlers.go index 953858406..51573ec40 100644 --- a/handlers/guild_handlers.go +++ b/handlers/guild_handlers.go @@ -58,6 +58,10 @@ func gatewayHandlerGuildCreate(client bot.Client, sequenceNumber int, shardID in client.Caches().AddGuildScheduledEvent(guildScheduledEvent) } + for _, soundboardSound := range event.SoundboardSounds { + client.Caches().AddGuildSoundboardSound(soundboardSound) + } + for _, presence := range event.Presences { presence.GuildID = event.ID // populate unset field client.Caches().AddPresence(presence) @@ -128,6 +132,7 @@ func gatewayHandlerGuildDelete(client bot.Client, sequenceNumber int, shardID in client.Caches().RemoveStickersByGuildID(event.ID) client.Caches().RemoveRolesByGuildID(event.ID) client.Caches().RemoveStageInstancesByGuildID(event.ID) + client.Caches().RemoveGuildSoundboardSoundsByGuildID(event.ID) client.Caches().RemoveMessagesByGuildID(event.ID) if event.Unavailable { diff --git a/handlers/guild_soundboard_handlers.go b/handlers/guild_soundboard_handlers.go index 48e91da03..5c14dda90 100644 --- a/handlers/guild_soundboard_handlers.go +++ b/handlers/guild_soundboard_handlers.go @@ -7,6 +7,8 @@ import ( ) func gatewayHandlerGuildSoundboardSoundCreate(client bot.Client, sequenceNumber int, shardID int, event gateway.EventGuildSoundboardSoundCreate) { + client.Caches().AddGuildSoundboardSound(event.SoundboardSound) + client.EventManager().DispatchEvent(&events.GuildSoundboardSoundCreate{ GenericGuildSoundboardSound: &events.GenericGuildSoundboardSound{ GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), @@ -16,15 +18,21 @@ func gatewayHandlerGuildSoundboardSoundCreate(client bot.Client, sequenceNumber } func gatewayHandlerGuildSoundboardSoundUpdate(client bot.Client, sequenceNumber int, shardID int, event gateway.EventGuildSoundboardSoundUpdate) { + oldSound, _ := client.Caches().GuildSoundboardSound(*event.GuildID, event.SoundID) + client.Caches().AddGuildSoundboardSound(event.SoundboardSound) + client.EventManager().DispatchEvent(&events.GuildSoundboardSoundUpdate{ GenericGuildSoundboardSound: &events.GenericGuildSoundboardSound{ GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), SoundboardSound: event.SoundboardSound, }, + OldGuildSoundboardSound: oldSound, }) } func gatewayHandlerGuildSoundboardSoundDelete(client bot.Client, sequenceNumber int, shardID int, event gateway.EventGuildSoundboardSoundDelete) { + client.Caches().RemoveGuildSoundboardSound(event.GuildID, event.SoundID) + client.EventManager().DispatchEvent(&events.GuildSoundboardSoundDelete{ GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID), SoundID: event.SoundID, From c1c843d0a4bf9408fc212ae0d8eae39d7210f00c Mon Sep 17 00:00:00 2001 From: mlnrDev Date: Thu, 16 May 2024 17:57:31 +0200 Subject: [PATCH 19/36] remove SoundOverridePath --- gateway/gateway_events.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index efc784f28..a5d2a7dbf 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -564,15 +564,14 @@ func (EventUserUpdate) messageData() {} func (EventUserUpdate) eventData() {} type EventVoiceChannelEffectSend struct { - ChannelID snowflake.ID `json:"channel_id"` - GuildID snowflake.ID `json:"guild_id"` - UserID snowflake.ID `json:"user_id"` - Emoji *discord.Emoji `json:"emoji"` - AnimationType *discord.SoundboardEffectAnimationType `json:"animation_type,omitempty"` - AnimationID *int `json:"animation_id,omitempty"` - SoundID *snowflake.ID `json:"sound_id,omitempty"` - SoundOverridePath *string `json:"sound_override_path"` - SoundVolume *float64 `json:"sound_volume,omitempty"` + ChannelID snowflake.ID `json:"channel_id"` + GuildID snowflake.ID `json:"guild_id"` + UserID snowflake.ID `json:"user_id"` + Emoji *discord.Emoji `json:"emoji"` + AnimationType *discord.SoundboardEffectAnimationType `json:"animation_type,omitempty"` + AnimationID *int `json:"animation_id,omitempty"` + SoundID *snowflake.ID `json:"sound_id,omitempty"` + SoundVolume *float64 `json:"sound_volume,omitempty"` } func (EventVoiceChannelEffectSend) messageData() {} From c3695a64b30cd4ef8624d865d5e067451b1518a7 Mon Sep 17 00:00:00 2001 From: sebm253 Date: Sat, 27 Jul 2024 13:57:55 +0200 Subject: [PATCH 20/36] updates --- discord/soundboard.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/discord/soundboard.go b/discord/soundboard.go index f7052711b..011be9113 100644 --- a/discord/soundboard.go +++ b/discord/soundboard.go @@ -13,17 +13,15 @@ const ( ) type SoundboardSound struct { - Name string `json:"name"` - SoundID snowflake.ID `json:"sound_id"` - ID *snowflake.ID `json:"id"` - Volume float64 `json:"volume"` - EmojiID *snowflake.ID `json:"emoji_id"` - EmojiName *string `json:"emoji_name"` - OverridePath *string `json:"override_path"` - GuildID *snowflake.ID `json:"guild_id,omitempty"` - UserID snowflake.ID `json:"user_id"` - Available *bool `json:"available,omitempty"` - User *User `json:"user"` + Name string `json:"name"` + SoundID snowflake.ID `json:"sound_id"` + Volume float64 `json:"volume"` + EmojiID *snowflake.ID `json:"emoji_id"` + EmojiName *string `json:"emoji_name"` + GuildID *snowflake.ID `json:"guild_id,omitempty"` + UserID snowflake.ID `json:"user_id"` + Available *bool `json:"available,omitempty"` + User *User `json:"user"` } type SoundboardSoundCreate struct { @@ -39,4 +37,4 @@ type SoundboardSoundUpdate struct { Volume *json.Nullable[float64] `json:"volume,omitempty"` EmojiID *json.Nullable[snowflake.ID] `json:"emoji_id,omitempty"` EmojiName *json.Nullable[string] `json:"emoji_name,omitempty"` -} \ No newline at end of file +} From 598fe31b4141070e3bd2fa94aabb5d069defd79a Mon Sep 17 00:00:00 2001 From: sebm253 Date: Tue, 30 Jul 2024 13:00:31 +0200 Subject: [PATCH 21/36] remove UserID from SoundboardSound --- discord/soundboard.go | 1 - 1 file changed, 1 deletion(-) diff --git a/discord/soundboard.go b/discord/soundboard.go index 011be9113..5fd22ae36 100644 --- a/discord/soundboard.go +++ b/discord/soundboard.go @@ -19,7 +19,6 @@ type SoundboardSound struct { EmojiID *snowflake.ID `json:"emoji_id"` EmojiName *string `json:"emoji_name"` GuildID *snowflake.ID `json:"guild_id,omitempty"` - UserID snowflake.ID `json:"user_id"` Available *bool `json:"available,omitempty"` User *User `json:"user"` } From 16682b6fb17880759efa401e8175b862f813ad59 Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Thu, 15 Aug 2024 14:07:21 +0200 Subject: [PATCH 22/36] updates https://github.com/discord/discord-api-docs/pull/6260/commits/8b05cc635a003706658b997450ecfef4e4cf9e23 --- discord/soundboard.go | 5 +++++ events/guild_emoji_events.go | 8 ++++---- events/guild_soundboard_events.go | 14 ++++++++++---- events/guild_sticker_events.go | 8 ++++---- events/listener_adapter.go | 13 +++++++++---- gateway/gateway_event_type.go | 1 + gateway/gateway_events.go | 5 +++++ gateway/gateway_intents.go | 7 +++++-- gateway/gateway_messages.go | 5 +++++ handlers/all_handlers.go | 1 + handlers/guild_soundboard_handlers.go | 11 +++++++++++ rest/rest_endpoints.go | 4 ++++ rest/soundboard_sounds.go | 25 +++++++++++++++++++++++++ 13 files changed, 89 insertions(+), 18 deletions(-) diff --git a/discord/soundboard.go b/discord/soundboard.go index 5fd22ae36..8450cbe8b 100644 --- a/discord/soundboard.go +++ b/discord/soundboard.go @@ -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"` +} diff --git a/events/guild_emoji_events.go b/events/guild_emoji_events.go index 8ffa30d22..80d97235b 100644 --- a/events/guild_emoji_events.go +++ b/events/guild_emoji_events.go @@ -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 } diff --git a/events/guild_soundboard_events.go b/events/guild_soundboard_events.go index 863228238..0bce60aa1 100644 --- a/events/guild_soundboard_events.go +++ b/events/guild_soundboard_events.go @@ -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 diff --git a/events/guild_sticker_events.go b/events/guild_sticker_events.go index 39f40ad3f..9984f5318 100644 --- a/events/guild_sticker_events.go +++ b/events/guild_sticker_events.go @@ -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 } diff --git a/events/listener_adapter.go b/events/listener_adapter.go index e26bd2d63..b560fc226 100644 --- a/events/listener_adapter.go +++ b/events/listener_adapter.go @@ -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) @@ -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) diff --git a/gateway/gateway_event_type.go b/gateway/gateway_event_type.go index 8e6192ac8..fbc9f758c 100644 --- a/gateway/gateway_event_type.go +++ b/gateway/gateway_event_type.go @@ -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" diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index 57120da24..fef7bab27 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -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 } diff --git a/gateway/gateway_intents.go b/gateway/gateway_intents.go index 68f6c4ec2..2945dd691 100644 --- a/gateway/gateway_intents.go +++ b/gateway/gateway_intents.go @@ -10,6 +10,7 @@ const ( IntentGuilds Intents = 1 << iota IntentGuildMembers IntentGuildModeration + // Deprecated: Use IntentGuildExpressions instead IntentGuildEmojisAndStickers IntentGuildIntegrations IntentGuildWebhooks @@ -34,10 +35,12 @@ const ( IntentGuildMessagePolls IntentDirectMessagePolls + IntentGuildExpressions = IntentGuildEmojisAndStickers + IntentsGuild = IntentGuilds | IntentGuildMembers | IntentGuildModeration | - IntentGuildEmojisAndStickers | + IntentGuildExpressions | IntentGuildIntegrations | IntentGuildWebhooks | IntentGuildInvites | @@ -59,7 +62,7 @@ const ( IntentsNonPrivileged = IntentGuilds | IntentGuildModeration | - IntentGuildEmojisAndStickers | + IntentGuildExpressions | IntentGuildIntegrations | IntentGuildWebhooks | IntentGuildInvites | diff --git a/gateway/gateway_messages.go b/gateway/gateway_messages.go index 5b783cda3..1f33114a6 100644 --- a/gateway/gateway_messages.go +++ b/gateway/gateway_messages.go @@ -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) diff --git a/handlers/all_handlers.go b/handlers/all_handlers.go index 73f179e06..e3a5ff24d 100644 --- a/handlers/all_handlers.go +++ b/handlers/all_handlers.go @@ -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), diff --git a/handlers/guild_soundboard_handlers.go b/handlers/guild_soundboard_handlers.go index 5c14dda90..6ee340c22 100644 --- a/handlers/guild_soundboard_handlers.go +++ b/handlers/guild_soundboard_handlers.go @@ -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), diff --git a/rest/rest_endpoints.go b/rest/rest_endpoints.go index fa537aae0..a19b195ad 100644 --- a/rest/rest_endpoints.go +++ b/rest/rest_endpoints.go @@ -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}") ) @@ -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 diff --git a/rest/soundboard_sounds.go b/rest/soundboard_sounds.go index 024401184..7886e6b68 100644 --- a/rest/soundboard_sounds.go +++ b/rest/soundboard_sounds.go @@ -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 { @@ -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 @@ -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"` +} From 2082aa89355dac906edf2a62b25746a7ba8e0649 Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Thu, 15 Aug 2024 15:55:50 +0200 Subject: [PATCH 23/36] add URL() --- discord/soundboard.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/discord/soundboard.go b/discord/soundboard.go index 8450cbe8b..7633a0920 100644 --- a/discord/soundboard.go +++ b/discord/soundboard.go @@ -23,6 +23,10 @@ type SoundboardSound struct { User *User `json:"user"` } +func (s SoundboardSound) URL(opts ...CDNOpt) string { + return formatAssetURL(SoundboardSoundFile, opts, s.SoundID) +} + type SoundboardSoundCreate struct { Name string `json:"name"` Sound Sound `json:"sound"` From d2253dd7020b8e99a10b487346b7d0274fcbfdf1 Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:41:58 +0200 Subject: [PATCH 24/36] add required intent + fix docs --- events/guild_voice_events.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/events/guild_voice_events.go b/events/guild_voice_events.go index b9543ee9a..3f8d4593f 100644 --- a/events/guild_voice_events.go +++ b/events/guild_voice_events.go @@ -5,37 +5,37 @@ import ( "github.com/disgoorg/disgo/gateway" ) -// GuildVoiceChannelEffectSend indicates that a discord.User sent an effect in a discord.GuildVoiceChannel +// GuildVoiceChannelEffectSend indicates that a discord.Member sent an effect in a discord.GuildVoiceChannel (requires gateway.IntentGuildVoiceStates) type GuildVoiceChannelEffectSend struct { *GenericEvent gateway.EventVoiceChannelEffectSend } -// GenericGuildVoiceState is called upon receiving GuildVoiceJoin , GuildVoiceMove , GuildVoiceLeave +// GenericGuildVoiceState is called upon receiving GuildVoiceJoin, GuildVoiceMove and GuildVoiceLeave type GenericGuildVoiceState struct { *GenericEvent VoiceState discord.VoiceState Member discord.Member } -// GuildVoiceStateUpdate indicates that the discord.VoiceState of a discord.Member has updated(requires gateway.IntentsGuildVoiceStates) +// GuildVoiceStateUpdate indicates that the discord.VoiceState of a discord.Member has updated (requires gateway.IntentGuildVoiceStates) type GuildVoiceStateUpdate struct { *GenericGuildVoiceState OldVoiceState discord.VoiceState } -// GuildVoiceJoin indicates that a discord.Member joined a discord.Channel(requires gateway.IntentsGuildVoiceStates) +// GuildVoiceJoin indicates that a discord.Member joined a discord.GuildVoiceChannel (requires gateway.IntentGuildVoiceStates) type GuildVoiceJoin struct { *GenericGuildVoiceState } -// GuildVoiceMove indicates that a discord.Member moved a discord.Channel(requires gateway.IntentsGuildVoiceStates) +// GuildVoiceMove indicates that a discord.Member was moved to a different discord.GuildVoiceChannel (requires gateway.IntentGuildVoiceStates) type GuildVoiceMove struct { *GenericGuildVoiceState OldVoiceState discord.VoiceState } -// GuildVoiceLeave indicates that a discord.Member left a discord.Channel(requires gateway.IntentsGuildVoiceStates) +// GuildVoiceLeave indicates that a discord.Member left a discord.GuildVoiceChannel (requires gateway.IntentGuildVoiceStates) type GuildVoiceLeave struct { *GenericGuildVoiceState OldVoiceState discord.VoiceState From ae06f00b08b53dde89a902eea420d22435ce0e65 Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:46:20 +0200 Subject: [PATCH 25/36] SoundboardEffectAnimationType -> VoiceChannelEffectAnimationType --- discord/soundboard.go | 6 +++--- gateway/gateway_events.go | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/discord/soundboard.go b/discord/soundboard.go index 37f769d8d..c8df7d907 100644 --- a/discord/soundboard.go +++ b/discord/soundboard.go @@ -1,8 +1,8 @@ package discord -type SoundboardEffectAnimationType int +type VoiceChannelEffectAnimationType int const ( - SoundboardEffectAnimationTypePremium SoundboardEffectAnimationType = iota - SoundboardEffectAnimationTypeBasic + VoiceChannelEffectAnimationTypePremium VoiceChannelEffectAnimationType = iota + VoiceChannelEffectAnimationTypeBasic ) diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index 4823ff269..a69726973 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -604,14 +604,14 @@ func (EventUserUpdate) messageData() {} func (EventUserUpdate) eventData() {} type EventVoiceChannelEffectSend struct { - ChannelID snowflake.ID `json:"channel_id"` - GuildID snowflake.ID `json:"guild_id"` - UserID snowflake.ID `json:"user_id"` - Emoji *discord.Emoji `json:"emoji"` - AnimationType *discord.SoundboardEffectAnimationType `json:"animation_type,omitempty"` - AnimationID *int `json:"animation_id,omitempty"` - SoundID *snowflake.ID `json:"sound_id,omitempty"` - SoundVolume *float64 `json:"sound_volume,omitempty"` + ChannelID snowflake.ID `json:"channel_id"` + GuildID snowflake.ID `json:"guild_id"` + UserID snowflake.ID `json:"user_id"` + Emoji *discord.Emoji `json:"emoji"` + AnimationType *discord.VoiceChannelEffectAnimationType `json:"animation_type,omitempty"` + AnimationID *int `json:"animation_id,omitempty"` + SoundID *snowflake.ID `json:"sound_id,omitempty"` + SoundVolume *float64 `json:"sound_volume,omitempty"` } func (EventVoiceChannelEffectSend) messageData() {} From 7957f483ca35650cc3d051f94b3f2b69f33b2f38 Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Wed, 21 Aug 2024 22:56:21 +0200 Subject: [PATCH 26/36] oh man --- gateway/gateway_events.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index a69726973..45d1cf636 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -610,7 +610,7 @@ type EventVoiceChannelEffectSend struct { Emoji *discord.Emoji `json:"emoji"` AnimationType *discord.VoiceChannelEffectAnimationType `json:"animation_type,omitempty"` AnimationID *int `json:"animation_id,omitempty"` - SoundID *snowflake.ID `json:"sound_id,omitempty"` + SoundID *snowflake.ID `json:"sound_id,string"` SoundVolume *float64 `json:"sound_volume,omitempty"` } From 5d5e919289e1444f5c4545a7af698c49b68a543e Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Fri, 23 Aug 2024 21:38:47 +0200 Subject: [PATCH 27/36] Revert "oh man" This reverts commit 7957f483ca35650cc3d051f94b3f2b69f33b2f38. --- gateway/gateway_events.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index 45d1cf636..a69726973 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -610,7 +610,7 @@ type EventVoiceChannelEffectSend struct { Emoji *discord.Emoji `json:"emoji"` AnimationType *discord.VoiceChannelEffectAnimationType `json:"animation_type,omitempty"` AnimationID *int `json:"animation_id,omitempty"` - SoundID *snowflake.ID `json:"sound_id,string"` + SoundID *snowflake.ID `json:"sound_id,omitempty"` SoundVolume *float64 `json:"sound_volume,omitempty"` } From df95c4b6b6e7d6a8378542b80209eb19a580047d Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Fri, 23 Aug 2024 21:44:28 +0200 Subject: [PATCH 28/36] change SoundID type to int64 with ,string --- gateway/gateway_events.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index a69726973..dc897e5da 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -610,7 +610,7 @@ type EventVoiceChannelEffectSend struct { Emoji *discord.Emoji `json:"emoji"` AnimationType *discord.VoiceChannelEffectAnimationType `json:"animation_type,omitempty"` AnimationID *int `json:"animation_id,omitempty"` - SoundID *snowflake.ID `json:"sound_id,omitempty"` + SoundID *int64 `json:"sound_id,string"` SoundVolume *float64 `json:"sound_volume,omitempty"` } From 843e2b952a0cd438da2b032c38c8da6da1589bce Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:20:33 +0200 Subject: [PATCH 29/36] add event umarshaler --- gateway/gateway_events.go | 23 ++++++++++++++++++++++- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/gateway/gateway_events.go b/gateway/gateway_events.go index dc897e5da..8afcee379 100644 --- a/gateway/gateway_events.go +++ b/gateway/gateway_events.go @@ -610,10 +610,31 @@ type EventVoiceChannelEffectSend struct { Emoji *discord.Emoji `json:"emoji"` AnimationType *discord.VoiceChannelEffectAnimationType `json:"animation_type,omitempty"` AnimationID *int `json:"animation_id,omitempty"` - SoundID *int64 `json:"sound_id,string"` + SoundID *int64 `json:"-"` SoundVolume *float64 `json:"sound_volume,omitempty"` } +func (e *EventVoiceChannelEffectSend) UnmarshalJSON(data []byte) error { + type eventVoiceChannelEffectSend EventVoiceChannelEffectSend + var v struct { + SoundID *json.Number `json:"sound_id"` + eventVoiceChannelEffectSend + } + if err := json.Unmarshal(data, &v); err != nil { + return err + } + *e = EventVoiceChannelEffectSend(v.eventVoiceChannelEffectSend) + if v.SoundID == nil { + return nil + } + i, err := v.SoundID.Int64() + if err != nil { + return err + } + e.SoundID = &i + return nil +} + func (EventVoiceChannelEffectSend) messageData() {} func (EventVoiceChannelEffectSend) eventData() {} diff --git a/go.mod b/go.mod index b0052dcab..22e68fb73 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/disgoorg/disgo go 1.21 require ( - github.com/disgoorg/json v1.1.0 + github.com/disgoorg/json v1.2.0 github.com/disgoorg/snowflake/v2 v2.0.3 github.com/gorilla/websocket v1.5.3 github.com/sasha-s/go-csync v0.0.0-20240107134140-fcbab37b09ad diff --git a/go.sum b/go.sum index 9d343049a..4d38e69da 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys= -github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA= +github.com/disgoorg/json v1.2.0 h1:6e/j4BCfSHIvucG1cd7tJPAOp1RgnnMFSqkvZUtEd1Y= +github.com/disgoorg/json v1.2.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA= github.com/disgoorg/snowflake/v2 v2.0.3 h1:3B+PpFjr7j4ad7oeJu4RlQ+nYOTadsKapJIzgvSI2Ro= github.com/disgoorg/snowflake/v2 v2.0.3/go.mod h1:W6r7NUA7DwfZLwr00km6G4UnZ0zcoLBRufhkFWgAc4c= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= From dbc3bb9c1416421eb6e8b9ed61fe24d7a33ede50 Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:31:31 +0200 Subject: [PATCH 30/36] damn this shit is broken --- cache/caches.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/cache/caches.go b/cache/caches.go index d12bf42dd..686268541 100644 --- a/cache/caches.go +++ b/cache/caches.go @@ -885,7 +885,7 @@ func New(opts ...ConfigOpt) Caches { channelCache: config.ChannelCache, stageInstanceCache: config.StageInstanceCache, guildScheduledEventCache: config.GuildScheduledEventCache, - guildSoundboardSoundCache: config.GuildSoundboardSoundCache, + guildSoundboardSoundCache: config.GuildSoundboardSoundCache, roleCache: config.RoleCache, memberCache: config.MemberCache, threadMemberCache: config.ThreadMemberCache, @@ -899,19 +899,20 @@ func New(opts ...ConfigOpt) Caches { // these type aliases are needed to allow having the GuildCache, ChannelCache, etc. as methods on the cachesImpl struct type ( - guildCache = GuildCache - channelCache = ChannelCache - stageInstanceCache = StageInstanceCache - guildScheduledEventCache = GuildScheduledEventCache - roleCache = RoleCache - memberCache = MemberCache - threadMemberCache = ThreadMemberCache - presenceCache = PresenceCache - voiceStateCache = VoiceStateCache - messageCache = MessageCache - emojiCache = EmojiCache - stickerCache = StickerCache - selfUserCache = SelfUserCache + guildCache = GuildCache + channelCache = ChannelCache + stageInstanceCache = StageInstanceCache + guildScheduledEventCache = GuildScheduledEventCache + guildSoundboardSoundCache = GuildSoundboardSoundCache + roleCache = RoleCache + memberCache = MemberCache + threadMemberCache = ThreadMemberCache + presenceCache = PresenceCache + voiceStateCache = VoiceStateCache + messageCache = MessageCache + emojiCache = EmojiCache + stickerCache = StickerCache + selfUserCache = SelfUserCache ) type cachesImpl struct { @@ -921,7 +922,7 @@ type cachesImpl struct { channelCache stageInstanceCache guildScheduledEventCache - guildSoundboardSoundCache + guildSoundboardSoundCache roleCache memberCache threadMemberCache From 49d9570832ae7ebea1ca06ab5f649be793fcbf28 Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:49:56 +0200 Subject: [PATCH 31/36] add GuildFeatureMoreSoundboard https://github.com/discord/discord-api-docs/pull/6260/commits/5a13333fb29e2324058bec21306125b9a69dfcbd --- discord/guild.go | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/guild.go b/discord/guild.go index faaf0b490..03a383dee 100644 --- a/discord/guild.go +++ b/discord/guild.go @@ -111,6 +111,7 @@ const ( GuildFeatureInvitesDisabled GuildFeature = "INVITES_DISABLED" GuildFeatureInviteSplash GuildFeature = "INVITE_SPLASH" GuildFeatureMemberVerificationGateEnabled GuildFeature = "MEMBER_VERIFICATION_GATE_ENABLED" + GuildFeatureMoreSoundboard GuildFeature = "MORE_SOUNDBOARD" GuildFeatureMoreStickers GuildFeature = "MORE_STICKERS" GuildFeatureNews GuildFeature = "NEWS" GuildFeaturePartnered GuildFeature = "PARTNERED" From e0fafc92c65413ff178d462b129302d89ffd9109 Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Sat, 31 Aug 2024 21:50:10 +0200 Subject: [PATCH 32/36] add missing cache getter --- cache/caches.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cache/caches.go b/cache/caches.go index 686268541..dbc9cdfa9 100644 --- a/cache/caches.go +++ b/cache/caches.go @@ -297,6 +297,7 @@ func (c *guildScheduledEventCacheImpl) RemoveGuildScheduledEventsByGuildID(guild } type GuildSoundboardSoundCache interface { + GuildSoundboardSoundCache() GroupedCache[discord.SoundboardSound] GuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID) (discord.SoundboardSound, bool) GuildSoundboardSoundsForEach(guildID snowflake.ID, fn func(sound discord.SoundboardSound)) GuildSoundboardSoundsAllLen() int @@ -316,6 +317,10 @@ type guildSoundboardSoundCacheImpl struct { cache GroupedCache[discord.SoundboardSound] } +func (c *guildSoundboardSoundCacheImpl) GuildSoundboardSoundCache() GroupedCache[discord.SoundboardSound] { + return c.cache +} + func (c *guildSoundboardSoundCacheImpl) GuildSoundboardSound(guildID snowflake.ID, soundID snowflake.ID) (discord.SoundboardSound, bool) { return c.cache.Get(guildID, soundID) } From 88f0566067520009376585296270acc369f33746 Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Sat, 21 Sep 2024 17:25:31 +0200 Subject: [PATCH 33/36] add request func to client interface --- bot/client.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bot/client.go b/bot/client.go index 53816ecbc..eb5936512 100644 --- a/bot/client.go +++ b/bot/client.go @@ -92,6 +92,9 @@ type Client interface { // limit : The number of discord.Member(s) to return. RequestMembersWithQuery(ctx context.Context, guildID snowflake.ID, presence bool, nonce string, query string, limit int) error + // RequestSoundboardSounds a gateway.MessageDataRequestSoundboardSounds to the specific gateway.Gateway and requests the SoundboardSounds of the specified guilds. + RequestSoundboardSounds(ctx context.Context, guildIDs ...snowflake.ID) error + // SetPresence sends new presence data to the gateway.Gateway. SetPresence(ctx context.Context, opts ...gateway.PresenceOpt) error From d66a8d79877c8d973c8e2ebb54b37ea7965f0281 Mon Sep 17 00:00:00 2001 From: sebm253 <42180891+sebm253@users.noreply.github.com> Date: Sat, 21 Sep 2024 20:39:26 +0200 Subject: [PATCH 34/36] fix endpoint method --- rest/rest_endpoints.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest/rest_endpoints.go b/rest/rest_endpoints.go index 16f4059d0..5015e6b9d 100644 --- a/rest/rest_endpoints.go +++ b/rest/rest_endpoints.go @@ -144,7 +144,7 @@ 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}") + GetGuildSoundboardSound = NewEndpoint(http.MethodGet, "/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}") ) From 71d6d64a5292eef523b7dbe6850a1a89db9c935b Mon Sep 17 00:00:00 2001 From: Sebastian <42180891+sebm253@users.noreply.github.com> Date: Sat, 21 Sep 2024 21:01:26 +0200 Subject: [PATCH 35/36] Update discord/soundboard.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Toπ --- discord/soundboard.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/soundboard.go b/discord/soundboard.go index 01b5fd772..0dc4b72ac 100644 --- a/discord/soundboard.go +++ b/discord/soundboard.go @@ -20,7 +20,7 @@ type SoundboardSound struct { EmojiName *string `json:"emoji_name"` GuildID *snowflake.ID `json:"guild_id,omitempty"` Available *bool `json:"available,omitempty"` - User *User `json:"user"` + User *User `json:"user,omitempty"` } func (s SoundboardSound) URL(opts ...CDNOpt) string { From 39a71ec33532e1927786a45317b28e5a11e4f379 Mon Sep 17 00:00:00 2001 From: Sebastian <42180891+sebm253@users.noreply.github.com> Date: Sat, 21 Sep 2024 21:02:21 +0200 Subject: [PATCH 36/36] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Toπ --- discord/sound.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/discord/sound.go b/discord/sound.go index 18d05250f..0bd2908fe 100644 --- a/discord/sound.go +++ b/discord/sound.go @@ -17,11 +17,11 @@ const ( SoundTypeUnknown = SoundTypeMP3 ) -func (t SoundType) GetMIME() string { +func (t SoundType) MIME() string { return string(t) } -func (t SoundType) GetHeader() string { +func (t SoundType) Header() string { return "data:" + string(t) + ";base64" } @@ -55,5 +55,5 @@ func (s Sound) String() string { if len(s.Data) == 0 { return "" } - return s.Type.GetHeader() + "," + string(s.Data) + return s.Type.Header() + "," + string(s.Data) }