Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: application role connections #1791

Merged
merged 41 commits into from Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f52b491
feat: start of application role connection
plun1331 Nov 21, 2022
9554237
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2022
d4f6cb1
Merge branch 'master' into role-connections
Lulalaby Nov 22, 2022
b3bb0a6
Apply suggestions from code review
Lulalaby Nov 22, 2022
3626180
Merge branch 'master' into role-connections
plun1331 Nov 23, 2022
8459bf9
Merge branch 'master' into role-connections
plun1331 Nov 23, 2022
ba791d1
fix: type imports
plun1331 Nov 23, 2022
b6573dd
Merge branch 'master' into role-connections
Lulalaby Nov 30, 2022
bafba6c
Merge branch 'master' into role-connections
plun1331 Dec 1, 2022
929048f
Update http.py
plun1331 Dec 9, 2022
7ff181e
Update application_role_connection.py
plun1331 Dec 9, 2022
36e131f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 9, 2022
ed91252
Update application_role_connection.py
plun1331 Dec 9, 2022
2ac88db
Update client.py
plun1331 Dec 9, 2022
02b63ea
Merge branch 'master' into role-connections
plun1331 Dec 9, 2022
36b13f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 9, 2022
f1dcb85
Update CHANGELOG.md
plun1331 Dec 9, 2022
91993cc
Update CHANGELOG.md
plun1331 Dec 9, 2022
d77cf7e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 9, 2022
c15acd0
Update application_role_connection.py
plun1331 Dec 9, 2022
7f29c79
Update data_classes.rst
plun1331 Dec 9, 2022
5388ac5
Update enums.py
plun1331 Dec 9, 2022
aaddc94
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 9, 2022
04c626d
Update enums.rst
plun1331 Dec 9, 2022
3f64daa
Update application_role_connection.py
plun1331 Dec 9, 2022
0b3da5f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 9, 2022
df20619
Update client.py
plun1331 Dec 9, 2022
f03eade
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 9, 2022
40666dc
Update __init__.py
plun1331 Dec 9, 2022
e61d06d
Update __init__.py
plun1331 Dec 9, 2022
52bfcea
Update application_role_connection.py
plun1331 Dec 9, 2022
0274845
Merge branch 'master' into role-connections
Lulalaby Dec 12, 2022
2fcc9a0
Merge branch 'master' into role-connections
Lulalaby Dec 20, 2022
aca3f76
Merge branch 'master' into role-connections
Lulalaby Jan 5, 2023
bc6adc1
Update CHANGELOG.md
Lulalaby Jan 5, 2023
808c262
Merge branch 'master' into role-connections
Lulalaby Jan 5, 2023
0446ceb
Merge branch 'master' into role-connections
Lulalaby Jan 17, 2023
efb2ddb
Merge branch 'master' into role-connections
Lulalaby Jan 26, 2023
8d84668
Merge branch 'master' into role-connections
plun1331 Jan 30, 2023
fd391da
feat: add __repr__ and __str__
plun1331 Jan 30, 2023
69fbaf2
Merge branch 'master' into role-connections
plun1331 Feb 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 81 additions & 0 deletions discord/application_role_connection.py
@@ -0,0 +1,81 @@
"""
The MIT License (MIT)

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 (
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
ApplicationRoleConnection as ApplicationRoleConnectionPayload,
)


class ApplicationRoleConnection:
plun1331 marked this conversation as resolved.
Show resolved Hide resolved
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
13 changes: 13 additions & 0 deletions discord/enums.py
Expand Up @@ -904,6 +904,19 @@ 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")


Expand Down
26 changes: 26 additions & 0 deletions discord/http.py
Expand Up @@ -56,6 +56,7 @@
from .file import File
from .types import (
appinfo,
application_role_connection,
audit_log,
automod,
channel,
Expand Down Expand Up @@ -2817,6 +2818,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
plun1331 marked this conversation as resolved.
Show resolved Hide resolved
) -> 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]:
Expand Down
40 changes: 40 additions & 0 deletions discord/types/application_role_connection.py
@@ -0,0 +1,40 @@
"""
The MIT License (MIT)

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