mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-13 09:19:48 +00:00
Add Client.application_info to retrieve the current app info.
Fixes #241.
This commit is contained in:
parent
fe5c369fe9
commit
a175c86aa1
@ -17,7 +17,7 @@ __license__ = 'MIT'
|
|||||||
__copyright__ = 'Copyright 2015-2016 Rapptz'
|
__copyright__ = 'Copyright 2015-2016 Rapptz'
|
||||||
__version__ = '0.10.0-alpha'
|
__version__ = '0.10.0-alpha'
|
||||||
|
|
||||||
from .client import Client
|
from .client import Client, AppInfo
|
||||||
from .user import User
|
from .user import User
|
||||||
from .game import Game
|
from .game import Game
|
||||||
from .channel import Channel, PrivateChannel
|
from .channel import Channel, PrivateChannel
|
||||||
|
@ -53,12 +53,23 @@ import tempfile, os, hashlib
|
|||||||
import itertools
|
import itertools
|
||||||
import datetime
|
import datetime
|
||||||
from random import randint as random_integer
|
from random import randint as random_integer
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
PY35 = sys.version_info >= (3, 5)
|
PY35 = sys.version_info >= (3, 5)
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
request_logging_format = '{method} {response.url} has returned {response.status}'
|
request_logging_format = '{method} {response.url} has returned {response.status}'
|
||||||
request_success_log = '{response.url} with {json} received {data}'
|
request_success_log = '{response.url} with {json} received {data}'
|
||||||
|
|
||||||
|
AppInfo = namedtuple('AppInfo', 'id name description icon')
|
||||||
|
def app_info_icon_url(self):
|
||||||
|
"""Retrieves the application's icon_url if it exists. Empty string otherwise."""
|
||||||
|
if not self.icon:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
return 'https://cdn.discordapp.com/app-icons/{0.id}/{0.icon}.jpg'.format(self)
|
||||||
|
|
||||||
|
AppInfo.icon_url = property(app_info_icon_url)
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
"""Represents a client connection that connects to Discord.
|
"""Represents a client connection that connects to Discord.
|
||||||
This class is used to interact with the Discord WebSocket and API.
|
This class is used to interact with the Discord WebSocket and API.
|
||||||
@ -2787,3 +2798,31 @@ class Client:
|
|||||||
The voice client associated with the server.
|
The voice client associated with the server.
|
||||||
"""
|
"""
|
||||||
return self.connection._get_voice_client(server.id)
|
return self.connection._get_voice_client(server.id)
|
||||||
|
|
||||||
|
|
||||||
|
# Miscellaneous stuff
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def application_info(self):
|
||||||
|
"""|coro|
|
||||||
|
|
||||||
|
Retrieve's the bot's application information.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
--------
|
||||||
|
:class:`AppInfo`
|
||||||
|
A namedtuple representing the application info.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
-------
|
||||||
|
HTTPException
|
||||||
|
Retrieving the information failed somehow.
|
||||||
|
"""
|
||||||
|
url = '{}/@me'.format(endpoints.APPLICATIONS)
|
||||||
|
resp = yield from self.session.get(url, headers=self.headers)
|
||||||
|
yield from utils._verify_successful_response(resp)
|
||||||
|
data = yield from resp.json()
|
||||||
|
return AppInfo(id=data['id'], name=data['name'],
|
||||||
|
description=data['description'], icon=data['icon'])
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,3 +34,4 @@ LOGIN = API_BASE + '/auth/login'
|
|||||||
LOGOUT = API_BASE + '/auth/logout'
|
LOGOUT = API_BASE + '/auth/logout'
|
||||||
SERVERS = API_BASE + '/guilds'
|
SERVERS = API_BASE + '/guilds'
|
||||||
CHANNELS = API_BASE + '/channels'
|
CHANNELS = API_BASE + '/channels'
|
||||||
|
APPLICATIONS = API_BASE + '/oauth2/applications'
|
||||||
|
26
docs/api.rst
26
docs/api.rst
@ -31,7 +31,6 @@ There are two main ways to query version information about the library.
|
|||||||
|
|
||||||
A string representation of the version. e.g. ``'0.10.0-alpha0'``.
|
A string representation of the version. e.g. ``'0.10.0-alpha0'``.
|
||||||
|
|
||||||
|
|
||||||
Client
|
Client
|
||||||
-------
|
-------
|
||||||
|
|
||||||
@ -345,6 +344,31 @@ Utility Functions
|
|||||||
|
|
||||||
.. autofunction:: discord.utils.oauth_url
|
.. autofunction:: discord.utils.oauth_url
|
||||||
|
|
||||||
|
Application Info
|
||||||
|
------------------
|
||||||
|
|
||||||
|
.. class:: AppInfo
|
||||||
|
|
||||||
|
A namedtuple representing the bot's application info.
|
||||||
|
|
||||||
|
.. attribute:: id
|
||||||
|
|
||||||
|
The application's ``client_id``.
|
||||||
|
.. attribute:: name
|
||||||
|
|
||||||
|
The application's name.
|
||||||
|
.. attribute:: description
|
||||||
|
|
||||||
|
The application's description
|
||||||
|
.. attribute:: icon
|
||||||
|
|
||||||
|
The application's icon hash if it exists, ``None`` otherwise.
|
||||||
|
.. attribute:: icon_url
|
||||||
|
|
||||||
|
A property that retrieves the application's icon URL if it exists.
|
||||||
|
|
||||||
|
If it doesn't exist an empty string is returned.
|
||||||
|
|
||||||
.. _discord-api-enums:
|
.. _discord-api-enums:
|
||||||
|
|
||||||
Enumerations
|
Enumerations
|
||||||
|
Loading…
x
Reference in New Issue
Block a user