diff options
| author | Rapptz <[email protected]> | 2015-12-13 22:53:48 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2015-12-13 22:53:48 -0500 |
| commit | 9137d92f67a6d50782e199ca6d6558c1ea6015e2 (patch) | |
| tree | d900865b68c18ad1712de4d6d6914f93c43bb7bf /discord/channel.py | |
| parent | Changed functions that return a constant value into properties. (diff) | |
| download | discord.py-9137d92f67a6d50782e199ca6d6558c1ea6015e2.tar.xz discord.py-9137d92f67a6d50782e199ca6d6558c1ea6015e2.zip | |
All data classes now support !=, == and str(obj).
Diffstat (limited to 'discord/channel.py')
| -rw-r--r-- | discord/channel.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/discord/channel.py b/discord/channel.py index edb45817..41445a12 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -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`. |