From 624cb3a30a6ad581c6ab139c3420ebb2d13c8c79 Mon Sep 17 00:00:00 2001 From: MCausc78 Date: Fri, 19 Jan 2024 17:43:09 +0200 Subject: [PATCH] impl --- src/audit_log.v | 11 +++++++++++ src/channel.v | 11 +++++++++++ src/events.v | 41 +++++++++++++++++++++++++++++++++++++++++ src/permissions.v | 3 +++ 4 files changed, 66 insertions(+) diff --git a/src/audit_log.v b/src/audit_log.v index a929e19..a9211c9 100644 --- a/src/audit_log.v +++ b/src/audit_log.v @@ -120,6 +120,10 @@ pub enum AuditLogEvent { creator_monetization_request_created = 150 // Creator monetization terms were accepted creator_monetization_terms_accepted + // 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 { @@ -181,6 +185,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 { @@ -247,6 +253,11 @@ pub fn AuditEntryInfo.parse(j json2.Any) !AuditEntryInfo { } else { none } + status: if s := j['status'] { + s as string + } else { + none + } } } else { diff --git a/src/channel.v b/src/channel.v index 57e7c38..7ba9005 100644 --- a/src/channel.v +++ b/src/channel.v @@ -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) @@ -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 { diff --git a/src/events.v b/src/events.v index 08d7b88..15a3ea2 100644 --- a/src/events.v +++ b/src/events.v @@ -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: @@ -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] @@ -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 @@ -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 diff --git a/src/permissions.v b/src/permissions.v index e71604a..460f79f 100644 --- a/src/permissions.v +++ b/src/permissions.v @@ -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.zero() Permissions {