From 9137d92f67a6d50782e199ca6d6558c1ea6015e2 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 13 Dec 2015 22:53:48 -0500 Subject: All data classes now support !=, == and str(obj). --- discord/channel.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'discord/channel.py') 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 " | + +-----------+-------------------------------------------------+ + 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`. -- cgit v1.2.3