Skip to content

Commit

Permalink
Improve permission checks
Browse files Browse the repository at this point in the history
  • Loading branch information
tandemdude committed Dec 23, 2022
1 parent 6f7b5e6 commit c8c89ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/source/changelogs/v2-changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Version 2.3.2

- Slash commands now have full custom converter support.

- Permission checks improved to use interaction permission fields where appropriate.

Version 2.3.1
=============

Expand Down
19 changes: 19 additions & 0 deletions lightbulb/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ def _has_guild_permissions(context: context_.base.Context, *, perms: hikari.Perm

_guild_only(context)

if isinstance(context, context_.base.ApplicationContext):
assert context.interaction.member is not None
missing_perms = ~context.interaction.member.permissions & perms
if missing_perms is not hikari.Permissions.NONE:
raise errors.MissingRequiredPermission(
"You are missing one or more permissions required in order to run this command", perms=missing_perms
)
return True

channel = context.get_channel()

# Threads do not have permissions attached to them, they inherit that from
Expand Down Expand Up @@ -324,6 +333,16 @@ def _has_channel_permissions(context: context_.base.Context, *, perms: hikari.Pe
def _bot_has_guild_permissions(context: context_.base.Context, *, perms: hikari.Permissions) -> bool:
_guild_only(context)

# TODO - do we need to check for dm_enabled for these checks?
if isinstance(context, context_.base.ApplicationContext):
assert context.interaction.app_permissions is not None
missing_perms = ~context.interaction.app_permissions & perms
if missing_perms is not hikari.Permissions.NONE:
raise errors.BotMissingRequiredPermission(
"The bot is missing one or more permissions required in order to run this command", perms=missing_perms
)
return True

channel = context.get_channel()

# Threads do not have permissions attached to them, they inherit that from
Expand Down

0 comments on commit c8c89ca

Please sign in to comment.