From f52b4912a44c0cbcbfb164d03e3220f694d62b8c Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Mon, 21 Nov 2022 23:34:08 +0000 Subject: [PATCH 01/27] feat: start of application role connection --- discord/application_role_connection.py | 77 ++++++++++++++++++++ discord/enums.py | 14 ++++ discord/http.py | 26 +++++++ discord/types/application_role_connection.py | 44 +++++++++++ 4 files changed, 161 insertions(+) create mode 100644 discord/application_role_connection.py create mode 100644 discord/types/application_role_connection.py diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py new file mode 100644 index 0000000000..b701de8c6c --- /dev/null +++ b/discord/application_role_connection.py @@ -0,0 +1,77 @@ +""" +The MIT License (MIT) + +Copyright (c) 2015-2021 Rapptz +Copyright (c) 2021-present Pycord Development + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING +from .enums import ApplicationRoleConnectionMetadataType, try_enum +from .utils import MISSING + +if TYPE_CHECKING: + from .state import ConnectionState + from .types.guild import ApplicationRoleConnection as ApplicationRoleConnectionPayload + +class ApplicationRoleConnection: + def __init__( + self, + *, + type: ApplicationRoleConnectionMetadataType, + key: str, + name: str, + description: str, + name_localizations: dict[str, str] = MISSING, + description_localizations: dict[str, str] = MISSING, + ): + self.type: ApplicationRoleConnectionMetadataType = type + self.key: str = key + self.name: str = name + self.name_localizations: dict[str, str] = name_localizations + self.description: str = description + self.description_localizations: dict[str, str] = description_localizations + + @classmethod + def from_dict(cls, data: ApplicationRoleConnectionPayload) -> ApplicationRoleConnection: + return cls( + type=try_enum(ApplicationRoleConnectionMetadataType, data['type']), + key=data['key'], + name=data['name'], + description=data['description'], + name_localizations=data.get('name_localizations'), + description_localizations=data.get('description_localizations'), + ) + + def to_dict(self) -> ApplicationRoleConnectionPayload: + data = { + 'type': self.type.value, + 'key': self.key, + 'name': self.name, + 'description': self.description, + } + if self.name_localizations is not MISSING: + data['name_localizations'] = self.name_localizations + if self.description_localizations is not MISSING: + data['description_localizations'] = self.description_localizations + return data + diff --git a/discord/enums.py b/discord/enums.py index 4e17fd5dd0..5ae226cc76 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -888,6 +888,20 @@ class AutoModKeywordPresetType(Enum): slurs = 3 +class ApplicationRoleConnectionMetadataType(Enum): + """Application role connection metadata type""" + + integer_less_than_or_equal = 1 + integer_greater_than_or_equal = 2 + integer_equal = 3 + integer_not_equal = 4 + datetime_less_than_or_equal = 5 + datetime_greater_than_or_equal = 6 + boolean_equal = 7 + boolean_not_equal = 8 + + + T = TypeVar("T") diff --git a/discord/http.py b/discord/http.py index 1479870a21..9e5bdf52c8 100644 --- a/discord/http.py +++ b/discord/http.py @@ -56,6 +56,7 @@ from .file import File from .types import ( appinfo, + application_role_connection, audit_log, automod, channel, @@ -2808,6 +2809,31 @@ def bulk_edit_guild_application_command_permissions( ) return self.request(r, json=payload) + # Application Role Connections + + def get_application_role_connection_metadata_records( + self, + application_id: Snowflake, + ) -> Response[application_role_connection.ApplicationRoleConnectionMetadata]: + r = Route( + "GET", + "/applications/{application_id}/role-connections/metadata", + application_id=application_id, + ) + return self.request(r) + + def update_application_role_connection_metadata_records( + self, + application_id: Snowflake, + payload, # TODO: payload typehint, check return type + ) -> Response[None]: + r = Route( + "PUT", + "/applications/{application_id}/role-connections/metadata", + application_id=application_id, + ) + return self.request(r, json=payload) + # Misc def application_info(self) -> Response[appinfo.AppInfo]: diff --git a/discord/types/application_role_connection.py b/discord/types/application_role_connection.py new file mode 100644 index 0000000000..93bef49460 --- /dev/null +++ b/discord/types/application_role_connection.py @@ -0,0 +1,44 @@ +""" +The MIT License (MIT) + +Copyright (c) 2015-2021 Rapptz +Copyright (c) 2021-present Pycord Development + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + +from __future__ import annotations + +from typing import Literal +from .._typed_dict import NotRequired, TypedDict + + +ApplicationRoleConnectionMetadataType = Literal[1, 2, 3, 4, 5, 6, 7, 8] + + +class ApplicationRoleConnectionMetadata(TypedDict): + type: ApplicationRoleConnectionMetadataType + key: str + name: str + name_localizations: NotRequired[dict[str, str]] + description: str + description_localizations: NotRequired[dict[str, str]] + + + From 9554237676764e640dedfc7281c44e408916f0dd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 21 Nov 2022 23:36:11 +0000 Subject: [PATCH 02/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- discord/application_role_connection.py | 35 +++++++++++--------- discord/enums.py | 3 +- discord/types/application_role_connection.py | 5 +-- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index b701de8c6c..f00f0eb55a 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -26,12 +26,16 @@ from __future__ import annotations from typing import TYPE_CHECKING + from .enums import ApplicationRoleConnectionMetadataType, try_enum from .utils import MISSING if TYPE_CHECKING: from .state import ConnectionState - from .types.guild import ApplicationRoleConnection as ApplicationRoleConnectionPayload + from .types.guild import ( + ApplicationRoleConnection as ApplicationRoleConnectionPayload, + ) + class ApplicationRoleConnection: def __init__( @@ -52,26 +56,27 @@ def __init__( self.description_localizations: dict[str, str] = description_localizations @classmethod - def from_dict(cls, data: ApplicationRoleConnectionPayload) -> ApplicationRoleConnection: + def from_dict( + cls, data: ApplicationRoleConnectionPayload + ) -> ApplicationRoleConnection: return cls( - type=try_enum(ApplicationRoleConnectionMetadataType, data['type']), - key=data['key'], - name=data['name'], - description=data['description'], - name_localizations=data.get('name_localizations'), - description_localizations=data.get('description_localizations'), + type=try_enum(ApplicationRoleConnectionMetadataType, data["type"]), + key=data["key"], + name=data["name"], + description=data["description"], + name_localizations=data.get("name_localizations"), + description_localizations=data.get("description_localizations"), ) def to_dict(self) -> ApplicationRoleConnectionPayload: data = { - 'type': self.type.value, - 'key': self.key, - 'name': self.name, - 'description': self.description, + "type": self.type.value, + "key": self.key, + "name": self.name, + "description": self.description, } if self.name_localizations is not MISSING: - data['name_localizations'] = self.name_localizations + data["name_localizations"] = self.name_localizations if self.description_localizations is not MISSING: - data['description_localizations'] = self.description_localizations + data["description_localizations"] = self.description_localizations return data - diff --git a/discord/enums.py b/discord/enums.py index 5ae226cc76..a357757fe2 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -890,7 +890,7 @@ class AutoModKeywordPresetType(Enum): class ApplicationRoleConnectionMetadataType(Enum): """Application role connection metadata type""" - + integer_less_than_or_equal = 1 integer_greater_than_or_equal = 2 integer_equal = 3 @@ -901,7 +901,6 @@ class ApplicationRoleConnectionMetadataType(Enum): boolean_not_equal = 8 - T = TypeVar("T") diff --git a/discord/types/application_role_connection.py b/discord/types/application_role_connection.py index 93bef49460..1838472790 100644 --- a/discord/types/application_role_connection.py +++ b/discord/types/application_role_connection.py @@ -26,8 +26,8 @@ from __future__ import annotations from typing import Literal -from .._typed_dict import NotRequired, TypedDict +from .._typed_dict import NotRequired, TypedDict ApplicationRoleConnectionMetadataType = Literal[1, 2, 3, 4, 5, 6, 7, 8] @@ -39,6 +39,3 @@ class ApplicationRoleConnectionMetadata(TypedDict): name_localizations: NotRequired[dict[str, str]] description: str description_localizations: NotRequired[dict[str, str]] - - - From b3bb0a684d94376239a73f30cf5e170eb5e2b1b9 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Tue, 22 Nov 2022 14:57:57 +0100 Subject: [PATCH 03/27] Apply suggestions from code review Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- discord/application_role_connection.py | 1 - discord/types/application_role_connection.py | 1 - 2 files changed, 2 deletions(-) diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index f00f0eb55a..5bc6c10f1f 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -1,7 +1,6 @@ """ The MIT License (MIT) -Copyright (c) 2015-2021 Rapptz Copyright (c) 2021-present Pycord Development Permission is hereby granted, free of charge, to any person obtaining a diff --git a/discord/types/application_role_connection.py b/discord/types/application_role_connection.py index 1838472790..40bcae1014 100644 --- a/discord/types/application_role_connection.py +++ b/discord/types/application_role_connection.py @@ -1,7 +1,6 @@ """ The MIT License (MIT) -Copyright (c) 2015-2021 Rapptz Copyright (c) 2021-present Pycord Development Permission is hereby granted, free of charge, to any person obtaining a From ba791d18a4b0297fd02ee9cd99a54b3ab05a4b85 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Wed, 23 Nov 2022 21:17:00 +0000 Subject: [PATCH 04/27] fix: type imports --- discord/application_role_connection.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index 5bc6c10f1f..2810145059 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -30,8 +30,7 @@ from .utils import MISSING if TYPE_CHECKING: - from .state import ConnectionState - from .types.guild import ( + from .types.application_role_connection import ( ApplicationRoleConnection as ApplicationRoleConnectionPayload, ) From 929048fd9e10931ef0f02ae8e4277b8768047fe8 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:16:35 -0800 Subject: [PATCH 05/27] Update http.py --- discord/http.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/discord/http.py b/discord/http.py index 10138a49d4..d9533898d5 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2823,7 +2823,7 @@ def bulk_edit_guild_application_command_permissions( def get_application_role_connection_metadata_records( self, application_id: Snowflake, - ) -> Response[application_role_connection.ApplicationRoleConnectionMetadata]: + ) -> Response[list[application_role_connection.ApplicationRoleConnectionMetadata]]: r = Route( "GET", "/applications/{application_id}/role-connections/metadata", @@ -2834,8 +2834,8 @@ def get_application_role_connection_metadata_records( def update_application_role_connection_metadata_records( self, application_id: Snowflake, - payload, # TODO: payload typehint, check return type - ) -> Response[None]: + payload: list[application_role_connection.ApplicationRoleConnectionMetadata], + ) -> Response[list[application_role_connection.ApplicationRoleConnectionMetadata]]: r = Route( "PUT", "/applications/{application_id}/role-connections/metadata", From 7ff181e49e67c63eaab0e24c05563bdb6acb0142 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:26:43 -0800 Subject: [PATCH 06/27] Update application_role_connection.py --- discord/application_role_connection.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index 2810145059..e5dc5c7c51 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -31,11 +31,31 @@ if TYPE_CHECKING: from .types.application_role_connection import ( - ApplicationRoleConnection as ApplicationRoleConnectionPayload, + ApplicationRoleConnectionMetadata as ApplicationRoleConnectionMetadataPayload, ) -class ApplicationRoleConnection: +class ApplicationRoleConnectionMetadata: + r"""Represents role connection metadata for a Discord application. + + Attributes + ---------- + type: :class:`ApplicationRoleConnectionMetadataType` + The type of metadata value. + key: :class:`str` + The key for this metadata field. + May only be the ``a-z``, ``0-9``, or ``_`` characters, with a maximum of 50 characters. + name: :class:`str` + The name for this metadata field. Maximum 100 characters. + description: :class:`str` + The description for this metadata field. Maximum 200 characters. + name_localizations: Optional[Dict[:class:`str`, :class:`str`]] + The name localizations for this metadata field. The values of this should be ``"locale": "name"``. + See `here `_ for a list of valid locales. + description_localizations: Optional[Dict[:class:`str`, :class:`str`]] + The description localizations for this metadata field. The values of this should be ``"locale": "name"``. + See `here `_ for a list of valid locales. + """ def __init__( self, *, From 36e131fc146b173564061f1e731bd89498fc2e7b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Dec 2022 23:27:15 +0000 Subject: [PATCH 07/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- discord/application_role_connection.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index e5dc5c7c51..73a42715cf 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -37,13 +37,13 @@ class ApplicationRoleConnectionMetadata: r"""Represents role connection metadata for a Discord application. - + Attributes ---------- type: :class:`ApplicationRoleConnectionMetadataType` The type of metadata value. key: :class:`str` - The key for this metadata field. + The key for this metadata field. May only be the ``a-z``, ``0-9``, or ``_`` characters, with a maximum of 50 characters. name: :class:`str` The name for this metadata field. Maximum 100 characters. @@ -56,6 +56,7 @@ class ApplicationRoleConnectionMetadata: The description localizations for this metadata field. The values of this should be ``"locale": "name"``. See `here `_ for a list of valid locales. """ + def __init__( self, *, From ed912525c71b509467931768066e68389114ecec Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:31:58 -0800 Subject: [PATCH 08/27] Update application_role_connection.py --- discord/application_role_connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index 73a42715cf..66596ef4c7 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -38,7 +38,7 @@ class ApplicationRoleConnectionMetadata: r"""Represents role connection metadata for a Discord application. - Attributes + Parameters ---------- type: :class:`ApplicationRoleConnectionMetadataType` The type of metadata value. From 2ac88dbbc1190d41839900ff6c89f4e9e395f578 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:34:53 -0800 Subject: [PATCH 09/27] Update client.py --- discord/client.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/discord/client.py b/discord/client.py index 0be48554f7..5431c0c0d6 100644 --- a/discord/client.py +++ b/discord/client.py @@ -37,6 +37,7 @@ from . import utils from .activity import ActivityTypes, BaseActivity, create_activity from .appinfo import AppInfo, PartialAppInfo +from .application_role_connection import ApplicationRoleConnectionMetadata from .backoff import ExponentialBackoff from .channel import PartialMessageable, _threaded_channel_factory from .emoji import Emoji @@ -1782,3 +1783,39 @@ def persistent_views(self) -> Sequence[View]: .. versionadded:: 2.0 """ return self._connection.persistent_views + + async def fetch_role_connection_metadata_records(self) -> list[ApplicationRoleConnectionMetadata]: + """|coro| + + Fetches the bot's role connection metadata records. + + .. versionadded:: 2.3.3 + + Returns + ------- + List[:class:`.ApplicationRoleConnectionMetadata`] + The bot's role connection metadata records. + """ + data = await self._connection.http.get_application_role_connection_metadata_records(self.application_id) + return [ApplicationRoleConnectionMetadata.from_dict(r) for r in data] + + async def update_role_connection_metadata_records(self, *role_connection_metadata) -> list[ApplicationRoleConnectionMetadata]: + """|coro| + + Updates the bot's role connection metadata records. + + .. versionadded:: 2.3.3 + + Parameters + ---------- + *role_connection_metadata: :class:`ApplicationRoleConnectionMetadata` + The new metadata records to send to Discord. + + Returns + ------- + List[:class:`.ApplicationRoleConnectionMetadata`] + The updated role connection metadata records. + """ + payload = [r.to_dict() for r in role_connection_metadata] + data = await self._connection.http.update_application_role_connection_metadata_records(self.application_id, payload) + return [ApplicationRoleConnectionMetadata.from_dict(r) for r in data] From 36b13f0bcf2b6181398d4e4ffc25a99974142339 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Dec 2022 23:35:16 +0000 Subject: [PATCH 10/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- discord/client.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/discord/client.py b/discord/client.py index 5431c0c0d6..bbe62a725e 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1783,8 +1783,10 @@ def persistent_views(self) -> Sequence[View]: .. versionadded:: 2.0 """ return self._connection.persistent_views - - async def fetch_role_connection_metadata_records(self) -> list[ApplicationRoleConnectionMetadata]: + + async def fetch_role_connection_metadata_records( + self, + ) -> list[ApplicationRoleConnectionMetadata]: """|coro| Fetches the bot's role connection metadata records. @@ -1796,10 +1798,14 @@ async def fetch_role_connection_metadata_records(self) -> list[ApplicationRoleCo List[:class:`.ApplicationRoleConnectionMetadata`] The bot's role connection metadata records. """ - data = await self._connection.http.get_application_role_connection_metadata_records(self.application_id) + data = await self._connection.http.get_application_role_connection_metadata_records( + self.application_id + ) return [ApplicationRoleConnectionMetadata.from_dict(r) for r in data] - - async def update_role_connection_metadata_records(self, *role_connection_metadata) -> list[ApplicationRoleConnectionMetadata]: + + async def update_role_connection_metadata_records( + self, *role_connection_metadata + ) -> list[ApplicationRoleConnectionMetadata]: """|coro| Updates the bot's role connection metadata records. @@ -1817,5 +1823,7 @@ async def update_role_connection_metadata_records(self, *role_connection_metadat The updated role connection metadata records. """ payload = [r.to_dict() for r in role_connection_metadata] - data = await self._connection.http.update_application_role_connection_metadata_records(self.application_id, payload) + data = await self._connection.http.update_application_role_connection_metadata_records( + self.application_id, payload + ) return [ApplicationRoleConnectionMetadata.from_dict(r) for r in data] From f1dcb85b33bb81007a853330d2d2f9992f0fa3e5 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:38:15 -0800 Subject: [PATCH 11/27] Update CHANGELOG.md --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 524adfbe19..6a19cc2bc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,9 @@ possible (see our [Version Guarantees] for more info). These changes are available on the `master` branch, but have not yet been released. -_No changes yet_ +## Added +- `ApplicationRoleConnectionMetadata` class for application role connection metadata, along with the `fetch_role_connection_metadata_records` and `update_role_connection_metadata_records` methods in `Client`. + ([#1791](https://github.com/Pycord-Development/pycord/pull/1791)) ## [2.3.2] - 2022-12-03 From 91993cc40db39abcfb803be5a0b16d8e2af5368e Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:38:31 -0800 Subject: [PATCH 12/27] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a19cc2bc7..43519cf370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ possible (see our [Version Guarantees] for more info). These changes are available on the `master` branch, but have not yet been released. ## Added -- `ApplicationRoleConnectionMetadata` class for application role connection metadata, along with the `fetch_role_connection_metadata_records` and `update_role_connection_metadata_records` methods in `Client`. +- New `ApplicationRoleConnectionMetadata` class for application role connection metadata, along with the `fetch_role_connection_metadata_records` and `update_role_connection_metadata_records` methods in `Client`. ([#1791](https://github.com/Pycord-Development/pycord/pull/1791)) ## [2.3.2] - 2022-12-03 From d77cf7e9cd3e4a8be1056f8c3733cc3cfa99b2f0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Dec 2022 23:39:07 +0000 Subject: [PATCH 13/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43519cf370..ee009f8281 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,10 @@ possible (see our [Version Guarantees] for more info). These changes are available on the `master` branch, but have not yet been released. ## Added -- New `ApplicationRoleConnectionMetadata` class for application role connection metadata, along with the `fetch_role_connection_metadata_records` and `update_role_connection_metadata_records` methods in `Client`. + +- New `ApplicationRoleConnectionMetadata` class for application role connection + metadata, along with the `fetch_role_connection_metadata_records` and + `update_role_connection_metadata_records` methods in `Client`. ([#1791](https://github.com/Pycord-Development/pycord/pull/1791)) ## [2.3.2] - 2022-12-03 From c15acd0a678aa1112bf68f538f209ce35299b8c1 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:41:26 -0800 Subject: [PATCH 14/27] Update application_role_connection.py --- discord/application_role_connection.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index 66596ef4c7..bf9b1caf9b 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -34,6 +34,9 @@ ApplicationRoleConnectionMetadata as ApplicationRoleConnectionMetadataPayload, ) +__all__ = ( + "ApplicationRoleConnectionMetadata", +) class ApplicationRoleConnectionMetadata: r"""Represents role connection metadata for a Discord application. @@ -56,6 +59,15 @@ class ApplicationRoleConnectionMetadata: The description localizations for this metadata field. The values of this should be ``"locale": "name"``. See `here `_ for a list of valid locales. """ + + __slots__ = ( + "type", + "key", + "name", + "description", + "name_localizations", + "description_localizations", + ) def __init__( self, From 7f29c79773c506b4403fcefb203247e2f0d1ecbb Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:41:43 -0800 Subject: [PATCH 15/27] Update data_classes.rst --- docs/api/data_classes.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/api/data_classes.rst b/docs/api/data_classes.rst index 02989e693a..236aa64851 100644 --- a/docs/api/data_classes.rst +++ b/docs/api/data_classes.rst @@ -154,3 +154,11 @@ Permissions .. autoclass:: PermissionOverwrite :members: + +Application Role Connections +----------------------------- + +.. attributetable:: ApplicationRoleConnectionMetadata + +.. autoclass:: ApplicationRoleConnectionMetadata + :members: From 5388ac5698c2743e684506888e1333794bcd02b0 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:42:44 -0800 Subject: [PATCH 16/27] Update enums.py --- discord/enums.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/enums.py b/discord/enums.py index 90d4f89823..d221400374 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -67,6 +67,7 @@ "AutoModEventType", "AutoModActionType", "AutoModKeywordPresetType", + "ApplicationRoleConnectionMetadataType", ) From aaddc94df7db7494be691feb0cd5b1ae099f2dbe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Dec 2022 23:43:04 +0000 Subject: [PATCH 17/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- discord/application_role_connection.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index bf9b1caf9b..d15a68ffb8 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -34,9 +34,8 @@ ApplicationRoleConnectionMetadata as ApplicationRoleConnectionMetadataPayload, ) -__all__ = ( - "ApplicationRoleConnectionMetadata", -) +__all__ = ("ApplicationRoleConnectionMetadata",) + class ApplicationRoleConnectionMetadata: r"""Represents role connection metadata for a Discord application. @@ -59,7 +58,7 @@ class ApplicationRoleConnectionMetadata: The description localizations for this metadata field. The values of this should be ``"locale": "name"``. See `here `_ for a list of valid locales. """ - + __slots__ = ( "type", "key", From 04c626da7c1c4fd9f9dac721d998f4febfa611c1 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:49:43 -0800 Subject: [PATCH 18/27] Update enums.rst --- docs/api/enums.rst | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/docs/api/enums.rst b/docs/api/enums.rst index f0ad60afb8..63677035c9 100644 --- a/docs/api/enums.rst +++ b/docs/api/enums.rst @@ -1867,3 +1867,48 @@ of :class:`enum.Enum`. .. attribute:: guild_only Represents a scheduled event that is only available to members inside the guild. + +.. class:: ApplicationRoleConnectionMetadataType + + Represents an application role connection metadata type. + + Each metadata type offers a comparison operation that allows guilds to + configure role requirements based on metadata values stored by the bot. + Bots specify a ``metadata value`` for each user and guilds specify the + required ``guild's configured value`` within the guild role settings. + + .. versionadded:: 2.4 + + .. attribute:: integer_less_than_or_equal + + The metadata value (``integer``) is less than or equal to the guild's configured value (``integer``). + + .. attribute:: integer_greater_than_or_equal + + The metadata value (``integer``) is greater than or equal to the guild's configured value (``integer``). + + .. attribute:: integer_equal + + The metadata value (``integer``) is equal to the guild's configured value (``integer``). + + .. attribute:: integer_not_equal + + The metadata value (``integer``) is not equal to the guild's configured value (``integer``). + + .. attribute:: datetime_less_than_or_equal + + The metadata value (``datetime``) is less than or equal to the guild's configured value + (``integer``; the number of days before the current date). + + .. attribute:: datetime_greater_than_or_equal + + The metadata value (``datetime``) is greater than or equal to the guild's configured value + (``integer``; the number of days before the current date). + + .. attribute:: boolean_equal + + The metadata value (``integer``) is equal to the guild's configured value (``integer``; 1). + + .. attribute:: boolean_not_equal + + The metadata value (``integer``) is not equal to the guild's configured value (``integer``; 1). From 3f64daaf1e14b15a11cd1a851c8d008b434e7706 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:50:06 -0800 Subject: [PATCH 19/27] Update application_role_connection.py --- discord/application_role_connection.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index d15a68ffb8..912345b174 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -39,6 +39,8 @@ class ApplicationRoleConnectionMetadata: r"""Represents role connection metadata for a Discord application. + + .. versionadded:: 2.4 Parameters ---------- From 0b3da5f65c6084b2f278099d89392b817a49cfe9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Dec 2022 23:50:08 +0000 Subject: [PATCH 20/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/api/enums.rst | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/api/enums.rst b/docs/api/enums.rst index 63677035c9..f841728e82 100644 --- a/docs/api/enums.rst +++ b/docs/api/enums.rst @@ -1867,48 +1867,48 @@ of :class:`enum.Enum`. .. attribute:: guild_only Represents a scheduled event that is only available to members inside the guild. - + .. class:: ApplicationRoleConnectionMetadataType Represents an application role connection metadata type. - - Each metadata type offers a comparison operation that allows guilds to - configure role requirements based on metadata values stored by the bot. - Bots specify a ``metadata value`` for each user and guilds specify the + + Each metadata type offers a comparison operation that allows guilds to + configure role requirements based on metadata values stored by the bot. + Bots specify a ``metadata value`` for each user and guilds specify the required ``guild's configured value`` within the guild role settings. - + .. versionadded:: 2.4 - + .. attribute:: integer_less_than_or_equal - + The metadata value (``integer``) is less than or equal to the guild's configured value (``integer``). .. attribute:: integer_greater_than_or_equal - + The metadata value (``integer``) is greater than or equal to the guild's configured value (``integer``). - + .. attribute:: integer_equal - + The metadata value (``integer``) is equal to the guild's configured value (``integer``). - + .. attribute:: integer_not_equal - + The metadata value (``integer``) is not equal to the guild's configured value (``integer``). - + .. attribute:: datetime_less_than_or_equal - - The metadata value (``datetime``) is less than or equal to the guild's configured value + + The metadata value (``datetime``) is less than or equal to the guild's configured value (``integer``; the number of days before the current date). .. attribute:: datetime_greater_than_or_equal - - The metadata value (``datetime``) is greater than or equal to the guild's configured value + + The metadata value (``datetime``) is greater than or equal to the guild's configured value (``integer``; the number of days before the current date). - + .. attribute:: boolean_equal - + The metadata value (``integer``) is equal to the guild's configured value (``integer``; 1). - + .. attribute:: boolean_not_equal - + The metadata value (``integer``) is not equal to the guild's configured value (``integer``; 1). From df20619df264ac0fb5ae67fdfffece73b1351f01 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:50:22 -0800 Subject: [PATCH 21/27] Update client.py --- discord/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/client.py b/discord/client.py index bbe62a725e..21abf9e7c0 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1791,7 +1791,7 @@ async def fetch_role_connection_metadata_records( Fetches the bot's role connection metadata records. - .. versionadded:: 2.3.3 + .. versionadded:: 2.4 Returns ------- @@ -1810,7 +1810,7 @@ async def update_role_connection_metadata_records( Updates the bot's role connection metadata records. - .. versionadded:: 2.3.3 + .. versionadded:: 2.4 Parameters ---------- From f03eadedcaedf0e8c91eb8856b7e707ef0a0ccf7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Dec 2022 23:50:30 +0000 Subject: [PATCH 22/27] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- discord/application_role_connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index 912345b174..a7f9bf84c6 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -39,7 +39,7 @@ class ApplicationRoleConnectionMetadata: r"""Represents role connection metadata for a Discord application. - + .. versionadded:: 2.4 Parameters From 40666dccb00cf52337bbe9941979429adeb001a4 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:53:09 -0800 Subject: [PATCH 23/27] Update __init__.py --- discord/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/__init__.py b/discord/__init__.py index 8196c56e1c..881bb32c79 100644 --- a/discord/__init__.py +++ b/discord/__init__.py @@ -27,6 +27,7 @@ from . import abc, opus, sinks, ui, utils from .activity import * from .appinfo import * +from .application_role_connections import * from .asset import * from .audit_logs import * from .automod import * From e61d06dd570bbd72d24e0ba8525f2ac11a960a21 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:53:25 -0800 Subject: [PATCH 24/27] Update __init__.py --- discord/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/__init__.py b/discord/__init__.py index 881bb32c79..1b73d1bafc 100644 --- a/discord/__init__.py +++ b/discord/__init__.py @@ -27,7 +27,7 @@ from . import abc, opus, sinks, ui, utils from .activity import * from .appinfo import * -from .application_role_connections import * +from .application_role_connection import * from .asset import * from .audit_logs import * from .automod import * From 52bfcea102fc44a23aa92547c8a1705a833c0a70 Mon Sep 17 00:00:00 2001 From: plun1331 <49261529+plun1331@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:54:57 -0800 Subject: [PATCH 25/27] Update application_role_connection.py --- discord/application_role_connection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index a7f9bf84c6..b419dcf3ff 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -89,8 +89,8 @@ def __init__( @classmethod def from_dict( - cls, data: ApplicationRoleConnectionPayload - ) -> ApplicationRoleConnection: + cls, data: ApplicationRoleConnectionMetadataPayload + ) -> ApplicationRoleConnectionMetadata: return cls( type=try_enum(ApplicationRoleConnectionMetadataType, data["type"]), key=data["key"], @@ -100,7 +100,7 @@ def from_dict( description_localizations=data.get("description_localizations"), ) - def to_dict(self) -> ApplicationRoleConnectionPayload: + def to_dict(self) -> ApplicationRoleConnectionMetadataPayload: data = { "type": self.type.value, "key": self.key, From bc6adc12d22d85a239e97d2f619afb5c05eb4e2f Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Thu, 5 Jan 2023 18:29:12 +0100 Subject: [PATCH 26/27] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff7b529989..2921c34ac1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ possible (see our [Version Guarantees] for more info). These changes are available on the `master` branch, but have not yet been released. -## Added +### Added - Added new AutoMod trigger metadata properties `regex_patterns`, `allow_list`, and `mention_total_limit`; and added the `mention_spam` trigger type. From fd391da82440b99baeacbce8574b3a34864faf32 Mon Sep 17 00:00:00 2001 From: plun1331 Date: Sun, 29 Jan 2023 21:41:34 -0800 Subject: [PATCH 27/27] feat: add __repr__ and __str__ --- discord/application_role_connection.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/discord/application_role_connection.py b/discord/application_role_connection.py index b419dcf3ff..ac031c007c 100644 --- a/discord/application_role_connection.py +++ b/discord/application_role_connection.py @@ -87,6 +87,20 @@ def __init__( self.description: str = description self.description_localizations: dict[str, str] = description_localizations + def __repr__(self): + return ( + f"" + ) + + def __str__(self): + return self.name + @classmethod def from_dict( cls, data: ApplicationRoleConnectionMetadataPayload