aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-06-04 15:37:16 -0700
committerZeyla Hellyer <[email protected]>2017-06-04 15:37:16 -0700
commitd03390968ec7a5e1e93dbcc508c3b8a5f44b792d (patch)
tree80c81bd512c944eba44bac939cfc6fe797267f21 /src
parentAlphabetize CurrentUser/User methods (diff)
downloadserenity-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.rs24
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.