Lingo.Permissions (Lingo v0.4.2)

Copy Markdown View Source

Permission bitfields.

Discord sends permissions as bitfields (often as strings). These functions check and build them using atoms like :send_messages and :ban_members.

Lingo.Permissions.has?(member_permissions, :manage_messages)
Lingo.Permissions.from_list([:view_channel, :send_messages])
#=> 3072

Summary

Functions

Every permission atom Lingo knows.

Effective permissions of a member in a channel: the @everyone role's permissions, plus their roles', then the channel's overwrites for @everyone, their roles and them. Administrators get everything.

Combines permission atoms (and raw bits) into a bitfield.

Whether the bitfield includes permission. Administrator doesn't imply anything here; use compute/5 for effective permissions.

Whether the bitfield includes every one of permissions.

Whether the bitfield includes at least one of permissions.

The permission atoms set in a bitfield.

Types

permission()

@type permission() :: atom()

Functions

all()

@spec all() :: [permission()]

Every permission atom Lingo knows.

compute(everyone_perms, member_role_ids, roles, overwrites \\ [], member_id \\ nil)

@spec compute(
  base_permissions :: String.t() | integer(),
  member_role_ids :: [String.t()],
  roles :: [%{id: String.t(), permissions: String.t()}],
  channel_overwrites :: [
    %{
      id: String.t(),
      type: :role | :member,
      allow: String.t(),
      deny: String.t()
    }
  ],
  member_id :: String.t() | nil
) :: integer()

Effective permissions of a member in a channel: the @everyone role's permissions, plus their roles', then the channel's overwrites for @everyone, their roles and them. Administrators get everything.

roles are the guild's Lingo.Type.Role structs and overwrites the channel's Lingo.Type.Overwrite structs. Lingo.Helper.Channel.permissions/2 does this from the cache.

from_list(permissions)

@spec from_list([permission()]) :: integer()

Combines permission atoms (and raw bits) into a bitfield.

has?(bitfield, permission)

@spec has?(String.t() | integer(), permission()) :: boolean()

Whether the bitfield includes permission. Administrator doesn't imply anything here; use compute/5 for effective permissions.

has_all?(bitfield, permissions)

@spec has_all?(String.t() | integer(), [permission()]) :: boolean()

Whether the bitfield includes every one of permissions.

has_any?(bitfield, permissions)

@spec has_any?(String.t() | integer(), [permission()]) :: boolean()

Whether the bitfield includes at least one of permissions.

to_list(bitfield)

@spec to_list(String.t() | integer()) :: [permission()]

The permission atoms set in a bitfield.