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 stuff #8

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/audit_log.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import x.json2
// The table below lists audit log events and values (the `action_type` field) that your app may receive.
// The `Object Changed` column notes which object's values may be included in the entry. Though there are exceptions, possible keys in the `changes` array typically correspond to the object's fields. The descriptions and types for those fields can be found in the linked documentation for the object.
// If no object is noted, there won't be a `changes` array in the entry, though other fields like the `target_id` still exist and many have fields in the options array.

pub enum AuditLogEvent {
// Server settings were updated
guild_update = 1
Expand Down Expand Up @@ -119,7 +118,8 @@ pub enum AuditLogEvent {
// Creator monetization request was created
creator_monetization_request_created = 150
// Creator monetization terms were accepted
creator_monetization_terms_accepted
creator_monetization_terms_accepted = 151

// Guild Onboarding Question was created
onboarding_question_create = 163
// Guild Onboarding Question was updated
Expand All @@ -130,6 +130,10 @@ pub enum AuditLogEvent {
server_guide_create = 190
// Guild Server Guide was updated
server_guide_update
// A voice channel status was updated by a user
voice_channel_status_update = 192
// A voice channel status was deleted by a user
voice_channel_status_delete
}

pub struct AuditLogChange {
Expand Down Expand Up @@ -191,6 +195,8 @@ pub:
typ ?string
// The type of integration which performed the action
integration_type ?string
// The new voice channel status
status ?string
}

pub fn AuditEntryInfo.parse(j json2.Any) !AuditEntryInfo {
Expand Down Expand Up @@ -257,6 +263,11 @@ pub fn AuditEntryInfo.parse(j json2.Any) !AuditEntryInfo {
} else {
none
}
status: if s := j['status'] {
s as string
} else {
none
}
}
}
else {
Expand Down
11 changes: 11 additions & 0 deletions src/channel.v
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ pub:
name string
// the channel topic (0-4096 characters for GUILD_FORUM and GUILD_MEDIA channels, 0-1024 characters for all others)
topic ?string
// the voice channel status (0-500 characters)
status ?NullOr[string]
// whether the channel is nsfw
nsfw ?bool
// the id of the last message sent in this channel (or thread for GUILD_FORUM or GUILD_MEDIA channels) (may not point to an existing or valid message or thread)
Expand Down Expand Up @@ -621,6 +623,15 @@ pub fn Channel.parse(j json2.Any) !Channel {
} else {
none
}
status: if s := j['status'] {
if s !is json2.Null {
some(s as string)
} else {
null[string]()
}
} else {
none
}
nsfw: if b := j['nsfw'] {
b as bool
} else {
Expand Down
41 changes: 41 additions & 0 deletions src/events.v
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,38 @@ pub fn ChannelDeleteEvent.parse(j json2.Any, base BaseEvent) !ChannelDeleteEvent
}
}

pub struct VoiceChannelStatusUpdateEvent {
BaseEvent
pub:
// The channel id
id Snowflake
// The guild id
guild_id Snowflake
// The new voice channel status
status ?string
}

pub fn VoiceChannelStatusUpdateEvent.parse(j json2.Any, base BaseEvent) !VoiceChannelStatusUpdateEvent {
match j {
map[string]json2.Any {
status := j['status']!
return VoiceChannelStatusUpdateEvent{
BaseEvent: base
id: Snowflake.parse(j['id']!)!
guild_id: Snowflake.parse(j['guild_id']!)!
status: if status !is json2.Null {
status as string
} else {
none
}
}
}
else {
return error('expected VoiceChannelStatusUpdateEvent to be object, got ${j.type_name()}')
}
}
}

pub struct AutoModerationActionExecutionEvent {
BaseEvent
pub:
Expand Down Expand Up @@ -1551,6 +1583,7 @@ pub mut:
on_channel_create EventController[ChannelCreateEvent]
on_channel_update EventController[ChannelUpdateEvent]
on_channel_delete EventController[ChannelDeleteEvent]
on_voice_channel_status_update EventController[VoiceChannelStatusUpdateEvent]
on_thread_create EventController[ThreadCreateEvent]
on_thread_update EventController[ThreadUpdateEvent]
on_thread_delete EventController[ThreadDeleteEvent]
Expand Down Expand Up @@ -1688,6 +1721,13 @@ fn event_process_channel_delete(mut gc GatewayClient, data json2.Any, options Em
gc.cache.channels.delete(event.channel.id)
}

fn event_process_voice_channel_status_update(mut gc GatewayClient, data json2.Any, options EmitOptions) ! {
gc.events.on_voice_channel_status_update.emit(VoiceChannelStatusUpdateEvent.parse(data,
BaseEvent{
creator: gc
})!, options)
}

fn event_process_thread_create(mut gc GatewayClient, data json2.Any, options EmitOptions) ! {
event := ThreadCreateEvent.parse(data, BaseEvent{
creator: gc
Expand Down Expand Up @@ -2230,6 +2270,7 @@ const events_table = EventsTable({
'CHANNEL_CREATE': event_process_channel_create
'CHANNEL_UPDATE': event_process_channel_update
'CHANNEL_DELETE': event_process_channel_delete
'VOICE_CHANNEL_STATUS_UPDATE': event_process_voice_channel_status_update
'THREAD_CREATE': event_process_thread_create
'THREAD_UPDATE': event_process_thread_update
'THREAD_DELETE': event_process_thread_delete
Expand Down
3 changes: 3 additions & 0 deletions src/permissions.v
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ pub enum Permissions as u64 {
use_external_sounds
// Allows sending voice messages
send_voice_messages
reserved_17
// Allows setting voice channel status
set_voice_channel_status
}

pub fn Permissions.all() Permissions {
Expand Down
Loading