twilight_util::permission_calculator

Struct PermissionCalculator

Source
pub struct PermissionCalculator<'a> { /* private fields */ }
Available on crate feature permission-calculator only.
Expand description

Calculate the permissions of a member.

Using the member calculator you can calculate the member’s permissions in the root-level of a guild or in a given channel.

Implementations§

Source§

impl<'a> PermissionCalculator<'a>

Source

pub const fn new( guild_id: Id<GuildMarker>, user_id: Id<UserMarker>, everyone_role: Permissions, member_roles: &'a [(Id<RoleMarker>, Permissions)], ) -> Self

Create a calculator to calculate the permissions of a member.

everyone_role is the permissions of the @everyone role on a guild-level; the permissions may be empty. The @everyone role’s ID is the same as that of the guild_id.

The provided member’s roles should not contain the @everyone role.

Source

pub const fn owner_id(self, owner_id: Id<UserMarker>) -> Self

Configure the ID of the owner of the guild.

This should be used if you don’t want to manually take the user ID and owner ID in account beforehand.

If the member’s ID is the same as the owner’s ID then permission calculating methods such as root will return all permissions enabled.

Source

pub const fn root(&self) -> Permissions

Calculate the guild-level permissions of a member.

Source

pub const fn in_channel( self, channel_type: ChannelType, channel_overwrites: &[PermissionOverwrite], ) -> Permissions

Calculate the permissions of the member in a channel, taking into account a combination of the guild-level permissions and channel-level permissions.

Note that this method will not return guild-level permissions such as Manage Guild Expressions; if you need the guild-level permissions use root.

§Conditional exclusions

When the member doesn’t have the “View Channel” permission then an empty permission set will be returned. This will happen in the following circumstances:

  • When the permission is denied on the role level and isn’t enabled on a role or member permission overwrite;
  • When the permission is denied on a role permission overwrite but isn’t enabled on a member permission overwrite; or
  • When permission isn’t enabled on a guild level and isn’t enabled via a permission overwrite.

When the Send Messages permission is denied and is not similarly enabled like above then the Attach Files, Embed Links, Mention Everyone, and Send TTS Messages permissions will not be present in the returned permission set.

§Channel-based exclusions

Permissions are removed based on the type of a channel. For example, when calculating the permissions of a voice channel we can know that if Send Messages is granted on a guild-level to everyone then it is omitted from the permissions for a specific channel.

§Stage Channels

When the given channel type is a guild stage channel then the following permissions will be removed:

§Text Channels

When the given channel type is a guild text channel then the following permissions will be removed:

§Voice Channels

When the given channel type is a guild voice channel then the following permissions will be removed:

§Guild-based exclusions

The following guild-level permissions will always be removed:

If you need to know a member’s guild-level permissions - such as whether they have the View Audit Log permission - use root instead.

§Examples

See the crate-level documentation for an example.

Trait Implementations§

Source§

impl<'a> Clone for PermissionCalculator<'a>

Source§

fn clone(&self) -> PermissionCalculator<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for PermissionCalculator<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for PermissionCalculator<'a>

Source§

fn eq(&self, other: &PermissionCalculator<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for PermissionCalculator<'a>

Source§

impl<'a> StructuralPartialEq for PermissionCalculator<'a>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.