diff options
| author | Zeyla Hellyer <[email protected]> | 2017-06-04 15:37:16 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-06-04 15:37:16 -0700 |
| commit | d03390968ec7a5e1e93dbcc508c3b8a5f44b792d (patch) | |
| tree | 80c81bd512c944eba44bac939cfc6fe797267f21 /src | |
| parent | Alphabetize CurrentUser/User methods (diff) | |
| download | serenity-d03390968ec7a5e1e93dbcc508c3b8a5f44b792d.tar.xz serenity-d03390968ec7a5e1e93dbcc508c3b8a5f44b792d.zip | |
Add CurrentUser::face(), User::face()
These functions return the user's avatar URL, or their default avatar
URL as a fallback.
Diffstat (limited to 'src')
| -rw-r--r-- | src/model/user.rs | 24 |
1 files changed, 24 insertions, 0 deletions
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. |