From 4d4b03b310eaa295bf78fdb77c8a0bf89dcd5603 Mon Sep 17 00:00:00 2001 From: davfsa Date: Sat, 18 Nov 2023 15:26:51 +0100 Subject: [PATCH] Add missing permissions (#1758) --- changes/1758.deprecation.md | 1 + changes/1758.feature.md | 1 + hikari/internal/enums.py | 54 +++++++++++++++++--------------- hikari/permissions.py | 24 ++++++++++++-- tests/hikari/test_permissions.py | 2 +- 5 files changed, 53 insertions(+), 29 deletions(-) create mode 100644 changes/1758.deprecation.md create mode 100644 changes/1758.feature.md diff --git a/changes/1758.deprecation.md b/changes/1758.deprecation.md new file mode 100644 index 0000000000..726c67d0e9 --- /dev/null +++ b/changes/1758.deprecation.md @@ -0,0 +1 @@ +Deprecate `Permissions.MANAGE_EMOJIS_AND_STICKERS` in favour of `Permissions.MANAGE_GUILD_EXPREASSIONS` diff --git a/changes/1758.feature.md b/changes/1758.feature.md new file mode 100644 index 0000000000..be7f2df73b --- /dev/null +++ b/changes/1758.feature.md @@ -0,0 +1 @@ +Add missing permissions diff --git a/hikari/internal/enums.py b/hikari/internal/enums.py index 9307e8ef2d..bff61dcbc9 100644 --- a/hikari/internal/enums.py +++ b/hikari/internal/enums.py @@ -203,19 +203,21 @@ def __new__( for name, value in namespace.names_to_values.items(): member = new_namespace.get(name) - if not isinstance(member, _DeprecatedAlias): - # Patching the member init call is around 100ns faster per call than - # using the default type.__call__ which would make us do the lookup - # in cls.__new__. Reason for this is that python will also always - # invoke cls.__init__ if we do this, so we end up with two function - # calls. - member = cls.__new__(cls, value) - member._name_ = name - member._value_ = value - setattr(cls, name, member) + if isinstance(member, _DeprecatedAlias): + continue + + # Patching the member init call is around 100ns faster per call than + # using the default type.__call__ which would make us do the lookup + # in cls.__new__. Reason for this is that python will also always + # invoke cls.__init__ if we do this, so we end up with two function + # calls. + member = cls.__new__(cls, value) + member._name_ = name + member._value_ = value + setattr(cls, name, member) name_to_member[name] = member - value_to_member.setdefault(value, member) + value_to_member[value] = member member_names.append(name) return cls @@ -471,24 +473,26 @@ def __new__( for name, value in namespace.names_to_values.items(): member = new_namespace.get(name) - if not isinstance(member, _DeprecatedAlias): - # Patching the member init call is around 100ns faster per call than - # using the default type.__call__ which would make us do the lookup - # in cls.__new__. Reason for this is that python will also always - # invoke cls.__init__ if we do this, so we end up with two function - # calls. - member = cls.__new__(cls, value) - member._name_ = name - member._value_ = value - setattr(cls, name, member) - - if not (value & value - 1): - powers_of_2_map[value] = member + if isinstance(member, _DeprecatedAlias): + continue + + # Patching the member init call is around 100ns faster per call than + # using the default type.__call__ which would make us do the lookup + # in cls.__new__. Reason for this is that python will also always + # invoke cls.__init__ if we do this, so we end up with two function + # calls. + member = cls.__new__(cls, value) + member._name_ = name + member._value_ = value + setattr(cls, name, member) name_to_member[name] = member - value_to_member.setdefault(value, member) + value_to_member[value] = member member_names.append(name) + if not (value & value - 1): + powers_of_2_map[value] = member + all_bits = functools.reduce(operator.or_, value_to_member.keys()) all_bits_member = cls.__new__(cls, all_bits) all_bits_member._name_ = None diff --git a/hikari/permissions.py b/hikari/permissions.py index c6d1aa46c4..61587467a7 100644 --- a/hikari/permissions.py +++ b/hikari/permissions.py @@ -227,8 +227,8 @@ class Permissions(enums.Flag): (or their owner's account in the case of bot users) and the guild owner. """ - MANAGE_EMOJIS_AND_STICKERS = 1 << 30 - """Allows management and editing of emojis and stickers. + MANAGE_GUILD_EXPRESSIONS = 1 << 30 + """Allows management and editing emojis, stickers and soundboard sounds. .. note:: In guilds with server-wide 2FA enabled this permission can only be used @@ -236,6 +236,9 @@ class Permissions(enums.Flag): (or their owner's account in the case of bot users) and the guild owner. """ + MANAGE_EMOJIS_AND_STICKERS = enums.deprecated(MANAGE_GUILD_EXPRESSIONS, removal_version="2.0.0.dev123") + """Deprecated alias for MANAGE_GUILD_EXPRESSIONS.""" + USE_APPLICATION_COMMANDS = 1 << 31 """Allows for using the application commands of guild integrations within a text channel.""" @@ -249,7 +252,7 @@ class Permissions(enums.Flag): """ MANAGE_EVENTS = 1 << 33 - """Allows for creating, editing, and deleting scheduled events """ + """Allows for management and editing scheduled events""" MANAGE_THREADS = 1 << 34 """Allows for deleting and archiving threads, and viewing all private threads. @@ -284,6 +287,21 @@ class Permissions(enums.Flag): USE_SOUNDBOARD = 1 << 42 """Allows the use of soundboard in a voice chat.""" + CREATE_GUILD_EXPRESSIONS = 1 << 43 + """Allows to create guild emojis, stickers and soundboard sounds. + + Additionally, it allows to edit and manage those created by the user. + """ + + CREATE_EVENTS = 1 << 44 + """Allows to create scheduled events. + + Additionally, it allows to edit and manage those created by the user. + """ + + USE_EXTERNAL_SOUNDS = 1 << 45 + """Allows the use of soundboard sounds from external servers.""" + SEND_VOICE_MESSAGES = 1 << 46 """Allows sending voice messages.""" diff --git a/tests/hikari/test_permissions.py b/tests/hikari/test_permissions.py index c119ddd546..3512f805a4 100644 --- a/tests/hikari/test_permissions.py +++ b/tests/hikari/test_permissions.py @@ -27,4 +27,4 @@ def test_all_permissions(self): all_perms = permissions.Permissions.all_permissions() assert isinstance(all_perms, permissions.Permissions) - assert all_perms == 79164837199871 + assert all_perms == 140737488355327