6 changed files with 295 additions and 242 deletions
@ -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 |
@ -0,0 +1,101 @@ |
|||||
|
# -*- 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. |
||||
|
""" |
||||
|
|
||||
|
from .user import User |
||||
|
from .utils import parse_time |
||||
|
|
||||
|
class Member(User): |
||||
|
"""Represents a Discord member to a :class:`Server`. |
||||
|
|
||||
|
This is a subclass of :class:`User` that extends more functionality |
||||
|
that server members have such as roles and permissions. |
||||
|
|
||||
|
Instance attributes: |
||||
|
|
||||
|
.. attribute:: deaf |
||||
|
|
||||
|
A boolean that specifies if the member is currently deafened by the server. |
||||
|
.. attribute:: mute |
||||
|
|
||||
|
A boolean that specifies if the member is currently muted by the server. |
||||
|
.. attribute:: self_mute |
||||
|
|
||||
|
A boolean that specifies if the member is currently muted by their own accord. |
||||
|
.. attribute:: self_deaf |
||||
|
|
||||
|
A boolean that specifies if the member is currently deafened by their own accord. |
||||
|
.. attribute:: is_afk |
||||
|
|
||||
|
A boolean that specifies if the member is currently in the AFK channel in the server. |
||||
|
.. attribute:: voice_channel |
||||
|
|
||||
|
A voice :class:`Channel` that the member is currently connected to. None if the member |
||||
|
is not currently in a voice channel. |
||||
|
.. attribute:: roles |
||||
|
|
||||
|
An array of :class:`Role` that the member belongs to. |
||||
|
.. attribute:: joined_at |
||||
|
|
||||
|
A datetime object that specifies the date and time in UTC that the member joined the server for |
||||
|
the first time. |
||||
|
.. attribute:: status |
||||
|
|
||||
|
A string that denotes the user's status. Can be 'online', 'offline' or 'idle'. |
||||
|
.. attribute:: game_id |
||||
|
|
||||
|
The game ID that the user is currently playing. Could be None if no game is being played. |
||||
|
.. attribute:: server |
||||
|
|
||||
|
The :class:`Server` that the member belongs to. |
||||
|
""" |
||||
|
|
||||
|
def __init__(self, deaf, joined_at, user, roles, mute, **kwargs): |
||||
|
super(Member, self).__init__(**user) |
||||
|
self.deaf = deaf |
||||
|
self.mute = mute |
||||
|
self.joined_at = parse_time(joined_at) |
||||
|
self.roles = roles |
||||
|
self.status = 'offline' |
||||
|
self.game_id = kwargs.get('game_id', None) |
||||
|
self.server = kwargs.get('server', None) |
||||
|
self.update_voice_state(mute=mute, deaf=deaf) |
||||
|
|
||||
|
def update_voice_state(self, **kwargs): |
||||
|
self.self_mute = kwargs.get('self_mute', False) |
||||
|
self.self_deaf = kwargs.get('self_deaf', False) |
||||
|
self.is_afk = kwargs.get('suppress', False) |
||||
|
self.mute = kwargs.get('mute', False) |
||||
|
self.deaf = kwargs.get('deaf', False) |
||||
|
old_channel = getattr(self, 'voice_channel', None) |
||||
|
self.voice_channel = kwargs.get('voice_channel') |
||||
|
|
||||
|
if old_channel is None and self.voice_channel is not None: |
||||
|
# we joined a channel |
||||
|
self.voice_channel.voice_members.append(self) |
||||
|
elif old_channel is not None and self.voice_channel is None: |
||||
|
if self in old_channel.voice_members: |
||||
|
# we left a channel |
||||
|
old_channel.voice_members.remove(self) |
Loading…
Reference in new issue