-
-
Notifications
You must be signed in to change notification settings - Fork 482
feat: Add support for user.primary_guild #2876
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
Merged
+152
−0
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1cdc82a
feat: Add support for user.primary_guild
Lulalaby 8598e8a
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 27aabd4
Instantiate PrimaryGuild object in BaseUser
Lulalaby 4fe7d77
Check identity_enabled for primary_guild assignment
Lulalaby df73e36
Update discord/primary_guild.py
Lulalaby 58acdb7
Merge branch 'master' into users/tags
NeloBlivion 1e717ce
:memo: Fix docstring indentation
Paillat-dev 6363e7b
:adhesive_bandage: Convert to int
Paillat-dev 9a7022b
:adhesive_bandage: primary_guild -> primary_guild_payload
Paillat-dev 41aaf40
:label: Add typing
Paillat-dev e25221e
:art: move `__all__` at the top
Paillat-dev c0806ec
Update discord/primary_guild.py
Lulalaby 5b3b25e
Merge branch 'master' into users/tags
Lulalaby d4e6f27
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] dbe63e2
Apply suggestion from @Lulalaby
Lulalaby ac2ef05
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
""" | ||
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 typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from .state import ConnectionState | ||
|
||
from .asset import Asset | ||
from .types.primary_guild import PrimaryGuild as PrimaryGuildPayload | ||
|
||
__all__ = ("PrimaryGuild",) | ||
|
||
|
||
class PrimaryGuild: | ||
""" | ||
Represents a Discord Primary Guild. | ||
.. versionadded:: 2.7 | ||
Attributes | ||
---------- | ||
identity_guild_id: int | ||
The ID of the guild. | ||
identity_enabled: :class:`bool` | ||
Whether the primary guild is enabled. | ||
tag: str | ||
The tag of the primary guild. | ||
""" | ||
|
||
def __init__(self, data: PrimaryGuildPayload, state: "ConnectionState") -> None: | ||
self.identity_guild_id: int | None = ( | ||
int(data.get("identity_guild_id", 0)) or None | ||
) | ||
self.identity_enabled: bool | None = data.get("identity_enabled", None) | ||
Paillat-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.tag: str | None = data.get("tag", None) | ||
self._badge: str | None = data.get("badge", None) | ||
self._state: "ConnectionState" = state | ||
|
||
def __repr__(self) -> str: | ||
return f"<PrimaryGuild identity_guild_id={self.identity_guild_id} identity_enabled={self.identity_enabled} tag={self.tag}>" | ||
|
||
@property | ||
def badge(self) -> Asset | None: | ||
"""Returns the badge asset, if available. | ||
.. versionadded:: 2.7 | ||
""" | ||
if self._badge is None: | ||
return None | ||
return Asset._from_user_primary_guild_tag( | ||
self._state, self.identity_guild_id, self._badge | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
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 TypedDict | ||
|
||
from .snowflake import Snowflake | ||
|
||
|
||
class PrimaryGuild(TypedDict): | ||
identity_guild_id: Snowflake | ||
identity_enabled: bool | None | ||
tag: str | ||
badge: str |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.