aboutsummaryrefslogtreecommitdiff
path: root/src/model/user.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-12-28 11:11:46 -0800
committerAustin Hellyer <[email protected]>2016-12-28 11:11:46 -0800
commitab778f8a9cf47c4e27fe688a61effb0caa4f8a6e (patch)
treec19e5a5ca6e65a22d124c76031340fb6643931f3 /src/model/user.rs
parentAccept u64 shard counts (diff)
downloadserenity-ab778f8a9cf47c4e27fe688a61effb0caa4f8a6e.tar.xz
serenity-ab778f8a9cf47c4e27fe688a61effb0caa4f8a6e.zip
Support webp/gif avatars
If the avatar hash begins with "a_", then the avatar is animated and is a GIF. Otherwise, use WEBP.
Diffstat (limited to 'src/model/user.rs')
-rw-r--r--src/model/user.rs28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/model/user.rs b/src/model/user.rs
index af026ea..46da757 100644
--- a/src/model/user.rs
+++ b/src/model/user.rs
@@ -35,9 +35,19 @@ use ::client::CACHE;
impl CurrentUser {
/// Returns the formatted URL of the user's icon, if one exists.
+ ///
+ /// This will produce a WEBP image URL, or GIF if the user has a GIF avatar.
pub fn avatar_url(&self) -> Option<String> {
- self.avatar.as_ref().map(|av|
- format!(cdn!("/avatars/{}/{}.jpg"), self.id.0, av))
+ self.avatar.as_ref()
+ .map(|av| {
+ let ext = if av.starts_with("a_") {
+ "gif"
+ } else {
+ "webp"
+ };
+
+ format!(cdn!("/avatars/{}/{}.{}?size=1024"), self.id.0, av, ext)
+ })
}
/// Edits the current user's profile settings.
@@ -99,9 +109,19 @@ impl CurrentUser {
impl User {
/// Returns the formatted URL of the user's icon, if one exists.
+ ///
+ /// This will produce a WEBP image URL, or GIF if the user has a GIF avatar.
pub fn avatar_url(&self) -> Option<String> {
- self.avatar.as_ref().map(|av|
- format!(cdn!("/avatars/{}/{}.jpg"), self.id.0, av))
+ self.avatar.as_ref()
+ .map(|av| {
+ let ext = if av.starts_with("a_") {
+ "gif"
+ } else {
+ "webp"
+ };
+
+ format!(cdn!("/avatars/{}/{}.{}?size=1024"), self.id.0, av, ext)
+ })
}
/// Gets user as `Member` of a guild.