aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--discord/__init__.py2
-rw-r--r--discord/http.py3
-rw-r--r--discord/user.py38
-rw-r--r--docs/api.rst29
4 files changed, 70 insertions, 2 deletions
diff --git a/discord/__init__.py b/discord/__init__.py
index 7ecad72c..68184615 100644
--- a/discord/__init__.py
+++ b/discord/__init__.py
@@ -18,7 +18,7 @@ __copyright__ = 'Copyright 2015-2017 Rapptz'
__version__ = '1.0.0a0'
from .client import Client, AppInfo, ChannelPermissions
-from .user import User, ClientUser
+from .user import User, ClientUser, Profile
from .game import Game
from .emoji import Emoji, PartialEmoji
from .channel import *
diff --git a/discord/http.py b/discord/http.py
index 42cf14e5..2750a792 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -666,3 +666,6 @@ class HTTPClient:
def get_user_info(self, user_id):
return self.request(Route('GET', '/users/{user_id}', user_id=user_id))
+
+ def get_user_profile(self, user_id):
+ return self.request(Route('GET', '/users/{user_id}/profile', user_id=user_id))
diff --git a/discord/user.py b/discord/user.py
index 789167be..683c525c 100644
--- a/discord/user.py
+++ b/discord/user.py
@@ -24,13 +24,17 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
-from .utils import snowflake_time, _bytes_to_base64_data
+from .utils import snowflake_time, _bytes_to_base64_data, parse_time
from .enums import DefaultAvatar, RelationshipType
from .errors import ClientException
+from collections import namedtuple
+
import discord.abc
import asyncio
+Profile = namedtuple('Profile', 'premium user mutual_guilds connected_accounts premium_since')
+
class BaseUser:
__slots__ = ('name', 'id', 'discriminator', 'avatar', 'bot', '_state')
@@ -424,3 +428,35 @@ class User(BaseUser, discord.abc.Messageable):
Sending the friend request failed.
"""
yield from self._state.http.send_friend_request(username=self.name, discriminator=self.discriminator)
+
+ @asyncio.coroutine
+ def profile(self):
+ """|coro|
+
+ Gets the user's profile. This can only be used by non-bot accounts.
+
+ Raises
+ -------
+ Forbidden
+ Not allowed to fetch profiles.
+ HTTPException
+ Fetching the profile failed.
+
+ Returns
+ --------
+ :class:`Profile`
+ The profile of the user.
+ """
+
+ state = self._state
+ data = yield from state.http.get_user_profile(self.id)
+
+ def transform(d):
+ return state._get_guild(int(d['id']))
+
+ mutual_guilds = list(filter(None, map(transform, data.get('mutual_guilds', []))))
+ return Profile(premium=data['premium'],
+ premium_since=parse_time(data.get('premium_since')),
+ mutual_guilds=mutual_guilds,
+ user=self,
+ connected_accounts=data['connected_accounts'])
diff --git a/docs/api.rst b/docs/api.rst
index b31fa280..87d31759 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -481,6 +481,35 @@ Application Info
The owner of the application. This is a :class:`User` instance
with the owner's information at the time of the call.
+Profile
+---------
+
+.. class:: Profile
+
+ A namedtuple representing a user's Discord public profile.
+
+ .. attribute:: user
+
+ The :class:`User` the profile belongs to.
+ .. attribute:: premium
+
+ A boolean indicating if the user has premium (i.e. Discord Nitro).
+ .. attribute:: premium_since
+
+ A naive UTC datetime indicating how long the user has been premium since.
+ This could be ``None`` if not applicable.
+ .. attribute:: mutual_guilds
+
+ A list of :class:`Guild` that the :class:`ClientUser` shares with this
+ user.
+ .. attribute:: connected_accounts
+
+ A list of dict objects indicating the accounts the user has connected.
+
+ An example entry can be seen below: ::
+
+ {type: "twitch", id: "92473777", name: "discordapp"}
+
.. _discord-api-enums:
Enumerations