Skip to content

Commit

Permalink
Add pagination for CurrentUser::guilds (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsIrl committed Jun 7, 2020
1 parent 94d22c3 commit 9eadffa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/model/user.rs
Expand Up @@ -164,9 +164,20 @@ impl CurrentUser {
/// # #[cfg(not(feature = "cache"))]
/// # fn main() {}
/// ```
#[inline]
pub fn guilds(&self, http: impl AsRef<Http>) -> Result<Vec<GuildInfo>> {
http.as_ref().get_guilds(&GuildPagination::After(GuildId(1)), 100)
let mut guilds = Vec::new();
loop {
let mut pagination = http.as_ref().get_guilds(
&GuildPagination::After(guilds.last().map_or(GuildId(1), |g: &GuildInfo| g.id)),
100,
)?;
let len = pagination.len();
guilds.append(&mut pagination);
if len != 100 {
break;
}
}
Ok(guilds)
}

/// Returns the invite url for the bot with the given permissions.
Expand Down

0 comments on commit 9eadffa

Please sign in to comment.