From 66433be371eacb331c63ae56acdbf8a2e9adfbb2 Mon Sep 17 00:00:00 2001 From: Andrei Date: Sat, 18 Mar 2017 03:58:04 -0700 Subject: [PATCH] Add default avatars --- disco/types/user.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/disco/types/user.py b/disco/types/user.py index d4c32cd..3192abc 100644 --- a/disco/types/user.py +++ b/disco/types/user.py @@ -2,6 +2,14 @@ from holster.enum import Enum from disco.types.base import SlottedModel, Field, snowflake, text, binary, with_equality, with_hash +DefaultAvatars = Enum( + BLURPLE=0, + GREY=1, + GREEN=2, + ORANGE=3, + RED=4, +) + class User(SlottedModel, with_equality('id'), with_hash('id')): id = Field(snowflake) @@ -16,7 +24,7 @@ class User(SlottedModel, with_equality('id'), with_hash('id')): def get_avatar_url(self, fmt='webp', size=1024): if not self.avatar: - return None + return 'https://cdn.discordapp.com/embed/avatars/{}.png'.format(self.default_avatar.value) return 'https://cdn.discordapp.com/avatars/{}/{}.{}?size={}'.format( self.id, @@ -25,6 +33,10 @@ class User(SlottedModel, with_equality('id'), with_hash('id')): size ) + @property + def default_avatar(self): + return DefaultAvatars[int(self.discriminator) % len(DefaultAvatars.attrs)] + @property def avatar_url(self): return self.get_avatar_url()