-
-
Notifications
You must be signed in to change notification settings - Fork 169
feat: voice channel status #2419
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
base: main
Are you sure you want to change the base?
Changes from all commits
c0fb81d
e76e456
2b07c91
f4a7b10
3290b3c
034503b
5205cce
da5e8c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ mod interaction; | |
|
|
||
| pub use self::{builder::ClientBuilder, interaction::InteractionClient}; | ||
|
|
||
| use crate::request::channel::SetVoiceChannelStatus; | ||
| use crate::request::{ | ||
| application::{ | ||
| emoji::{ | ||
|
|
@@ -2882,6 +2883,14 @@ impl Client { | |
| DeleteApplicationEmoji::new(self, application_id, emoji_id) | ||
| } | ||
|
|
||
| /// Sets the status of a voice channel. | ||
| pub const fn set_voice_channel_status( | ||
| &self, | ||
| channel_id: Id<ChannelMarker>, | ||
| ) -> SetVoiceChannelStatus<'_> { | ||
| SetVoiceChannelStatus::new(self, channel_id) | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's ultimately no real organizational scheme to client method ordering, but would this make more sense somewhere around |
||
| /// Execute a request, returning a future resolving to a [`Response`]. | ||
| /// | ||
| /// # Errors | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,72 @@ | ||||||||
| use crate::client::Client; | ||||||||
| use crate::request::{Request, TryIntoRequest}; | ||||||||
| use crate::response::marker::EmptyBody; | ||||||||
| use crate::response::ResponseFuture; | ||||||||
| use crate::routing::Route; | ||||||||
| use crate::{Error, Response}; | ||||||||
| use serde::Serialize; | ||||||||
| use std::future::IntoFuture; | ||||||||
| use twilight_model::id::{marker::ChannelMarker, Id}; | ||||||||
| use twilight_validate::channel::{status as validate_status, ChannelValidationError}; | ||||||||
|
|
||||||||
| #[derive(Serialize)] | ||||||||
| pub(crate) struct SetVoiceChannelStatusFields<'a> { | ||||||||
| #[serde(skip_serializing_if = "Option::is_none")] | ||||||||
| status: Option<&'a str>, | ||||||||
|
Comment on lines
+14
to
+15
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment below. If None then this should serialize as
Suggested change
|
||||||||
| } | ||||||||
|
|
||||||||
| /// Sets the status of a voice channel. | ||||||||
| #[must_use = "requests must be configured and executed"] | ||||||||
| pub struct SetVoiceChannelStatus<'a> { | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||
| channel_id: Id<ChannelMarker>, | ||||||||
| fields: Result<SetVoiceChannelStatusFields<'a>, ChannelValidationError>, | ||||||||
| http: &'a Client, | ||||||||
| } | ||||||||
|
|
||||||||
| impl<'a> SetVoiceChannelStatus<'a> { | ||||||||
| pub(crate) const fn new(http: &'a Client, channel_id: Id<ChannelMarker>) -> Self { | ||||||||
| Self { | ||||||||
| channel_id, | ||||||||
| fields: Ok(SetVoiceChannelStatusFields { status: None }), | ||||||||
| http, | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| pub fn status(mut self, status: &'a str) -> Self { | ||||||||
| self.fields = self.fields.and_then(|mut fields| { | ||||||||
| validate_status(status)?; | ||||||||
| fields.status.replace(status); | ||||||||
|
|
||||||||
| Ok(fields) | ||||||||
| }); | ||||||||
|
|
||||||||
| self | ||||||||
|
Comment on lines
+35
to
+43
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| impl IntoFuture for SetVoiceChannelStatus<'_> { | ||||||||
| type Output = Result<Response<EmptyBody>, Error>; | ||||||||
|
|
||||||||
| type IntoFuture = ResponseFuture<EmptyBody>; | ||||||||
|
|
||||||||
| fn into_future(self) -> Self::IntoFuture { | ||||||||
| let http = self.http; | ||||||||
|
|
||||||||
| match self.try_into_request() { | ||||||||
| Ok(request) => http.request(request), | ||||||||
| Err(source) => ResponseFuture::error(source), | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| impl TryIntoRequest for SetVoiceChannelStatus<'_> { | ||||||||
| fn try_into_request(self) -> Result<Request, Error> { | ||||||||
| let fields = self.fields.map_err(Error::validation)?; | ||||||||
|
|
||||||||
| Request::builder(&Route::SetVoiceChannelStatus { | ||||||||
| channel_id: self.channel_id.get(), | ||||||||
| }) | ||||||||
| .json(&fields) | ||||||||
| .build() | ||||||||
| } | ||||||||
| } | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has since been used and a new bit will have to be used.