-
-
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
Changes from 33 commits
4e1d3c9
a9413a6
b422aaf
81e63bc
644aba8
e3e234c
106ad77
cb6d304
1aa48a1
ddf68cb
6eb8e05
f6d93c4
2f4000d
db82935
9dc9c40
82b9483
d63672e
3a8e441
f718627
15cff6a
7802aaa
4929a17
96bebf4
23e054f
d942762
e27c62d
279ae2e
878930a
5c69689
4875a3d
0218fed
3897ace
85f9830
d2fda92
fcda2e6
84dc82b
551129b
0ff7bb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| """ | ||
| 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` | ||
| 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
|
||
| .. note:: | ||
blord0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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') | ||
|
|
||
| if TYPE_CHECKING: | ||
blord0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| id: Optional[int] | ||
| identity_enabled: Optional[bool] | ||
blord0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| tag: Optional[str] | ||
| _badge: Optional[str] | ||
| _state: ConnectionState | ||
blord0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def __init__(self, *, state, 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 and self.id: | ||
| 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: | ||
blord0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return snowflake_time(self.id) | ||
| return None | ||
|
|
||
| @classmethod | ||
| def _default(cls, state: ConnectionState) -> Self: | ||
| payload: PrimaryGuildPayload = {"identity_guild_id": None, "identity_enabled": False, "tag": None, "badge": None} | ||
| 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}>' | ||
Uh oh!
There was an error while loading. Please reload this page.