mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-14 17:59:48 +00:00
Add support for flag alias
This commit is contained in:
parent
7126f5a78c
commit
0ebf5b2fa7
@ -50,6 +50,9 @@ class flag_value:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<flag_value flag={.flag!r}>'.format(self)
|
return '<flag_value flag={.flag!r}>'.format(self)
|
||||||
|
|
||||||
|
class alias_flag_value(flag_value):
|
||||||
|
pass
|
||||||
|
|
||||||
def fill_with_flags(*, inverted=False):
|
def fill_with_flags(*, inverted=False):
|
||||||
def decorator(cls):
|
def decorator(cls):
|
||||||
cls.VALID_FLAGS = {
|
cls.VALID_FLAGS = {
|
||||||
@ -98,6 +101,9 @@ class BaseFlags:
|
|||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for name, value in self.__class__.__dict__.items():
|
for name, value in self.__class__.__dict__.items():
|
||||||
|
if isinstance(value, alias_flag_value):
|
||||||
|
continue
|
||||||
|
|
||||||
if isinstance(value, flag_value):
|
if isinstance(value, flag_value):
|
||||||
yield (name, self._has_flag(value.flag))
|
yield (name, self._has_flag(value.flag))
|
||||||
|
|
||||||
@ -248,6 +254,14 @@ class PublicUserFlags(BaseFlags):
|
|||||||
.. describe:: x != y
|
.. describe:: x != y
|
||||||
|
|
||||||
Checks if two PublicUserFlags are not equal.
|
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
|
.. versionadded:: 1.4
|
||||||
|
|
||||||
@ -323,7 +337,15 @@ class PublicUserFlags(BaseFlags):
|
|||||||
|
|
||||||
@flag_value
|
@flag_value
|
||||||
def verified_bot_developer(self):
|
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
|
return UserFlags.verified_bot_developer.value
|
||||||
|
|
||||||
def all(self):
|
def all(self):
|
||||||
|
@ -24,7 +24,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|||||||
DEALINGS IN THE SOFTWARE.
|
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__ = (
|
__all__ = (
|
||||||
'Permissions',
|
'Permissions',
|
||||||
@ -33,7 +33,7 @@ __all__ = (
|
|||||||
|
|
||||||
# A permission alias works like a regular flag but is marked
|
# A permission alias works like a regular flag but is marked
|
||||||
# So the PermissionOverwrite knows to work with it
|
# So the PermissionOverwrite knows to work with it
|
||||||
class permission_alias(flag_value):
|
class permission_alias(alias_flag_value):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def make_permission_alias(alias):
|
def make_permission_alias(alias):
|
||||||
@ -131,14 +131,6 @@ class Permissions(BaseFlags):
|
|||||||
__lt__ = is_strict_subset
|
__lt__ = is_strict_subset
|
||||||
__gt__ = is_strict_superset
|
__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
|
@classmethod
|
||||||
def none(cls):
|
def none(cls):
|
||||||
"""A factory method that creates a :class:`Permissions` with all
|
"""A factory method that creates a :class:`Permissions` with all
|
||||||
|
Loading…
x
Reference in New Issue
Block a user