From 8727472b850995db34d9bbfec4eaa8714bf4ef3a Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 10 Feb 2017 17:07:08 -0500 Subject: [PATCH] Add Client.get_user_profile to get an arbitrary user's profile. --- discord/client.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/discord/client.py b/discord/client.py index 9d7903e04..d856a1c57 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'])