Skip to content

Commit

Permalink
Add missing permissions (#1758)
Browse files Browse the repository at this point in the history
  • Loading branch information
davfsa authored Nov 18, 2023
1 parent fcd45e0 commit 4d4b03b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 29 deletions.
1 change: 1 addition & 0 deletions changes/1758.deprecation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate `Permissions.MANAGE_EMOJIS_AND_STICKERS` in favour of `Permissions.MANAGE_GUILD_EXPREASSIONS`
1 change: 1 addition & 0 deletions changes/1758.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing permissions
54 changes: 29 additions & 25 deletions hikari/internal/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 21 additions & 3 deletions hikari/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,18 @@ 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
by users who have two-factor authentication enabled on their account
(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."""

Expand All @@ -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.
Expand Down Expand Up @@ -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."""

Expand Down
2 changes: 1 addition & 1 deletion tests/hikari/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4d4b03b

Please sign in to comment.