def current(cls):
"""Returns the current User if applicable, None if not authenticated."""
token = session.get('oauth2_token')
if token is None:
return None
with make_session(token=token) as discord:
data = cache.get_cached_user_data(token)
if data is None:
user = discord.get(DISCORD_API_URL + '/users/@me')
if user.status_code == 401:
# our token is invalidated
session.pop('oauth2_token')
return None
data = user.json()
cache.set_cached_user_data(token, data)
return cls(data) if data else None
评论列表
文章目录