Browse Source

Add support for flag alias

pull/5852/head
apple502j 5 years ago
committed by GitHub
parent
commit
0ebf5b2fa7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      discord/flags.py
  2. 12
      discord/permissions.py

24
discord/flags.py

@ -50,6 +50,9 @@ class flag_value:
def __repr__(self):
return '<flag_value flag={.flag!r}>'.format(self)
class alias_flag_value(flag_value):
pass
def fill_with_flags(*, inverted=False):
def decorator(cls):
cls.VALID_FLAGS = {
@ -98,6 +101,9 @@ class BaseFlags:
def __iter__(self):
for name, value in self.__class__.__dict__.items():
if isinstance(value, alias_flag_value):
continue
if isinstance(value, flag_value):
yield (name, self._has_flag(value.flag))
@ -248,6 +254,14 @@ class PublicUserFlags(BaseFlags):
.. describe:: x != y
Checks if two PublicUserFlags 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:: 1.4
@ -323,7 +337,15 @@ class PublicUserFlags(BaseFlags):
@flag_value
def verified_bot_developer(self):
""":class:`bool`: Returns ``True`` if the user is a Verified Bot Developer."""
""":class:`bool`: Returns ``True`` if the user is an Early Verified Bot Developer."""
return UserFlags.verified_bot_developer.value
@alias_flag_value
def early_verified_bot_developer(self):
""":class:`bool`: An alias for :attr:`verified_bot_developer`.
.. versionadded:: 1.5
"""
return UserFlags.verified_bot_developer.value
def all(self):

12
discord/permissions.py

@ -24,7 +24,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from .flags import BaseFlags, flag_value, fill_with_flags
from .flags import BaseFlags, flag_value, fill_with_flags, alias_flag_value
__all__ = (
'Permissions',
@ -33,7 +33,7 @@ __all__ = (
# A permission alias works like a regular flag but is marked
# So the PermissionOverwrite knows to work with it
class permission_alias(flag_value):
class permission_alias(alias_flag_value):
pass
def make_permission_alias(alias):
@ -131,14 +131,6 @@ class Permissions(BaseFlags):
__lt__ = is_strict_subset
__gt__ = is_strict_superset
def __iter__(self):
for name, value in self.__class__.__dict__.items():
if isinstance(value, permission_alias):
continue
if isinstance(value, flag_value):
yield (name, self._has_flag(value.flag))
@classmethod
def none(cls):
"""A factory method that creates a :class:`Permissions` with all

Loading…
Cancel
Save