|
| 1 | +""" |
| 2 | +The MIT License (MIT) |
| 3 | +
|
| 4 | +Copyright (c) 2021-present Pycord Development |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | +copy of this software and associated documentation files (the "Software"), |
| 8 | +to deal in the Software without restriction, including without limitation |
| 9 | +the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | +and/or sell copies of the Software, and to permit persons to whom the |
| 11 | +Software is furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in |
| 14 | +all copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 | +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | +DEALINGS IN THE SOFTWARE. |
| 23 | +""" |
| 24 | +from __future__ import annotations |
| 25 | + |
| 26 | +from typing import TYPE_CHECKING |
| 27 | + |
| 28 | +if TYPE_CHECKING: |
| 29 | + from ..app.state import ConnectionState |
| 30 | + from ..types.appinfo import PartialAppInfo as PartialAppInfoPayload |
| 31 | + from ..asset import Asset |
| 32 | + |
| 33 | + |
| 34 | +class PartialAppInfo: |
| 35 | + """Represents a partial AppInfo given by :func:`~discord.abc.GuildChannel.create_invite` |
| 36 | +
|
| 37 | + .. versionadded:: 2.0 |
| 38 | +
|
| 39 | + Attributes |
| 40 | + ---------- |
| 41 | + id: :class:`int` |
| 42 | + The application ID. |
| 43 | + name: :class:`str` |
| 44 | + The application name. |
| 45 | + description: :class:`str` |
| 46 | + The application description. |
| 47 | + rpc_origins: Optional[List[:class:`str`]] |
| 48 | + A list of RPC origin URLs, if RPC is enabled. |
| 49 | + summary: :class:`str` |
| 50 | + If this application is a game sold on Discord, |
| 51 | + this field will be the summary field for the store page of its primary SKU. |
| 52 | + verify_key: :class:`str` |
| 53 | + The hex encoded key for verification in interactions and the |
| 54 | + GameSDK's `GetTicket <https://discord.com/developers/docs/game-sdk/applications#getticket>`_. |
| 55 | + terms_of_service_url: Optional[:class:`str`] |
| 56 | + The application's terms of service URL, if set. |
| 57 | + privacy_policy_url: Optional[:class:`str`] |
| 58 | + The application's privacy policy URL, if set. |
| 59 | + """ |
| 60 | + |
| 61 | + __slots__ = ( |
| 62 | + "_state", |
| 63 | + "id", |
| 64 | + "name", |
| 65 | + "description", |
| 66 | + "rpc_origins", |
| 67 | + "summary", |
| 68 | + "verify_key", |
| 69 | + "terms_of_service_url", |
| 70 | + "privacy_policy_url", |
| 71 | + "_icon", |
| 72 | + ) |
| 73 | + |
| 74 | + def __init__(self, *, state: ConnectionState, data: PartialAppInfoPayload): |
| 75 | + self._state: ConnectionState = state |
| 76 | + self.id: int = int(data["id"]) |
| 77 | + self.name: str = data["name"] |
| 78 | + self._icon: str | None = data.get("icon") |
| 79 | + self.description: str = data["description"] |
| 80 | + self.rpc_origins: list[str] | None = data.get("rpc_origins") |
| 81 | + self.summary: str = data["summary"] |
| 82 | + self.verify_key: str = data["verify_key"] |
| 83 | + self.terms_of_service_url: str | None = data.get("terms_of_service_url") |
| 84 | + self.privacy_policy_url: str | None = data.get("privacy_policy_url") |
| 85 | + |
| 86 | + def __repr__(self) -> str: |
| 87 | + return f"<{self.__class__.__name__} id={self.id} name={self.name!r} description={self.description!r}>" |
| 88 | + |
| 89 | + @property |
| 90 | + def icon(self) -> Asset | None: |
| 91 | + """Retrieves the application's icon asset, if any.""" |
| 92 | + if self._icon is None: |
| 93 | + return None |
| 94 | + return Asset._from_icon(self._state, self.id, self._icon, path="app") |
0 commit comments