23
23
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
24
DEALINGS IN THE SOFTWARE.
25
25
"""
26
+ from __future__ import annotations
27
+
28
+ from typing import (
29
+ TYPE_CHECKING ,
30
+ Optional ,
31
+ List ,
32
+ NamedTuple
33
+ )
34
+ from typing_extensions import Literal
35
+
26
36
27
37
from . import utils
28
38
from .user import User
29
39
from .asset import Asset
30
40
from .team import Team
31
41
from .flags import ApplicationFlags
32
42
43
+ if TYPE_CHECKING :
44
+ from .state import ConnectionState
45
+ from .guild import Guild
46
+ from .types .appinfo import AppInfo as AppInfoPayload
47
+
48
+ __all__ = (
49
+ 'InstallParams' ,
50
+ 'AppInfo' ,
51
+ )
52
+
53
+
54
+ class InstallParams (NamedTuple ):
55
+ """Represents the default install-parameters for an application.
56
+
57
+ Attributes
58
+ -------------
59
+ scopes: List[:class:`str`]
60
+ The scopes to add the application to the server with
61
+ permissions: :class:`str`
62
+ The permissions to request for the bot role
63
+ """
64
+ scopes : List [str ]
65
+ permissions : str
66
+
33
67
34
68
class AppInfo :
35
69
"""Represents the application info for the bot provided by Discord.
@@ -63,8 +97,11 @@ class AppInfo:
63
97
summary: :class:`str`
64
98
If this application is a game sold on Discord,
65
99
this field will be the summary field for the store page of its primary SKU.
66
-
100
+
101
+ Deprecated: This field is deprecated and will be removed in API v11
102
+
67
103
.. versionadded:: 1.3
104
+ .. deprecated:: 2.0
68
105
69
106
verify_key: :class:`str`
70
107
The hex encoded key for verification in interactions and the
@@ -99,7 +136,10 @@ class AppInfo:
99
136
100
137
custom_install_url: Optional[:class:`str`]
101
138
The default invite-url for the bot if its set.
102
-
139
+
140
+ install_params: Optional[:class:`InstallParams`]
141
+ The settings for the application's default in-app authorization link, if enabled.
142
+
103
143
privacy_policy_url: Optional[:class:`str`]
104
144
The link to this application's Privacy Policy if set.
105
145
@@ -114,43 +154,48 @@ class AppInfo:
114
154
'bot_public' , 'bot_require_code_grant' , 'owner' , 'icon' ,
115
155
'summary' , 'verify_key' , 'team' , 'guild_id' , 'primary_sku_id' ,
116
156
'slug' , 'custom_install_url' , 'tags' , '_flags' , 'cover_image' ,
117
- 'privacy_policy_url' , 'terms_of_service_url' , 'interactions_endpoint_url' )
118
-
119
- def __init__ (self , state , data ):
120
- self ._state = state
121
- self .id = int (data ['id' ])
122
- self .name = data ['name' ]
123
- self .description = data ['description' ]
124
- self .icon = data ['icon' ]
125
- self .rpc_origins = data ['rpc_origins' ]
126
- self .bot_public = data ['bot_public' ]
127
- self .bot_require_code_grant = data ['bot_require_code_grant' ]
128
- self .custom_install_url = data .get ('custom_install_url' , None )
129
- self .tags = data .get ('tags' , [])
130
- self ._flags = data .get ('flags' , 0 )
131
- self .owner = User (state = self ._state , data = data ['owner' ])
157
+ 'privacy_policy_url' , 'terms_of_service_url' , 'install_params' ,
158
+ 'interactions_endpoint_url' )
159
+
160
+ def __init__ (self , * , state : ConnectionState , data : AppInfoPayload ):
161
+ self ._state : ConnectionState = state
162
+ self .id : int = int (data ['id' ])
163
+ self .name : str = data ['name' ]
164
+ self .description : str = data ['description' ]
165
+ self .icon : str = data ['icon' ]
166
+ self .rpc_origins : Optional [List [str ]] = data ['rpc_origins' ]
167
+ self .bot_public : bool = data ['bot_public' ]
168
+ self .bot_require_code_grant : bool = data ['bot_require_code_grant' ]
169
+ self .custom_install_url : Optional [str ] = data .get ('custom_install_url' , None )
170
+ install_params = data .get ('install_params' , None )
171
+
172
+ self .install_params : Optional [InstallParams ] = InstallParams (install_params ) if install_params else None
173
+
174
+ self .tags : List [str ] = data .get ('tags' , [])
175
+ self ._flags : int = data .get ('flags' , 0 )
176
+ self .owner : User = User (state = self ._state , data = data ['owner' ])
132
177
133
178
team = data .get ('team' )
134
- self .team = Team (state , team ) if team else None
179
+ self .team : Optional [ Team ] = Team (state , team ) if team else None
135
180
136
- self .summary = data [ 'summary' ]
137
- self .verify_key = data ['verify_key' ]
181
+ self .summary = '' # Deprecated - Will be removed in API v11
182
+ self .verify_key : str = data ['verify_key' ]
138
183
139
- self .guild_id = utils ._get_as_snowflake (data , 'guild_id' )
184
+ self .guild_id : Optional [ int ] = utils ._get_as_snowflake (data , 'guild_id' )
140
185
141
- self .primary_sku_id = utils ._get_as_snowflake (data , 'primary_sku_id' )
142
- self .slug = data .get ('slug' )
143
- self .cover_image = data .get ('cover_image' )
144
- self .privacy_policy_url = data .get ('privacy_policy_url' , None )
145
- self .terms_of_service_url = data .get ('terms_of_service_url' , None )
146
- self .interactions_endpoint_url = data .get ('interactions_endpoint_url' , None )
186
+ self .primary_sku_id : Optional [ int ] = utils ._get_as_snowflake (data , 'primary_sku_id' )
187
+ self .slug : Optional [ str ] = data .get ('slug' )
188
+ self .cover_image : Optional [ str ] = data .get ('cover_image' )
189
+ self .privacy_policy_url : Optional [ str ] = data .get ('privacy_policy_url' , None )
190
+ self .terms_of_service_url : Optional [ str ] = data .get ('terms_of_service_url' , None )
191
+ self .interactions_endpoint_url : Optional [ str ] = data .get ('interactions_endpoint_url' , None )
147
192
148
193
def __repr__ (self ):
149
194
return '<{0.__class__.__name__} id={0.id} name={0.name!r} description={0.description!r} public={0.bot_public} ' \
150
195
'owner={0.owner!r}>' .format (self )
151
196
152
197
@property
153
- def icon_url (self ):
198
+ def icon_url (self ) -> Asset :
154
199
""":class:`.Asset`: Retrieves the application's icon asset.
155
200
156
201
This is equivalent to calling :meth:`icon_url_as` with
@@ -160,7 +205,12 @@ def icon_url(self):
160
205
"""
161
206
return self .icon_url_as ()
162
207
163
- def icon_url_as (self , * , format = 'webp' , size = 1024 ):
208
+ def icon_url_as (
209
+ self ,
210
+ * ,
211
+ format : Literal ['png' , 'jpeg' , 'jpg' , 'webp' ] = 'webp' ,
212
+ size = 1024
213
+ ) -> Asset :
164
214
"""Returns an :class:`Asset` for the icon the application has.
165
215
166
216
The format must be one of 'webp', 'jpeg', 'jpg' or 'png'.
@@ -187,9 +237,8 @@ def icon_url_as(self, *, format='webp', size=1024):
187
237
"""
188
238
return Asset ._from_icon (self ._state , self , 'app' , format = format , size = size )
189
239
190
-
191
240
@property
192
- def cover_image_url (self ):
241
+ def cover_image_url (self ) -> Asset :
193
242
""":class:`.Asset`: Retrieves the cover image on a store embed.
194
243
195
244
This is equivalent to calling :meth:`cover_image_url_as` with
@@ -199,7 +248,7 @@ def cover_image_url(self):
199
248
"""
200
249
return self .cover_image_url_as ()
201
250
202
- def cover_image_url_as (self , * , format = 'webp' , size = 1024 ):
251
+ def cover_image_url_as (self , * , format = 'webp' , size = 1024 ) -> Asset :
203
252
"""Returns an :class:`Asset` for the image on store embeds
204
253
if this application is a game sold on Discord.
205
254
@@ -228,7 +277,7 @@ def cover_image_url_as(self, *, format='webp', size=1024):
228
277
return Asset ._from_cover_image (self ._state , self , format = format , size = size )
229
278
230
279
@property
231
- def guild (self ):
280
+ def guild (self ) -> Optional [ Guild ] :
232
281
"""Optional[:class:`Guild`]: If this application is a game sold on Discord,
233
282
this field will be the guild to which it has been linked
234
283
@@ -237,5 +286,6 @@ def guild(self):
237
286
return self ._state ._get_guild (int (self .guild_id ))
238
287
239
288
@property
240
- def flags (self ):
289
+ def flags (self ) -> ApplicationFlags :
241
290
return ApplicationFlags ._from_value (self ._flags )
291
+
0 commit comments