diff options
| author | Rapptz <[email protected]> | 2015-08-26 07:43:05 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2015-08-26 07:43:05 -0400 |
| commit | 108f0a6c45599d783fdb1d991fc1b5af87ca0f47 (patch) | |
| tree | 5a23a2041bfd9e39e486e330a43ac93dec6d654e /discord/server.py | |
| parent | Preliminary work on permission parsing. (diff) | |
| download | discord.py-108f0a6c45599d783fdb1d991fc1b5af87ca0f47.tar.xz discord.py-108f0a6c45599d783fdb1d991fc1b5af87ca0f47.zip | |
Server members are now their own class that subclass Users.
Roles are also now properly parsed.
Diffstat (limited to 'discord/server.py')
| -rw-r--r-- | discord/server.py | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/discord/server.py b/discord/server.py index ae4d8164..7c796721 100644 --- a/discord/server.py +++ b/discord/server.py @@ -25,6 +25,59 @@ DEALINGS IN THE SOFTWARE. """ from user import User +from permissions import Permissions +import datetime, re + +class Role(object): + """"Represents a Discord role in a :class:`Server`. + + Instance attributes: + + .. attribute:: id + + The ID for the role. + .. attribute:: name + + The name of the role. + .. attribute:: permissions + + A :class:`Permissions` that represents the role's permissions. + """ + + def __init__(self, id, name, permissions): + self.id = id + self.name = name + self.permissions = Permissions(permissions) + +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 + + Specifies if the member is currently deafened by the user. + .. attribute:: mute + + Specifies if the member is currently muted by the user. + .. attribute:: roles + + An array of :class:`Role` that the member belongs to. + .. attribute:: joined_at + + A datetime object that specifies the date and time that the member joined the server for + the first time. + """ + + def __init__(self, deaf, joined_at, user, roles, mute): + super(Member, self).__init__(**user) + self.deaf = deaf + self.mute = mute + self.joined_at = datetime.datetime(*map(int, re.split(r'[^\d]', joined_at.replace('+00:00', '')))) + self.roles = roles class Server(object): """Represents a Discord server. @@ -36,7 +89,7 @@ class Server(object): The server name. .. attribute:: roles - An array of role names. + An array of :class:`Role` that the server has available. .. attribute:: region The region the server belongs on. @@ -48,7 +101,7 @@ class Server(object): The channel ID for the AFK channel. None if it doesn't exist. .. attribute:: members - An array of :class:`User` that are currently on the server. + An array of :class:`Member` that are currently on the server. .. attribute:: channels An array of :class:`Channel` that are currently on the server. |