Browse Source

Implement PremiumUsageFlags, PurchasedFlags; small user docs improvements

pull/10109/head
dolfies 3 years ago
parent
commit
1440f61ab1
  1. 117
      discord/flags.py
  2. 53
      discord/user.py
  3. 10
      docs/api.rst

117
discord/flags.py

@ -40,6 +40,8 @@ __all__ = (
'MemberCacheFlags',
'ApplicationFlags',
'ChannelFlags',
'PremiumUsageFlags',
'PurchasedFlags',
)
BF = TypeVar('BF', bound='BaseFlags')
@ -478,6 +480,23 @@ class PublicUserFlags(BaseFlags):
class PrivateUserFlags(PublicUserFlags):
r"""Wraps up the Discord User flags.
.. container:: operations
.. describe:: x == y
Checks if two PrivateUserFlags are equal.
.. describe:: x != y
Checks if two PrivateUserFlags are not equal.
.. describe:: hash(x)
Return the flag's hash.
.. describe:: iter(x)
Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.
.. note::
These are only available on your own user flags.
@ -524,6 +543,104 @@ class PrivateUserFlags(PublicUserFlags):
return UserFlags.disable_premium.value
@fill_with_flags()
class PremiumUsageFlags(BaseFlags):
r"""Wraps up the Discord premium usage flags.
.. container:: operations
.. describe:: x == y
Checks if two PremiumUsageFlags are equal.
.. describe:: x != y
Checks if two PremiumUsageFlags are not equal.
.. describe:: hash(x)
Return the flag's hash.
.. describe:: iter(x)
Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.
.. versionadded:: 2.0
Attributes
-----------
value: :class:`int`
The raw value. This value is a bit array field of a 53-bit integer
representing the currently available flags. You should query
flags via the properties rather than using this raw value.
"""
__slots__ = ()
@flag_value
def premium_discriminator(self):
""":class:`bool`: Returns ``True`` if the user utilized premium discriminators."""
return 1 << 0
@flag_value
def animated_avatar(self):
""":class:`bool`: Returns ``True`` if the user utilized animated avatars."""
return 1 << 1
@flag_value
def profile_banner(self):
""":class:`bool`: Returns ``True`` if the user utilized profile banners."""
return 1 << 2
@fill_with_flags()
class PurchasedFlags(BaseFlags):
r"""Wraps up the Discord purchased flags.
.. container:: operations
.. describe:: x == y
Checks if two PurchasedFlags are equal.
.. describe:: x != y
Checks if two PurchasedFlags are not equal.
.. describe:: hash(x)
Return the flag's hash.
.. describe:: iter(x)
Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.
.. versionadded:: 2.0
Attributes
-----------
value: :class:`int`
The raw value. This value is a bit array field of a 53-bit integer
representing the currently available flags. You should query
flags via the properties rather than using this raw value.
"""
__slots__ = ()
@flag_value
def nitro_classic(self):
""":class:`bool`: Returns ``True`` if the user has previously purchased Nitro classic."""
return 1 << 0
@flag_value
def nitro(self):
""":class:`bool`: Returns ``True`` if the user has previously purchased Nitro."""
return 1 << 1
@flag_value
def guild_boost(self):
""":class:`bool`: Returns ``True`` if the user has previously purchased a guild boost."""
return 1 << 2
@fill_with_flags()
class MemberCacheFlags(BaseFlags):
"""Controls the library's cache policy when it comes to members.

53
discord/user.py

@ -39,7 +39,7 @@ from .enums import (
try_enum,
)
from .errors import ClientException, NotFound
from .flags import PublicUserFlags
from .flags import PublicUserFlags, PrivateUserFlags, PremiumUsageFlags, PurchasedFlags
from .iterators import FakeCommandIterator
from .object import Object
from .relationship import Relationship
@ -543,6 +543,8 @@ class ClientUser(BaseUser):
'note',
'bio',
'nsfw_allowed',
'_purchased_flags',
'_premium_usage_flags',
)
if TYPE_CHECKING:
@ -573,6 +575,8 @@ class ClientUser(BaseUser):
self.phone = _get_as_snowflake(data, 'phone')
self.locale = try_enum(Locale, data.get('locale', 'en-US'))
self._flags = data.get('flags', 0)
self._purchased_flags = data.get('purchased_flags', 0)
self._premium_usage_flags = data.get('premium_usage_flags', 0)
self.mfa_enabled = data.get('mfa_enabled', False)
self.premium_type = try_enum(PremiumType, data['premium_type']) if 'premium_type' in data else None
self.bio = data.get('bio')
@ -602,24 +606,63 @@ class ClientUser(BaseUser):
@property
def relationships(self) -> List[Relationship]:
"""List[:class:`User`]: Returns all the relationships that the user has."""
"""List[:class:`Relationship`]: Returns all the relationships that the user has.
.. versionchanged:: 2.0
This now returns a :class:`Relationship`.
"""
return list(self._state._relationships.values())
@property
def friends(self) -> List[Relationship]:
r"""List[:class:`User`]: Returns all the users that the user is friends with."""
r"""List[:class:`Relationship`]: Returns all the users that the user is friends with.
.. versionchanged:: 2.0
This now returns a :class:`Relationship`.
"""
return [r for r in self._state._relationships.values() if r.type is RelationshipType.friend]
@property
def blocked(self) -> List[Relationship]:
r"""List[:class:`User`]: Returns all the users that the user has blocked."""
r"""List[:class:`Relationship`]: Returns all the users that the user has blocked.
.. versionchanged:: 2.0
This now returns a :class:`Relationship`.
"""
return [r for r in self._state._relationships.values() if r.type is RelationshipType.blocked]
@property
def settings(self) -> Optional[UserSettings]:
"""Optional[:class:`UserSettings`]: Returns the user's settings."""
"""Optional[:class:`UserSettings`]: Returns the user's settings.
.. versionadded:: 1.9
"""
return self._state.settings
@property
def flags(self) -> PrivateUserFlags:
""":class:`PrivateUserFlags`: Returns the user's flags (including private).
.. versionadded:: 2.0
"""
return PrivateUserFlags._from_value(self._flags)
@property
def premium_usage_flags(self) -> PremiumUsageFlags:
""":class:`PremiumUsageFlags`: Returns the user's premium usage flags.
.. versionadded:: 2.0
"""
return PremiumUsageFlags._from_value(self._premium_usage_flags)
@property
def purchased_flags(self) -> PurchasedFlags:
""":class:`PurchasedFlags`: Returns the user's purchased flags.
.. versionadded:: 2.0
"""
return PurchasedFlags._from_value(self._purchased_flags)
async def edit(
self,
*,

10
docs/api.rst

@ -4795,6 +4795,16 @@ Flags
:members:
:inherited-members:
.. attributetable:: PremiumUsageFlags
.. autoclass:: PremiumUsageFlags()
:members:
.. attributetable:: PurchasedFlags
.. autoclass:: PurchasedFlags()
:members:
.. attributetable:: MemberCacheFlags
.. autoclass:: MemberCacheFlags()

Loading…
Cancel
Save