Browse Source

Add support for public user flags

pull/4167/head
JohnyTheCarrot 5 years ago
committed by Rapptz
parent
commit
ab5f995d78
  1. 3
      discord/enums.py
  2. 97
      discord/flags.py
  3. 2
      discord/member.py
  4. 9
      discord/user.py
  5. 6
      docs/api.rst

3
discord/enums.py

@ -400,6 +400,9 @@ class UserFlags(Enum):
early_supporter = 512 early_supporter = 512
team_user = 1024 team_user = 1024
system = 4096 system = 4096
bug_hunter_level_2 = 16384
verified_bot = 65536
verified_bot_developer = 131072
class ActivityType(Enum): class ActivityType(Enum):
unknown = -1 unknown = -1

97
discord/flags.py

@ -24,9 +24,12 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
""" """
from .enums import UserFlags
__all__ = ( __all__ = (
'SystemChannelFlags', 'SystemChannelFlags',
'MessageFlags', 'MessageFlags',
'PublicUserFlags'
) )
class flag_value: class flag_value:
@ -230,3 +233,97 @@ class MessageFlags(BaseFlags):
An urgent message is one sent by Discord Trust and Safety. An urgent message is one sent by Discord Trust and Safety.
""" """
return 16 return 16
@fill_with_flags()
class PublicUserFlags(BaseFlags):
r"""Wraps up the Discord User Public flags.
.. container:: operations
.. describe:: x == y
Checks if two PublicUserFlags are equal.
.. describe:: x != y
Checks if two PublicUserFlags are not equal.
.. versionadded:: 1.4
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 staff(self):
""":class:`bool`: Returns ``True`` if the user is a Discord Employee."""
return UserFlags.staff.value
@flag_value
def partner(self):
""":class:`bool`: Returns ``True`` if the user is a Discord Partner."""
return UserFlags.partner.value
@flag_value
def hypesquad(self):
""":class:`bool`: Returns ``True`` if the user is a HypeSquad Events member."""
return UserFlags.hypesquad.value
@flag_value
def bug_hunter(self):
""":class:`bool`: Returns ``True`` if the user is a Bug Hunter"""
return UserFlags.bug_hunter.value
@flag_value
def hypesquad_bravery(self):
""":class:`bool`: Returns ``True`` if the user is a HypeSquad Bravery member."""
return UserFlags.hypesquad_bravery.value
@flag_value
def hypesquad_brilliance(self):
""":class:`bool`: Returns ``True`` if the user is a HypeSquad Brilliance member."""
return UserFlags.hypesquad_brilliance.value
@flag_value
def hypesquad_balance(self):
""":class:`bool`: Returns ``True`` if the user is a HypeSquad Balance member."""
return UserFlags.hypesquad_balance.value
@flag_value
def early_supporter(self):
""":class:`bool`: Returns ``True`` if the user is an Early Supporter."""
return UserFlags.early_supporter.value
@flag_value
def team_user(self):
""":class:`bool`: Returns ``True`` if the user is a Team User."""
return UserFlags.team_user.value
@flag_value
def system(self):
""":class:`bool`: Returns ``True`` if the user is a system user (i.e. represents Discord officially)."""
return UserFlags.system.value
@flag_value
def bug_hunter_level_2(self):
""":class:`bool`: Returns ``True`` if the user is a Bug Hunter Level 2"""
return UserFlags.bug_hunter_level_2.value
@flag_value
def verified_bot(self):
""":class:`bool`: Returns ``True`` if the user is a Verified Bot."""
return UserFlags.verified_bot.value
@flag_value
def verified_bot_developer(self):
""":class:`bool`: Returns ``True`` if the user is a Verified Bot Developer."""
return UserFlags.verified_bot_developer.value
def all(self):
"""List[:class:`UserFlags`]: Returns all public flags the user has."""
return [public_flag for public_flag in UserFlags if self._has_flag(public_flag.value)]

2
discord/member.py

@ -33,7 +33,7 @@ from . import utils
from .user import BaseUser, User from .user import BaseUser, User
from .activity import create_activity from .activity import create_activity
from .permissions import Permissions from .permissions import Permissions
from .enums import Status, try_enum from .enums import Status, try_enum, UserFlags, HypeSquadHouse
from .colour import Colour from .colour import Colour
from .object import Object from .object import Object

9
discord/user.py

@ -27,6 +27,7 @@ DEALINGS IN THE SOFTWARE.
from collections import namedtuple from collections import namedtuple
import discord.abc import discord.abc
from .flags import PublicUserFlags
from .utils import snowflake_time, _bytes_to_base64_data, parse_time from .utils import snowflake_time, _bytes_to_base64_data, parse_time
from .enums import DefaultAvatar, RelationshipType, UserFlags, HypeSquadHouse, PremiumType, try_enum from .enums import DefaultAvatar, RelationshipType, UserFlags, HypeSquadHouse, PremiumType, try_enum
from .errors import ClientException from .errors import ClientException
@ -82,7 +83,7 @@ class Profile(namedtuple('Profile', 'flags user mutual_guilds connected_accounts
_BaseUser = discord.abc.User _BaseUser = discord.abc.User
class BaseUser(_BaseUser): class BaseUser(_BaseUser):
__slots__ = ('name', 'id', 'discriminator', 'avatar', 'bot', 'system', '_state') __slots__ = ('name', 'id', 'discriminator', 'avatar', 'bot', 'system', '_public_flags', '_state')
def __init__(self, *, state, data): def __init__(self, *, state, data):
self._state = state self._state = state
@ -105,6 +106,7 @@ class BaseUser(_BaseUser):
self.id = int(data['id']) self.id = int(data['id'])
self.discriminator = data['discriminator'] self.discriminator = data['discriminator']
self.avatar = data['avatar'] self.avatar = data['avatar']
self._public_flags = data.get('public_flags', 0)
self.bot = data.get('bot', False) self.bot = data.get('bot', False)
self.system = data.get('system', False) self.system = data.get('system', False)
@ -130,6 +132,11 @@ class BaseUser(_BaseUser):
'bot': self.bot, 'bot': self.bot,
} }
@property
def public_flags(self):
""":class:`PublicFlags`: The publicly available flags the user has."""
return PublicUserFlags._from_value(self._public_flags)
@property @property
def avatar_url(self): def avatar_url(self):
"""Returns an :class:`Asset` for the avatar the user has. """Returns an :class:`Asset` for the avatar the user has.

6
docs/api.rst

@ -2647,6 +2647,12 @@ MessageFlags
.. autoclass:: MessageFlags .. autoclass:: MessageFlags
:members: :members:
PublicUserFlags
~~~~~~~~~~~~~~~
.. autoclass:: PublicUserFlags
:members:
Exceptions Exceptions
------------ ------------

Loading…
Cancel
Save