diff options
| author | apple502j <[email protected]> | 2020-09-24 13:16:37 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-09-24 00:16:37 -0400 |
| commit | 0ebf5b2fa729414af3e6ecaf169a33d55304ced9 (patch) | |
| tree | 33f2582b4be88b559352e868b31985526c76f842 /discord | |
| parent | Use delete_message_days instead of delete-message-days (diff) | |
| download | discord.py-0ebf5b2fa729414af3e6ecaf169a33d55304ced9.tar.xz discord.py-0ebf5b2fa729414af3e6ecaf169a33d55304ced9.zip | |
Add support for flag alias
Diffstat (limited to 'discord')
| -rw-r--r-- | discord/flags.py | 24 | ||||
| -rw-r--r-- | discord/permissions.py | 12 |
2 files changed, 25 insertions, 11 deletions
diff --git a/discord/flags.py b/discord/flags.py index f568c26f..57695912 100644 --- a/discord/flags.py +++ b/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): diff --git a/discord/permissions.py b/discord/permissions.py index 55e26f91..9bd9f4e7 100644 --- a/discord/permissions.py +++ b/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 |