From 302d771182308f907423ed73be9b736f268737fe Mon Sep 17 00:00:00 2001 From: Mei Date: Fri, 19 May 2017 01:07:46 -0400 Subject: [PATCH] Add support for retrieving invites with counts Previously retrieving an invite with the `?with_counts=true` wasn't possible. Added support to `get_invite` for retrieving an invite with the counts, this requires the user to pass true to the function. The counts include `approximate_presence_count` and `approximate_member_count` which have been added to the `Invite` stuct, as well as `text_channel_count` and `voice_channel_count` to the `InviteGuild` struct. --- src/client/rest/mod.rs | 10 ++++++++-- src/model/invite.rs | 21 +++++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/client/rest/mod.rs b/src/client/rest/mod.rs index 31d7a17ae81..3890a46254e 100644 --- a/src/client/rest/mod.rs +++ b/src/client/rest/mod.rs @@ -1136,9 +1136,15 @@ pub fn get_guilds(target: &GuildPagination, limit: u64) -> Result } /// Gets information about a specific invite. -pub fn get_invite(code: &str) -> Result { +pub fn get_invite(code: &str, stats: bool) -> Result { let invite = ::utils::parse_invite(code); - let response = request!(Route::InvitesCode, get, "/invites/{}", invite); + let mut uri = format!("/invites/{}", invite); + + if stats { + uri.push_str("?with_counts=true"); + } + + let response = request!(Route::InvitesCode, get, "{}", uri); serde_json::from_reader::(response).map_err(From::from) } diff --git a/src/model/invite.rs b/src/model/invite.rs index 338d90cc6d5..f7e8e488a3b 100644 --- a/src/model/invite.rs +++ b/src/model/invite.rs @@ -14,6 +14,19 @@ use super::utils as model_utils; /// Information can not be accessed for guilds the current user is banned from. #[derive(Clone, Debug, Deserialize)] pub struct Invite { + /// The approximate number of [`Member`]s in the related [`Guild`]. + /// + /// [`Guild`]: struct.Guild.html + /// [`Member`]: struct.Member.html + pub approximate_member_count: Option, + /// The approximate number of [`Member`]s with an active session in the + /// related [`Guild`]. + /// + /// An active session is defined as an open, heartbeating WebSocket connection. + /// These include [invisible][`OnlineStatus::Invisible`] members. + /// + /// [`OnlineStatus::Invisible`]: enum.OnlineStatus.html#variant.Invisible + pub approximate_presence_count: Option, /// The unique code for the invite. pub code: String, /// A representation of the minimal amount of information needed about the @@ -23,8 +36,6 @@ pub struct Invite { pub channel: InviteChannel, /// a representation of the minimal amount of information needed about the /// [`Guild`] being invited to. - /// - /// [`Guild`]: struct.Guild.html pub guild: InviteGuild, } @@ -89,8 +100,8 @@ impl Invite { } /// Gets the information about an invite. - pub fn get(code: &str) -> Result { - rest::get_invite(utils::parse_invite(code)) + pub fn get(code: &str, stats: bool) -> Result { + rest::get_invite(utils::parse_invite(code), stats) } } @@ -110,6 +121,8 @@ pub struct InviteGuild { pub icon: Option, pub name: String, pub splash_hash: Option, + pub text_channel_count: Option, + pub voice_channel_count: Option, } impl InviteGuild {