mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-12 08:49:48 +00:00
Add default avatar property to User.
This commit is contained in:
parent
174016c918
commit
5f776f369d
@ -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
|
||||
|
@ -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…
x
Reference in New Issue
Block a user