Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite permission checks #325

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

GnomedDev
Copy link
Member

Based on #286, but as a straight up rewrite instead of rework.

This splits permission checks up into all possible branches, and performs them efficiently without unnecessary cache or http calls. I have also been liberal with panicking on incorrect assumptions, as that's what they are for.

The algorithm described is written below:

for interactions (which is infallible):

  • author permissions: interaction.member.permissions (if member is none, use Permissions::dm_permissions, expect permissions)
  • bot permissions: interaction.app_permissions (expect, since it is documented as always Some)

for prefix (only fallible with no cache):

  • author permissions:
    • cache: message.author_permissions()
    • no cache: PartialGuild::user_permissions_in, Message::member
  • bot permissions:
    • cache: Guild::user_permissions_in, bot member is always cached
    • no cache: PartialGuild::user_permissions_in, PartialGuild::member

@GnomedDev GnomedDev merged commit b8ce188 into serenity-rs:next Nov 13, 2024
12 checks passed
@GnomedDev GnomedDev deleted the rework-permission-checks branch November 13, 2024 19:34
GnomedDev added a commit that referenced this pull request Nov 13, 2024
GnomedDev added a commit that referenced this pull request Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants