mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2025-12-10 12:29:30 +02:00
Merge pull request #2 from dorilahav1234561/dev
Fix get_connections on dev branch.
This commit is contained in:
@@ -11,4 +11,4 @@ __all__ = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
__version__ = "0.1.03"
|
__version__ = "0.1.06"
|
||||||
|
|||||||
@@ -62,7 +62,10 @@ class DiscordOAuth2Session(_http.DiscordOAuth2HttpClient):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
for session_key in self.SESSION_KEYS:
|
for session_key in self.SESSION_KEYS:
|
||||||
session.pop(session_key)
|
try:
|
||||||
|
session.pop(session_key)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def authorized(self):
|
def authorized(self):
|
||||||
@@ -79,7 +82,7 @@ class DiscordOAuth2Session(_http.DiscordOAuth2HttpClient):
|
|||||||
"""
|
"""
|
||||||
return models.User(self.get("/users/@me"))
|
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.
|
"""Requests and returns connections of current user from discord.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
@@ -87,7 +90,8 @@ class DiscordOAuth2Session(_http.DiscordOAuth2HttpClient):
|
|||||||
flask_discord.models.UserConnection
|
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:
|
def fetch_guilds(self) -> list:
|
||||||
"""Requests and returns guilds of current user from discord.
|
"""Requests and returns guilds of current user from discord.
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ DEFAULT_SCOPES = [
|
|||||||
|
|
||||||
|
|
||||||
IMAGE_BASE_URL = "https://cdn.discordapp.com/"
|
IMAGE_BASE_URL = "https://cdn.discordapp.com/"
|
||||||
|
IMAGE_FORMAT = "png"
|
||||||
USER_AVATAR_BASE_URL = IMAGE_BASE_URL + "avatars/{user_id}/{avatar_hash}.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"
|
GUILD_ICON_BASE_URL = IMAGE_BASE_URL + "icons/{guild_id}/{icon_hash}.png"
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class UserConnection(object):
|
|||||||
|
|
||||||
Attributes
|
Attributes
|
||||||
----------
|
----------
|
||||||
id : int
|
id : str
|
||||||
ID of the connection account.
|
ID of the connection account.
|
||||||
name : str
|
name : str
|
||||||
The username of the connection account.
|
The username of the connection account.
|
||||||
@@ -80,7 +80,7 @@ class UserConnection(object):
|
|||||||
|
|
||||||
def __init__(self, payload):
|
def __init__(self, payload):
|
||||||
self._payload = payload
|
self._payload = payload
|
||||||
self.id = int(self._payload.get("id", 0))
|
self.id = self._payload["id"]
|
||||||
self.name = self._payload.get("name")
|
self.name = self._payload.get("name")
|
||||||
self.type = self._payload.get("type")
|
self.type = self._payload.get("type")
|
||||||
self.revoked = self._payload.get("revoked")
|
self.revoked = self._payload.get("revoked")
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ class User(DiscordModelsBase):
|
|||||||
The discord ID of the user.
|
The discord ID of the user.
|
||||||
username : str
|
username : str
|
||||||
The discord username of the user.
|
The discord username of the user.
|
||||||
discriminator : int
|
discriminator : str
|
||||||
4 - digits discord tag of the user.
|
4 length string representing discord tag of the user.
|
||||||
avatar_hash : str
|
avatar_hash : str
|
||||||
Hash of users avatar.
|
Hash of users avatar.
|
||||||
bot : bool
|
bot : bool
|
||||||
@@ -39,7 +39,7 @@ class User(DiscordModelsBase):
|
|||||||
self._payload = payload
|
self._payload = payload
|
||||||
self.id = int(self._payload["id"])
|
self.id = int(self._payload["id"])
|
||||||
self.username = self._payload["username"]
|
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.avatar_hash = self._payload.get("avatar", self.discriminator)
|
||||||
self.bot = self._payload.get("bot", False)
|
self.bot = self._payload.get("bot", False)
|
||||||
self.mfa_enabled = self._payload.get("mfa_enabled")
|
self.mfa_enabled = self._payload.get("mfa_enabled")
|
||||||
@@ -60,7 +60,8 @@ class User(DiscordModelsBase):
|
|||||||
@property
|
@property
|
||||||
def avatar_url(self):
|
def avatar_url(self):
|
||||||
"""A property returning direct URL to user's avatar."""
|
"""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
|
@property
|
||||||
def is_avatar_animated(self):
|
def is_avatar_animated(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user