Merge pull request #2 from dorilahav1234561/dev

Fix get_connections on dev branch.
This commit is contained in:
thec0sm0s
2020-02-08 11:59:07 +05:30
committed by GitHub
5 changed files with 18 additions and 12 deletions

View File

@@ -11,4 +11,4 @@ __all__ = [
]
__version__ = "0.1.03"
__version__ = "0.1.06"

View File

@@ -62,7 +62,10 @@ class DiscordOAuth2Session(_http.DiscordOAuth2HttpClient):
"""
for session_key in self.SESSION_KEYS:
session.pop(session_key)
try:
session.pop(session_key)
except KeyError:
pass
@property
def authorized(self):
@@ -79,7 +82,7 @@ class DiscordOAuth2Session(_http.DiscordOAuth2HttpClient):
"""
return models.User(self.get("/users/@me"))
def fetch_connections(self) -> models.UserConnection:
def fetch_connections(self) -> list:
"""Requests and returns connections of current user from discord.
Returns
@@ -87,7 +90,8 @@ class DiscordOAuth2Session(_http.DiscordOAuth2HttpClient):
flask_discord.models.UserConnection
"""
return models.UserConnection(self.get("/users/@me/connections"))
connections_payload = self.get("/users/@me/connections")
return [models.UserConnection(payload) for payload in connections_payload]
def fetch_guilds(self) -> list:
"""Requests and returns guilds of current user from discord.

View File

@@ -15,6 +15,7 @@ DEFAULT_SCOPES = [
IMAGE_BASE_URL = "https://cdn.discordapp.com/"
USER_AVATAR_BASE_URL = IMAGE_BASE_URL + "avatars/{user_id}/{avatar_hash}.png"
IMAGE_FORMAT = "png"
ANIMATED_IMAGE_FORMAT = "gif"
USER_AVATAR_BASE_URL = IMAGE_BASE_URL + "avatars/{user_id}/{avatar_hash}.{format}"
GUILD_ICON_BASE_URL = IMAGE_BASE_URL + "icons/{guild_id}/{icon_hash}.png"

View File

@@ -54,7 +54,7 @@ class UserConnection(object):
Attributes
----------
id : int
id : str
ID of the connection account.
name : str
The username of the connection account.
@@ -80,7 +80,7 @@ class UserConnection(object):
def __init__(self, payload):
self._payload = payload
self.id = int(self._payload.get("id", 0))
self.id = self._payload["id"]
self.name = self._payload.get("name")
self.type = self._payload.get("type")
self.revoked = self._payload.get("revoked")

View File

@@ -12,8 +12,8 @@ class User(DiscordModelsBase):
The discord ID of the user.
username : str
The discord username of the user.
discriminator : int
4 - digits discord tag of the user.
discriminator : str
4 length string representing discord tag of the user.
avatar_hash : str
Hash of users avatar.
bot : bool
@@ -39,7 +39,7 @@ class User(DiscordModelsBase):
self._payload = payload
self.id = int(self._payload["id"])
self.username = self._payload["username"]
self.discriminator = int(self._payload["discriminator"])
self.discriminator = 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")
@@ -60,7 +60,8 @@ class User(DiscordModelsBase):
@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)
image_format = configs.ANIMATED_IMAGE_FORMAT if self.is_avatar_animated else configs.IMAGE_FORMAT
return configs.USER_AVATAR_BASE_URL.format(user_id=self.id, avatar_hash=self.avatar_hash, format=image_format)
@property
def is_avatar_animated(self):