Merge pull request #13 from A-Trash-Coder/master

Add a __eq__ and __ne__ to models Guild and User
This commit is contained in:
thec0sm0s
2020-05-21 10:46:07 +05:30
committed by GitHub
2 changed files with 31 additions and 0 deletions

View File

@@ -6,6 +6,15 @@ from .. import configs
class Guild(DiscordModelsBase):
"""Class representing discord Guild the user is part of.
Operations
----------
x == y
Checks if two guild's are the same.
x != y
Checks if two guild's are not the same.
str(x)
Returns the guild's name.
Attributes
----------
id : int
@@ -35,6 +44,12 @@ class Guild(DiscordModelsBase):
def __str__(self):
return self.name
def __eq__(self, guild):
return isinstance(guild, Guild) and guild.id == self.id
def __ne__(self, guild):
return not self.__eq__(guild)
@property
def icon_url(self):
"""A property returning direct URL to the guild's icon. Returns None if guild has no icon set."""

View File

@@ -9,6 +9,16 @@ from .connections import UserConnection
class User(DiscordModelsBase):
"""Class representing Discord User.
Operations
----------
x == y
Checks if two user's are the same.
x != y
Checks if two user's are not the same.
str(x)
Returns the user's name with discriminator.
Attributes
----------
id : int
@@ -78,6 +88,12 @@ class User(DiscordModelsBase):
def __str__(self):
return f"{self.name}#{self.discriminator}"
def __eq__(self, user):
return isinstance(user, User) and user.id == self.id
def __ne__(self, user):
return not self.__eq__(user)
@property
def name(self):
"""An alias to the username attribute."""