From 56e511b5a079135a3afb912daa10fc3ff7efe0a6 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Sat, 3 Sep 2022 20:52:38 +0200 Subject: [PATCH 1/4] feat: add `BotIntegration.scopes` --- disnake/integrations.py | 7 ++++++- disnake/types/integration.py | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/disnake/integrations.py b/disnake/integrations.py index cac0c5e565..6e626e841c 100644 --- a/disnake/integrations.py +++ b/disnake/integrations.py @@ -409,13 +409,18 @@ class BotIntegration(Integration): The integration account information. application: :class:`IntegrationApplication` The application tied to this integration. + scopes: List[:class:`str`] + The OAuth2 scopes the application has been authorized for. + + .. versionadded:: 2.6 """ - __slots__ = ("application",) + __slots__ = ("application", "scopes") def _from_data(self, data: BotIntegrationPayload) -> None: super()._from_data(data) self.application = IntegrationApplication(data=data["application"], state=self._state) + self.scopes = data.get("scopes") or [] def _integration_factory(value: str) -> Tuple[Type[Integration], str]: diff --git a/disnake/types/integration.py b/disnake/types/integration.py index 90bc5a10a0..fa835a52eb 100644 --- a/disnake/types/integration.py +++ b/disnake/types/integration.py @@ -25,7 +25,7 @@ from __future__ import annotations -from typing import Literal, Optional, TypedDict, Union +from typing import List, Literal, Optional, TypedDict, Union from .snowflake import Snowflake from .user import User @@ -83,6 +83,7 @@ class StreamIntegration(BaseIntegration): class BotIntegration(BaseIntegration): application: IntegrationApplication + scopes: List[str] Integration = Union[BaseIntegration, StreamIntegration, BotIntegration] From e7295fc24aed75899f04494313c2bcb3debb1e68 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Sat, 3 Sep 2022 20:53:23 +0200 Subject: [PATCH 2/4] docs: add changelog --- changelog/729.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/729.feature.rst diff --git a/changelog/729.feature.rst b/changelog/729.feature.rst new file mode 100644 index 0000000000..63c537f4ac --- /dev/null +++ b/changelog/729.feature.rst @@ -0,0 +1 @@ +Add :attr:`BotIntegration.scopes`. From e51cb9d549f9e535a8c35358dbcc41a92109f639 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Sat, 3 Sep 2022 22:59:18 +0200 Subject: [PATCH 3/4] chore: add annotations --- disnake/integrations.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/disnake/integrations.py b/disnake/integrations.py index 6e626e841c..9b11f30f90 100644 --- a/disnake/integrations.py +++ b/disnake/integrations.py @@ -26,7 +26,7 @@ from __future__ import annotations import datetime -from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Type +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Type from .enums import ExpireBehaviour, try_enum from .user import User @@ -419,8 +419,10 @@ class BotIntegration(Integration): def _from_data(self, data: BotIntegrationPayload) -> None: super()._from_data(data) - self.application = IntegrationApplication(data=data["application"], state=self._state) - self.scopes = data.get("scopes") or [] + self.application: IntegrationApplication = IntegrationApplication( + data=data["application"], state=self._state + ) + self.scopes: List[str] = data.get("scopes") or [] def _integration_factory(value: str) -> Tuple[Type[Integration], str]: From 1a31521e4ae1e7ea40ed011c0c06474966021281 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Sat, 3 Sep 2022 23:05:15 +0200 Subject: [PATCH 4/4] feat: add scopes to `BotIntegration.__repr__` --- disnake/integrations.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/disnake/integrations.py b/disnake/integrations.py index 9b11f30f90..35515fb86c 100644 --- a/disnake/integrations.py +++ b/disnake/integrations.py @@ -424,6 +424,12 @@ def _from_data(self, data: BotIntegrationPayload) -> None: ) self.scopes: List[str] = data.get("scopes") or [] + def __repr__(self): + return ( + f"<{self.__class__.__name__} id={self.id}" + f" name={self.name!r} scopes={self.scopes!r}>" + ) + def _integration_factory(value: str) -> Tuple[Type[Integration], str]: if value == "discord":