|
@ -24,7 +24,7 @@ DEALINGS IN THE SOFTWARE. |
|
|
|
|
|
|
|
|
import types |
|
|
import types |
|
|
from collections import namedtuple |
|
|
from collections import namedtuple |
|
|
from typing import Any, Dict, Optional, TYPE_CHECKING, Type, TypeVar |
|
|
from typing import Any, ClassVar, Dict, List, Optional, TYPE_CHECKING, Type, TypeVar |
|
|
|
|
|
|
|
|
__all__ = ( |
|
|
__all__ = ( |
|
|
'Enum', |
|
|
'Enum', |
|
@ -56,16 +56,25 @@ __all__ = ( |
|
|
'NSFWLevel', |
|
|
'NSFWLevel', |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _create_value_cls(name): |
|
|
def _create_value_cls(name): |
|
|
cls = namedtuple('_EnumValue_' + name, 'name value') |
|
|
cls = namedtuple('_EnumValue_' + name, 'name value') |
|
|
cls.__repr__ = lambda self: f'<{name}.{self.name}: {self.value!r}>' |
|
|
cls.__repr__ = lambda self: f'<{name}.{self.name}: {self.value!r}>' |
|
|
cls.__str__ = lambda self: f'{name}.{self.name}' |
|
|
cls.__str__ = lambda self: f'{name}.{self.name}' |
|
|
return cls |
|
|
return cls |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _is_descriptor(obj): |
|
|
def _is_descriptor(obj): |
|
|
return hasattr(obj, '__get__') or hasattr(obj, '__set__') or hasattr(obj, '__delete__') |
|
|
return hasattr(obj, '__get__') or hasattr(obj, '__set__') or hasattr(obj, '__delete__') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EnumMeta(type): |
|
|
class EnumMeta(type): |
|
|
|
|
|
if TYPE_CHECKING: |
|
|
|
|
|
__name__: ClassVar[str] |
|
|
|
|
|
_enum_member_names_: ClassVar[List[str]] |
|
|
|
|
|
_enum_member_map_: ClassVar[Dict[str, Any]] |
|
|
|
|
|
_enum_value_map_: ClassVar[Dict[Any, Any]] |
|
|
|
|
|
|
|
|
def __new__(cls, name, bases, attrs): |
|
|
def __new__(cls, name, bases, attrs): |
|
|
value_mapping = {} |
|
|
value_mapping = {} |
|
|
member_mapping = {} |
|
|
member_mapping = {} |
|
@ -101,7 +110,7 @@ class EnumMeta(type): |
|
|
attrs['_enum_member_names_'] = member_names |
|
|
attrs['_enum_member_names_'] = member_names |
|
|
attrs['_enum_value_cls_'] = value_cls |
|
|
attrs['_enum_value_cls_'] = value_cls |
|
|
actual_cls = super().__new__(cls, name, bases, attrs) |
|
|
actual_cls = super().__new__(cls, name, bases, attrs) |
|
|
value_cls._actual_enum_cls_ = actual_cls |
|
|
value_cls._actual_enum_cls_ = actual_cls # type: ignore |
|
|
return actual_cls |
|
|
return actual_cls |
|
|
|
|
|
|
|
|
def __iter__(cls): |
|
|
def __iter__(cls): |
|
@ -143,9 +152,11 @@ class EnumMeta(type): |
|
|
except AttributeError: |
|
|
except AttributeError: |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING: |
|
|
if TYPE_CHECKING: |
|
|
from enum import Enum |
|
|
from enum import Enum |
|
|
else: |
|
|
else: |
|
|
|
|
|
|
|
|
class Enum(metaclass=EnumMeta): |
|
|
class Enum(metaclass=EnumMeta): |
|
|
@classmethod |
|
|
@classmethod |
|
|
def try_value(cls, value): |
|
|
def try_value(cls, value): |
|
@ -154,6 +165,7 @@ else: |
|
|
except (KeyError, TypeError): |
|
|
except (KeyError, TypeError): |
|
|
return value |
|
|
return value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChannelType(Enum): |
|
|
class ChannelType(Enum): |
|
|
text = 0 |
|
|
text = 0 |
|
|
private = 1 |
|
|
private = 1 |
|
@ -170,6 +182,7 @@ class ChannelType(Enum): |
|
|
def __str__(self): |
|
|
def __str__(self): |
|
|
return self.name |
|
|
return self.name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MessageType(Enum): |
|
|
class MessageType(Enum): |
|
|
default = 0 |
|
|
default = 0 |
|
|
recipient_add = 1 |
|
|
recipient_add = 1 |
|
@ -195,6 +208,7 @@ class MessageType(Enum): |
|
|
thread_starter_message = 21 |
|
|
thread_starter_message = 21 |
|
|
guild_invite_reminder = 22 |
|
|
guild_invite_reminder = 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VoiceRegion(Enum): |
|
|
class VoiceRegion(Enum): |
|
|
us_west = 'us-west' |
|
|
us_west = 'us-west' |
|
|
us_east = 'us-east' |
|
|
us_east = 'us-east' |
|
@ -223,6 +237,7 @@ class VoiceRegion(Enum): |
|
|
def __str__(self): |
|
|
def __str__(self): |
|
|
return self.value |
|
|
return self.value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SpeakingState(Enum): |
|
|
class SpeakingState(Enum): |
|
|
none = 0 |
|
|
none = 0 |
|
|
voice = 1 |
|
|
voice = 1 |
|
@ -235,6 +250,7 @@ class SpeakingState(Enum): |
|
|
def __int__(self): |
|
|
def __int__(self): |
|
|
return self.value |
|
|
return self.value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VerificationLevel(Enum): |
|
|
class VerificationLevel(Enum): |
|
|
none = 0 |
|
|
none = 0 |
|
|
low = 1 |
|
|
low = 1 |
|
@ -245,6 +261,7 @@ class VerificationLevel(Enum): |
|
|
def __str__(self): |
|
|
def __str__(self): |
|
|
return self.name |
|
|
return self.name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ContentFilter(Enum): |
|
|
class ContentFilter(Enum): |
|
|
disabled = 0 |
|
|
disabled = 0 |
|
|
no_role = 1 |
|
|
no_role = 1 |
|
@ -253,6 +270,7 @@ class ContentFilter(Enum): |
|
|
def __str__(self): |
|
|
def __str__(self): |
|
|
return self.name |
|
|
return self.name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Status(Enum): |
|
|
class Status(Enum): |
|
|
online = 'online' |
|
|
online = 'online' |
|
|
offline = 'offline' |
|
|
offline = 'offline' |
|
@ -264,6 +282,7 @@ class Status(Enum): |
|
|
def __str__(self): |
|
|
def __str__(self): |
|
|
return self.value |
|
|
return self.value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DefaultAvatar(Enum): |
|
|
class DefaultAvatar(Enum): |
|
|
blurple = 0 |
|
|
blurple = 0 |
|
|
grey = 1 |
|
|
grey = 1 |
|
@ -275,16 +294,20 @@ class DefaultAvatar(Enum): |
|
|
def __str__(self): |
|
|
def __str__(self): |
|
|
return self.name |
|
|
return self.name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NotificationLevel(Enum): |
|
|
class NotificationLevel(Enum): |
|
|
all_messages = 0 |
|
|
all_messages = 0 |
|
|
only_mentions = 1 |
|
|
only_mentions = 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AuditLogActionCategory(Enum): |
|
|
class AuditLogActionCategory(Enum): |
|
|
create = 1 |
|
|
create = 1 |
|
|
delete = 2 |
|
|
delete = 2 |
|
|
update = 3 |
|
|
update = 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AuditLogAction(Enum): |
|
|
class AuditLogAction(Enum): |
|
|
|
|
|
# fmt: off |
|
|
guild_update = 1 |
|
|
guild_update = 1 |
|
|
channel_create = 10 |
|
|
channel_create = 10 |
|
|
channel_update = 11 |
|
|
channel_update = 11 |
|
@ -323,9 +346,11 @@ class AuditLogAction(Enum): |
|
|
stage_instance_create = 83 |
|
|
stage_instance_create = 83 |
|
|
stage_instance_update = 84 |
|
|
stage_instance_update = 84 |
|
|
stage_instance_delete = 85 |
|
|
stage_instance_delete = 85 |
|
|
|
|
|
# fmt: on |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def category(self) -> Optional[AuditLogActionCategory]: |
|
|
def category(self) -> Optional[AuditLogActionCategory]: |
|
|
|
|
|
# fmt: off |
|
|
lookup: Dict[AuditLogAction, Optional[AuditLogActionCategory]] = { |
|
|
lookup: Dict[AuditLogAction, Optional[AuditLogActionCategory]] = { |
|
|
AuditLogAction.guild_update: AuditLogActionCategory.update, |
|
|
AuditLogAction.guild_update: AuditLogActionCategory.update, |
|
|
AuditLogAction.channel_create: AuditLogActionCategory.create, |
|
|
AuditLogAction.channel_create: AuditLogActionCategory.create, |
|
@ -366,6 +391,7 @@ class AuditLogAction(Enum): |
|
|
AuditLogAction.stage_instance_update: AuditLogActionCategory.update, |
|
|
AuditLogAction.stage_instance_update: AuditLogActionCategory.update, |
|
|
AuditLogAction.stage_instance_delete: AuditLogActionCategory.delete, |
|
|
AuditLogAction.stage_instance_delete: AuditLogActionCategory.delete, |
|
|
} |
|
|
} |
|
|
|
|
|
# fmt: on |
|
|
return lookup[self] |
|
|
return lookup[self] |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
@ -396,6 +422,7 @@ class AuditLogAction(Enum): |
|
|
elif v < 90: |
|
|
elif v < 90: |
|
|
return 'stage_instance' |
|
|
return 'stage_instance' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserFlags(Enum): |
|
|
class UserFlags(Enum): |
|
|
staff = 1 |
|
|
staff = 1 |
|
|
partner = 2 |
|
|
partner = 2 |
|
@ -415,6 +442,7 @@ class UserFlags(Enum): |
|
|
verified_bot_developer = 131072 |
|
|
verified_bot_developer = 131072 |
|
|
discord_certified_moderator = 262144 |
|
|
discord_certified_moderator = 262144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ActivityType(Enum): |
|
|
class ActivityType(Enum): |
|
|
unknown = -1 |
|
|
unknown = -1 |
|
|
playing = 0 |
|
|
playing = 0 |
|
@ -427,36 +455,44 @@ class ActivityType(Enum): |
|
|
def __int__(self): |
|
|
def __int__(self): |
|
|
return self.value |
|
|
return self.value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TeamMembershipState(Enum): |
|
|
class TeamMembershipState(Enum): |
|
|
invited = 1 |
|
|
invited = 1 |
|
|
accepted = 2 |
|
|
accepted = 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WebhookType(Enum): |
|
|
class WebhookType(Enum): |
|
|
incoming = 1 |
|
|
incoming = 1 |
|
|
channel_follower = 2 |
|
|
channel_follower = 2 |
|
|
application = 3 |
|
|
application = 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExpireBehaviour(Enum): |
|
|
class ExpireBehaviour(Enum): |
|
|
remove_role = 0 |
|
|
remove_role = 0 |
|
|
kick = 1 |
|
|
kick = 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExpireBehavior = ExpireBehaviour |
|
|
ExpireBehavior = ExpireBehaviour |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StickerType(Enum): |
|
|
class StickerType(Enum): |
|
|
png = 1 |
|
|
png = 1 |
|
|
apng = 2 |
|
|
apng = 2 |
|
|
lottie = 3 |
|
|
lottie = 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InviteTarget(Enum): |
|
|
class InviteTarget(Enum): |
|
|
unknown = 0 |
|
|
unknown = 0 |
|
|
stream = 1 |
|
|
stream = 1 |
|
|
embedded_application = 2 |
|
|
embedded_application = 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InteractionType(Enum): |
|
|
class InteractionType(Enum): |
|
|
ping = 1 |
|
|
ping = 1 |
|
|
application_command = 2 |
|
|
application_command = 2 |
|
|
component = 3 |
|
|
component = 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InteractionResponseType(Enum): |
|
|
class InteractionResponseType(Enum): |
|
|
pong = 1 |
|
|
pong = 1 |
|
|
# ack = 2 (deprecated) |
|
|
# ack = 2 (deprecated) |
|
@ -466,6 +502,7 @@ class InteractionResponseType(Enum): |
|
|
deferred_message_update = 6 # for components |
|
|
deferred_message_update = 6 # for components |
|
|
message_update = 7 # for components |
|
|
message_update = 7 # for components |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VideoQualityMode(Enum): |
|
|
class VideoQualityMode(Enum): |
|
|
auto = 1 |
|
|
auto = 1 |
|
|
full = 2 |
|
|
full = 2 |
|
@ -473,6 +510,7 @@ class VideoQualityMode(Enum): |
|
|
def __int__(self): |
|
|
def __int__(self): |
|
|
return self.value |
|
|
return self.value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ComponentType(Enum): |
|
|
class ComponentType(Enum): |
|
|
action_row = 1 |
|
|
action_row = 1 |
|
|
button = 2 |
|
|
button = 2 |
|
@ -481,6 +519,7 @@ class ComponentType(Enum): |
|
|
def __int__(self): |
|
|
def __int__(self): |
|
|
return self.value |
|
|
return self.value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ButtonStyle(Enum): |
|
|
class ButtonStyle(Enum): |
|
|
primary = 1 |
|
|
primary = 1 |
|
|
secondary = 2 |
|
|
secondary = 2 |
|
@ -499,24 +538,29 @@ class ButtonStyle(Enum): |
|
|
def __int__(self): |
|
|
def __int__(self): |
|
|
return self.value |
|
|
return self.value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StagePrivacyLevel(Enum): |
|
|
class StagePrivacyLevel(Enum): |
|
|
public = 1 |
|
|
public = 1 |
|
|
closed = 2 |
|
|
closed = 2 |
|
|
guild_only = 2 |
|
|
guild_only = 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NSFWLevel(Enum): |
|
|
class NSFWLevel(Enum): |
|
|
default = 0 |
|
|
default = 0 |
|
|
explicit = 1 |
|
|
explicit = 1 |
|
|
safe = 2 |
|
|
safe = 2 |
|
|
age_restricted = 3 |
|
|
age_restricted = 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
T = TypeVar('T') |
|
|
T = TypeVar('T') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_unknown_value(cls: Type[T], val: Any) -> T: |
|
|
def create_unknown_value(cls: Type[T], val: Any) -> T: |
|
|
value_cls = cls._enum_value_cls_ # type: ignore |
|
|
value_cls = cls._enum_value_cls_ # type: ignore |
|
|
name = f'unknown_{val}' |
|
|
name = f'unknown_{val}' |
|
|
return value_cls(name=name, value=val) |
|
|
return value_cls(name=name, value=val) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def try_enum(cls: Type[T], val: Any) -> T: |
|
|
def try_enum(cls: Type[T], val: Any) -> T: |
|
|
"""A function that tries to turn the value into enum ``cls``. |
|
|
"""A function that tries to turn the value into enum ``cls``. |
|
|
|
|
|
|
|
|