Implement AutoMod

This commit is contained in:
Alex Nørgaard
2022-06-27 05:47:52 +01:00
committed by GitHub
parent 7ad00750c6
commit 5426d19dc7
12 changed files with 1279 additions and 2 deletions

View File

@ -24,6 +24,7 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations
from functools import reduce
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, Iterator, List, Optional, Tuple, Type, TypeVar, overload
from .enums import UserFlags
@ -40,6 +41,7 @@ __all__ = (
'MemberCacheFlags',
'ApplicationFlags',
'ChannelFlags',
'AutoModPresets',
)
BF = TypeVar('BF', bound='BaseFlags')
@ -655,8 +657,7 @@ class Intents(BaseFlags):
@classmethod
def all(cls: Type[Intents]) -> Intents:
"""A factory method that creates a :class:`Intents` with everything enabled."""
bits = max(cls.VALID_FLAGS.values()).bit_length()
value = (1 << bits) - 1
value = reduce(lambda a, b: a | b, cls.VALID_FLAGS.values())
self = cls.__new__(cls)
self.value = value
return self
@ -1104,6 +1105,31 @@ class Intents(BaseFlags):
"""
return 1 << 16
@flag_value
def auto_moderation_configuration(self):
""":class:`bool`: Whether auto moderation configuration related events are enabled.
This corresponds to the following events:
- :func:`on_automod_rule_create`
- :func:`on_automod_rule_update`
- :func:`on_automod_rule_delete`
.. versionadded:: 2.0
"""
return 1 << 20
@flag_value
def auto_moderation_execution(self):
""":class:`bool`: Whether auto moderation execution related events are enabled.
This corresponds to the following events:
- :func:`on_automod_action`
.. versionadded:: 2.0
"""
return 1 << 21
@fill_with_flags()
class MemberCacheFlags(BaseFlags):
@ -1436,3 +1462,106 @@ class ChannelFlags(BaseFlags):
def pinned(self):
""":class:`bool`: Returns ``True`` if the thread is pinned to the forum channel."""
return 1 << 1
class ArrayFlags(BaseFlags):
@classmethod
def _from_value(cls: Type[Self], value: List[int]) -> Self:
self = cls.__new__(cls)
self.value = reduce(lambda a, b: a | (1 << b - 1), value)
return self
def to_array(self) -> List[int]:
return [i + 1 for i in range(self.value.bit_length()) if self.value & (1 << i)]
@fill_with_flags()
class AutoModPresets(ArrayFlags):
r"""Wraps up the Discord :class:`AutoModRule` presets.
.. versionadded:: 2.0
.. container:: operations
.. describe:: x == y
Checks if two AutoMod preset flags are equal.
.. describe:: x != y
Checks if two AutoMod preset flags are not equal.
.. describe:: x | y, x |= y
Returns a AutoModPresets instance with all enabled flags from
both x and y.
.. versionadded:: 2.0
.. describe:: x & y, x &= y
Returns a AutoModPresets instance with only flags enabled on
both x and y.
.. versionadded:: 2.0
.. describe:: x ^ y, x ^= y
Returns a AutoModPresets instance with only flags enabled on
only one of x or y, not on both.
.. versionadded:: 2.0
.. describe:: ~x
Returns a AutoModPresets instance with all flags inverted from x.
.. versionadded:: 2.0
.. 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.
Attributes
-----------
value: :class:`int`
The raw value. You should query flags via the properties
rather than using this raw value.
"""
@flag_value
def profanity(self):
""":class:`bool`: Whether to use the preset profanity filter."""
return 1 << 0
@flag_value
def sexual_content(self):
""":class:`bool`: Whether to use the preset sexual content filter."""
return 1 << 1
@flag_value
def slurs(self):
""":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