-
Notifications
You must be signed in to change notification settings - Fork 134
/
appinfo.py
335 lines (268 loc) · 10.7 KB
/
appinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# SPDX-License-Identifier: MIT
from __future__ import annotations
from typing import TYPE_CHECKING, List, Optional
from . import utils
from .asset import Asset
from .flags import ApplicationFlags
from .permissions import Permissions
if TYPE_CHECKING:
from .guild import Guild
from .state import ConnectionState
from .types.appinfo import (
AppInfo as AppInfoPayload,
InstallParams as InstallParamsPayload,
PartialAppInfo as PartialAppInfoPayload,
Team as TeamPayload,
)
from .user import User
__all__ = (
"AppInfo",
"PartialAppInfo",
"InstallParams",
)
class InstallParams:
"""Represents the installation parameters for the application, provided by Discord.
.. versionadded:: 2.5
Attributes
----------
scopes: List[:class:`str`]
The scopes requested by the application.
permissions: :class:`Permissions`
The permissions requested for the bot role.
"""
__slots__ = (
"_app_id",
"scopes",
"permissions",
)
def __init__(self, data: InstallParamsPayload, parent: AppInfo):
self._app_id = parent.id
self.scopes = data["scopes"]
self.permissions = Permissions(int(data["permissions"]))
def __repr__(self):
return f"<InstallParams scopes={self.scopes!r} permissions={self.permissions!r}>"
def to_url(self) -> str:
"""Return a string that can be used to add this application to a server.
Returns
-------
:class:`str`
The invite url.
"""
return utils.oauth_url(self._app_id, scopes=self.scopes, permissions=self.permissions)
class AppInfo:
"""Represents the application info for the bot provided by Discord.
Attributes
----------
id: :class:`int`
The application's ID.
name: :class:`str`
The application's name.
owner: :class:`User`
The application's owner.
team: Optional[:class:`Team`]
The application's team.
.. versionadded:: 1.3
description: :class:`str`
The application's description.
bot_public: :class:`bool`
Whether the bot can be invited by anyone or if it is locked
to the application owner.
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.
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>`_.
.. versionadded:: 1.3
guild_id: Optional[:class:`int`]
If this application is a game sold on Discord,
this field will be the guild to which it has been linked to.
.. versionadded:: 1.3
primary_sku_id: Optional[:class:`int`]
If this application is a game sold on Discord,
this field will be the ID of the "Game SKU" that is created,
if it exists.
.. versionadded:: 1.3
slug: Optional[:class:`str`]
If this application is a game sold on Discord,
this field will be the URL slug that links to the store page.
.. versionadded:: 1.3
terms_of_service_url: Optional[:class:`str`]
The application's terms of service URL, if set.
.. versionadded:: 2.0
privacy_policy_url: Optional[:class:`str`]
The application's privacy policy URL, if set.
.. versionadded:: 2.0
flags: Optional[:class:`ApplicationFlags`]
The application's public flags.
.. versionadded:: 2.3
tags: Optional[List[:class:`str`]]
The application's tags.
.. versionadded:: 2.5
install_params: Optional[:class:`InstallParams`]
The installation parameters for this application.
.. versionadded:: 2.5
custom_install_url: Optional[:class:`str`]
The custom installation url for this application.
.. versionadded:: 2.5
"""
__slots__ = (
"_state",
"description",
"id",
"name",
"rpc_origins",
"bot_public",
"bot_require_code_grant",
"owner",
"_icon",
"_summary",
"verify_key",
"team",
"guild_id",
"primary_sku_id",
"slug",
"_cover_image",
"terms_of_service_url",
"privacy_policy_url",
"flags",
"tags",
"install_params",
"custom_install_url",
)
def __init__(self, state: ConnectionState, data: AppInfoPayload):
from .team import Team
self._state: ConnectionState = state
self.id: int = int(data["id"])
self.name: str = data["name"]
self.description: str = data["description"]
self._icon: Optional[str] = data["icon"]
self.rpc_origins: List[str] = data["rpc_origins"]
self.bot_public: bool = data["bot_public"]
self.bot_require_code_grant: bool = data["bot_require_code_grant"]
self.owner: User = state.create_user(data["owner"])
team: Optional[TeamPayload] = data.get("team")
self.team: Optional[Team] = Team(state, team) if team else None
self._summary: str = data.get("summary", "")
self.verify_key: str = data["verify_key"]
self.guild_id: Optional[int] = utils._get_as_snowflake(data, "guild_id")
self.primary_sku_id: Optional[int] = utils._get_as_snowflake(data, "primary_sku_id")
self.slug: Optional[str] = data.get("slug")
self._cover_image: Optional[str] = data.get("cover_image")
self.terms_of_service_url: Optional[str] = data.get("terms_of_service_url")
self.privacy_policy_url: Optional[str] = data.get("privacy_policy_url")
flags: Optional[int] = data.get("flags")
self.flags: Optional[ApplicationFlags] = (
ApplicationFlags._from_value(flags) if flags is not None else None
)
self.tags: Optional[List[str]] = data.get("tags")
self.install_params: Optional[InstallParams] = (
InstallParams(data["install_params"], parent=self) if "install_params" in data else None
)
self.custom_install_url: Optional[str] = data.get("custom_install_url")
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} "
f"owner={self.owner!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")
@property
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.
"""
if self._cover_image is None:
return None
return Asset._from_cover_image(self._state, self.id, self._cover_image)
@property
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(self.guild_id)
@property
def summary(self) -> str:
""":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.
.. versionadded:: 1.3
.. deprecated:: 2.5
This field is deprecated by discord and is now always blank. Consider using :attr:`.description` instead.
"""
utils.warn_deprecated(
"summary is deprecated and will be removed in a future version. Consider using description instead.",
stacklevel=2,
)
return self._summary
class PartialAppInfo:
"""Represents a partial AppInfo given by :func:`~disnake.abc.GuildChannel.create_invite`.
.. versionadded:: 2.0
Attributes
----------
id: :class:`int`
The application's ID.
name: :class:`str`
The application's name.
description: :class:`str`
The application's description.
rpc_origins: Optional[List[:class:`str`]]
A list of RPC origin URLs, if RPC is enabled.
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: ConnectionState = state
self.id: int = int(data["id"])
self.name: str = data["name"]
self._icon: Optional[str] = data.get("icon")
self.description: str = data["description"]
self.rpc_origins: Optional[List[str]] = data.get("rpc_origins")
self._summary: str = data.get("summary", "")
self.verify_key: str = data["verify_key"]
self.terms_of_service_url: Optional[str] = data.get("terms_of_service_url")
self.privacy_policy_url: Optional[str] = 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")
@property
def summary(self) -> str:
""":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.
.. deprecated:: 2.5
This field is deprecated by discord and is now always blank. Consider using :attr:`.description` instead.
"""
utils.warn_deprecated(
"summary is deprecated and will be removed in a future version. Consider using description instead.",
stacklevel=2,
)
return self._summary