From ed146bac228861f2a3542702b28470cac82652a6 Mon Sep 17 00:00:00 2001 From: trainboy2019 Date: Mon, 2 Jul 2018 14:12:32 -0400 Subject: [PATCH] Add support for animated avatars (#66) --- DiscordChatExporter.Core/Models/User.cs | 30 ++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/DiscordChatExporter.Core/Models/User.cs b/DiscordChatExporter.Core/Models/User.cs index e953009..f6a7436 100644 --- a/DiscordChatExporter.Core/Models/User.cs +++ b/DiscordChatExporter.Core/Models/User.cs @@ -1,4 +1,5 @@ -using Tyrrrz.Extensions; +using System; +using Tyrrrz.Extensions; namespace DiscordChatExporter.Core.Models { @@ -14,13 +15,32 @@ namespace DiscordChatExporter.Core.Models public string FullName => $"{Name}#{Discriminator:0000}"; + public string DefaultAvatarHash => $"{Discriminator % 5}"; + public string AvatarHash { get; } - public string DefaultAvatarHash => $"{Discriminator % 5}"; + public bool IsAvatarAnimated => + AvatarHash.IsNotBlank() && AvatarHash.StartsWith("a_", StringComparison.Ordinal); - public string AvatarUrl => AvatarHash.IsNotBlank() - ? $"https://cdn.discordapp.com/avatars/{Id}/{AvatarHash}.png" - : $"https://cdn.discordapp.com/embed/avatars/{DefaultAvatarHash}.png"; + public string AvatarUrl + { + get + { + // Custom avatar + if (AvatarHash.IsNotBlank()) + { + // Animated + if (IsAvatarAnimated) + return $"https://cdn.discordapp.com/avatars/{Id}/{AvatarHash}.gif"; + + // Non-animated + return $"https://cdn.discordapp.com/avatars/{Id}/{AvatarHash}.png"; + } + + // Default avatar + return $"https://cdn.discordapp.com/embed/avatars/{DefaultAvatarHash}.png"; + } + } public User(string id, int discriminator, string name, string avatarHash) {