aboutsummaryrefslogtreecommitdiff
path: root/discord/colour.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-10-27 16:23:20 -0400
committerRapptz <[email protected]>2015-10-27 16:23:20 -0400
commita0073c734e16c2c060d62c2ff6c8d129b90077db (patch)
tree54ec26b0c6a8b14ffafbf38fce1208d28fee1085 /discord/colour.py
parentRemove the name from logging. (diff)
downloaddiscord.py-a0073c734e16c2c060d62c2ff6c8d129b90077db.tar.xz
discord.py-a0073c734e16c2c060d62c2ff6c8d129b90077db.zip
Split data classes into more files.
Diffstat (limited to 'discord/colour.py')
-rw-r--r--discord/colour.py187
1 files changed, 187 insertions, 0 deletions
diff --git a/discord/colour.py b/discord/colour.py
new file mode 100644
index 00000000..afa0acab
--- /dev/null
+++ b/discord/colour.py
@@ -0,0 +1,187 @@
+# -*- coding: utf-8 -*-
+
+"""
+The MIT License (MIT)
+
+Copyright (c) 2015 Rapptz
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+"""
+
+class Colour(object):
+ """Represents a Discord role colour. This class is similar
+ to an (red, green, blue) tuple.
+
+ There is an alias for this called Color.
+
+ Supported operations:
+
+ +-----------+--------------------------------------+
+ | Operation | Description |
+ +===========+======================================+
+ | x == y | Checks if two colours are equal. |
+ +-----------+--------------------------------------+
+ | x != y | Checks if two colours are not equal. |
+ +-----------+--------------------------------------+
+
+ Instance attributes:
+
+ .. attribute:: value
+
+ The raw integer colour value.
+ """
+
+ def __init__(self, value):
+ self.value = value
+
+ def _get_byte(self, byte):
+ return (self.value >> (8 * byte)) & 0xff
+
+ def __eq__(self, other):
+ return self.value == getattr(other, 'value', None)
+
+ def __ne__(self, other):
+ return isinstance(other, Colour) and self.value != other.value
+
+ @property
+ def r(self):
+ """Returns the red component of the colour."""
+ return self._get_byte(2)
+
+ @property
+ def g(self):
+ """Returns the green component of the colour."""
+ return self._get_byte(1)
+
+ @property
+ def b(self):
+ """Returns the blue component of the colour."""
+ return self._get_byte(0)
+
+ def to_tuple(self):
+ """Returns an (r, g, b) tuple representing the colour."""
+ return (self.r, self.g, self.b)
+
+ @classmethod
+ def default(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0."""
+ return cls(0)
+
+ @classmethod
+ def cyan(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x1abc9c."""
+ return cls(0x1abc9c)
+
+ @classmethod
+ def green(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x2ecc71."""
+ return cls(0x2ecc71)
+
+ @classmethod
+ def blue(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x3498db."""
+ return cls(0x3498db)
+
+ @classmethod
+ def purple(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x9b59b6."""
+ return cls(0x9b59b6)
+
+ @classmethod
+ def yellow(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0xf1c40f."""
+ return cls(0xf1c40f)
+
+ @classmethod
+ def orange(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0xe67e22."""
+ return cls(0xe67e22)
+
+ @classmethod
+ def red(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0xe74c3c."""
+ return cls(0xe74c3c)
+
+ @classmethod
+ def grey(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x95a5a6."""
+ return cls(0x95a5a6)
+
+ @classmethod
+ def dark_grey(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x7f8c8d."""
+ return cls(0x7f8c8d)
+
+ @classmethod
+ def navy_blue(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x34495e."""
+ return cls(0x34495e)
+
+ @classmethod
+ def dark_cyan(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x11806a."""
+ return cls(0x11806a)
+
+ @classmethod
+ def dark_green(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x1f8b4c."""
+ return cls(0x1f8b4c)
+
+ @classmethod
+ def dark_blue(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x206694."""
+ return cls(0x206694)
+
+ @classmethod
+ def dark_purple(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x71368a."""
+ return cls(0x71368a)
+
+ @classmethod
+ def strong_orange(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0xc27c0e."""
+ return cls(0xc27c0e)
+
+ @classmethod
+ def dark_orange(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0xa84300."""
+ return cls(0xa84300)
+
+ @classmethod
+ def dark_red(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x992d22."""
+ return cls(0x992d22)
+
+ @classmethod
+ def dark_grey_blue(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x979c9f."""
+ return cls(0x979c9f)
+
+ @classmethod
+ def light_grey(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0xbcc0c0."""
+ return cls(0xbcc0c0)
+
+ @classmethod
+ def dark_navy_blue(cls):
+ """A factory method that returns a :class:`Colour` with a value of 0x2c3e50."""
+ return cls(0x2c3e50)
+
+
+Color = Colour