mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-07 10:22:59 +00:00
First pass at supporting user apps
Co-authored-by: red <red@kalab.sk> Co-authored-by: Vioshim <63890837+Vioshim@users.noreply.github.com>
This commit is contained in:
176
discord/flags.py
176
discord/flags.py
@ -58,8 +58,10 @@ __all__ = (
|
||||
'ChannelFlags',
|
||||
'AutoModPresets',
|
||||
'MemberFlags',
|
||||
'AppCommandContext',
|
||||
'AttachmentFlags',
|
||||
'RoleFlags',
|
||||
'AppInstallationType',
|
||||
'SKUFlags',
|
||||
)
|
||||
|
||||
@ -1660,8 +1662,24 @@ class ArrayFlags(BaseFlags):
|
||||
self.value = reduce(or_, map((1).__lshift__, value), 0) >> 1
|
||||
return self
|
||||
|
||||
def to_array(self) -> List[int]:
|
||||
return [i + 1 for i in range(self.value.bit_length()) if self.value & (1 << i)]
|
||||
def to_array(self, *, offset: int = 0) -> List[int]:
|
||||
return [i + offset for i in range(self.value.bit_length()) if self.value & (1 << i)]
|
||||
|
||||
@classmethod
|
||||
def all(cls: Type[Self]) -> Self:
|
||||
"""A factory method that creates an instance of ArrayFlags with everything enabled."""
|
||||
bits = max(cls.VALID_FLAGS.values()).bit_length()
|
||||
value = (1 << bits) - 1
|
||||
self = cls.__new__(cls)
|
||||
self.value = value
|
||||
return self
|
||||
|
||||
@classmethod
|
||||
def none(cls: Type[Self]) -> Self:
|
||||
"""A factory method that creates an instance of ArrayFlags with everything disabled."""
|
||||
self = cls.__new__(cls)
|
||||
self.value = self.DEFAULT_VALUE
|
||||
return self
|
||||
|
||||
|
||||
@fill_with_flags()
|
||||
@ -1728,6 +1746,9 @@ class AutoModPresets(ArrayFlags):
|
||||
rather than using this raw value.
|
||||
"""
|
||||
|
||||
def to_array(self) -> List[int]:
|
||||
return super().to_array(offset=1)
|
||||
|
||||
@flag_value
|
||||
def profanity(self):
|
||||
""":class:`bool`: Whether to use the preset profanity filter."""
|
||||
@ -1743,21 +1764,144 @@ class AutoModPresets(ArrayFlags):
|
||||
""":class:`bool`: Whether to use the preset slurs filter."""
|
||||
return 1 << 2
|
||||
|
||||
@classmethod
|
||||
def all(cls: Type[Self]) -> Self:
|
||||
"""A factory method that creates a :class:`AutoModPresets` with everything enabled."""
|
||||
bits = max(cls.VALID_FLAGS.values()).bit_length()
|
||||
value = (1 << bits) - 1
|
||||
self = cls.__new__(cls)
|
||||
self.value = value
|
||||
return self
|
||||
|
||||
@classmethod
|
||||
def none(cls: Type[Self]) -> Self:
|
||||
"""A factory method that creates a :class:`AutoModPresets` with everything disabled."""
|
||||
self = cls.__new__(cls)
|
||||
self.value = self.DEFAULT_VALUE
|
||||
return self
|
||||
@fill_with_flags()
|
||||
class AppCommandContext(ArrayFlags):
|
||||
r"""Wraps up the Discord :class:`~discord.app_commands.Command` execution context.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
|
||||
.. container:: operations
|
||||
|
||||
.. describe:: x == y
|
||||
|
||||
Checks if two AppCommandContext flags are equal.
|
||||
|
||||
.. describe:: x != y
|
||||
|
||||
Checks if two AppCommandContext flags are not equal.
|
||||
|
||||
.. describe:: x | y, x |= y
|
||||
|
||||
Returns an AppCommandContext instance with all enabled flags from
|
||||
both x and y.
|
||||
|
||||
.. describe:: x & y, x &= y
|
||||
|
||||
Returns an AppCommandContext instance with only flags enabled on
|
||||
both x and y.
|
||||
|
||||
.. describe:: x ^ y, x ^= y
|
||||
|
||||
Returns an AppCommandContext instance with only flags enabled on
|
||||
only one of x or y, not on both.
|
||||
|
||||
.. describe:: ~x
|
||||
|
||||
Returns an AppCommandContext instance with all flags inverted from x
|
||||
|
||||
.. 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.
|
||||
|
||||
.. describe:: bool(b)
|
||||
|
||||
Returns whether any flag is set to ``True``.
|
||||
|
||||
Attributes
|
||||
-----------
|
||||
value: :class:`int`
|
||||
The raw value. You should query flags via the properties
|
||||
rather than using this raw value.
|
||||
"""
|
||||
|
||||
DEFAULT_VALUE = 3
|
||||
|
||||
@flag_value
|
||||
def guild(self):
|
||||
""":class:`bool`: Whether the context allows usage in a guild."""
|
||||
return 1 << 0
|
||||
|
||||
@flag_value
|
||||
def dm_channel(self):
|
||||
""":class:`bool`: Whether the context allows usage in a DM channel."""
|
||||
return 1 << 1
|
||||
|
||||
@flag_value
|
||||
def private_channel(self):
|
||||
""":class:`bool`: Whether the context allows usage in a DM or a GDM channel."""
|
||||
return 1 << 2
|
||||
|
||||
|
||||
@fill_with_flags()
|
||||
class AppInstallationType(ArrayFlags):
|
||||
r"""Represents the installation location of an application command.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
|
||||
.. container:: operations
|
||||
|
||||
.. describe:: x == y
|
||||
|
||||
Checks if two AppInstallationType flags are equal.
|
||||
|
||||
.. describe:: x != y
|
||||
|
||||
Checks if two AppInstallationType flags are not equal.
|
||||
|
||||
.. describe:: x | y, x |= y
|
||||
|
||||
Returns an AppInstallationType instance with all enabled flags from
|
||||
both x and y.
|
||||
|
||||
.. describe:: x & y, x &= y
|
||||
|
||||
Returns an AppInstallationType instance with only flags enabled on
|
||||
both x and y.
|
||||
|
||||
.. describe:: x ^ y, x ^= y
|
||||
|
||||
Returns an AppInstallationType instance with only flags enabled on
|
||||
only one of x or y, not on both.
|
||||
|
||||
.. describe:: ~x
|
||||
|
||||
Returns an AppInstallationType instance with all flags inverted from x
|
||||
|
||||
.. 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.
|
||||
|
||||
.. describe:: bool(b)
|
||||
|
||||
Returns whether any flag is set to ``True``.
|
||||
|
||||
Attributes
|
||||
-----------
|
||||
value: :class:`int`
|
||||
The raw value. You should query flags via the properties
|
||||
rather than using this raw value.
|
||||
"""
|
||||
|
||||
@flag_value
|
||||
def guild(self):
|
||||
""":class:`bool`: Whether the integration is a guild install."""
|
||||
return 1 << 0
|
||||
|
||||
@flag_value
|
||||
def user(self):
|
||||
""":class:`bool`: Whether the integration is a user install."""
|
||||
return 1 << 1
|
||||
|
||||
|
||||
@fill_with_flags()
|
||||
|
Reference in New Issue
Block a user