|
| 1 | +""" |
| 2 | +The MIT License (MIT) |
| 3 | +
|
| 4 | +Copyright (c) 2021-present Pycord Development |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | +copy of this software and associated documentation files (the "Software"), |
| 8 | +to deal in the Software without restriction, including without limitation |
| 9 | +the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | +and/or sell copies of the Software, and to permit persons to whom the |
| 11 | +Software is furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in |
| 14 | +all copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 | +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | +DEALINGS IN THE SOFTWARE. |
| 23 | +""" |
| 24 | + |
| 25 | +from typing import TYPE_CHECKING |
| 26 | + |
| 27 | +if TYPE_CHECKING: |
| 28 | + from .state import ConnectionState |
| 29 | + |
| 30 | +from .asset import Asset |
| 31 | +from .types.primary_guild import PrimaryGuild as PrimaryGuildPayload |
| 32 | + |
| 33 | +__all__ = ("PrimaryGuild",) |
| 34 | + |
| 35 | + |
| 36 | +class PrimaryGuild: |
| 37 | + """ |
| 38 | + Represents a Discord Primary Guild. |
| 39 | +
|
| 40 | + .. versionadded:: 2.7 |
| 41 | +
|
| 42 | + Attributes |
| 43 | + ---------- |
| 44 | + identity_guild_id: int |
| 45 | + The ID of the guild. |
| 46 | + identity_enabled: :class:`bool` |
| 47 | + Whether the primary guild is enabled. |
| 48 | + tag: str |
| 49 | + The tag of the primary guild. |
| 50 | + """ |
| 51 | + |
| 52 | + def __init__(self, data: PrimaryGuildPayload, state: "ConnectionState") -> None: |
| 53 | + self.identity_guild_id: int | None = ( |
| 54 | + int(data.get("identity_guild_id") or 0) or None |
| 55 | + ) |
| 56 | + self.identity_enabled: bool | None = data.get("identity_enabled", None) |
| 57 | + self.tag: str | None = data.get("tag", None) |
| 58 | + self._badge: str | None = data.get("badge", None) |
| 59 | + self._state: "ConnectionState" = state |
| 60 | + |
| 61 | + def __repr__(self) -> str: |
| 62 | + return f"<PrimaryGuild identity_guild_id={self.identity_guild_id} identity_enabled={self.identity_enabled} tag={self.tag}>" |
| 63 | + |
| 64 | + @property |
| 65 | + def badge(self) -> Asset | None: |
| 66 | + """Returns the badge asset, if available. |
| 67 | +
|
| 68 | + .. versionadded:: 2.7 |
| 69 | + """ |
| 70 | + if self._badge is None: |
| 71 | + return None |
| 72 | + return Asset._from_user_primary_guild_tag( |
| 73 | + self._state, self.identity_guild_id, self._badge |
| 74 | + ) |
0 commit comments