Documentation

This commit is contained in:
thecosmos
2019-05-08 15:46:24 +05:30
parent b34f201155
commit ce488393e6
7 changed files with 282 additions and 10 deletions

View File

@@ -2,15 +2,44 @@ from .user import User
class Integration(object):
""""Class representing discord server integrations.
Attributes
----------
id : int
Integration ID.
name : str
Name of integration.
type : str
Integration type (twitch, youtube, etc).
enabled : bool
A boolean representing if this integration is enabled.
syncing : bool
A boolean representing if this integration is syncing.
role_id : int
ID that this integration uses for subscribers.
expire_behaviour : int
An integer representing the behaviour of expiring subscribers.
expire_grace_period : int
An integer representing the grace period before expiring subscribers.
user : User
Object representing user of this integration.
account : dict
A dictionary representing raw
`account <https://discordapp.com/developers/docs/resources/guild#integration-account-object>`_ object.
synced_at : ISO8601 timestamp
Representing when this integration was last synced.
"""
def __init__(self, payload):
self._payload = payload
self.id = self._payload.get("id")
self.id = int(self._payload.get("id", 0))
self.name = self._payload.get("name")
self.type = self._payload.get("type")
self.enabled = self._payload.get("enabled")
self.syncing = self._payload.get("syncing")
self.role_id = self._payload.get("role_id")
self.role_id = int(self._payload.get("role_id", 0))
self.expire_behaviour = self._payload.get("expire_behaviour")
self.expire_grace_period = self._payload.get("expire_grace_period")
self.user = User(self._payload.get("user", dict()))
@@ -19,10 +48,37 @@ class Integration(object):
class UserConnection(object):
"""Class representing connections in discord account of the user.
Attributes
----------
id : int
ID of the connection account.
name : str
The username of the connection account.
type : str
The service of connection (twitch, youtube).
revoked : bool
A boolean representing whether the connection is revoked.
integrations : list
A list of server Integration objects.
verified : bool
A boolean representing whether the connection is verified.
friend_sync : bool
A boolean representing whether friend sync is enabled for this connection.
show_activity : bool
A boolean representing whether activities related to this connection will
be shown in presence updates.
visibility : int
An integer representing
`visibility <https://discordapp.com/developers/docs/resources/user#user-object-visibility-types>`_
of this connection.
"""
def __init__(self, payload):
self._payload = payload
self.id = self._payload.get("id")
self.id = int(self._payload.get("id", 0))
self.name = self._payload.get("name")
self.type = self._payload.get("type")
self.revoked = self._payload.get("revoked")
@@ -37,4 +93,5 @@ class UserConnection(object):
@property
def is_visible(self):
"""A property returning bool if this integration is visible to everyone."""
return bool(self.visibility)

View File

@@ -2,10 +2,26 @@ from .. import configs
class Guild(object):
"""Class representing discord Guild the user is part of.
Attributes
----------
id : int
Discord ID of the guild.
name : str
Name of the guild.
icon_hash : str
Hash of guild's icon.
is_owner : bool
Boolean determining if current user is owner of the guild or not.
permissions_value : int
An integer representing permissions of current user in the guild.
"""
def __init__(self, payload):
self._payload = payload
self.id = self._payload["id"]
self.id = int(self._payload["id"])
self.name = self._payload["name"]
self.icon_hash = self._payload.get("icon")
self.is_owner = self._payload.get("owner")
@@ -16,4 +32,5 @@ class Guild(object):
@property
def icon_url(self):
"""A property returning direct URL to the guild's icon."""
return configs.GUILD_ICON_BASE_URL.format(guild_id=self.id, icon_hash=self.icon_hash)

View File

@@ -2,12 +2,42 @@ from .. import configs
class User(object):
"""Class representing Discord User.
Attributes
----------
id : int
The discord ID of the user.
username : str
The discord username of the user.
discriminator : int
4 - digits discord tag of the user.
avatar_hash : str
Hash of users avatar.
bot : bool
A boolean representing whether the user belongs to an OAuth2 application.
mfa_enabled : bool
A boolean representing whether the user has two factor enabled on their account.
locale : str
The user's chosen language option.
verified : bool
A boolean representing whether the email on this account has been verified.
email : str
User's email ID.
flags : int
An integer representing the
`user flags <https://discordapp.com/developers/docs/resources/user#user-object-user-flags>`_.
premium_type : int
An integer representing the
`type of nitro subscription <https://discordapp.com/developers/docs/resources/user#user-object-premium-types>`_.
"""
def __init__(self, payload):
self._payload = payload
self.id = self._payload["id"]
self.id = int(self._payload["id"])
self.username = self._payload["username"]
self.discriminator = self._payload["discriminator"]
self.discriminator = int(self._payload["discriminator"])
self.avatar_hash = self._payload.get("avatar", self.discriminator)
self.bot = self._payload.get("bot", False)
self.mfa_enabled = self._payload.get("mfa_enabled")
@@ -22,20 +52,33 @@ class User(object):
@property
def name(self):
"""An alias to the username attribute."""
return self.username
@property
def avatar_url(self):
"""A property returning direct URL to user's avatar."""
return configs.USER_AVATAR_BASE_URL.format(user_id=self.id, avatar_hash=self.avatar_hash)
@property
def is_avatar_animated(self):
"""A boolean representing if avatar of user is animated. Meaning user has GIF avatar."""
return self.avatar_hash.startswith("a_")
def to_json(self):
"""A utility method which returns raw user object as it was returned from discord.
Returns
-------
dict
A dict of user's document.
"""
return self._payload
class Bot(User):
"""Class representing the client user itself.
"""
pass