aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2019-08-27 18:34:40 -0400
committerRapptz <[email protected]>2019-08-27 18:34:40 -0400
commit5c0b127c96347b3ccf1d194b47eb941f33b43dae (patch)
treeea56906a69ca69850f42d5e1e9a236b384ef7d92
parentFix _get_message returning the message cache. (diff)
downloaddiscord.py-5c0b127c96347b3ccf1d194b47eb941f33b43dae.tar.xz
discord.py-5c0b127c96347b3ccf1d194b47eb941f33b43dae.zip
Create Permissions and Colour objects when necessary in Role
This should have some memory savings of ~24 bytes per role. * 8 bytes for Permissions * 8 bytes for Colour * 8 bytes for the alias I'm not sure how significant it is but it should be a decent amount.
-rw-r--r--discord/role.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/discord/role.py b/discord/role.py
index 8608c5e1..647afb55 100644
--- a/discord/role.py
+++ b/discord/role.py
@@ -73,12 +73,8 @@ class Role(Hashable):
The ID for the role.
name: :class:`str`
The name of the role.
- permissions: :class:`Permissions`
- Represents the role's permissions.
guild: :class:`Guild`
The guild the role belongs to.
- colour: :class:`Colour`
- Represents the role colour. An alias exists under ``color``.
hoist: :class:`bool`
Indicates if the role will be displayed separately from other members.
position: :class:`int`
@@ -91,7 +87,7 @@ class Role(Hashable):
Indicates if the role can be mentioned by users.
"""
- __slots__ = ('id', 'name', 'permissions', 'color', 'colour', 'position',
+ __slots__ = ('id', 'name', '_permissions', '_colour', 'position',
'managed', 'mentionable', 'hoist', 'guild', '_state')
def __init__(self, *, guild, state, data):
@@ -144,19 +140,30 @@ class Role(Hashable):
def _update(self, data):
self.name = data['name']
- self.permissions = Permissions(data.get('permissions', 0))
+ self._permissions = data.get('permissions', 0)
self.position = data.get('position', 0)
- self.colour = Colour(data.get('color', 0))
+ self._colour = data.get('color', 0)
self.hoist = data.get('hoist', False)
self.managed = data.get('managed', False)
self.mentionable = data.get('mentionable', False)
- self.color = self.colour
def is_default(self):
"""Checks if the role is the default role."""
return self.guild.id == self.id
@property
+ def permissions(self):
+ """:class:`Permissions`: Returns the role's permissions."""
+ return Permissions(self._permissions)
+
+ @property
+ def colour(self):
+ """:class:`Colour`: Returns the role colour. An alias exists under ``color``."""
+ return Colour(self._colour)
+
+ color = colour
+
+ @property
def created_at(self):
""":class:`datetime.datetime`: Returns the role's creation time in UTC."""
return snowflake_time(self.id)