Skip to content

Commit

Permalink
Add CurrentUser::face(), User::face()
Browse files Browse the repository at this point in the history
These functions return the user's avatar URL, or their default avatar
URL as a fallback.
  • Loading branch information
Zeyla Hellyer committed Jun 4, 2017
1 parent 96ce530 commit d033909
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/model/user.rs
Expand Up @@ -116,6 +116,18 @@ impl CurrentUser {
}
}

/// Retrieves the URL to the current user's avatar, falling back to the
/// default avatar if needed.
///
/// This will call [`avatar_url`] first, and if that returns `None`, it
/// then falls back to [`default_avatar_url`].
///
/// [`avatar_url`]: #method.avatar_url
/// [`default_avatar_url`]: #method.default_avatar_url
pub fn face(&self) -> String {
self.avatar_url().unwrap_or_else(|| self.default_avatar_url())
}

/// Gets a list of guilds that the current user is in.
///
/// # Examples
Expand Down Expand Up @@ -474,6 +486,18 @@ impl User {
self.direct_message(content)
}

/// Retrieves the URL to the user's avatar, falling back to the default
/// avatar if needed.
///
/// This will call [`avatar_url`] first, and if that returns `None`, it
/// then falls back to [`default_avatar_url`].
///
/// [`avatar_url`]: #method.avatar_url
/// [`default_avatar_url`]: #method.default_avatar_url
pub fn face(&self) -> String {
self.avatar_url().unwrap_or_else(|| self.default_avatar_url())
}

/// Gets a user by its Id over the REST API.
///
/// **Note**: The current user must be a bot user.
Expand Down

0 comments on commit d033909

Please sign in to comment.