diff options
author | 2019-08-15 18:24:06 +0200 | |
---|---|---|
committer | 2019-08-15 18:24:06 +0200 | |
commit | 1d08bd96cb089a0881ffec2ee0e9c7f4adf5493d (patch) | |
tree | 8815494032873c9dc62f89447df49b2b3f674c30 /pydis_site/apps/api/models/bot | |
parent | Merge pull request #235 from python-discord/ouroboros-logging-handler (diff) |
Adding position, role hierarchy comparisons to Role model; top_role to User model
Diffstat (limited to 'pydis_site/apps/api/models/bot')
-rw-r--r-- | pydis_site/apps/api/models/bot/role.py | 10 | ||||
-rw-r--r-- | pydis_site/apps/api/models/bot/user.py | 4 |
2 files changed, 14 insertions, 0 deletions
diff --git a/pydis_site/apps/api/models/bot/role.py b/pydis_site/apps/api/models/bot/role.py index 34e74009..777168b8 100644 --- a/pydis_site/apps/api/models/bot/role.py +++ b/pydis_site/apps/api/models/bot/role.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models @@ -43,7 +45,15 @@ class Role(ModelReprMixin, models.Model): ), help_text="The integer value of the permission bitset of this role from Discord." ) + position = models.IntegerField( + default=-1, + help_text="The position of the role in the role hierarchy of the Discord Guild." + ) def __str__(self): """Returns the name of the current role, for display purposes.""" return self.name + + def __lt__(self, other: Role): + """Compares the roles based on their position in the role hierarchy of the guild.""" + return self.position < other.position diff --git a/pydis_site/apps/api/models/bot/user.py b/pydis_site/apps/api/models/bot/user.py index d4deb630..1c566989 100644 --- a/pydis_site/apps/api/models/bot/user.py +++ b/pydis_site/apps/api/models/bot/user.py @@ -51,3 +51,7 @@ class User(ModelReprMixin, models.Model): def __str__(self): """Returns the name and discriminator for the current user, for display purposes.""" return f"{self.name}#{self.discriminator}" + + @property + def top_role(self) -> Role: + return max(self.roles.all()) |