aboutsummaryrefslogtreecommitdiff
path: root/discord/appinfo.py
diff options
context:
space:
mode:
authorNCPlayz <[email protected]>2019-03-21 19:59:58 +0000
committerRapptz <[email protected]>2019-04-06 19:12:50 -0400
commitbe227ebcf0c8bad6b56798339b5414b8da414dc0 (patch)
treec7ea93ffc51e9a490b42d36e5c734b6b19ec3909 /discord/appinfo.py
parentPropagate Cloudflare 429 HTML text. (diff)
downloaddiscord.py-be227ebcf0c8bad6b56798339b5414b8da414dc0.tar.xz
discord.py-be227ebcf0c8bad6b56798339b5414b8da414dc0.zip
Redesign asset retrieval in the library.
Most assets now return a new class named `Asset`. This allows for the assets to be consistently saved via a `save` method instead of special casing for `Attachment`. `AppInfo` is no longer a namedtuple it is a fully documented dataclass, as well as having the state attached to it. Fixes #1997
Diffstat (limited to 'discord/appinfo.py')
-rw-r--r--discord/appinfo.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/discord/appinfo.py b/discord/appinfo.py
new file mode 100644
index 00000000..c93113ce
--- /dev/null
+++ b/discord/appinfo.py
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+
+"""
+The MIT License (MIT)
+
+Copyright (c) 2015-2019 Rapptz
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+"""
+
+from .user import User
+from .asset import Asset
+
+
+class AppInfo:
+ """Represents the application info for the bot provided by Discord.
+
+
+ Attributes
+ -------------
+ id: :class:`int`
+ The application ID.
+ name: :class:`str`
+ The application name.
+ owner: :class:`User`
+ The application's owner.
+ icon: Optional[:class:`str`]
+ The icon hash.
+ description: Optional[:class:`str`]
+ The application description.
+ bot_public: :class:`bool`
+ Whether the bot is public.
+ bot_require_code_grant: :class:`bool`
+ Whether the bot requires the completion of the full oauth2 code
+ grant flow to join.
+ rpc_origins: Optional[List[:class:`str`]]
+ A list of RPC origin URLs, if RPC is enabled.
+ """
+ __slots__ = ('_state', 'description', 'id', 'name', 'rpc_origins',
+ 'bot_public', 'bot_require_code_grant', 'owner', 'icon')
+
+ def __init__(self, state, data):
+ self._state = state
+
+ self.id = int(data['id'])
+ self.name = data['name']
+ self.description = data['description']
+ self.icon = data['icon']
+ self.rpc_origins = data['rpc_origins']
+ self.bot_public = data['bot_public']
+ self.bot_require_code_grant = data['bot_require_code_grant']
+ self.owner = User(state=self._state, data=data['owner'])
+
+ @property
+ def icon_url(self):
+ """:class:`.Asset`: Retrieves the application's icon asset."""
+ return Asset._from_icon(self._state, self, 'app')