From 57c060fa2fccfbb3b3d4b2d18aad2faa5929deb3 Mon Sep 17 00:00:00 2001 From: Austin Hellyer Date: Fri, 2 Dec 2016 13:57:49 -0800 Subject: Paginate rest::get_guilds and add helper methods Paginate the rest::get_guilds endpoint, which can be used to retrieve the guilds after-or-before a certain guild's Id, with a limit of results to return (100 is the max). Example usage: ```rs use serenity::client::rest::GuildPagination; let target = GuildPagination::After(GuildId(81384788765712384)); let guilds = context.get_guilds(target, 50); ``` Additionally, add a method of `CurrentUser::guilds()`, to retrieve the current user's guilds. A limit of 100 is set, as (most) users can not be in more than 100 guilds. --- src/client/context.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/client/context.rs') diff --git a/src/client/context.rs b/src/client/context.rs index a5c9ffa..bc983bf 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -4,7 +4,7 @@ use std::fmt::Write as FmtWrite; use std::io::Read; use std::sync::{Arc, Mutex}; use super::gateway::Shard; -use super::rest; +use super::rest::{self, GuildPagination}; use super::login_type::LoginType; use ::utils::builder::{ CreateEmbed, @@ -1050,9 +1050,29 @@ impl Context { rest::get_guild_prune_count(guild_id.into().0, map) } - /// Gets all guilds that the current user is in. - pub fn get_guilds(&self) -> Result> { - rest::get_guilds() + /// Gets a paginated list of guilds that the current user is in. + /// + /// The `limit` has a maximum value of 100. + /// + /// See also: [`CurrentUser::guilds`]. + /// + /// # Examples + /// + /// Get the first 10 guilds after the current [`Message`]'s guild's Id: + /// + /// ```rust,ignore + /// use serenity::client::rest::GuildPagination; + /// + /// // assuming you are in a context + /// + /// let guild_id = message.guild_id.unwrap(); + /// context.get_guilds(GuildPagination::After(guild_id, 10)).unwrap(); + /// ``` + /// + /// [`CurrentUser::guilds`]: ../model/struct.CurrentUser.html#method.guilds + /// [`Message`]: ../model/struct.Message.html + pub fn get_guilds(&self, target: GuildPagination, limit: u8) -> Result> { + rest::get_guilds(target, limit as u64) } /// Gets all integrations of a guild via the given Id. -- cgit v1.2.3