diff options
| author | Zomatree <[email protected]> | 2021-05-29 05:15:46 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-05-29 00:15:46 -0400 |
| commit | b48f510e154e40b8ba3bef58e5c513fccf90c89c (patch) | |
| tree | 917f2da2ee25e0fcac4fbc9e3762d89c4d10e604 /discord/appinfo.py | |
| parent | Default SelectOption.value to the label if not given (diff) | |
| download | discord.py-b48f510e154e40b8ba3bef58e5c513fccf90c89c.tar.xz discord.py-b48f510e154e40b8ba3bef58e5c513fccf90c89c.zip | |
Add invite targets for voice channel invites
Diffstat (limited to 'discord/appinfo.py')
| -rw-r--r-- | discord/appinfo.py | 83 |
1 files changed, 72 insertions, 11 deletions
diff --git a/discord/appinfo.py b/discord/appinfo.py index 40a4e402..a7f8da82 100644 --- a/discord/appinfo.py +++ b/discord/appinfo.py @@ -22,13 +22,22 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ +from __future__ import annotations + +from typing import TYPE_CHECKING, Optional + from . import utils -from .user import User from .asset import Asset -from .team import Team + +if TYPE_CHECKING: + from .guild import Guild + from .types.appinfo import AppInfo as AppInfoPayload, PartialAppInfo as PartialAppInfoPayload + + from .state import ConnectionState __all__ = ( 'AppInfo', + 'PartialAppInfo', ) @@ -49,7 +58,7 @@ class AppInfo: .. versionadded:: 1.3 - description: Optional[:class:`str`] + description: :class:`str` The application description. bot_public: :class:`bool` Whether the bot can be invited by anyone or if it is locked @@ -122,9 +131,10 @@ class AppInfo: 'privacy_policy_url', ) - def __init__(self, state, data): - self._state = state + def __init__(self, state, data: AppInfoPayload): + from .team import Team + self._state = state self.id = int(data['id']) self.name = data['name'] self.description = data['description'] @@ -132,7 +142,7 @@ class AppInfo: 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']) + self.owner = state.store_user(data['owner']) team = data.get('team') self.team = Team(state, team) if team else None @@ -148,7 +158,7 @@ class AppInfo: self.terms_of_service_url = data.get('terms_of_service_url') self.privacy_policy_url = data.get('privacy_policy_url') - def __repr__(self): + def __repr__(self) -> str: return ( f'<{self.__class__.__name__} id={self.id} name={self.name!r} ' f'description={self.description!r} public={self.bot_public} ' @@ -156,14 +166,14 @@ class AppInfo: ) @property - def icon(self): + def icon(self) -> Optional[Asset]: """Optional[:class:`.Asset`]: Retrieves the application's icon asset, if any.""" if self._icon is None: return None return Asset._from_icon(self._state, self.id, self._icon, path='app') @property - def cover_image(self): + def cover_image(self) -> Optional[Asset]: """Optional[:class:`.Asset`]: Retrieves the cover image on a store embed, if any. This is only available if the application is a game sold on Discord. @@ -173,10 +183,61 @@ class AppInfo: return Asset._from_cover_image(self._state, self.id, self._cover_image) @property - def guild(self): + def guild(self) -> Optional[Guild]: """Optional[:class:`Guild`]: If this application is a game sold on Discord, this field will be the guild to which it has been linked .. versionadded:: 1.3 """ - return self._state._get_guild(int(self.guild_id)) + return self._state._get_guild(self.guild_id) + +class PartialAppInfo: + """Represents a partial AppInfo given by :func:`~GuildChannel.create_invite` + + .. versionadded:: 2.0 + + Attributes + ------------- + id: :class:`int` + The application ID. + name: :class:`str` + The application name. + description: :class:`str` + The application description. + rpc_origins: Optional[List[:class:`str`]] + A list of RPC origin URLs, if RPC is enabled. + summary: :class:`str` + If this application is a game sold on Discord, + this field will be the summary field for the store page of its primary SKU. + verify_key: :class:`str` + The hex encoded key for verification in interactions and the + GameSDK's `GetTicket <https://discord.com/developers/docs/game-sdk/applications#getticket>`_. + terms_of_service_url: Optional[:class:`str`] + The application's terms of service URL, if set. + privacy_policy_url: Optional[:class:`str`] + The application's privacy policy URL, if set. + """ + + __slots__ = ('_state', 'id', 'name', 'description', 'rpc_origins', 'summary', 'verify_key', 'terms_of_service_url', 'privacy_policy_url', '_icon') + + def __init__(self, *, state: ConnectionState, data: PartialAppInfoPayload): + self._state = state + self.id = int(data['id']) + self.name = data['name'] + self._icon = data.get('icon') + self.description = data['description'] + self.rpc_origins = data.get('rpc_origins') + self.summary = data['summary'] + self.verify_key = data['verify_key'] + self.terms_of_service_url = data.get('terms_of_service_url') + self.privacy_policy_url = data.get('privacy_policy_url') + + def __repr__(self) -> str: + return f'<{self.__class__.__name__} id={self.id} name={self.name!r} description={self.description!r}>' + + @property + def icon(self) -> Optional[Asset]: + """Optional[:class:`.Asset`]: Retrieves the application's icon asset, if any.""" + if self._icon is None: + return None + return Asset._from_icon(self._state, self.id, self._icon, path='app') |