aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--discord/channel.py10
-rw-r--r--discord/colour.py5
-rw-r--r--discord/invite.py6
-rw-r--r--discord/mixins.py4
-rw-r--r--discord/permissions.py5
-rw-r--r--discord/role.py6
-rw-r--r--discord/server.py6
-rw-r--r--discord/user.py5
8 files changed, 38 insertions, 9 deletions
diff --git a/discord/channel.py b/discord/channel.py
index 983b4fb9..5f53b837 100644
--- a/discord/channel.py
+++ b/discord/channel.py
@@ -28,11 +28,11 @@ from . import utils
from .permissions import Permissions
from .enums import ChannelType
from collections import namedtuple
-from .mixins import EqualityComparable
+from .mixins import Hashable
Overwrites = namedtuple('Overwrites', 'id allow deny type')
-class Channel(EqualityComparable):
+class Channel(Hashable):
"""Represents a Discord server channel.
Supported Operations:
@@ -44,6 +44,8 @@ class Channel(EqualityComparable):
+-----------+---------------------------------------+
| x != y | Checks if two channels are not equal. |
+-----------+---------------------------------------+
+ | hash(x) | Returns the channel's hash. |
+ +-----------+---------------------------------------+
| str(x) | Returns the channel's name. |
+-----------+---------------------------------------+
@@ -196,7 +198,7 @@ class Channel(EqualityComparable):
return base
-class PrivateChannel(EqualityComparable):
+class PrivateChannel(Hashable):
"""Represents a Discord private channel.
Supported Operations:
@@ -208,6 +210,8 @@ class PrivateChannel(EqualityComparable):
+-----------+-------------------------------------------------+
| x != y | Checks if two channels are not equal. |
+-----------+-------------------------------------------------+
+ | hash(x) | Returns the channel's hash. |
+ +-----------+-------------------------------------------------+
| str(x) | Returns the string "Direct Message with <User>" |
+-----------+-------------------------------------------------+
diff --git a/discord/colour.py b/discord/colour.py
index 0b63a608..67137cb4 100644
--- a/discord/colour.py
+++ b/discord/colour.py
@@ -39,6 +39,8 @@ class Colour(object):
+-----------+----------------------------------------+
| x != y | Checks if two colours are not equal. |
+-----------+----------------------------------------+
+ | hash(x) | Return the colour's hash. |
+ +-----------+----------------------------------------+
| str(x) | Returns the hex format for the colour. |
+-----------+----------------------------------------+
@@ -63,6 +65,9 @@ class Colour(object):
def __str__(self):
return '#' + format(self.value, 'x')
+ def __hash__(self):
+ return hash(self.value)
+
@property
def r(self):
"""Returns the red component of the colour."""
diff --git a/discord/invite.py b/discord/invite.py
index bc1ae3fb..ad6b2673 100644
--- a/discord/invite.py
+++ b/discord/invite.py
@@ -26,9 +26,9 @@ DEALINGS IN THE SOFTWARE.
from .user import User
from .utils import parse_time
-from .mixins import EqualityComparable
+from .mixins import Hashable
-class Invite(EqualityComparable):
+class Invite(Hashable):
"""Represents a Discord :class:`Server` or :class:`Channel` invite.
Depending on the way this object was created, some of the attributes can
@@ -43,6 +43,8 @@ class Invite(EqualityComparable):
+-----------+--------------------------------------+
| x != y | Checks if two invites are not equal. |
+-----------+--------------------------------------+
+ | hash(x) | Return the invite's hash. |
+ +-----------+--------------------------------------+
| str(x) | Returns the invite's URL. |
+-----------+--------------------------------------+
diff --git a/discord/mixins.py b/discord/mixins.py
index 8a11a7c1..cdbd67d7 100644
--- a/discord/mixins.py
+++ b/discord/mixins.py
@@ -32,3 +32,7 @@ class EqualityComparable:
if isinstance(other, self.__class__):
return other.id != self.id
return True
+
+class Hashable(EqualityComparable):
+ def __hash__(self):
+ return hash(self.id)
diff --git a/discord/permissions.py b/discord/permissions.py
index d41d22d9..ee0ad555 100644
--- a/discord/permissions.py
+++ b/discord/permissions.py
@@ -36,6 +36,8 @@ class Permissions(object):
+-----------+------------------------------------------+
| x != y | Checks if two permissions are not equal. |
+-----------+------------------------------------------+
+ | hash(x) | Return the permission's hash. |
+ +-----------+------------------------------------------+
Attributes
-----------
@@ -57,6 +59,9 @@ class Permissions(object):
def __ne__(self, other):
return not self.__eq__(other)
+ def __hash__(self):
+ return hash(self.value)
+
@classmethod
def none(cls):
"""A factory method that creates a :class:`Permission` with all
diff --git a/discord/role.py b/discord/role.py
index eb44795a..a78a4af7 100644
--- a/discord/role.py
+++ b/discord/role.py
@@ -26,9 +26,9 @@ DEALINGS IN THE SOFTWARE.
from .permissions import Permissions
from .colour import Colour
-from .mixins import EqualityComparable
+from .mixins import Hashable
-class Role(EqualityComparable):
+class Role(Hashable):
"""Represents a Discord role in a :class:`Server`.
Supported Operations:
@@ -40,6 +40,8 @@ class Role(EqualityComparable):
+-----------+------------------------------------+
| x != y | Checks if two roles are not equal. |
+-----------+------------------------------------+
+ | hash(x) | Return the role's hash. |
+ +-----------+------------------------------------+
| str(x) | Returns the role's name. |
+-----------+------------------------------------+
diff --git a/discord/server.py b/discord/server.py
index f9f1333c..0a6b7091 100644
--- a/discord/server.py
+++ b/discord/server.py
@@ -29,9 +29,9 @@ from .role import Role
from .member import Member
from .channel import Channel
from .enums import ServerRegion, Status
-from .mixins import EqualityComparable
+from .mixins import Hashable
-class Server(EqualityComparable):
+class Server(Hashable):
"""Represents a Discord server.
Supported Operations:
@@ -43,6 +43,8 @@ class Server(EqualityComparable):
+-----------+--------------------------------------+
| x != y | Checks if two servers are not equal. |
+-----------+--------------------------------------+
+ | hash(x) | Returns the server's hash. |
+ +-----------+--------------------------------------+
| str(x) | Returns the server's name. |
+-----------+--------------------------------------+
diff --git a/discord/user.py b/discord/user.py
index a5ef2edb..d2f149c3 100644
--- a/discord/user.py
+++ b/discord/user.py
@@ -36,6 +36,8 @@ class User:
+-----------+------------------------------------+
| x != y | Checks if two users are not equal. |
+-----------+------------------------------------+
+ | hash(x) | Return the user's hash. |
+ +-----------+------------------------------------+
| str(x) | Returns the user's name. |
+-----------+------------------------------------+
@@ -66,6 +68,9 @@ class User:
def __ne__(self, other):
return not self.__eq__(other)
+ def __hash__(self):
+ return hash(self.id)
+
@property
def avatar_url(self):
"""Returns a friendly URL version of the avatar variable the user has. An empty string if