All data classes now support !=, == and str(obj).

This commit is contained in:
Rapptz
2015-12-13 22:53:48 -05:00
parent ab46afee1d
commit 9137d92f67
8 changed files with 149 additions and 17 deletions

View File

@ -28,12 +28,25 @@ from . import utils
from .permissions import Permissions
from .enums import ChannelType
from collections import namedtuple
from .mixins import EqualityComparable
Overwrites = namedtuple('Overwrites', 'id allow deny type')
class Channel:
class Channel(EqualityComparable):
"""Represents a Discord server channel.
Supported Operations:
+-----------+---------------------------------------+
| Operation | Description |
+===========+=======================================+
| x == y | Checks if two channels are equal. |
+-----------+---------------------------------------+
| x != y | Checks if two channels are not equal. |
+-----------+---------------------------------------+
| str(x) | Returns the channel's name. |
+-----------+---------------------------------------+
Attributes
-----------
name : str
@ -63,6 +76,9 @@ class Channel:
self.update(**kwargs)
self.voice_members = []
def __str__(self):
return self.name
def update(self, **kwargs):
self.name = kwargs.get('name')
self.server = kwargs.get('server')
@ -179,9 +195,21 @@ class Channel:
return base
class PrivateChannel:
class PrivateChannel(EqualityComparable):
"""Represents a Discord private channel.
Supported Operations:
+-----------+-------------------------------------------------+
| Operation | Description |
+===========+=================================================+
| x == y | Checks if two channels are equal. |
+-----------+-------------------------------------------------+
| x != y | Checks if two channels are not equal. |
+-----------+-------------------------------------------------+
| str(x) | Returns the string "Direct Message with <User>" |
+-----------+-------------------------------------------------+
Attributes
----------
user : :class:`User`
@ -197,6 +225,9 @@ class PrivateChannel:
self.id = id
self.is_private = True
def __str__(self):
return 'Direct Message with {0.name}'.format(self.user)
def permissions_for(user):
"""Handles permission resolution for a :class:`User`.