aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-02-10 17:07:08 -0500
committerRapptz <[email protected]>2017-02-10 17:07:08 -0500
commit8727472b850995db34d9bbfec4eaa8714bf4ef3a (patch)
tree9b4a7122df12a08757bc7c0acb99d85bb9eec3b6
parentAdd Client.emojis to get all emojis. (diff)
downloaddiscord.py-8727472b850995db34d9bbfec4eaa8714bf4ef3a.tar.xz
discord.py-8727472b850995db34d9bbfec4eaa8714bf4ef3a.zip
Add Client.get_user_profile to get an arbitrary user's profile.
-rw-r--r--discord/client.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/discord/client.py b/discord/client.py
index 9d7903e0..d856a1c5 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -24,7 +24,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
-from .user import User
+from .user import User, Profile
from .invite import Invite
from .object import Object
from .errors import *
@@ -834,3 +834,40 @@ class Client:
"""
data = yield from self.http.get_user_info(user_id)
return User(state=self.connection, data=data)
+
+ @asyncio.coroutine
+ def get_user_profile(self, user_id):
+ """|coro|
+
+ Gets an arbitrary user's profile. This can only be used by non-bot accounts.
+
+ Parameters
+ ------------
+ user_id: int
+ The ID of the user to fetch their profile for.
+
+ Raises
+ -------
+ Forbidden
+ Not allowed to fetch profiles.
+ HTTPException
+ Fetching the profile failed.
+
+ Returns
+ --------
+ :class:`Profile`
+ The profile of the user.
+ """
+
+ state = self.connection
+ data = yield from self.http.get_user_profile(user_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=utils.parse_time(data.get('premium_since')),
+ mutual_guilds=mutual_guilds,
+ user=User(data=data['user'], state=state),
+ connected_accounts=data['connected_accounts'])