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 voice channel status #308

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions discord/audit_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ const (
AuditLogCreatorMonetizationTermsAccepted
)

const (
AuditLogVoiceChannelStatusCreate AuditLogEvent = iota + 192
AuditLogVoiceChannelStatusDelete
)

// AuditLog (https://discord.com/developers/docs/resources/audit-log) These are logs of events that occurred, accessible via the Discord
type AuditLog struct {
ApplicationCommands []ApplicationCommand `json:"application_commands"`
Expand Down Expand Up @@ -255,4 +260,5 @@ type OptionalAuditLogEntryInfo struct {
AutoModerationRuleName *string `json:"auto_moderation_rule_name"`
AutoModerationRuleTriggerType *AutoModerationTriggerType `json:"auto_moderation_rule_trigger_type,string"`
IntegrationType *IntegrationType `json:"integration_type"`
Status *string `json:"status"`
}
11 changes: 11 additions & 0 deletions discord/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ type GuildVoiceChannel struct {
rtcRegion string
VideoQualityMode VideoQualityMode
lastMessageID *snowflake.ID
status *string
nsfw bool
rateLimitPerUser int
}
Expand All @@ -463,6 +464,7 @@ func (c *GuildVoiceChannel) UnmarshalJSON(data []byte) error {
c.rtcRegion = v.RTCRegion
c.VideoQualityMode = v.VideoQualityMode
c.lastMessageID = v.LastMessageID
c.status = v.Status
c.nsfw = v.NSFW
c.rateLimitPerUser = v.RateLimitPerUser
return nil
Expand All @@ -482,6 +484,7 @@ func (c GuildVoiceChannel) MarshalJSON() ([]byte, error) {
RTCRegion: c.rtcRegion,
VideoQualityMode: c.VideoQualityMode,
LastMessageID: c.lastMessageID,
Status: c.status,
NSFW: c.nsfw,
RateLimitPerUser: c.rateLimitPerUser,
})
Expand Down Expand Up @@ -545,6 +548,10 @@ func (c GuildVoiceChannel) Topic() *string {
return nil
}

func (c GuildVoiceChannel) Status() *string {
return c.status
}

func (c GuildVoiceChannel) NSFW() bool {
return c.nsfw
}
Expand Down Expand Up @@ -1304,6 +1311,10 @@ type PartialChannel struct {
Type ChannelType `json:"type"`
}

type VoiceStatusUpdate struct {
Status string `json:"status"`
}

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

Expand Down
1 change: 1 addition & 0 deletions discord/channels_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ type guildVoiceChannel struct {
RTCRegion string `json:"rtc_region"`
VideoQualityMode VideoQualityMode `json:"video_quality_mode"`
LastMessageID *snowflake.ID `json:"last_message_id"`
Status *string `json:"status"`
NSFW bool `json:"nsfw"`
RateLimitPerUser int `json:"rate_limit_per_user"`
}
Expand Down
6 changes: 5 additions & 1 deletion discord/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const (
_
PermissionUseExternalSounds
PermissionSendVoiceMessages
_
PermissionSetVoiceChannelStatus

PermissionsAllText = PermissionViewChannel |
PermissionSendMessages |
Expand Down Expand Up @@ -91,7 +93,8 @@ const (
PermissionUseSoundboard |
PermissionUseExternalSounds |
PermissionRequestToSpeak |
PermissionUseEmbeddedActivities
PermissionUseEmbeddedActivities |
PermissionSetVoiceChannelStatus

PermissionsAllChannel = PermissionsAllText |
PermissionsAllThread |
Expand Down Expand Up @@ -168,6 +171,7 @@ var permissions = map[Permissions]string{
PermissionStream: "Video",
PermissionViewGuildInsights: "View Server Insights",
PermissionSendVoiceMessages: "Send Voice Messages",
PermissionSetVoiceChannelStatus: "Set Voice Channel Status",
}

func (p Permissions) String() string {
Expand Down
5 changes: 5 additions & 0 deletions events/guild_voice_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ type VoiceServerUpdate struct {
*GenericEvent
gateway.EventVoiceServerUpdate
}

type VoiceChannelStatusUpdate struct {
*GenericEvent
gateway.EventVoiceChannelStatusUpdate
}
15 changes: 10 additions & 5 deletions events/listener_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
OnVoiceChannelStatusUpdate func(event *VoiceChannelStatusUpdate)
OnVoiceServerUpdate func(event *VoiceServerUpdate)
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 @@ -445,6 +446,10 @@ func (l *ListenerAdapter) OnEvent(event bot.Event) {
}

// Guild Voice Events
case *VoiceChannelStatusUpdate:
if listener := l.OnVoiceChannelStatusUpdate; listener != nil {
listener(e)
}
case *VoiceServerUpdate:
if listener := l.OnVoiceServerUpdate; 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 @@ -66,6 +66,7 @@ const (
EventTypeStageInstanceUpdate EventType = "STAGE_INSTANCE_UPDATE"
EventTypeTypingStart EventType = "TYPING_START"
EventTypeUserUpdate EventType = "USER_UPDATE"
EventTypeVoiceChannelStatusUpdate EventType = "VOICE_CHANNEL_STATUS_UPDATE"
EventTypeVoiceStateUpdate EventType = "VOICE_STATE_UPDATE"
EventTypeVoiceServerUpdate EventType = "VOICE_SERVER_UPDATE"
EventTypeWebhooksUpdate EventType = "WEBHOOKS_UPDATE"
Expand Down
9 changes: 9 additions & 0 deletions gateway/gateway_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,15 @@ type EventUserUpdate struct {
func (EventUserUpdate) messageData() {}
func (EventUserUpdate) eventData() {}

type EventVoiceChannelStatusUpdate struct {
ID snowflake.ID `json:"id"`
GuildID snowflake.ID `json:"guild_id"`
Status *string `json:"status"`
}

func (EventVoiceChannelStatusUpdate) messageData() {}
func (EventVoiceChannelStatusUpdate) 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 @@ -394,6 +394,11 @@ func UnmarshalEventData(data []byte, eventType EventType) (EventData, error) {
err = json.Unmarshal(data, &d)
eventData = d

case EventTypeVoiceChannelStatusUpdate:
var d EventVoiceChannelStatusUpdate
err = json.Unmarshal(data, &d)
eventData = d

case EventTypeVoiceStateUpdate:
var d EventVoiceStateUpdate
err = json.Unmarshal(data, &d)
Expand Down
1 change: 1 addition & 0 deletions handlers/all_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ var allEventHandlers = []bot.GatewayEventHandler{
bot.NewGatewayEventHandler(gateway.EventTypeTypingStart, gatewayHandlerTypingStart),
bot.NewGatewayEventHandler(gateway.EventTypeUserUpdate, gatewayHandlerUserUpdate),

bot.NewGatewayEventHandler(gateway.EventTypeVoiceChannelStatusUpdate, gatewayHandlerVoiceChannelStatusUpdate),
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 @@ -61,3 +61,10 @@ func gatewayHandlerVoiceServerUpdate(client bot.Client, sequenceNumber int, shar
EventVoiceServerUpdate: event,
})
}

func gatewayHandlerVoiceChannelStatusUpdate(client bot.Client, sequenceNumber int, shardID int, event gateway.EventVoiceChannelStatusUpdate) {
client.EventManager().DispatchEvent(&events.VoiceChannelStatusUpdate{
GenericEvent: events.NewGenericEvent(client, sequenceNumber, shardID),
EventVoiceChannelStatusUpdate: event,
})
}
6 changes: 6 additions & 0 deletions rest/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type Channels interface {
PinMessage(channelID snowflake.ID, messageID snowflake.ID, opts ...RequestOpt) error
UnpinMessage(channelID snowflake.ID, messageID snowflake.ID, opts ...RequestOpt) error
Follow(channelID snowflake.ID, targetChannelID snowflake.ID, opts ...RequestOpt) (*discord.FollowedChannel, error)

UpdateVoiceStatus(channelID snowflake.ID, status string, opts ...RequestOpt) error
}

type channelImpl struct {
Expand Down Expand Up @@ -222,3 +224,7 @@ func (s *channelImpl) Follow(channelID snowflake.ID, targetChannelID snowflake.I
err = s.client.Do(FollowChannel.Compile(nil, channelID), discord.FollowChannel{ChannelID: targetChannelID}, &followedChannel, opts...)
return
}

func (s *channelImpl) UpdateVoiceStatus(channelID snowflake.ID, status string, opts ...RequestOpt) error {
return s.client.Do(UpdateVoiceStatus.Compile(nil, channelID), discord.VoiceStatusUpdate{Status: status}, nil, opts...)
}
2 changes: 2 additions & 0 deletions rest/rest_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ var (

SendTyping = NewEndpoint(http.MethodPost, "/channels/{channel.id}/typing")
FollowChannel = NewEndpoint(http.MethodPost, "/channels/{channel.id}/followers")

UpdateVoiceStatus = NewEndpoint(http.MethodPut, "/channels/{channel.id}/voice-status")
)

// Threads
Expand Down