Browse Source

Change ThirdPartySKU.os type to an enum

pull/10109/head
dolfies 2 years ago
parent
commit
ebf912e953
  1. 16
      discord/application.py
  2. 6
      discord/http.py
  3. 29
      discord/types/application.py

16
discord/application.py

@ -31,7 +31,6 @@ from typing import (
AsyncIterator, AsyncIterator,
Collection, Collection,
List, List,
Literal,
Mapping, Mapping,
Optional, Optional,
Sequence, Sequence,
@ -55,6 +54,7 @@ from .enums import (
EmbeddedActivityOrientation, EmbeddedActivityOrientation,
EmbeddedActivityPlatform, EmbeddedActivityPlatform,
Locale, Locale,
OperatingSystem,
RPCApplicationState, RPCApplicationState,
StoreApplicationState, StoreApplicationState,
UserFlags, UserFlags,
@ -84,6 +84,7 @@ if TYPE_CHECKING:
Achievement as AchievementPayload, Achievement as AchievementPayload,
ActivityStatistics as ActivityStatisticsPayload, ActivityStatistics as ActivityStatisticsPayload,
Application as ApplicationPayload, Application as ApplicationPayload,
ApplicationExecutable as ApplicationExecutablePayload,
ApplicationInstallParams as ApplicationInstallParamsPayload, ApplicationInstallParams as ApplicationInstallParamsPayload,
Asset as AssetPayload, Asset as AssetPayload,
BaseApplication as BaseApplicationPayload, BaseApplication as BaseApplicationPayload,
@ -95,6 +96,7 @@ if TYPE_CHECKING:
Manifest as ManifestPayload, Manifest as ManifestPayload,
ManifestLabel as ManifestLabelPayload, ManifestLabel as ManifestLabelPayload,
PartialApplication as PartialApplicationPayload, PartialApplication as PartialApplicationPayload,
ThirdPartySKU as ThirdPartySKUPayload,
UnverifiedApplication as UnverifiedApplicationPayload, UnverifiedApplication as UnverifiedApplicationPayload,
WhitelistedUser as WhitelistedUserPayload, WhitelistedUser as WhitelistedUserPayload,
) )
@ -424,7 +426,7 @@ class ThirdPartySKU:
__slots__ = ('application', 'distributor', 'id', 'sku_id') __slots__ = ('application', 'distributor', 'id', 'sku_id')
def __init__(self, *, data: dict, application: PartialApplication): def __init__(self, *, data: ThirdPartySKUPayload, application: PartialApplication):
self.application = application self.application = application
self.distributor: Distributor = try_enum(Distributor, data['distributor']) self.distributor: Distributor = try_enum(Distributor, data['distributor'])
self.id: Optional[str] = data.get('id') self.id: Optional[str] = data.get('id')
@ -732,8 +734,12 @@ class ApplicationExecutable:
----------- -----------
name: :class:`str` name: :class:`str`
The name of the executable. The name of the executable.
os: :class:`str` os: :class:`OperatingSystem`
The operating system the executable is for. The operating system the executable is for.
.. versionchanged:: 2.1
The type of this attribute has changed to :class:`OperatingSystem`.
launcher: :class:`bool` launcher: :class:`bool`
Whether the executable is a launcher or not. Whether the executable is a launcher or not.
application: :class:`PartialApplication` application: :class:`PartialApplication`
@ -747,9 +753,9 @@ class ApplicationExecutable:
'application', 'application',
) )
def __init__(self, *, data: dict, application: PartialApplication): def __init__(self, *, data: ApplicationExecutablePayload, application: PartialApplication):
self.name: str = data['name'] self.name: str = data['name']
self.os: Literal['win32', 'linux', 'darwin'] = data['os'] self.os: OperatingSystem = OperatingSystem.from_string(data['os'])
self.launcher: bool = data['is_launcher'] self.launcher: bool = data['is_launcher']
self.application = application self.application = application

6
discord/http.py

@ -3336,7 +3336,7 @@ class HTTPClient:
super_properties_to_track=True, super_properties_to_track=True,
) )
def botify_app(self, app_id: Snowflake) -> Response[application.Token]: def botify_app(self, app_id: Snowflake) -> Response[application.OptionalToken]:
return self.request( return self.request(
Route('POST', '/applications/{app_id}/bot', app_id=app_id), json={}, super_properties_to_track=True Route('POST', '/applications/{app_id}/bot', app_id=app_id), json={}, super_properties_to_track=True
) )
@ -3346,10 +3346,10 @@ class HTTPClient:
Route('PATCH', '/applications/{app_id}/bot', app_id=app_id), json=payload, super_properties_to_track=True Route('PATCH', '/applications/{app_id}/bot', app_id=app_id), json=payload, super_properties_to_track=True
) )
def reset_secret(self, app_id: Snowflake) -> Response[dict]: def reset_secret(self, app_id: Snowflake) -> Response[application.Secret]:
return self.request(Route('POST', '/applications/{app_id}/reset', app_id=app_id), super_properties_to_track=True) return self.request(Route('POST', '/applications/{app_id}/reset', app_id=app_id), super_properties_to_track=True)
def reset_bot_token(self, app_id: Snowflake) -> Response[dict]: def reset_bot_token(self, app_id: Snowflake) -> Response[application.Token]:
return self.request(Route('POST', '/applications/{app_id}/bot/reset', app_id=app_id), super_properties_to_track=True) return self.request(Route('POST', '/applications/{app_id}/bot/reset', app_id=app_id), super_properties_to_track=True)
def get_detectable_applications(self) -> Response[List[application.PartialApplication]]: def get_detectable_applications(self) -> Response[List[application.PartialApplication]]:

29
discord/types/application.py

@ -34,10 +34,18 @@ from .user import APIUser, PartialUser
class Token(TypedDict): class Token(TypedDict):
token: str
class OptionalToken(TypedDict):
# Missing if a bot already exists 😭 # Missing if a bot already exists 😭
token: Optional[str] token: Optional[str]
class Secret(TypedDict):
secret: str
class BaseApplication(TypedDict): class BaseApplication(TypedDict):
id: Snowflake id: Snowflake
name: str name: str
@ -62,12 +70,11 @@ class PartialApplication(BaseApplication):
owner: NotRequired[APIUser] # Not actually ever present in partial app owner: NotRequired[APIUser] # Not actually ever present in partial app
team: NotRequired[Team] team: NotRequired[Team]
verify_key: str verify_key: str
description: str
cover_image: NotRequired[Optional[str]]
flags: NotRequired[int] flags: NotRequired[int]
rpc_origins: NotRequired[List[str]] rpc_origins: NotRequired[List[str]]
hook: NotRequired[bool] hook: NotRequired[bool]
overlay: NotRequired[bool] overlay: NotRequired[bool]
overlay_warn: NotRequired[bool]
overlay_compatibility_hook: NotRequired[bool] overlay_compatibility_hook: NotRequired[bool]
terms_of_service_url: NotRequired[str] terms_of_service_url: NotRequired[str]
privacy_policy_url: NotRequired[str] privacy_policy_url: NotRequired[str]
@ -87,6 +94,9 @@ class PartialApplication(BaseApplication):
guild: NotRequired[PartialGuild] guild: NotRequired[PartialGuild]
install_params: NotRequired[ApplicationInstallParams] install_params: NotRequired[ApplicationInstallParams]
deeplink_uri: NotRequired[str] deeplink_uri: NotRequired[str]
store_listing_sku_id: NotRequired[Snowflake]
executables: NotRequired[List[ApplicationExecutable]]
third_party_skus: NotRequired[List[ThirdPartySKU]]
class ApplicationDiscoverability(TypedDict): class ApplicationDiscoverability(TypedDict):
@ -97,12 +107,13 @@ class ApplicationDiscoverability(TypedDict):
class Application(PartialApplication, IntegrationApplication, ApplicationDiscoverability): class Application(PartialApplication, IntegrationApplication, ApplicationDiscoverability):
redirect_uris: List[str] redirect_uris: List[str]
interactions_endpoint_url: Optional[str] interactions_endpoint_url: Optional[str]
interactions_version: Literal[1, 2]
interactions_event_types: List[str]
verification_state: int verification_state: int
store_application_state: int store_application_state: int
rpc_application_state: int rpc_application_state: int
creator_monetization_state: int creator_monetization_state: int
role_connections_verification_url: NotRequired[Optional[str]] role_connections_verification_url: NotRequired[Optional[str]]
# GET /applications/{application.id} only
approximate_guild_count: NotRequired[int] approximate_guild_count: NotRequired[int]
@ -136,6 +147,18 @@ class EULA(TypedDict):
content: str content: str
class ApplicationExecutable(TypedDict):
name: str
os: Literal['win32', 'linux', 'darwin']
is_launcher: bool
class ThirdPartySKU(TypedDict):
distributor: Literal['discord', 'steam', 'twitch', 'uplay', 'battlenet', 'origin', 'gog', 'epic', 'google_play']
id: Optional[str]
sku_id: Optional[str]
class BaseAchievement(TypedDict): class BaseAchievement(TypedDict):
id: Snowflake id: Snowflake
name: Union[str, Dict[str, Union[str, Dict[str, str]]]] name: Union[str, Dict[str, Union[str, Dict[str, str]]]]

Loading…
Cancel
Save