-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http): add get voice state endpoints (#2398)
Discord supports endpoints that allow to fetch voice state of the current user or another user in a guild. - discord/discord-api-docs#7061 --------- Co-authored-by: Quang Pham <73033278+BooTheDev@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
198 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
twilight-http/src/request/guild/user/get_current_user_voice_state.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::{ | ||
client::Client, | ||
error::Error, | ||
request::{Request, TryIntoRequest}, | ||
response::{Response, ResponseFuture}, | ||
routing::Route, | ||
}; | ||
use std::future::IntoFuture; | ||
use twilight_model::{ | ||
id::{marker::GuildMarker, Id}, | ||
voice::VoiceState, | ||
}; | ||
|
||
/// Get voice state of the current user by guild id. | ||
#[must_use = "requests must be configured and executed"] | ||
pub struct GetCurrentUserVoiceState<'a> { | ||
http: &'a Client, | ||
guild_id: Id<GuildMarker>, | ||
} | ||
|
||
impl<'a> GetCurrentUserVoiceState<'a> { | ||
pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self { | ||
Self { http, guild_id } | ||
} | ||
} | ||
|
||
impl IntoFuture for GetCurrentUserVoiceState<'_> { | ||
type Output = Result<Response<VoiceState>, Error>; | ||
|
||
type IntoFuture = ResponseFuture<VoiceState>; | ||
|
||
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 GetCurrentUserVoiceState<'_> { | ||
fn try_into_request(self) -> Result<Request, Error> { | ||
Ok(Request::from_route(&Route::GetCurrentUserVoiceState { | ||
guild_id: self.guild_id.get(), | ||
})) | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
twilight-http/src/request/guild/user/get_user_voice_state.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::{ | ||
client::Client, | ||
error::Error, | ||
request::{Request, TryIntoRequest}, | ||
response::{Response, ResponseFuture}, | ||
routing::Route, | ||
}; | ||
use std::future::IntoFuture; | ||
use twilight_model::{ | ||
id::{ | ||
marker::{GuildMarker, UserMarker}, | ||
Id, | ||
}, | ||
voice::VoiceState, | ||
}; | ||
|
||
/// Get voice state of a user by guild and user ids. | ||
#[must_use = "requests must be configured and executed"] | ||
pub struct GetUserVoiceState<'a> { | ||
http: &'a Client, | ||
guild_id: Id<GuildMarker>, | ||
user_id: Id<UserMarker>, | ||
} | ||
|
||
impl<'a> GetUserVoiceState<'a> { | ||
pub(crate) const fn new( | ||
http: &'a Client, | ||
guild_id: Id<GuildMarker>, | ||
user_id: Id<UserMarker>, | ||
) -> Self { | ||
Self { | ||
http, | ||
guild_id, | ||
user_id, | ||
} | ||
} | ||
} | ||
|
||
impl IntoFuture for GetUserVoiceState<'_> { | ||
type Output = Result<Response<VoiceState>, Error>; | ||
|
||
type IntoFuture = ResponseFuture<VoiceState>; | ||
|
||
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 GetUserVoiceState<'_> { | ||
fn try_into_request(self) -> Result<Request, Error> { | ||
Ok(Request::from_route(&Route::GetUserVoiceState { | ||
guild_id: self.guild_id.get(), | ||
user_id: self.user_id.get(), | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
mod get_current_user_voice_state; | ||
mod get_user_voice_state; | ||
mod update_current_user_voice_state; | ||
mod update_user_voice_state; | ||
|
||
pub use self::{ | ||
get_current_user_voice_state::GetCurrentUserVoiceState, | ||
get_user_voice_state::GetUserVoiceState, | ||
update_current_user_voice_state::UpdateCurrentUserVoiceState, | ||
update_user_voice_state::UpdateUserVoiceState, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters