Skip to content

Instantly share code, notes, and snippets.

@Yonom
Created July 1, 2017 21:32
Show Gist options
  • Save Yonom/8ce83e383077e56c7e72bac166d19641 to your computer and use it in GitHub Desktop.
Save Yonom/8ce83e383077e56c7e72bac166d19641 to your computer and use it in GitHub Desktop.
using Discord;
// Original work by Rapptz
// Copyright (c) 2015-2016 Rapptz
// Source: https://github.com/Rapptz/discord.py/commit/5f776f369d350c005d419925e89e9ef9e5ff94ee#diff-e42d1e46f30339be8fb6f28250923015
// Copyright(c) 2017 Simon Farshid
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
namespace Yonom.DiscordTools
{
static class DiscordAvatar
{
private static readonly string[] _defaultAvatars =
{
"6debd47ed13483642cf09e832ed0bc1b", // blurple
"322c936a8c8be1b803cd94861bdfa868", // grey
"dd4dbc0016779df1378e7812eabaa04d", // green
"dd4dbc0016779df1378e7812eabaa04d", // orange
"dd4dbc0016779df1378e7812eabaa04d", // red
};
public static string GetAvatarUrlOrDefault(this IUser user)
{
return user.GetAvatarUrl() ?? GetDefaultAvatarUrl(user);
}
public static string GetDefaultAvatarUrl(this IUser user)
{
var imageId = _defaultAvatars[user.DiscriminatorValue % _defaultAvatars.Length];
return $"https://discordapp.com/assets/{imageId}.png";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment