Skip to content

Commit 913fb5e

Browse files
authored
Merge OAuth2 featue in developer (#65)
feat: Implement Discord OAuth2 API as a sub-package #65
2 parents 1e019ea + fc54ed1 commit 913fb5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+6760
-669
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
todo.md
22
test.py
3-
examples-test.py
3+
/local-tests/
44
voice_test.py
55
main-api.py
66
cprint.py
@@ -17,3 +17,4 @@ __pycache__
1717
# Default ignored files
1818
/shelf/
1919
workspace.xml
20+
/loca-tests/

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include README.rst
22
include LICENSE.txt
33
include discord/*
4+
include discord/oauth2/*
45
include discord/bin/*.dll
56
include discord/ext/commands/*
67
include discord/ext/tasks/__init__.py

discord/abc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def __subclasshook__(cls, C):
161161
return True
162162
return NotImplemented
163163

164+
164165
class PrivateChannel(metaclass=abc.ABCMeta):
165166
"""An ABC that details the common operations on a private Discord channel.
166167
@@ -1112,9 +1113,10 @@ async def send(
11121113
else:
11131114
reference = MISSING
11141115

1115-
if suppress_embeds or suppress_notifications:
1116+
if suppress_embeds or suppress_notifications or is_voice_message:
11161117
from .flags import MessageFlags
1117-
flags = MessageFlags._from_value(4)
1118+
flags = MessageFlags._from_value(0)
1119+
flags.suppress_embeds = suppress_embeds
11181120
flags.suppress_notifications = suppress_notifications
11191121
else:
11201122
flags = MISSING

discord/appinfo.py

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,47 @@
2323
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2424
DEALINGS IN THE SOFTWARE.
2525
"""
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+
2636

2737
from . import utils
2838
from .user import User
2939
from .asset import Asset
3040
from .team import Team
3141
from .flags import ApplicationFlags
3242

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+
3367

3468
class AppInfo:
3569
"""Represents the application info for the bot provided by Discord.
@@ -63,8 +97,11 @@ class AppInfo:
6397
summary: :class:`str`
6498
If this application is a game sold on Discord,
6599
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+
67103
.. versionadded:: 1.3
104+
.. deprecated:: 2.0
68105
69106
verify_key: :class:`str`
70107
The hex encoded key for verification in interactions and the
@@ -99,7 +136,10 @@ class AppInfo:
99136
100137
custom_install_url: Optional[:class:`str`]
101138
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+
103143
privacy_policy_url: Optional[:class:`str`]
104144
The link to this application's Privacy Policy if set.
105145
@@ -114,43 +154,48 @@ class AppInfo:
114154
'bot_public', 'bot_require_code_grant', 'owner', 'icon',
115155
'summary', 'verify_key', 'team', 'guild_id', 'primary_sku_id',
116156
'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'])
132177

133178
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
135180

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']
138183

139-
self.guild_id = utils._get_as_snowflake(data, 'guild_id')
184+
self.guild_id: Optional[int] = utils._get_as_snowflake(data, 'guild_id')
140185

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)
147192

148193
def __repr__(self):
149194
return '<{0.__class__.__name__} id={0.id} name={0.name!r} description={0.description!r} public={0.bot_public} ' \
150195
'owner={0.owner!r}>'.format(self)
151196

152197
@property
153-
def icon_url(self):
198+
def icon_url(self) -> Asset:
154199
""":class:`.Asset`: Retrieves the application's icon asset.
155200
156201
This is equivalent to calling :meth:`icon_url_as` with
@@ -160,7 +205,12 @@ def icon_url(self):
160205
"""
161206
return self.icon_url_as()
162207

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:
164214
"""Returns an :class:`Asset` for the icon the application has.
165215
166216
The format must be one of 'webp', 'jpeg', 'jpg' or 'png'.
@@ -187,9 +237,8 @@ def icon_url_as(self, *, format='webp', size=1024):
187237
"""
188238
return Asset._from_icon(self._state, self, 'app', format=format, size=size)
189239

190-
191240
@property
192-
def cover_image_url(self):
241+
def cover_image_url(self) -> Asset:
193242
""":class:`.Asset`: Retrieves the cover image on a store embed.
194243
195244
This is equivalent to calling :meth:`cover_image_url_as` with
@@ -199,7 +248,7 @@ def cover_image_url(self):
199248
"""
200249
return self.cover_image_url_as()
201250

202-
def cover_image_url_as(self, *, format='webp', size=1024):
251+
def cover_image_url_as(self, *, format='webp', size=1024) -> Asset:
203252
"""Returns an :class:`Asset` for the image on store embeds
204253
if this application is a game sold on Discord.
205254
@@ -228,7 +277,7 @@ def cover_image_url_as(self, *, format='webp', size=1024):
228277
return Asset._from_cover_image(self._state, self, format=format, size=size)
229278

230279
@property
231-
def guild(self):
280+
def guild(self) -> Optional[Guild]:
232281
"""Optional[:class:`Guild`]: If this application is a game sold on Discord,
233282
this field will be the guild to which it has been linked
234283
@@ -237,5 +286,6 @@ def guild(self):
237286
return self._state._get_guild(int(self.guild_id))
238287

239288
@property
240-
def flags(self):
289+
def flags(self) -> ApplicationFlags:
241290
return ApplicationFlags._from_value(self._flags)
291+

0 commit comments

Comments
 (0)