Split data classes into more files.

This commit is contained in:
Rapptz
2015-10-27 16:23:20 -04:00
parent 616f2bb4e9
commit a0073c734e
6 changed files with 295 additions and 242 deletions

View File

@ -24,83 +24,6 @@ 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)
class Server(object):
"""Represents a Discord server.