From d03390968ec7a5e1e93dbcc508c3b8a5f44b792d Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Sun, 4 Jun 2017 15:37:16 -0700 Subject: Add CurrentUser::face(), User::face() These functions return the user's avatar URL, or their default avatar URL as a fallback. --- src/model/user.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/model') diff --git a/src/model/user.rs b/src/model/user.rs index 441944d..e1483d2 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -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 @@ -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. -- cgit v1.2.3