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/colour.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/colour.py')
| -rw-r--r-- | discord/colour.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/discord/colour.py b/discord/colour.py index 169e6a04..0b63a608 100644 --- a/discord/colour.py +++ b/discord/colour.py @@ -32,13 +32,15 @@ class Colour(object): Supported operations: - +-----------+--------------------------------------+ - | Operation | Description | - +===========+======================================+ - | x == y | Checks if two colours are equal. | - +-----------+--------------------------------------+ - | x != y | Checks if two colours are not equal. | - +-----------+--------------------------------------+ + +-----------+----------------------------------------+ + | Operation | Description | + +===========+========================================+ + | x == y | Checks if two colours are equal. | + +-----------+----------------------------------------+ + | x != y | Checks if two colours are not equal. | + +-----------+----------------------------------------+ + | str(x) | Returns the hex format for the colour. | + +-----------+----------------------------------------+ Attributes ------------ @@ -53,10 +55,13 @@ class Colour(object): return (self.value >> (8 * byte)) & 0xff def __eq__(self, other): - return self.value == getattr(other, 'value', None) + return isinstance(other, Colour) and self.value == other.value def __ne__(self, other): - return isinstance(other, Colour) and self.value != other.value + return not self.__eq__(other) + + def __str__(self): + return '#' + format(self.value, 'x') @property def r(self): |