Browse Source

Add default avatar property to User.

pull/144/head
Khazhismel Kumykov 9 years ago
parent
commit
5f776f369d
  1. 17
      discord/enums.py
  2. 11
      discord/user.py

17
discord/enums.py

@ -54,3 +54,20 @@ class Status(Enum):
def __str__(self):
return self.value
class DefaultAvatar(Enum):
blurple = "6debd47ed13483642cf09e832ed0bc1b"
grey = "322c936a8c8be1b803cd94861bdfa868"
green = "dd4dbc0016779df1378e7812eabaa04d"
orange = "0e291f67c9274a1abdddeb3fd919cbaa"
red = "1cbd08c76f8af6dddce02c5138971129"
def __new__(cls, url):
value = len(cls.__members__)
obj = object.__new__(cls)
obj._value_ = value
obj.url = url
return obj
def __str__(self):
return self.name

11
discord/user.py

@ -25,6 +25,7 @@ DEALINGS IN THE SOFTWARE.
"""
from .utils import snowflake_time
from .enums import DefaultAvatar
class User:
"""Represents a Discord user.
@ -83,6 +84,16 @@ class User:
return ''
return 'https://discordapp.com/api/users/{0.id}/avatars/{0.avatar}.jpg'.format(self)
@property
def default_avatar(self):
"""Returns the default avatar for a given user. This is calculated by the user's descriminator"""
return DefaultAvatar(int(self.discriminator) % len(DefaultAvatar))
@property
def default_avatar_url(self):
"""Returns a URL for a user's default avatar."""
return 'https://discordapp.com/assets/{0.url}.png'.format(self.default_avatar)
@property
def mention(self):
"""Returns a string that allows you to mention the given user."""

Loading…
Cancel
Save