Skip to content

Commit

Permalink
Add support for changing voice status (#2982)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhgndf authored Oct 16, 2024
1 parent 57af3e0 commit 7cb10ad
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/builder/edit_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ impl<'a> EditChannel<'a> {
self
}

/// The status of the voice channel. Can be empty.
///
/// Must be between 0 and 1024 characters long.
///
/// This is for [voice] channels only.
///
/// [voice]: ChannelType::Voice
pub fn status(mut self, status: impl Into<String>) -> Self {
self.status = Some(status.into());
self
}

/// Is the channel inappropriate for work?
///
/// This is for [text] channels only.
Expand Down Expand Up @@ -324,6 +336,24 @@ impl<'a> Builder for EditChannel<'a> {
}
}

if let Some(status) = &self.status {
#[derive(Serialize)]
struct EditVoiceStatusBody<'a> {
status: &'a str,
}

cache_http
.http()
.edit_voice_status(
ctx,
&EditVoiceStatusBody {
status: status.as_str(),
},
self.audit_log_reason,
)
.await?;
}

cache_http.http().edit_channel(ctx, &self, self.audit_log_reason).await
}
}
22 changes: 22 additions & 0 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2412,6 +2412,28 @@ impl Http {
.await
}

/// Changes a voice channel's status.
pub async fn edit_voice_status(
&self,
channel_id: ChannelId,
map: &impl serde::Serialize,
audit_log_reason: Option<&str>,
) -> Result<()> {
let body = to_vec(map)?;

self.wind(204, Request {
body: Some(body),
multipart: None,
headers: audit_log_reason.map(reason_into_header),
method: LightMethod::Put,
route: Route::ChannelVoiceStatus {
channel_id,
},
params: None,
})
.await
}

/// Edits a the webhook with the given data.
///
/// The Value is a map with optional values of:
Expand Down
4 changes: 4 additions & 0 deletions src/http/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ routes! ('a, {
api!("/channels/{}/polls/{}/expire", channel_id, message_id),
Some(RatelimitingKind::PathAndId(channel_id.into()));

ChannelVoiceStatus { channel_id: ChannelId },
api!("/channels/{}/voice-status", channel_id),
Some(RatelimitingKind::PathAndId(channel_id.into()));

Gateway,
api!("/gateway"),
Some(RatelimitingKind::Path);
Expand Down

0 comments on commit 7cb10ad

Please sign in to comment.