Skip to content

Commit

Permalink
Merge pull request #13 from A-Trash-Coder/master
Browse files Browse the repository at this point in the history
Add a __eq__ and __ne__ to models Guild and User
  • Loading branch information
weibeu committed May 21, 2020
2 parents 4a2440e + 2417e9d commit fd753fb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions flask_discord/models/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
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
Expand Down Expand Up @@ -35,6 +44,12 @@ def __init__(self, payload):
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."""
Expand Down
16 changes: 16 additions & 0 deletions flask_discord/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
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
Expand Down Expand Up @@ -78,6 +88,12 @@ def guilds(self, value):
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."""
Expand Down

0 comments on commit fd753fb

Please sign in to comment.