-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add ability to use primary guild (clan) data for users #10211
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
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
4e1d3c9
Added clan property to user object
a9413a6
Added base code for clan properties
b422aaf
Added getting clan tag asset
81e63bc
Fix type corrections
644aba8
Comments
e3e234c
Fix circular import issues
106ad77
Rename all clan references to primary_guild
cb6d304
Apply suggestions from code review
blord0 1aa48a1
Fix import issues
ddf68cb
Fix as identity_enabled is only field assured to be returned
6eb8e05
Apply change from code review
blord0 f6d93c4
Styling changes
blord0 2f4000d
Add docs for PrimaryGuild
db82935
tab complete was not working for members. Not too sure if this is the…
9dc9c40
guild_id would sometimes return a string, convert to make sure it is …
82b9483
Apply suggestions from code review
blord0 d63672e
Change guild_id to id
3a8e441
Style fixes
f718627
Remove unnecessary returning of private attributes
15cff6a
Apply suggestions from code review
blord0 7802aaa
Apply suggestions from code review
blord0 4929a17
Mark identity_enabled and _badge as optional
96bebf4
Checks that identity_enabled is true when returning a PrimaryGuild
23e054f
Add default state for a PrimaryGuild
d942762
Fix doc issue that last commit created
e27c62d
Fix type for member modal
279ae2e
Update Member._update_inner_user() to return primary_guild
878930a
Apply suggestions from code review
blord0 5c69689
Move `primary_guild`'s type file into `user`'s as it was too small
4875a3d
Formatting
0218fed
Merge branch 'Rapptz:master' into master
blord0 3897ace
Update discord/asset.py
blord0 85f9830
Merge branch 'Rapptz:master' into master
blord0 d2fda92
Merge branch 'Rapptz:master' into master
blord0 fcda2e6
Add recommended changes
84dc82b
Forgot to run black
551129b
Reformat "is not None" checks to fit format
0ff7bb4
Give `state` the correct type hinting
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
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,90 @@ | ||
| """ | ||
| The MIT License (MIT) | ||
|
|
||
| Copyright (c) 2015-present Rapptz | ||
|
|
||
| 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 Optional, TYPE_CHECKING | ||
| from datetime import datetime | ||
|
|
||
| from .asset import Asset | ||
| from .utils import snowflake_time, _get_as_snowflake | ||
|
|
||
| if TYPE_CHECKING: | ||
| from .state import ConnectionState | ||
| from .types.user import PrimaryGuild as PrimaryGuildPayload | ||
| from typing_extensions import Self | ||
|
|
||
|
|
||
| class PrimaryGuild: | ||
| """Represents the primary guild identity of a :class:`User` | ||
|
|
||
| .. versionadded:: 2.6 | ||
|
|
||
| Attributes | ||
| ----------- | ||
| id: Optional[:class:`int`] | ||
| The ID of the user's primary guild, if any. | ||
| tag: Optional[:class:`str`] | ||
| The primary guild's tag. | ||
| identity_enabled: Optional[:class:`bool`] | ||
| Whether the user has their primary guild publicly displayed. If ``None``, the user has a public guild but has not reaffirmed the guild identity after a change | ||
blord0 marked this conversation as resolved.
Show resolved
Hide resolved
blord0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| .. warning:: | ||
|
|
||
| Users can have their primary guild publicly displayed while still having an :attr:`id` of ``None``. Be careful when checking this attribute! | ||
| """ | ||
|
|
||
| __slots__ = ('id', 'identity_enabled', 'tag', '_badge', '_state') | ||
|
|
||
| def __init__(self, *, state: ConnectionState, data: PrimaryGuildPayload) -> None: | ||
| self._state = state | ||
| self._update(data) | ||
|
|
||
| def _update(self, data: PrimaryGuildPayload): | ||
| self.id = _get_as_snowflake(data, 'identity_guild_id') | ||
| self.identity_enabled = data['identity_enabled'] | ||
blord0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.tag = data.get('tag', None) | ||
| self._badge = data.get('badge') | ||
|
|
||
| @property | ||
| def badge(self) -> Optional[Asset]: | ||
| """Optional[:class:`Asset`]: Returns the primary guild's asset""" | ||
| if self._badge is not None and self.id is not None: | ||
| return Asset._from_primary_guild(self._state, self.id, self._badge) | ||
| return None | ||
|
|
||
| @property | ||
| def created_at(self) -> Optional[datetime]: | ||
| """Optional[:class:`datetime.datetime`]: Returns the primary guild's creation time in UTC.""" | ||
| if self.id is not None: | ||
| return snowflake_time(self.id) | ||
| return None | ||
|
|
||
| @classmethod | ||
| def _default(cls, state: ConnectionState) -> Self: | ||
| payload: PrimaryGuildPayload = {"identity_enabled": False} # type: ignore | ||
| return cls(state=state, data=payload) | ||
|
|
||
| def __repr__(self) -> str: | ||
| return f'<PrimaryGuild id={self.id} identity_enabled={self.identity_enabled} tag={self.tag!r}>' | ||
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
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.