Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Rapptz/discord.py into v2…
Browse files Browse the repository at this point in the history
…-martine
  • Loading branch information
PredaaA committed Dec 8, 2023
2 parents 43fb368 + 536cf5c commit 16385d0
Show file tree
Hide file tree
Showing 20 changed files with 597 additions and 670 deletions.
148 changes: 148 additions & 0 deletions discord/appinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
from .asset import Asset
from .flags import ApplicationFlags
from .permissions import Permissions
from .utils import MISSING

if TYPE_CHECKING:
from typing import Dict, Any

from .guild import Guild
from .types.appinfo import (
AppInfo as AppInfoPayload,
Expand Down Expand Up @@ -131,6 +134,15 @@ class AppInfo:
a verification method in the guild's role verification configuration.
.. versionadded:: 2.2
interactions_endpoint_url: Optional[:class:`str`]
The interactions endpoint url of the application to receive interactions over this endpoint rather than
over the gateway, if configured.
.. versionadded:: 2.4
redirect_uris: List[:class:`str`]
A list of authentication redirect URIs.
.. versionadded:: 2.4
"""

__slots__ = (
Expand All @@ -156,6 +168,8 @@ class AppInfo:
'custom_install_url',
'install_params',
'role_connections_verification_url',
'interactions_endpoint_url',
'redirect_uris',
)

def __init__(self, state: ConnectionState, data: AppInfoPayload):
Expand Down Expand Up @@ -190,6 +204,8 @@ def __init__(self, state: ConnectionState, data: AppInfoPayload):

params = data.get('install_params')
self.install_params: Optional[AppInstallParams] = AppInstallParams(params) if params else None
self.interactions_endpoint_url: Optional[str] = data.get('interactions_endpoint_url')
self.redirect_uris: List[str] = data.get('redirect_uris', [])

def __repr__(self) -> str:
return (
Expand Down Expand Up @@ -232,6 +248,138 @@ def flags(self) -> ApplicationFlags:
"""
return ApplicationFlags._from_value(self._flags)

async def edit(
self,
*,
reason: Optional[str] = MISSING,
custom_install_url: Optional[str] = MISSING,
description: Optional[str] = MISSING,
role_connections_verification_url: Optional[str] = MISSING,
install_params_scopes: Optional[List[str]] = MISSING,
install_params_permissions: Optional[Permissions] = MISSING,
flags: Optional[ApplicationFlags] = MISSING,
icon: Optional[bytes] = MISSING,
cover_image: Optional[bytes] = MISSING,
interactions_endpoint_url: Optional[str] = MISSING,
tags: Optional[List[str]] = MISSING,
) -> AppInfo:
r"""|coro|
Edits the application info.
.. versionadded:: 2.4
Parameters
----------
custom_install_url: Optional[:class:`str`]
The new custom authorization URL for the application. Can be ``None`` to remove the URL.
description: Optional[:class:`str`]
The new application description. Can be ``None`` to remove the description.
role_connections_verification_url: Optional[:class:`str`]
The new application’s connection verification URL which will render the application
as a verification method in the guild’s role verification configuration. Can be ``None`` to remove the URL.
install_params_scopes: Optional[List[:class:`str`]]
The new list of :ddocs:`OAuth2 scopes <topics/oauth2#shared-resources-oauth2-scopes>` of
the :attr:`~install_params`. Can be ``None`` to remove the scopes.
install_params_permissions: Optional[:class:`Permissions`]
The new permissions of the :attr:`~install_params`. Can be ``None`` to remove the permissions.
flags: Optional[:class:`ApplicationFlags`]
The new application’s flags. Only limited intent flags (:attr:`~ApplicationFlags.gateway_presence_limited`,
:attr:`~ApplicationFlags.gateway_guild_members_limited`, :attr:`~ApplicationFlags.gateway_message_content_limited`)
can be edited. Can be ``None`` to remove the flags.
.. warning::
Editing the limited intent flags leads to the termination of the bot.
icon: Optional[:class:`bytes`]
The new application’s icon as a :term:`py:bytes-like object`. Can be ``None`` to remove the icon.
cover_image: Optional[:class:`bytes`]
The new application’s cover image as a :term:`py:bytes-like object` on a store embed.
The cover image is only available if the application is a game sold on Discord.
Can be ``None`` to remove the image.
interactions_endpoint_url: Optional[:class:`str`]
The new interactions endpoint url of the application to receive interactions over this endpoint rather than
over the gateway. Can be ``None`` to remove the URL.
tags: Optional[List[:class:`str`]]
The new list of tags describing the functionality of the application. Can be ``None`` to remove the tags.
reason: Optional[:class:`str`]
The reason for editing the application. Shows up on the audit log.
Raises
-------
HTTPException
Editing the application failed
ValueError
The image format passed in to ``icon`` or ``cover_image`` is invalid. This is also raised
when ``install_params_scopes`` and ``install_params_permissions`` are incompatible with each other.
Returns
-------
:class:`AppInfo`
The newly updated application info.
"""
payload: Dict[str, Any] = {}

if custom_install_url is not MISSING:
payload['custom_install_url'] = custom_install_url

if description is not MISSING:
payload['description'] = description

if role_connections_verification_url is not MISSING:
payload['role_connections_verification_url'] = role_connections_verification_url

if install_params_scopes is not MISSING:
install_params: Optional[Dict[str, Any]] = {}
if install_params_scopes is None:
install_params = None
else:
if "bot" not in install_params_scopes and install_params_permissions is not MISSING:
raise ValueError("'bot' must be in install_params_scopes if install_params_permissions is set")

install_params['scopes'] = install_params_scopes

if install_params_permissions is MISSING:
install_params['permissions'] = 0
else:
if install_params_permissions is None:
install_params['permissions'] = 0
else:
install_params['permissions'] = install_params_permissions.value

payload['install_params'] = install_params

else:
if install_params_permissions is not MISSING:
raise ValueError("install_params_scopes must be set if install_params_permissions is set")

if flags is not MISSING:
if flags is None:
payload['flags'] = flags
else:
payload['flags'] = flags.value

if icon is not MISSING:
if icon is None:
payload['icon'] = icon
else:
payload['icon'] = utils._bytes_to_base64_data(icon)

if cover_image is not MISSING:
if cover_image is None:
payload['cover_image'] = cover_image
else:
payload['cover_image'] = utils._bytes_to_base64_data(cover_image)

if interactions_endpoint_url is not MISSING:
payload['interactions_endpoint_url'] = interactions_endpoint_url

if tags is not MISSING:
payload['tags'] = tags
data = await self._state.http.edit_application_info(reason=reason, payload=payload)
return AppInfo(data=data, state=self._state)


class PartialAppInfo:
"""Represents a partial AppInfo given by :func:`~discord.abc.GuildChannel.create_invite`
Expand Down
37 changes: 37 additions & 0 deletions discord/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ def __init__(

@property
def type(self) -> SelectDefaultValueType:
""":class:`SelectDefaultValueType`: The type of value that ``id`` represents."""
return self._type

@type.setter
Expand Down Expand Up @@ -574,20 +575,56 @@ def to_dict(self) -> SelectDefaultValuesPayload:

@classmethod
def from_channel(cls, channel: Snowflake, /) -> Self:
"""Creates a :class:`SelectDefaultValue` with the type set to :attr:`~SelectDefaultValueType.channel`.
Parameters
-----------
channel: :class:`~discord.abc.Snowflake`
The channel to create the default value for.
Returns
--------
:class:`SelectDefaultValue`
The default value created with the channel.
"""
return cls(
id=channel.id,
type=SelectDefaultValueType.channel,
)

@classmethod
def from_role(cls, role: Snowflake, /) -> Self:
"""Creates a :class:`SelectDefaultValue` with the type set to :attr:`~SelectDefaultValueType.role`.
Parameters
-----------
role: :class:`~discord.abc.Snowflake`
The role to create the default value for.
Returns
--------
:class:`SelectDefaultValue`
The default value created with the role.
"""
return cls(
id=role.id,
type=SelectDefaultValueType.role,
)

@classmethod
def from_user(cls, user: Snowflake, /) -> Self:
"""Creates a :class:`SelectDefaultValue` with the type set to :attr:`~SelectDefaultValueType.user`.
Parameters
-----------
user: :class:`~discord.abc.Snowflake`
The user to create the default value for.
Returns
--------
:class:`SelectDefaultValue`
The default value created with the user.
"""
return cls(
id=user.id,
type=SelectDefaultValueType.user,
Expand Down
20 changes: 18 additions & 2 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2553,7 +2553,7 @@ def create_entitlement(
return self.request(
Route(
'POST',
'/applications/{application.id}/entitlements',
'/applications/{application_id}/entitlements',
application_id=application_id,
),
json=payload,
Expand All @@ -2574,6 +2574,22 @@ def delete_entitlement(self, application_id: Snowflake, entitlement_id: Snowflak
def application_info(self) -> Response[appinfo.AppInfo]:
return self.request(Route('GET', '/oauth2/applications/@me'))

def edit_application_info(self, *, reason: Optional[str], payload: Any) -> Response[appinfo.AppInfo]:
valid_keys = (
'custom_install_url',
'description',
'role_connections_verification_url',
'install_params',
'flags',
'icon',
'cover_image',
'interactions_endpoint_url ',
'tags',
)

payload = {k: v for k, v in payload.items() if k in valid_keys}
return self.request(Route('PATCH', '/applications/@me'), json=payload, reason=reason)

async def get_gateway(self, *, encoding: str = 'json', zlib: bool = False) -> str:
try:
data = await self.request(Route('GET', '/gateway'))
Expand All @@ -2585,7 +2601,7 @@ async def get_gateway(self, *, encoding: str = 'json', zlib: bool = False) -> st
value = '{0}?encoding={1}&v={2}&compress='
return value.format(data['url'], encoding, INTERNAL_API_VERSION)

async def get_bot_gateway(self, *, encoding: str = 'json', zlib: bool = True) -> Tuple[int, str]:
async def get_bot_gateway(self, *, encoding: str = 'json', zlib: bool = False) -> Tuple[int, str]:
try:
data = await self.request(Route('GET', '/gateway/bot'))
except HTTPException as exc:
Expand Down
7 changes: 3 additions & 4 deletions discord/types/appinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class BaseAppInfo(TypedDict):
terms_of_service_url: NotRequired[str]
privacy_policy_url: NotRequired[str]
rpc_origins: NotRequired[List[str]]
interactions_endpoint_url: NotRequired[Optional[str]]
redirect_uris: NotRequired[List[str]]
role_connections_verification_url: NotRequired[Optional[str]]


class AppInfo(BaseAppInfo):
Expand All @@ -64,16 +67,12 @@ class AppInfo(BaseAppInfo):
tags: NotRequired[List[str]]
install_params: NotRequired[InstallParams]
custom_install_url: NotRequired[str]
role_connections_verification_url: NotRequired[str]


class PartialAppInfo(BaseAppInfo, total=False):
hook: bool
max_participants: int
approximate_guild_count: int
redirect_uris: List[str]
interactions_endpoint_url: Optional[str]
role_connections_verification_url: Optional[str]


class GatewayAppInfo(TypedDict):
Expand Down
2 changes: 1 addition & 1 deletion discord/ui/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ class RoleSelect(BaseSelect[V]):
disabled: :class:`bool`
Whether the select is disabled or not.
default_values: Sequence[:class:`~discord.abc.Snowflake`]
A list of objects representing the users that should be selected by default.
A list of objects representing the roles that should be selected by default.
.. versionadded:: 2.4
row: Optional[:class:`int`]
Expand Down
4 changes: 4 additions & 0 deletions discord/voice_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ async def on_voice_state_update(self, data: GuildVoiceStatePayload, /) -> None:
An abstract method that is called when the client's voice state
has changed. This corresponds to ``VOICE_STATE_UPDATE``.
.. warning::
This method is not the same as the event. See: :func:`on_voice_state_update`
Parameters
------------
data: :class:`dict`
Expand Down
Loading

0 comments on commit 16385d0

Please sign in to comment.