Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GuildVoiceChannelEffectSend #282

Merged
merged 14 commits into from
Aug 24, 2024
8 changes: 8 additions & 0 deletions discord/soundboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package discord

type VoiceChannelEffectAnimationType int

const (
VoiceChannelEffectAnimationTypePremium VoiceChannelEffectAnimationType = iota
VoiceChannelEffectAnimationTypeBasic
)
16 changes: 11 additions & 5 deletions events/guild_voice_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,37 @@ import (
"github.com/disgoorg/disgo/gateway"
)

// GenericGuildVoiceState is called upon receiving GuildVoiceJoin , GuildVoiceMove , GuildVoiceLeave
// 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 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
Expand Down
15 changes: 10 additions & 5 deletions events/listener_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,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)
Expand Down Expand Up @@ -483,6 +484,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)
Expand Down
1 change: 1 addition & 0 deletions gateway/gateway_event_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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"
Expand Down
35 changes: 35 additions & 0 deletions gateway/gateway_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,41 @@ 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.VoiceChannelEffectAnimationType `json:"animation_type,omitempty"`
AnimationID *int `json:"animation_id,omitempty"`
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() {}

type EventVoiceStateUpdate struct {
discord.VoiceState
Member discord.Member `json:"member"`
Expand Down
5 changes: 5 additions & 0 deletions gateway/gateway_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
1 change: 1 addition & 0 deletions handlers/all_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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),

Expand Down
7 changes: 7 additions & 0 deletions handlers/voice_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading