mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-14 09:50:03 +00:00
Most data classes now support hashing.
This commit is contained in:
parent
613214f197
commit
51d91c2a82
@ -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>" |
|
||||
+-----------+-------------------------------------------------+
|
||||
|
||||
|
@ -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."""
|
||||
|
@ -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. |
|
||||
+-----------+--------------------------------------+
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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. |
|
||||
+-----------+------------------------------------+
|
||||
|
||||
|
@ -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. |
|
||||
+-----------+--------------------------------------+
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user